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() { |
|
|
|
|
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
|
|
|
|
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: