r42935 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42934‎ | r42935 | r42936 >
Date:20:07, 31 October 2008
Author:brion
Status:old
Tags:
Comment:
Switch from parsing to just doing a parsemag on the message for notice fields...
Remove some old funcs no longer needed
Modified paths:
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php (modified) (history)

Diff [purge]

Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeText.php
@@ -40,21 +40,6 @@
4141
4242 function getHtmlNotice( $noticeName ) {
4343 $this->noticeName = $noticeName;
44 - /*
45 - return strtr(
46 - $this->getHtmlNotice(),
47 - array(
48 - #'$heading' => $this->getHeadlines(), // Wikipedia: Making Life Easier.
49 - #'$subheading' => $this->getSubheading(),
50 - #'$meter' => $this->getMeter(), // dynamic selection
51 - '$amount' => $this->getMessage( 'amount' ),
52 - array ( $this->formatNum( $this->getDonationAmount() )), // lookup
53 - #'$target' => $this->getMessage( 'target' ), // "Our Goal 6 million
54 - #'$show' => $this->getMessage( 'show' ), // show
55 - #'$hide' => $this->getMessage( 'hide' ), // hide
56 - )
57 - );
58 - */
5944 return preg_replace_callback(
6045 '/{{{(.*?)}}}/',
6146 array( $this, 'getNoticeField' ),
@@ -241,11 +226,7 @@
242227 }
243228 $message = "centralnotice-{$this->noticeName}-$field";
244229 $source = $this->getMessage( $message, $params );
245 - if( $source == '' ) {
246 - return '{{{' . htmlspecialchars( $field ) . '}}}';
247 - } else {
248 - return $this->parse( $source );
249 - }
 230+ return $source;
250231 }
251232
252233 /*
@@ -274,88 +255,23 @@
275256 */
276257
277258 private function getMessage( $msg, $params=array() ) {
278 - /*
279 - $guard = array();
280 - for( $lang = $this->language; $lang; $lang = $this->safeLangFallback( $lang ) ) {
281 - if( isset( $guard[$lang] ) )
282 - break; // avoid loops...
283 - $guard[$lang] = true;
284 - if( $text = $this->getRawMessage( "$msg/$lang", $params ) ) {
285 - return $text;
286 - }
287 - }
288 - return $this->getRawMessage( $msg, $params );
289 - */
290 - array_unshift( $params, array( 'language' => $this->language ) );
291 - array_unshift( $params, $msg );
292 - return call_user_func_array( 'wfMsgExt', $params );
293 - }
294 -
295 - private function safeLangFallback( $lang ) {
296 - $fallback = Language::getFallbackFor( $lang );
297 - if( $fallback == 'en' ) {
298 - // We want to be able to special-case English
299 - // This lets us put _regular_ English in 'blah' and special-case in 'blah/en'
300 - return false;
301 - } else {
302 - return $fallback;
303 - }
304 - }
305 -
306 - private function getRawMessage( $msg, $params ) {
307 - $searchPath = array(
308 - "$msg/{$this->project}",
309 - "$msg" );
310 - foreach( $searchPath as $rawMsg ) {
311 - wfDebug( __METHOD__ . ": $rawMsg\n" );
312 - $xparams = array_merge( array( $rawMsg ), $params );
313 - wfDebug( __METHOD__ . ': ' . str_replace( "\n", " ", var_export( $xparams, true ) ) . "\n" );
314 - $text = call_user_func_array( 'wfMsgForContentNoTrans',
315 - $xparams );
316 - if( !wfEmptyMsg( $rawMsg, $text ) ) {
317 - return $text;
318 - }
319 - }
320 - return false;
321 - }
322 -
323 - /*
324 - private function splitList( $text, $callback=false ) {
325 - $list = array_filter(
326 - array_map(
327 - array( $this, 'filterListLine' ),
328 - explode( "\n", $text ) ) );
329 - if( is_callable( $callback ) ) {
330 - return array_map( $callback, $list );
331 - } else {
332 - return $list;
333 - }
334 - }
335 -
336 - private function filterListLine( $line ) {
337 - if( substr( $line, 0, 1 ) == '#' ) {
338 - return '';
339 - } else {
340 - return $this->parse( trim( ltrim( $line, '*' ) ) );
341 - }
342 - }
343 - */
344 -
345 - private function parse( $text ) {
346 - global $wgOut, $wgSitename;
347 -
348 - // A god-damned dirty hack!
 259+ // A god-damned dirty hack! :D
 260+ global $wgSitename;
349261 $old = array();
350262 $old['wgSitename'] = $wgSitename;
351263 $wgSitename = $this->projectName();
352264
353 - $out = preg_replace(
354 - '/^<p>(.*)\n?<\/p>\n?$/sU',
355 - '$1',
356 - $wgOut->parse( $text ) );
 265+ $options = array(
 266+ 'language' => $this->language,
 267+ 'parsemag',
 268+ );
 269+ array_unshift( $params, $options );
 270+ array_unshift( $params, $msg );
 271+ $out = call_user_func_array( 'wfMsgExt', $params );
357272
358273 // Restore globals
359274 $wgSitename = $old['wgSitename'];
 275+
360276 return $out;
361277 }
362278
@@ -440,19 +356,7 @@
441357 return '';
442358 }
443359 }
444 -
445 - private function getSubheading() {
446 - // Sigh... hack in another one real quick
447 - return $this->parse(
448 - $this->getMessage( 'centralnotice-subheading' ) );
449 - }
450 -
451 - private function getThanks() {
452 - // Sigh... hack in another one real quick
453 - return $this->parse(
454 - $this->getMessage( 'centralnotice-thanks' ) );
455 - }
456 -
 360+
457361 private function getCachedRssEntry( $url ) {
458362 global $wgMemc;
459363 $key = 'centralnotice:rss:' . md5( $url );

Status & tagging log