Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -13,6 +13,9 @@ |
14 | 14 | // |
15 | 15 | $wgNoticeCentralPath = false; |
16 | 16 | |
| 17 | +// Whether to use local notice loader |
| 18 | +$wgNoticeUseLocalNotice = false; |
| 19 | + |
17 | 20 | // This guy does much the same, but with the local sitenotice/anonnotice. |
18 | 21 | // Static generation isn't quite supported yet. |
19 | 22 | // |
— | — | @@ -111,14 +114,21 @@ |
112 | 115 | |
113 | 116 | function efCentralNoticeSetup() { |
114 | 117 | global $wgHooks, $wgNoticeInfrastructure, $wgAutoloadClasses, $wgSpecialPages; |
115 | | - global $wgCentralNoticeLoader; |
| 118 | + global $wgCentralNoticeLoader, $wgNoticeUseLocalNotice; |
116 | 119 | |
117 | 120 | $dir = dirname( __FILE__ ) . '/'; |
118 | 121 | |
119 | 122 | if ( $wgCentralNoticeLoader ) { |
120 | 123 | $wgHooks['BeforePageDisplay'][] = 'efCentralNoticeLoader'; |
121 | | - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeDisplay'; |
122 | 124 | $wgHooks['MakeGlobalVariablesScript'][] = 'efCentralNoticeDefaults'; |
| 125 | + |
| 126 | + if ( $wgNoticeUseLocalNotice ) { |
| 127 | + $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal'; |
| 128 | + $wgAutoloadClasses['SpecialNoticeLocal'] = $dir . 'SpecialNoticeLocal.php'; |
| 129 | + $wgHooks['SiteNoticeBefore'][] = 'efCentralNoticeDisplayBefore'; |
| 130 | + } else { |
| 131 | + $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeDisplayAfter'; |
| 132 | + } |
123 | 133 | } |
124 | 134 | |
125 | 135 | $wgAutoloadClasses['NoticePage'] = $dir . 'NoticePage.php'; |
— | — | @@ -138,56 +148,61 @@ |
139 | 149 | } |
140 | 150 | |
141 | 151 | function efCentralNoticeLoader( $out, $skin ) { |
142 | | - global $wgOut, $wgLang; |
143 | | - //global $wgUser; |
| 152 | + global $wgUser, $wgOut, $wgLang; |
| 153 | + global $wgNoticeProject, $wgNoticeCentralPath, $wgNoticeLocalPath, $wgNoticeUseLocalNotice; |
144 | 154 | |
145 | | - global $wgNoticeProject; |
146 | | - |
147 | | - global $wgNoticeCentralPath; |
148 | | - global $wgNoticeLocalPath; |
149 | | - |
150 | 155 | $lang = $wgLang->getCode(); |
151 | 156 | $centralNotice = "$wgNoticeProject/$lang/centralnotice.js"; |
152 | | - /* |
153 | | - $localNotice = ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) |
154 | | - ? 'sitenotice.js' |
155 | | - : 'anonnotice.js'; |
156 | | - */ |
157 | 157 | |
158 | | - |
159 | 158 | if ( $wgNoticeCentralPath === false ) { |
160 | 159 | $centralLoader = SpecialPage::getTitleFor( 'NoticeText', $centralNotice )->getLocalUrl(); |
161 | 160 | } else { |
162 | 161 | $centralLoader = "$wgNoticeCentralPath/$centralNotice"; |
163 | 162 | } |
164 | 163 | |
165 | | - /* |
166 | | - if ( $wgNoticeLocalPath === false ) { |
167 | | - $localLoader = SpecialPage::getTitleFor( 'NoticeLocal', $localNotice )->getLocalUrl(); |
168 | | - } else { |
169 | | - $localLoader = "$wgNoticeLocalPath/$localNotice"; |
170 | | - } |
171 | | - $encLocalLoader = htmlspecialchars( $localLoader ); |
172 | | - */ |
173 | | - |
174 | 164 | // Load the notice text from <head> |
175 | 165 | $wgOut->addScriptFile( $centralLoader ); |
176 | 166 | |
| 167 | + if ( $wgNoticeUseLocalNotice ) { |
| 168 | + $localNotice = ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) |
| 169 | + ? 'sitenotice.js' |
| 170 | + : 'anonnotice.js'; |
| 171 | + if ( $wgNoticeLocalPath === false ) { |
| 172 | + $localLoader = SpecialPage::getTitleFor( 'NoticeLocal', $localNotice )->getLocalUrl(); |
| 173 | + } else { |
| 174 | + $localLoader = "$wgNoticeLocalPath/$localNotice"; |
| 175 | + } |
| 176 | + $wgOut->addScriptFile( $localLoader ); |
| 177 | + } |
| 178 | + |
177 | 179 | return true; |
178 | 180 | } |
179 | 181 | |
180 | 182 | function efCentralNoticeDefaults( &$vars ) { |
| 183 | + global $wgNoticeUseLocalNotice; |
| 184 | + |
181 | 185 | // Initialize these variables to empty, so if the notice script fails |
182 | 186 | // we don't have any surprises. |
183 | 187 | $vars['wgNotice'] = ''; |
184 | | - $vars['wgNoticeLocal'] = ''; |
| 188 | + if ( $wgNoticeUseLocalNotice ) { |
| 189 | + $vars['wgNoticeLocal'] = ''; |
| 190 | + } |
185 | 191 | return true; |
186 | 192 | } |
187 | 193 | |
188 | | -function efCentralNoticeDisplay( &$notice ) { |
| 194 | +function efCentralNoticeDisplayAfter( &$notice ) { |
189 | 195 | // Slip in load of the data... |
190 | 196 | $notice = |
191 | 197 | Html::inlineScript( "if (wgNotice != '') document.writeln(wgNotice);" ) . |
192 | 198 | $notice; |
193 | 199 | return true; |
194 | 200 | } |
| 201 | + |
| 202 | +function efCentralNoticeDisplayBefore( &$notice ) { |
| 203 | + // Slip in load of the data... |
| 204 | + $notice = Html::inlineScript( |
| 205 | + "if (wgNotice != '') document.writeln(wgNotice);" . |
| 206 | + " if (wgNoticeLocal != '') document.writeln(wgNoticeLocal);" |
| 207 | + ); |
| 208 | + return false; |
| 209 | +} |
Index: trunk/extensions/CentralNotice/CentralNotice.alias.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | 'CentralNotice' => array( 'CentralNotice' ), |
11 | 11 | 'NoticeText' => array( 'NoticeText' ), |
12 | 12 | 'NoticeTemplate' => array( 'NoticeTemplate' ), |
| 13 | + 'NoticeLocal' => array( 'NoticeLocal' ), |
13 | 14 | ); |
14 | 15 | |
15 | 16 | /** Arabic (العربية) */ |