Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
SearchnamespaceTokenModule
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 getScript
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 supportsURLLoading
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getGroup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace AdvancedSearch;
4
5use MediaWiki\ResourceLoader as RL;
6use MediaWiki\ResourceLoader\ResourceLoader;
7use Xml;
8
9/**
10 * ResourceLoader module providing the users "searchnamespace" token.
11 */
12class SearchnamespaceTokenModule extends RL\Module {
13
14    /**
15     * @var int
16     */
17    protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
18
19    /**
20     * @var string[]
21     */
22    protected $targets = [ 'desktop', 'mobile' ];
23
24    /**
25     * @param RL\Context $context
26     * @return string JavaScript code
27     */
28    public function getScript( RL\Context $context ) {
29        $user = $context->getUserObj();
30        // Use FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
31        return ResourceLoader::FILTER_NOMIN .
32            Xml::encodeJsCall(
33                'mw.user.tokens.set',
34                [ 'searchnamespaceToken', $user->getEditToken( 'searchnamespace' ) ],
35                (bool)$context->getDebug()
36            );
37    }
38
39    /**
40     * @return bool
41     */
42    public function supportsURLLoading() {
43        return false;
44    }
45
46    /**
47     * @return string
48     */
49    public function getGroup() {
50        // Private modules can not be loaded as a dependency, only via OutputPage::addModules().
51        return 'private';
52    }
53
54}