r101129 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101128‎ | r101129 | r101130 >
Date:12:39, 28 October 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use local context to get messages
* Also override QuickTemplate::msg(), QuickTemplate::msgHtml() and QuickTemplate::msgWiki() in BaseTemplate to use the context
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -256,7 +256,7 @@
257257 $feeds = array();
258258 foreach( $out->getSyndicationLinks() as $format => $link ) {
259259 $feeds[$format] = array(
260 - 'text' => wfMsg( "feed-$format" ),
 260+ 'text' => $this->msg( "feed-$format" )->text(),
261261 'href' => $link
262262 );
263263 }
@@ -281,7 +281,7 @@
282282 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
283283 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
284284 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
285 - $tpl->set( 'helppage', wfMsg( 'helppage' ) );
 285+ $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
286286 */
287287 $tpl->set( 'searchaction', $this->escapeSearchLink() );
288288 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
@@ -336,9 +336,9 @@
337337 if ( $this->isRevisionCurrent() ) {
338338 $article = new Article( $this->getTitle(), 0 );
339339 if ( !$wgDisableCounters ) {
340 - $viewcount = $this->getLang()->formatNum( $article->getCount() );
 340+ $viewcount = $article->getCount();
341341 if ( $viewcount ) {
342 - $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
 342+ $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
343343 }
344344 }
345345
@@ -350,8 +350,7 @@
351351 );
352352 if( $num > 0 ) {
353353 $tpl->set( 'numberofwatchingusers',
354 - wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
355 - $this->getLang()->formatNum( $num ) )
 354+ $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
356355 );
357356 }
358357 }
@@ -566,20 +565,20 @@
567566 );
568567 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
569568 $personal_urls['mytalk'] = array(
570 - 'text' => wfMsg( 'mytalk' ),
 569+ 'text' => $this->msg( 'mytalk' )->text(),
571570 'href' => &$usertalkUrlDetails['href'],
572571 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
573572 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
574573 );
575574 $href = self::makeSpecialUrl( 'Preferences' );
576575 $personal_urls['preferences'] = array(
577 - 'text' => wfMsg( 'mypreferences' ),
 576+ 'text' => $this->msg( 'mypreferences' )->text(),
578577 'href' => $href,
579578 'active' => ( $href == $pageurl )
580579 );
581580 $href = self::makeSpecialUrl( 'Watchlist' );
582581 $personal_urls['watchlist'] = array(
583 - 'text' => wfMsg( 'mywatchlist' ),
 582+ 'text' => $this->msg( 'mywatchlist' )->text(),
584583 'href' => $href,
585584 'active' => ( $href == $pageurl )
586585 );
@@ -601,12 +600,12 @@
602601
603602 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
604603 $personal_urls['mycontris'] = array(
605 - 'text' => wfMsg( 'mycontris' ),
 604+ 'text' => $this->msg( 'mycontris' )->text(),
606605 'href' => $href,
607606 'active' => $active
608607 );
609608 $personal_urls['logout'] = array(
610 - 'text' => wfMsg( 'userlogout' ),
 609+ 'text' => $this->msg( 'userlogout' )->text(),
611610 'href' => self::makeSpecialUrl( 'Userlogout',
612611 // userlogout link must always contain an & character, otherwise we might not be able
613612 // to detect a buggy precaching proxy (bug 17790)
@@ -623,13 +622,13 @@
624623
625624 # anonlogin & login are the same
626625 $login_url = array(
627 - 'text' => wfMsg( $loginlink ),
 626+ 'text' => $this->msg( $loginlink )->text(),
628627 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
629628 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup )
630629 );
631630 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
632631 $createaccount_url = array(
633 - 'text' => wfMsg( 'createaccount' ),
 632+ 'text' => $this->msg( 'createaccount' )->text(),
634633 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
635634 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
636635 );
@@ -662,7 +661,7 @@
663662 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
664663 $href = &$usertalkUrlDetails['href'];
665664 $personal_urls['anontalk'] = array(
666 - 'text' => wfMsg( 'anontalk' ),
 665+ 'text' => $this->msg( 'anontalk' )->text(),
667666 'href' => $href,
668667 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
669668 'active' => ( $pageurl == $href )
@@ -702,7 +701,7 @@
703702
704703 // wfMessageFallback will nicely accept $message as an array of fallbacks
705704 // or just a single key
706 - $msg = wfMessageFallback( $message );
 705+ $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
707706 if ( is_array($message) ) {
708707 // for hook compatibility just keep the last message name
709708 $message = end($message);
@@ -882,7 +881,7 @@
883882 "edit" : "create";
884883 $content_navigation['views']['edit'] = array(
885884 'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
886 - 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
 885+ 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
887886 'href' => $title->getLocalURL( $this->editUrlOptions() ),
888887 'primary' => true, // don't collapse this in vector
889888 );
@@ -895,7 +894,7 @@
896895 //$content_navigation['actions']['addsection']
897896 $content_navigation['views']['addsection'] = array(
898897 'class' => $section == 'new' ? 'selected' : false,
899 - 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
 898+ 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
900899 'href' => $title->getLocalURL( 'action=edit&section=new' )
901900 );
902901 }
@@ -905,7 +904,7 @@
906905 // Adds view source view link
907906 $content_navigation['views']['viewsource'] = array(
908907 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
909 - 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
 908+ 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
910909 'href' => $title->getLocalURL( $this->editUrlOptions() ),
911910 'primary' => true, // don't collapse this in vector
912911 );
@@ -919,7 +918,7 @@
920919 // Adds history view link
921920 $content_navigation['views']['history'] = array(
922921 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
923 - 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
 922+ 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
924923 'href' => $title->getLocalURL( 'action=history' ),
925924 'rel' => 'archives',
926925 );
@@ -927,7 +926,7 @@
928927 if( $user->isAllowed( 'delete' ) ) {
929928 $content_navigation['actions']['delete'] = array(
930929 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
931 - 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
 930+ 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
932931 'href' => $title->getLocalURL( 'action=delete' )
933932 );
934933 }
@@ -935,7 +934,7 @@
936935 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
937936 $content_navigation['actions']['move'] = array(
938937 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
939 - 'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
 938+ 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
940939 'href' => $moveTitle->getLocalURL()
941940 );
942941 }
@@ -944,7 +943,7 @@
945944 $mode = !$title->isProtected() ? 'protect' : 'unprotect';
946945 $content_navigation['actions'][$mode] = array(
947946 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
948 - 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
 947+ 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
949948 'href' => $title->getLocalURL( "action=$mode" )
950949 );
951950 }
@@ -959,7 +958,7 @@
960959 $content_navigation['actions']['undelete'] = array(
961960 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
962961 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
963 - ->params( $this->getLang()->formatNum( $n ) )->text(),
 962+ ->setContext( $this->getContext() )->numParams( $n )->text(),
964963 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
965964 );
966965 }
@@ -969,7 +968,7 @@
970969 $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
971970 $content_navigation['actions'][$mode] = array(
972971 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
973 - 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
 972+ 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
974973 'href' => $title->getLocalURL( "action=$mode" )
975974 );
976975 }
@@ -991,7 +990,7 @@
992991 $token = WatchAction::getWatchToken( $title, $user, $mode );
993992 $content_navigation['actions'][$mode] = array(
994993 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
995 - 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
 994+ 'text' => $this->msg( $mode )->text(), // uses 'watch' or 'unwatch' message
996995 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
997996 );
998997 }
@@ -1001,7 +1000,7 @@
10021001 // If it's not content, it's got to be a special page
10031002 $content_navigation['namespaces']['special'] = array(
10041003 'class' => 'selected',
1005 - 'text' => wfMsg( 'nstab-special' ),
 1004+ 'text' => $this->msg( 'nstab-special' )->text(),
10061005 'href' => $request->getRequestURL(), // @bug 2457, 2510
10071006 'context' => 'subject'
10081007 );
@@ -1163,7 +1162,7 @@
11641163 if( $out->isArticle() ) {
11651164 if ( !$out->isPrintable() ) {
11661165 $nav_urls['print'] = array(
1167 - 'text' => wfMsg( 'printableversion' ),
 1166+ 'text' => $this->msg( 'printableversion' )->text(),
11681167 'href' => $this->getTitle()->getLocalURL(
11691168 $request->appendQueryValue( 'printable', 'yes', true ) )
11701169 );
@@ -1173,7 +1172,7 @@
11741173 $revid = $this->getRevisionId();
11751174 if ( $revid ) {
11761175 $nav_urls['permalink'] = array(
1177 - 'text' => wfMsg( 'permalink' ),
 1176+ 'text' => $this->msg( 'permalink' )->text(),
11781177 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
11791178 );
11801179 }
@@ -1411,6 +1410,28 @@
14121411 abstract class BaseTemplate extends QuickTemplate {
14131412
14141413 /**
 1414+ * Get a Message object with its context set
 1415+ *
 1416+ * @param $name Str message name
 1417+ * @return Message
 1418+ */
 1419+ public function getMsg( $name ) {
 1420+ return $this->getSkin()->msg( $name );
 1421+ }
 1422+
 1423+ function msg( $str ) {
 1424+ echo $this->getMsg( $str )->escaped();
 1425+ }
 1426+
 1427+ function msgHtml( $str ) {
 1428+ echo $this->getMsg( $str )->text();
 1429+ }
 1430+
 1431+ function msgWiki( $str ) {
 1432+ echo $this->getMsg( $str )->parseAsBlock();
 1433+ }
 1434+
 1435+ /**
14151436 * Create an array of common toolbox items from the data in the quicktemplate
14161437 * stored by SkinTemplate.
14171438 * The resulting array is built acording to a format intended to be passed
@@ -1533,13 +1554,13 @@
15341555 // Search is a special case, skins should custom implement this
15351556 $boxes[$boxName] = array(
15361557 'id' => "p-search",
1537 - 'header' => wfMessage( 'search' )->text(),
 1558+ 'header' => $this->getMsg( 'search' )->text(),
15381559 'generated' => false,
15391560 'content' => true,
15401561 );
15411562 break;
15421563 case 'TOOLBOX':
1543 - $msgObj = wfMessage( 'toolbox' );
 1564+ $msgObj = $this->getMsg( 'toolbox' );
15441565 $boxes[$boxName] = array(
15451566 'id' => "p-tb",
15461567 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
@@ -1549,7 +1570,7 @@
15501571 break;
15511572 case 'LANGUAGES':
15521573 if ( $this->data['language_urls'] ) {
1553 - $msgObj = wfMessage( 'otherlanguages' );
 1574+ $msgObj = $this->getMsg( 'otherlanguages' );
15541575 $boxes[$boxName] = array(
15551576 'id' => "p-lang",
15561577 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
@@ -1559,7 +1580,7 @@
15601581 }
15611582 break;
15621583 default:
1563 - $msgObj = wfMessage( $boxName );
 1584+ $msgObj = $this->getMsg( $boxName );
15641585 $boxes[$boxName] = array(
15651586 'id' => "p-$boxName",
15661587 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,

Status & tagging log