Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Hooks
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 onAPIQuerySiteInfoGeneralInfo
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
56
 onParserGetVariableValueSwitch
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 onMagicWordwgVariableIDs
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\SiteMatrix;
4
5use ApiQuerySiteinfo;
6use MediaWiki\Api\Hook\APIQuerySiteInfoGeneralInfoHook;
7use MediaWiki\Hook\MagicWordwgVariableIDsHook;
8use MediaWiki\Hook\ParserGetVariableValueSwitchHook;
9use Parser;
10use PPFrame;
11
12/**
13 * Hook handlers
14 */
15class Hooks implements
16    APIQuerySiteInfoGeneralInfoHook,
17    ParserGetVariableValueSwitchHook,
18    MagicWordwgVariableIDsHook
19{
20    /**
21     * Handler method for the APISiteInfoGeneralInfo hook
22     *
23     * @param ApiQuerySiteinfo $module
24     * @param array &$results
25     */
26    public function onAPIQuerySiteInfoGeneralInfo( $module, &$results ) {
27        global $wgDBname, $wgConf;
28
29        $matrix = new SiteMatrix();
30
31        [ $site, $lang ] = $wgConf->siteFromDB( $wgDBname );
32        if ( $site === null ) {
33            // No such site
34            return;
35        }
36
37        if ( $matrix->isClosed( $lang, $site ) ) {
38            $results['closed'] = '';
39        }
40
41        if ( $matrix->isSpecial( $wgDBname ) ) {
42            $results['special'] = '';
43        }
44
45        if ( $matrix->isPrivate( $wgDBname ) ) {
46            $results['private'] = '';
47        }
48
49        if ( $matrix->isFishbowl( $wgDBname ) ) {
50            $results['fishbowl'] = '';
51        }
52
53        if ( $matrix->isNonGlobal( $wgDBname ) ) {
54            $results['nonglobal'] = '';
55        }
56    }
57
58    /**
59     * @param Parser $parser
60     * @param array &$variableCache
61     * @param string $magicWordId
62     * @param string &$ret
63     * @param PPFrame $frame
64     */
65    public function onParserGetVariableValueSwitch(
66        $parser,
67        &$variableCache,
68        $magicWordId,
69        &$ret,
70        $frame
71    ) {
72        if ( $magicWordId === 'numberofwikis' ) {
73            global $wgLocalDatabases;
74            $ret = $variableCache[$magicWordId] = count( $wgLocalDatabases );
75        }
76    }
77
78    /**
79     * @param string[] &$customVariableIds
80     */
81    public function onMagicWordwgVariableIDs( &$customVariableIds ) {
82        $customVariableIds[] = 'numberofwikis';
83    }
84}