Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -117,13 +117,16 @@ |
118 | 118 | $dir = dirname( __FILE__ ) . '/'; |
119 | 119 | |
120 | 120 | if( $wgCentralNoticeLoader ) { |
121 | | - $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeLoader'; |
| 121 | + $wgHooks['BeforePageDisplay'][] = 'efCentralNoticeLoader'; |
| 122 | + $wgHooks['SiteNoticeAfter'][] = 'efCentralNoticeDisplay'; |
122 | 123 | } |
123 | 124 | |
124 | 125 | $wgAutoloadClasses['NoticePage'] = $dir . 'NoticePage.php'; |
125 | 126 | |
| 127 | + /* |
126 | 128 | $wgSpecialPages['NoticeLocal'] = 'SpecialNoticeLocal'; |
127 | 129 | $wgAutoloadClasses['SpecialNoticeLocal'] = $dir . 'SpecialNoticeLocal.php'; |
| 130 | + */ |
128 | 131 | |
129 | 132 | if ( $wgNoticeInfrastructure ) { |
130 | 133 | $wgSpecialPages['CentralNotice'] = 'CentralNotice'; |
— | — | @@ -139,8 +142,8 @@ |
140 | 143 | } |
141 | 144 | } |
142 | 145 | |
143 | | -function efCentralNoticeLoader( &$notice ) { |
144 | | - global $wgScript, $wgUser, $wgLang; |
| 146 | +function efCentralNoticeLoader( $out, $skin ) { |
| 147 | + global $wgScript, $wgUser, $wgOut, $wgLang; |
145 | 148 | global $wgNoticeProject; |
146 | 149 | |
147 | 150 | global $wgNoticeCentralPath; |
— | — | @@ -148,9 +151,11 @@ |
149 | 152 | |
150 | 153 | $lang = $wgLang->getCode(); |
151 | 154 | $centralNotice = "$wgNoticeProject/$lang/centralnotice.js"; |
| 155 | + /* |
152 | 156 | $localNotice = ( is_object( $wgUser ) && $wgUser->isLoggedIn() ) |
153 | 157 | ? 'sitenotice.js' |
154 | 158 | : 'anonnotice.js'; |
| 159 | + */ |
155 | 160 | |
156 | 161 | |
157 | 162 | if ( $wgNoticeCentralPath === false ) { |
— | — | @@ -160,29 +165,28 @@ |
161 | 166 | } |
162 | 167 | $encCentralLoader = htmlspecialchars( $centralLoader ); |
163 | 168 | |
| 169 | + /* |
164 | 170 | if ( $wgNoticeLocalPath === false ) { |
165 | 171 | $localLoader = SpecialPage::getTitleFor( 'NoticeLocal', $localNotice )->getLocalUrl(); |
166 | 172 | } else { |
167 | 173 | $localLoader = "$wgNoticeLocalPath/$localNotice"; |
168 | 174 | } |
169 | 175 | $encLocalLoader = htmlspecialchars( $localLoader ); |
| 176 | + */ |
170 | 177 | |
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; |
182 | 183 | } |
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; |
188 | 192 | return true; |
189 | 193 | } |
Index: trunk/extensions/CentralNotice/SpecialNoticeText.php |
— | — | @@ -112,6 +112,9 @@ |
113 | 113 | } |
114 | 114 | currentTemplate++; |
115 | 115 | } |
| 116 | + |
| 117 | + if (totalWeight == 0) |
| 118 | + return ''; |
116 | 119 | |
117 | 120 | var randomnumber=Math.floor(Math.random()*totalWeight); |
118 | 121 | return weightedTemplates[randomnumber]; |