Index: trunk/extensions/UserFunctions/UserFunctions.php |
— | — | @@ -31,11 +31,17 @@ |
32 | 32 | **/ |
33 | 33 | $wgUFEnablePersonalDataFunctions = false; |
34 | 34 | |
| 35 | +/** Restrict to certain namespaces **/ |
| 36 | +$wgUFAllowedNamespaces = array( |
| 37 | + NS_MEDIAWIKI => true |
| 38 | +); |
| 39 | + |
| 40 | + |
35 | 41 | $wgExtensionFunctions[] = 'wfSetupUserFunctions'; |
36 | 42 | $wgExtensionCredits['parserhook'][] = array( |
37 | 43 | 'path' => __FILE__, |
38 | 44 | 'name' => 'UserFunctions', |
39 | | - 'version' => '2.1.1', |
| 45 | + 'version' => '2.2', |
40 | 46 | 'url' => 'https://www.mediawiki.org/wiki/Extension:UserFunctions', |
41 | 47 | 'author' => array( 'Algorithm ', 'Toniher', 'Kghbln', 'Wikinaut', '...' ), |
42 | 48 | 'descriptionmsg' => 'userfunctions-desc', |
— | — | @@ -61,28 +67,49 @@ |
62 | 68 | */ |
63 | 69 | class UserFunctions_HookStub { |
64 | 70 | var $realObj; |
| 71 | + var $cur_ns; |
65 | 72 | |
66 | 73 | /** |
67 | 74 | * @param $parser Parser |
68 | 75 | * @return bool |
69 | 76 | */ |
70 | 77 | function registerParser( &$parser ) { |
71 | | - global $wgUFEnablePersonalDataFunctions; |
| 78 | + global $wgUFEnablePersonalDataFunctions, $wgUFAllowedNamespaces; |
72 | 79 | |
73 | | - // These functions accept DOM-style arguments |
74 | | - $parser->setFunctionHook( 'ifanon', array( &$this, 'ifanonObj' ), SFH_OBJECT_ARGS ); |
75 | | - $parser->setFunctionHook( 'ifblocked', array( &$this, 'ifblockedObj' ), SFH_OBJECT_ARGS ); |
76 | | - $parser->setFunctionHook( 'ifsysop', array( &$this, 'ifsysopObj' ), SFH_OBJECT_ARGS ); |
77 | | - $parser->setFunctionHook( 'ifingroup', array( &$this, 'ifingroupObj' ), SFH_OBJECT_ARGS ); |
| 80 | + // Depending on MW version |
| 81 | + if (class_exists("RequestContext")) { |
| 82 | + $cur_ns = RequestContext::getMain()->getTitle()->getNamespace(); |
| 83 | + } else { |
| 84 | + global $wgTitle; |
| 85 | + $cur_ns = $wgTitle->getNamespace(); |
| 86 | + } |
78 | 87 | |
79 | | - if ($wgUFEnablePersonalDataFunctions) { |
80 | | - $parser->setFunctionHook( 'realname', array( &$this, 'realname' ) ); |
81 | | - $parser->setFunctionHook( 'username', array( &$this, 'username' ) ); |
82 | | - $parser->setFunctionHook( 'useremail', array( &$this, 'useremail' ) ); |
83 | | - $parser->setFunctionHook( 'nickname', array( &$this, 'nickname' ) ); |
84 | | - $parser->setFunctionHook( 'ip', array( &$this, 'ip' ) ); |
| 88 | + $process = false; |
| 89 | + |
| 90 | + // Check if current page NS is in the allowed list |
| 91 | + if (isset($wgUFAllowedNamespaces[$cur_ns])) { |
| 92 | + if ($wgUFAllowedNamespaces[$cur_ns]) { |
| 93 | + $process = true; |
| 94 | + } |
85 | 95 | } |
86 | 96 | |
| 97 | + if ($process) { |
| 98 | + // These functions accept DOM-style arguments |
| 99 | + $parser->setFunctionHook( 'ifanon', array( &$this, 'ifanonObj' ), SFH_OBJECT_ARGS ); |
| 100 | + $parser->setFunctionHook( 'ifblocked', array( &$this, 'ifblockedObj' ), SFH_OBJECT_ARGS ); |
| 101 | + $parser->setFunctionHook( 'ifsysop', array( &$this, 'ifsysopObj' ), SFH_OBJECT_ARGS ); |
| 102 | + $parser->setFunctionHook( 'ifingroup', array( &$this, 'ifingroupObj' ), SFH_OBJECT_ARGS ); |
| 103 | + |
| 104 | + if ($wgUFEnablePersonalDataFunctions) { |
| 105 | + $parser->setFunctionHook( 'realname', array( &$this, 'realname' ) ); |
| 106 | + $parser->setFunctionHook( 'username', array( &$this, 'username' ) ); |
| 107 | + $parser->setFunctionHook( 'useremail', array( &$this, 'useremail' ) ); |
| 108 | + $parser->setFunctionHook( 'nickname', array( &$this, 'nickname' ) ); |
| 109 | + $parser->setFunctionHook( 'ip', array( &$this, 'ip' ) ); |
| 110 | + } |
| 111 | + |
| 112 | + } |
| 113 | + |
87 | 114 | return true; |
88 | 115 | } |
89 | 116 | |