Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialGlobalUsers
0.00% covered (danger)
0.00%
0 / 37
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
72
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CentralAuth\Special;
4
5use DerivativeContext;
6use Language;
7use MediaWiki\Cache\LinkBatchFactory;
8use MediaWiki\Extension\CentralAuth\CentralAuthDatabaseManager;
9use MediaWiki\Extension\CentralAuth\GlobalGroup\GlobalGroupLookup;
10use MediaWiki\Html\Html;
11use MediaWiki\SpecialPage\IncludableSpecialPage;
12use MediaWiki\Title\Title;
13
14class SpecialGlobalUsers extends IncludableSpecialPage {
15    /** @var Language */
16    private $contentLanguage;
17
18    /** @var LinkBatchFactory */
19    private $linkBatchFactory;
20
21    /** @var CentralAuthDatabaseManager */
22    private $dbManager;
23
24    /** @var GlobalGroupLookup */
25    private $globalGroupLookup;
26
27    /**
28     * @param Language $contentLanguage
29     * @param LinkBatchFactory $linkBatchFactory
30     * @param CentralAuthDatabaseManager $dbManager
31     * @param GlobalGroupLookup $globalGroupLookup
32     */
33    public function __construct(
34        Language $contentLanguage,
35        LinkBatchFactory $linkBatchFactory,
36        CentralAuthDatabaseManager $dbManager,
37        GlobalGroupLookup $globalGroupLookup
38    ) {
39        parent::__construct( 'GlobalUsers' );
40        $this->contentLanguage = $contentLanguage;
41        $this->linkBatchFactory = $linkBatchFactory;
42        $this->dbManager = $dbManager;
43        $this->globalGroupLookup = $globalGroupLookup;
44    }
45
46    /** @inheritDoc */
47    public function execute( $par ) {
48        $this->setHeaders();
49        $this->addHelpLink( 'Extension:CentralAuth' );
50
51        $context = new DerivativeContext( $this->getContext() );
52        // Remove subpage
53        $context->setTitle( $this->getPageTitle() );
54
55        $pg = new GlobalUsersPager(
56            $context,
57            $this->dbManager,
58            $this->globalGroupLookup,
59            $this->linkBatchFactory
60        );
61        $req = $this->getRequest();
62
63        if ( $par !== null && $par !== '' ) {
64            if ( in_array( $par, $this->globalGroupLookup->getDefinedGroups() ) ) {
65                $pg->setGroup( $par );
66            } else {
67                $pg->setUsername( $par );
68            }
69        }
70
71        $rqGroup = $req->getVal( 'group', '' );
72        if ( $rqGroup !== '' ) {
73            // XXX This is a horrible hack. We should not use Title for normalization. We need to
74            // prefix the group name so that the first letter doesn't get uppercased.
75            $groupTitle = Title::newFromText( "A/$rqGroup" );
76            if ( $groupTitle ) {
77                $pg->setGroup( ltrim( substr( $groupTitle->getDBkey(), 2 ), '_' ) );
78            }
79        }
80
81        $rqUsername = $this->contentLanguage->ucfirst( $req->getVal( 'username', '' ) );
82        if ( $rqUsername !== '' ) {
83            $pg->setUsername( $rqUsername );
84        }
85
86        $this->getOutput()->addModuleStyles( 'ext.centralauth.misc.styles' );
87        if ( !$this->including() ) {
88            $pg->getPageHeader();
89        }
90
91        $this->getOutput()->addHTML(
92            $pg->getNavigationBar() .
93            Html::rawElement( 'ul', [], $pg->getBody() ) .
94            $pg->getNavigationBar()
95        );
96    }
97
98    /** @inheritDoc */
99    protected function getGroupName() {
100        return 'users';
101    }
102}