r67782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67781‎ | r67782 | r67783 >
Date:07:55, 10 June 2010
Author:ialex
Status:ok
Tags:
Comment:
Readded the possibility to load the local site notice with Special:NoticeLocal. Can now be controlled with $wgNoticeUseLocalNotice (disabled by default)
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.alias.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -13,6 +13,9 @@
1414 //
1515 $wgNoticeCentralPath = false;
1616
 17+// Whether to use local notice loader
 18+$wgNoticeUseLocalNotice = false;
 19+
1720 // This guy does much the same, but with the local sitenotice/anonnotice.
1821 // Static generation isn't quite supported yet.
1922 //
@@ -111,14 +114,21 @@
112115
113116 function efCentralNoticeSetup() {
114117 global $wgHooks, $wgNoticeInfrastructure, $wgAutoloadClasses, $wgSpecialPages;
115 - global $wgCentralNoticeLoader;
 118+ global $wgCentralNoticeLoader, $wgNoticeUseLocalNotice;
116119
117120 $dir = dirname( __FILE__ ) . '/';
118121
119122 if ( $wgCentralNoticeLoader ) {
120123 $wgHooks['BeforePageDisplay'][] = 'efCentralNoticeLoader';
121 - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeDisplay';
122124 $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+ }
123133 }
124134
125135 $wgAutoloadClasses['NoticePage'] = $dir . 'NoticePage.php';
@@ -138,56 +148,61 @@
139149 }
140150
141151 function efCentralNoticeLoader( $out, $skin ) {
142 - global $wgOut, $wgLang;
143 - //global $wgUser;
 152+ global $wgUser, $wgOut, $wgLang;
 153+ global $wgNoticeProject, $wgNoticeCentralPath, $wgNoticeLocalPath, $wgNoticeUseLocalNotice;
144154
145 - global $wgNoticeProject;
146 -
147 - global $wgNoticeCentralPath;
148 - global $wgNoticeLocalPath;
149 -
150155 $lang = $wgLang->getCode();
151156 $centralNotice = "$wgNoticeProject/$lang/centralnotice.js";
152 - /*
153 - $localNotice = ( is_object( $wgUser ) && $wgUser->isLoggedIn() )
154 - ? 'sitenotice.js'
155 - : 'anonnotice.js';
156 - */
157157
158 -
159158 if ( $wgNoticeCentralPath === false ) {
160159 $centralLoader = SpecialPage::getTitleFor( 'NoticeText', $centralNotice )->getLocalUrl();
161160 } else {
162161 $centralLoader = "$wgNoticeCentralPath/$centralNotice";
163162 }
164163
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 -
174164 // Load the notice text from <head>
175165 $wgOut->addScriptFile( $centralLoader );
176166
 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+
177179 return true;
178180 }
179181
180182 function efCentralNoticeDefaults( &$vars ) {
 183+ global $wgNoticeUseLocalNotice;
 184+
181185 // Initialize these variables to empty, so if the notice script fails
182186 // we don't have any surprises.
183187 $vars['wgNotice'] = '';
184 - $vars['wgNoticeLocal'] = '';
 188+ if ( $wgNoticeUseLocalNotice ) {
 189+ $vars['wgNoticeLocal'] = '';
 190+ }
185191 return true;
186192 }
187193
188 -function efCentralNoticeDisplay( &$notice ) {
 194+function efCentralNoticeDisplayAfter( &$notice ) {
189195 // Slip in load of the data...
190196 $notice =
191197 Html::inlineScript( "if (wgNotice != '') document.writeln(wgNotice);" ) .
192198 $notice;
193199 return true;
194200 }
 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 @@
1010 'CentralNotice' => array( 'CentralNotice' ),
1111 'NoticeText' => array( 'NoticeText' ),
1212 'NoticeTemplate' => array( 'NoticeTemplate' ),
 13+ 'NoticeLocal' => array( 'NoticeLocal' ),
1314 );
1415
1516 /** Arabic (العربية) */

Status & tagging log