-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCrossReference.php
101 lines (87 loc) · 2.63 KB
/
CrossReference.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
/**
* CONFIGURATION
* These variables may be overridden in LocalSettings.php after you include the
* extension file.
*/
class CrossReferenceSetup {
public static function wfSetupCrossReference()
{
global $wgCrossReferenceHookStub, $wgHooks, $wgParser;
$wgCrossReferenceHookStub = new CrossReference_HookStub;
$wgHooks['LanguageGetMagic'][] = array( &$wgCrossReferenceHookStub, 'getMagicWords' );
$wgHooks['ParserFirstCallInit'][] = array( &$wgCrossReferenceHookStub, 'registerParser' );
$wgHooks['ParserClearState'][] = array( &$wgCrossReferenceHookStub, 'clearState' );
$wgHooks['ParserAfterTidy'][] = array( &$wgCrossReferenceHookStub, 'parserAfterTidy' );
}
}
/**
* Stub class to defer loading of the bulk of the code until a function is
* actually used.
*/
class CrossReference_HookStub
{
var $realObj = null;
var $crMagicWords = null;
public function registerParser( $parser )
{
require( dirname(__FILE__) . '/CrossReference.mapping.magic.php');
foreach($tagMapping as $magicWord => $phpFunction) {
$parser->setHook( $magicWord, array( &$this, $phpFunction ) );
}
foreach($functionMapping as $magicWord => $phpFunction) {
$parser->setFunctionHook( $magicWord, array( &$this, $phpFunction ) );
}
return true;
}
/** Replies magic word for given language.
*/
public function getMagicWords( &$globalMagicWords, $langCode = 'en' )
{
if ( is_null( $this->crMagicWords ) ) {
$magicWords = array();
$dirname = dirname(__FILE__).'/i18n';
$dir = @opendir($dirname);
if ($dir) {
while ($file = readdir($dir)) {
if (preg_match("/\\.magic\\.php\$/s", $file)) {
$fn = "$dirname/$file";
require_once($fn);
}
}
@closedir($dir);
if (array_key_exists($langCode, $magicWords)) {
$this->crMagicWords = $magicWords[$langCode];
}
else {
$this->crMagicWords = $magicWords['en'];
}
}
}
foreach($this->crMagicWords as $word => $language) {
$globalMagicWords[$word] = $language;
}
return true;
}
/** Defer ParserClearState */
public function clearState( $parser )
{
if ( !is_null( $this->realObj ) ) {
$this->realObj->clearState( $parser );
}
$this->crMagicWords = null;
return true;
}
/** Pass through function call */
public function __call( $name, $args )
{
if ( is_null( $this->realObj ) ) {
$this->realObj = new ExtCrossReference;
$this->realObj->clearState( $args[0] );
}
return call_user_func_array( array( $this->realObj, "$name" ), $args );
}
}