Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialRandomByTest
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace MediaWiki\Extension\WikimediaIncubator;
4
5use MediaWiki\Specials\SpecialRandomPage;
6use MediaWiki\Title\NamespaceInfo;
7use MediaWiki\User\Options\UserOptionsLookup;
8use Wikimedia\Rdbms\IConnectionProvider;
9
10/**
11 * Special page to go to a random page in your test wiki
12 * (or a specific wiki if it is defined through &testwiki=Wx/xx)
13 *
14 * @file
15 * @ingroup SpecialPage
16 * @author Robin Pepermans (SPQRobin)
17 */
18
19class SpecialRandomByTest extends SpecialRandomPage {
20
21    /**
22     * @param IConnectionProvider $dbProvider
23     * @param NamespaceInfo $nsInfo
24     * @param UserOptionsLookup $userOptionsLookup
25     */
26    public function __construct(
27        IConnectionProvider $dbProvider,
28        NamespaceInfo $nsInfo,
29        UserOptionsLookup $userOptionsLookup
30    ) {
31        global $wmincPref, $wmincProjectSite;
32        $target = $this->getRequest()->getVal( 'testwiki', '' );
33        $target = WikimediaIncubator::analyzePrefix( $target );
34        $project = $target['project'] ?? '';
35        $lang = $target['lang'] ?? '';
36        $user = $this->getUser();
37        if ( WikimediaIncubator::isContentProject( $user ) || ( $project && $lang ) ) {
38            $dbr = $dbProvider->getReplicaDatabase();
39            $this->extra[] = 'page_title' .
40                $dbr->buildLike( WikimediaIncubator::displayPrefix( $project, $lang ) .
41                    '/', $dbr->anyString() );
42        } elseif (
43            $userOptionsLookup->getOption( $user, $wmincPref . '-project' ) == $wmincProjectSite['short']
44        ) {
45            # project or help namespace
46            $this->extra['page_namespace'] = [ 4, 12 ];
47        }
48        parent::__construct(
49            $dbProvider,
50            $nsInfo
51        );
52        $this->mName = 'RandomByTest';
53    }
54}