r98066 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98065‎ | r98066 | r98067 >
Date:14:38, 25 September 2011
Author:ialex
Status:ok
Tags:
Comment:
Simplify things by using wfMessage() instead of wfMsg() et al.
Modified paths:
  • /trunk/phase3/includes/media/Generic.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/media/Generic.php
@@ -380,8 +380,10 @@
381381 * Note, everything here is passed through the parser later on (!)
382382 */
383383 protected static function addMeta( &$array, $visibility, $type, $id, $value, $param = false ) {
384 - $msgName = "$type-$id";
385 - if ( wfEmptyMsg( $msgName ) ) {
 384+ $msg = wfMessage( "$type-$id", $param );
 385+ if ( $msg->exists() ) {
 386+ $name = $msg->text();
 387+ } else {
386388 // This is for future compatibility when using instant commons.
387389 // So as to not display as ugly a name if a new metadata
388390 // property is defined that we don't know about
@@ -389,8 +391,6 @@
390392 // by default).
391393 wfDebug( __METHOD__ . ' Unknown metadata name: ' . $id . "\n" );
392394 $name = wfEscapeWikiText( $id );
393 - } else {
394 - $name = wfMsg( $msgName, $param );
395395 }
396396 $array[$visibility][] = array(
397397 'id' => "$type-$id",
@@ -404,10 +404,7 @@
405405 * @return string
406406 */
407407 function getShortDesc( $file ) {
408 - global $wgLang;
409 - $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
410 - $wgLang->formatNum( $file->getSize() ) );
411 - return "$nbytes";
 408+ return wfMessage( 'nbytes' )->numParams( $file->getSize() )->escaped();
412409 }
413410
414411 /**
@@ -416,9 +413,8 @@
417414 */
418415 function getLongDesc( $file ) {
419416 global $wgLang;
420 - return wfMsgExt( 'file-info', 'parseinline',
421 - $wgLang->formatSize( $file->getSize() ),
422 - $file->getMimeType() );
 417+ return wfMessage( 'file-info', $wgLang->formatSize( $file->getSize() ),
 418+ $file->getMimeType() )->parse();
423419 }
424420
425421 /**
@@ -426,10 +422,7 @@
427423 * @return string
428424 */
429425 static function getGeneralShortDesc( $file ) {
430 - global $wgLang;
431 - $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
432 - $wgLang->formatNum( $file->getSize() ) );
433 - return "$nbytes";
 426+ return wfMessage( 'nbytes' )->numParams( $file->getSize() )->escaped();
434427 }
435428
436429 /**
@@ -438,9 +431,8 @@
439432 */
440433 static function getGeneralLongDesc( $file ) {
441434 global $wgLang;
442 - return wfMsgExt( 'file-info', 'parseinline',
443 - $wgLang->formatSize( $file->getSize() ),
444 - $file->getMimeType() );
 435+ return wfMessage( 'file-info', $wgLang->formatSize( $file->getSize() ),
 436+ $file->getMimeType() )->parse();
445437 }
446438
447439 /**
@@ -712,10 +704,8 @@
713705 * @return string
714706 */
715707 function getShortDesc( $file ) {
716 - global $wgLang;
717 - $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
718 - $wgLang->formatNum( $file->getSize() ) );
719 - $widthheight = wfMsgHtml( 'widthheight', $wgLang->formatNum( $file->getWidth() ) ,$wgLang->formatNum( $file->getHeight() ) );
 708+ $nbytes = wfMessage( 'nbytes' )->numParams( $file->getSize() )->escaped();
 709+ $widthheight = wfMessage( 'widthheight' )->numParams( $file->getWidth(), $file->getHeight() )->escaped();
720710
721711 return "$widthheight ($nbytes)";
722712 }
@@ -728,18 +718,13 @@
729719 global $wgLang;
730720 $pages = $file->pageCount();
731721 if ( $pages === false || $pages <= 1 ) {
732 - $msg = wfMsgExt('file-info-size', 'parseinline',
733 - $wgLang->formatNum( $file->getWidth() ),
734 - $wgLang->formatNum( $file->getHeight() ),
735 - $wgLang->formatSize( $file->getSize() ),
736 - $file->getMimeType() );
 722+ $msg = wfMessage( 'file-info-size' )->numParams( $file->getWidth(),
 723+ $file->getHeight() )->params( $wgLang->formatSize( $file->getSize() ),
 724+ $file->getMimeType() )->parse();
737725 } else {
738 - $msg = wfMsgExt('file-info-size-pages', 'parseinline',
739 - $wgLang->formatNum( $file->getWidth() ),
740 - $wgLang->formatNum( $file->getHeight() ),
741 - $wgLang->formatSize( $file->getSize() ),
742 - $file->getMimeType(),
743 - $wgLang->formatNum( $pages ) );
 726+ $msg = wfMessage( 'file-info-size-pages' )->numParams( $file->getWidth(),
 727+ $file->getHeight() )->params( $wgLang->formatSize( $file->getSize() ),
 728+ $file->getMimeType() )->numParams( $pages )->parse();
744729 }
745730 return $msg;
746731 }
@@ -749,16 +734,11 @@
750735 * @return string
751736 */
752737 function getDimensionsString( $file ) {
753 - global $wgLang;
754738 $pages = $file->pageCount();
755 - $width = $wgLang->formatNum( $file->getWidth() );
756 - $height = $wgLang->formatNum( $file->getHeight() );
757 - $pagesFmt = $wgLang->formatNum( $pages );
758 -
759739 if ( $pages > 1 ) {
760 - return wfMsgExt( 'widthheightpage', 'parsemag', $width, $height, $pagesFmt );
 740+ return wfMessage( 'widthheightpage' )->numParams( $file->getWidth(), $file->getHeight(), $pages )->text();
761741 } else {
762 - return wfMsg( 'widthheight', $width, $height );
 742+ return wfMessage( 'widthheight' )->numParams( $file->getWidth(), $file->getHeight() )->text();
763743 }
764744 }
765745 }

Status & tagging log