r43108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43107‎ | r43108 | r43109 >
Date:01:56, 3 November 2008
Author:brion
Status:old
Tags:
Comment:
* Pull out the local notice loader for now; just handle the central one and leave the local one to be generated as currently, so I don't have to test as much crap. ;)
* Load the central notice JS from <head> instead of <body>:
** now wgNotice is defined when site/user JS runs
** browser doesn't pause during rendering to load -- it's loaded before rendering starts, which is less visually jarring
* Fix for "undefined" display when notices are enabled, but weights are 0
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeText.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -117,13 +117,16 @@
118118 $dir = dirname( __FILE__ ) . '/';
119119
120120 if( $wgCentralNoticeLoader ) {
121 - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader';
 121+ $wgHooks['BeforePageDisplay'][] = 'efCentralNoticeLoader';
 122+ $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeDisplay';
122123 }
123124
124125 $wgAutoloadClasses['NoticePage'] = $dir . 'NoticePage.php';
125126
 127+ /*
126128 $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal';
127129 $wgAutoloadClasses['SpecialNoticeLocal'] = $dir . 'SpecialNoticeLocal.php';
 130+ */
128131
129132 if ( $wgNoticeInfrastructure ) {
130133 $wgSpecialPages['CentralNotice'] = 'CentralNotice';
@@ -139,8 +142,8 @@
140143 }
141144 }
142145
143 -function efCentralNoticeLoader( &$notice ) {
144 - global $wgScript, $wgUser, $wgLang;
 146+function efCentralNoticeLoader( $out, $skin ) {
 147+ global $wgScript, $wgUser, $wgOut, $wgLang;
145148 global $wgNoticeProject;
146149
147150 global $wgNoticeCentralPath;
@@ -148,9 +151,11 @@
149152
150153 $lang = $wgLang->getCode();
151154 $centralNotice = "$wgNoticeProject/$lang/centralnotice.js";
 155+ /*
152156 $localNotice = ( is_object( $wgUser ) && $wgUser->isLoggedIn() )
153157 ? 'sitenotice.js'
154158 : 'anonnotice.js';
 159+ */
155160
156161
157162 if ( $wgNoticeCentralPath === false ) {
@@ -160,29 +165,28 @@
161166 }
162167 $encCentralLoader = htmlspecialchars( $centralLoader );
163168
 169+ /*
164170 if ( $wgNoticeLocalPath === false ) {
165171 $localLoader = SpecialPage::getTitleFor( 'NoticeLocal', $localNotice )->getLocalUrl();
166172 } else {
167173 $localLoader = "$wgNoticeLocalPath/$localNotice";
168174 }
169175 $encLocalLoader = htmlspecialchars( $localLoader );
 176+ */
170177
171 - // Throw away the classic notice, use the central loader...
172 - $notice = <<<EOT
173 -<script type="text/javascript">
174 -var wgNotice = "";
175 -var wgNoticeLocal = "";
176 -</script>
177 -<script type="text/javascript" src="$encCentralLoader"></script>
178 -<script type="text/javascript" src="$encLocalLoader"></script>
179 -<script type="text/javascript">
180 -if (wgNotice != "") {
181 - document.writeln(wgNotice);
 178+ // Load the notice text from <head>
 179+ $wgOut->addInlineScript( "var wgNotice='';var wgNoticeLocal='';" );
 180+ $wgOut->addScriptFile( $encCentralLoader );
 181+
 182+ return true;
182183 }
183 -if (wgNoticeLocal != "") {
184 - document.writeln(wgNoticeLocal);
185 -}
186 -</script>
187 -EOT;
 184+
 185+function efCentralNoticeDisplay( &$notice ) {
 186+ // Slip in load of the data...
 187+ $notice =
 188+ "<script type='text/javascript'>" .
 189+ "if (wgNotice != '') document.writeln(wgNotice);" .
 190+ "</script>" .
 191+ $notice;
188192 return true;
189193 }
Index: trunk/extensions/CentralNotice/SpecialNoticeText.php
@@ -112,6 +112,9 @@
113113 }
114114 currentTemplate++;
115115 }
 116+
 117+ if (totalWeight == 0)
 118+ return '';
116119
117120 var randomnumber=Math.floor(Math.random()*totalWeight);
118121 return weightedTemplates[randomnumber];

Status & tagging log