Completed
Branch master (fa787a)
by Stephan
02:24
created

Lingo::onGetDoubleUnderscoreIDs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * File containing the Lingo class
4
 *
5
 * This file is part of the MediaWiki extension Lingo.
6
 *
7
 * @copyright 2011 - 2016, Stephan Gambke
8
 * @license   GNU General Public License, version 2 (or any later version)
9
 *
10
 * The Lingo extension is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by the Free
12
 * Software Foundation; either version 2 of the License, or (at your option) any
13
 * later version.
14
 *
15
 * The Lingo extension is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18
 * details.
19
 *
20
 * You should have received a copy of the GNU General Public License along
21
 * with this program. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 * @file
24
 * @ingroup Lingo
25
 */
26
27
namespace Lingo;
28
29
/**
30
 * Class Lingo
31
 *
32
 * @package Lingo
33
 * @ingroup Lingo
34
 */
35
class Lingo {
36
37
	/**
38
	 * Deferred settings
39
	 * - registration of _NOGLOSSARY_ magic word
40
	 * - extension description shown on Special:Version
41
	 *
42
	 * @since 2.0.2
43
	 */
44
	public static function initExtension() {
0 ignored issues
show
Coding Style introduced by
initExtension uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
45
46
		$GLOBALS[ 'wgExtensionFunctions' ][] = function () {
47
48
			$parser = LingoParser::getInstance();
49
50
			$backend = new $GLOBALS[ 'wgexLingoBackend' ]();
51
52
			$parser->setBackend( $backend );
53
54
			\Hooks::register( 'ParserAfterParse', array( $parser, 'parse' ) );
55
56
			\Hooks::register( 'ParserFirstCallInit', function ( \Parser $parser ) {
57
58
				$parser->setHook( 'noglossary', function ( $input, array $args, \Parser $parser, \PPFrame $frame ) {
59
					$output = $parser->recursiveTagParse( $input, $frame );
60
					return '<span class="noglossary">' . $output . '</span>';
61
				} );
62
63
				return true;
64
			} );
65
66
			foreach ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ] as $index => $description ) {
67
68
				if ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ][ $index ][ 'name' ] === 'Lingo' ) {
69
70
					$lingoPageName = $GLOBALS[ 'wgexLingoPage' ] ? $GLOBALS[ 'wgexLingoPage' ] : wfMessage( 'lingo-terminologypagename' )->inContentLanguage()->text();
71
					$GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ][ $index ][ 'description' ] = wfMessage( 'lingo-desc', $lingoPageName )->inContentLanguage()->text();
72
73
					break;
74
				}
75
76
			}
77
		};
78
	}
79
80
	/**
81
	 * Hook: GetDoubleUnderscoreIDs
82
	 *
83
	 * @param array $doubleUnderscoreIDs
84
	 */
85
	public static function onGetDoubleUnderscoreIDs( array &$doubleUnderscoreIDs ) {
86
		$doubleUnderscoreIDs[] = 'noglossary';
87
	}
88
}
89