Index: trunk/extensions/HideNamespace/HideNamespace.php |
— | — | @@ -20,7 +20,6 @@ |
21 | 21 | $wgExtensionMessagesFiles['HideNamespace'] = $dir . 'HideNamespace.i18n.php'; |
22 | 22 | $wgExtensionMessagesFiles['HideNamespaceMagic'] = $dir . 'HideNamespace.i18n.magic.php'; |
23 | 23 | |
24 | | -$wgExtensionFunctions[] = 'wfHideNamespaceSetup'; |
25 | 24 | $wgExtensionCredits['other'][] = array( |
26 | 25 | 'path' => __FILE__, |
27 | 26 | 'name' => 'HideNamespace', |
— | — | @@ -30,27 +29,22 @@ |
31 | 30 | 'url' => 'http://www.mediawiki.org/wiki/Extension:HideNamespace', |
32 | 31 | ); |
33 | 32 | |
34 | | -function wfHideNamespaceSetup() { |
35 | | - global $wgHooks; |
| 33 | +$wgHidensNamespaces = array(); |
36 | 34 | |
37 | | - $extHidensObj = new ExtensionHideNamespace; |
| 35 | +$wgHooks['ParserFirstCallInit'][] = 'ExtensionHideNamespace::registerParser'; |
| 36 | +$wgHooks['ArticleViewHeader'][] = 'ExtensionHideNamespace::onArticleViewHeader'; |
| 37 | +$wgHooks['BeforePageDisplay'][] = 'ExtensionHideNamespace::onBeforePageDisplay'; |
38 | 38 | |
39 | | - // Register hooks |
40 | | - $wgHooks['ParserFirstCallInit'][] = array( &$extHidensObj, 'registerParser' ); |
41 | | - $wgHooks['ArticleViewHeader'][] = array( &$extHidensObj, 'onArticleViewHeader' ); |
42 | | - $wgHooks['BeforePageDisplay'][] = array( &$extHidensObj, 'onBeforePageDisplay' ); |
43 | | -} |
44 | | - |
45 | 39 | class ExtensionHideNamespace { |
46 | | - private $namespace, $namespaceText; |
47 | | - private $hide = null; |
| 40 | + private static $namespaceText; |
| 41 | + private static $hide = null; |
48 | 42 | |
49 | 43 | /** |
50 | 44 | * Register the parser functions |
51 | 45 | */ |
52 | | - public function registerParser( $parser ) { |
53 | | - $parser->setFunctionHook( 'hidens', array( &$this, 'hideNs' ) ); |
54 | | - $parser->setFunctionHook( 'showns', array( &$this, 'showNs' ) ); |
| 46 | + public static function registerParser( $parser ) { |
| 47 | + $parser->setFunctionHook( 'hidens', array( __CLASS__, 'hideNs' ) ); |
| 48 | + $parser->setFunctionHook( 'showns', array( __CLASS__, 'showNs' ) ); |
55 | 49 | |
56 | 50 | return true; |
57 | 51 | } |
— | — | @@ -58,8 +52,8 @@ |
59 | 53 | /** |
60 | 54 | * Callback for our parser function {{#hidens:}} |
61 | 55 | */ |
62 | | - public function hideNs() { |
63 | | - $this->hide = true; |
| 56 | + public static function hideNs() { |
| 57 | + self::$hide = true; |
64 | 58 | |
65 | 59 | return null; |
66 | 60 | } |
— | — | @@ -67,8 +61,8 @@ |
68 | 62 | /** |
69 | 63 | * Callback for our parser function {{#showns:}} |
70 | 64 | */ |
71 | | - public function showNs() { |
72 | | - $this->hide = false; |
| 65 | + public static function showNs() { |
| 66 | + self::$hide = false; |
73 | 67 | |
74 | 68 | return null; |
75 | 69 | } |
— | — | @@ -79,14 +73,14 @@ |
80 | 74 | * Retrieves the namespace and localized namespace text and decides whether the |
81 | 75 | * namespace should be hidden |
82 | 76 | */ |
83 | | - public function onArticleViewHeader( $article ) { |
| 77 | + public static function onArticleViewHeader( $article ) { |
84 | 78 | global $wgHidensNamespaces, $wgContLang; |
85 | 79 | |
86 | | - $this->namespace = $article->getTitle()->getNamespace(); |
87 | | - $this->namespaceText = $wgContLang->getNsText( $this->namespace ); |
| 80 | + $namespace = $article->getTitle()->getNamespace(); |
| 81 | + self::$namespaceText = $wgContLang->getNsText( $namespace ); |
88 | 82 | |
89 | | - if( $this->namespace == NS_MAIN ) { |
90 | | - $this->hide = false; |
| 83 | + if( $namespace == NS_MAIN ) { |
| 84 | + self::$hide = false; |
91 | 85 | } else { |
92 | 86 | /** |
93 | 87 | * Hide namespace if either |
— | — | @@ -94,26 +88,25 @@ |
95 | 89 | * - the current namespace is in $wgHidensNamespaces AND |
96 | 90 | * {{#showns:}} wasn't called |
97 | 91 | */ |
98 | | - $visibilityForced = !is_null( $this->hide ); |
99 | | - $hideByUser = $visibilityForced && $this->hide; |
100 | | - $hideBySetting = isset( $wgHidensNamespaces ) && |
101 | | - in_array( $this->namespace, $wgHidensNamespaces ); |
| 92 | + $visibilityForced = !is_null( self::$hide ); |
| 93 | + $hideByUser = $visibilityForced && self::$hide; |
| 94 | + $hideBySetting = in_array( $namespace, $wgHidensNamespaces ); |
102 | 95 | |
103 | | - $this->hide = $hideByUser || ( $hideBySetting && $this->hide !== false ); |
| 96 | + self::$hide = $hideByUser || ( $hideBySetting && self::$hide !== false ); |
104 | 97 | } |
105 | 98 | |
106 | 99 | return true; |
107 | 100 | } |
108 | 101 | |
109 | 102 | /** |
110 | | - * Callback for the OutputPageBeforeHTML hook |
| 103 | + * Callback for the BeforePageDisplay hook |
111 | 104 | * |
112 | 105 | * Removes the namespace from article header and page title |
113 | 106 | */ |
114 | | - public function onBeforePageDisplay( $out ) { |
115 | | - if( $this->hide ) { |
| 107 | + public static function onBeforePageDisplay( $out ) { |
| 108 | + if( self::$hide ) { |
116 | 109 | $out->setPageTitle( mb_substr( $out->getPageTitle(), |
117 | | - mb_strlen( $this->namespaceText ) + 1 ) ); |
| 110 | + mb_strlen( self::$namespaceText ) + 1 ) ); |
118 | 111 | } |
119 | 112 | |
120 | 113 | return true; |