r100445 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100444‎ | r100445 | r100446 >
Date:20:09, 21 October 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
Use local context to get messages
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Skin.php
@@ -383,14 +383,15 @@
384384 $pop = "</li>";
385385
386386 $s = '';
387 - $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
 387+ $colon = $this->msg( 'colon-separator' )->escaped();
388388
389389 if ( !empty( $allCats['normal'] ) ) {
390390 $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
391391
392 - $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
 392+ $msg = $this->msg( 'pagecategories', count( $allCats['normal'] ) )->escaped();
 393+ $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
393394 $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
394 - Linker::link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
 395+ Linker::link( Title::newFromText( $linkPage ), $msg )
395396 . $colon . '<ul>' . $t . '</ul>' . '</div>';
396397 }
397398
@@ -405,7 +406,7 @@
406407 }
407408
408409 $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
409 - wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
 410+ $this->msg( 'hidden-categories', count( $allCats['hidden'] ) )->escaped() .
410411 $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
411412 '</div>';
412413 }
@@ -605,7 +606,7 @@
606607 // oldid not available for non existing pages
607608 $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
608609 }
609 - return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
 610+ return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
610611 }
611612
612613 function getUndeleteLink() {
@@ -623,13 +624,11 @@
624625 $msg = 'viewdeleted';
625626 }
626627
627 - return wfMsg(
628 - $msg,
 628+ return $this->msg( $msg )->rawParams(
629629 Linker::linkKnown(
630630 SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
631 - wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) )
632 - )
633 - );
 631+ $this->msg( 'restorelink' )->numParams( $n )->escaped() )
 632+ )->text();
634633 }
635634 }
636635
@@ -667,7 +666,7 @@
668667 $c++;
669668
670669 if ( $c > 1 ) {
671 - $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
 670+ $subpages .= $this->msg( 'pipe-separator' )->escaped();
672671 } else {
673672 $subpages .= '&lt; ';
674673 }
@@ -707,7 +706,7 @@
708707 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
709708
710709 if ( $type == 'detect' ) {
711 - if ( !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
 710+ if ( !$this->isRevisionCurrent() && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled() ) {
712711 $type = 'history';
713712 } else {
714713 $type = 'normal';
@@ -737,14 +736,15 @@
738737
739738 wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
740739
 740+ $msgObj = $this->msg( $msg )->rawParams( $link );
741741 if ( $forContent ) {
742 - $msg = wfMsgForContent( $msg, $link );
 742+ $msg = $msgObj->inContentLanguage()->text();
743743 if ( $this->getLang()->getCode() !== $wgContLang->getCode() ) {
744744 $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $msg );
745745 }
746746 return $msg;
747747 } else {
748 - return wfMsg( $msg, $link );
 748+ return $msgObj->text();
749749 }
750750 }
751751
@@ -801,15 +801,15 @@
802802 }
803803
804804 if ( $timestamp ) {
805 - $d = $this->getLang()->date( $timestamp, true );
806 - $t = $this->getLang()->time( $timestamp, true );
807 - $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
 805+ $d = $this->getLang()->userDate( $timestamp, $this->getUser() );
 806+ $t = $this->getLang()->userTime( $timestamp, $this->getUser() );
 807+ $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text();
808808 } else {
809809 $s = '';
810810 }
811811
812812 if ( wfGetLB()->getLaggedSlaveMode() ) {
813 - $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
 813+ $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>';
814814 }
815815
816816 return $s;
@@ -822,7 +822,7 @@
823823 $a = '';
824824 }
825825
826 - $mp = wfMsgHtml( 'mainpage' );
 826+ $mp = $this->msg( 'mainpage' )->escaped();
827827 $mptitle = Title::newMainPage();
828828 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
829829
@@ -863,7 +863,7 @@
864864 function mainPageLink() {
865865 $s = Linker::linkKnown(
866866 Title::newMainPage(),
867 - wfMsgHtml( 'mainpage' )
 867+ $this->msg( 'mainpage' )->escaped()
868868 );
869869
870870 return $s;
@@ -871,18 +871,18 @@
872872
873873 public function footerLink( $desc, $page ) {
874874 // if the link description has been set to "-" in the default language,
875 - if ( wfMsgForContent( $desc ) == '-' ) {
 875+ if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
876876 // then it is disabled, for all languages.
877877 return '';
878878 } else {
879879 // Otherwise, we display the link for the user, described in their
880880 // language (which may or may not be the same as the default language),
881881 // but we make the link target be the one site-wide page.
882 - $title = Title::newFromText( wfMsgForContent( $page ) );
 882+ $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() );
883883
884884 return Linker::linkKnown(
885885 $title,
886 - wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
 886+ $this->msg( $desc )->escaped()
887887 );
888888 }
889889 }
@@ -1122,7 +1122,7 @@
11231123 $line = array_map( 'trim', explode( '|', $line, 2 ) );
11241124 $extraAttribs = array();
11251125
1126 - $msgLink = wfMessage( $line[0] )->inContentLanguage();
 1126+ $msgLink = $this->msg( $line[0] )->inContentLanguage();
11271127 if ( $msgLink->exists() ) {
11281128 $link = $msgLink->text();
11291129 if ( $link == '-' ) {
@@ -1132,7 +1132,7 @@
11331133 $link = $line[0];
11341134 }
11351135
1136 - $msgText = wfMessage( $line[1] );
 1136+ $msgText = $this->msg( $line[1] );
11371137 if ( $msgText->exists() ) {
11381138 $text = $msgText->text();
11391139 } else {
@@ -1206,29 +1206,29 @@
12071207 if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
12081208 $newMessagesLink = Linker::linkKnown(
12091209 $userTalkTitle,
1210 - wfMsgHtml( 'newmessageslink' ),
 1210+ $this->msg( 'newmessageslink' )->escaped(),
12111211 array(),
12121212 array( 'redirect' => 'no' )
12131213 );
12141214
12151215 $newMessagesDiffLink = Linker::linkKnown(
12161216 $userTalkTitle,
1217 - wfMsgHtml( 'newmessagesdifflink' ),
 1217+ $this->msg( 'newmessagesdifflink' )->escaped(),
12181218 array(),
12191219 array( 'diff' => 'cur' )
12201220 );
12211221
1222 - $ntl = wfMsg(
 1222+ $ntl = $this->msg(
12231223 'youhavenewmessages',
12241224 $newMessagesLink,
12251225 $newMessagesDiffLink
1226 - );
 1226+ )->text();
12271227 # Disable Squid cache
12281228 $out->setSquidMaxage( 0 );
12291229 }
12301230 } elseif ( count( $newtalks ) ) {
12311231 // _>" " for BC <= 1.16
1232 - $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
 1232+ $sep = str_replace( '_', ' ', $this->msg( 'newtalkseparator' )->escaped() );
12331233 $msgs = array();
12341234
12351235 foreach ( $newtalks as $newtalk ) {
@@ -1238,7 +1238,7 @@
12391239 );
12401240 }
12411241 $parts = implode( $sep, $msgs );
1242 - $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
 1242+ $ntl = $this->msg( 'youhavenewmessagesmulti' )->rawParams( $parts )->escaped();
12431243 $out->setSquidMaxage( 0 );
12441244 }
12451245
@@ -1267,7 +1267,7 @@
12681268 return false;
12691269 }
12701270 } else {
1271 - $msg = wfMessage( $name )->inContentLanguage();
 1271+ $msg = $this->msg( $name )->inContentLanguage();
12721272 if( $msg->isDisabled() ) {
12731273 wfProfileOut( __METHOD__ );
12741274 return false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r105796Per Platonides, fix for r100445: make sure user's language is English so that...ialex13:54, 11 December 2011

Comments

#Comment by Platonides (talk | contribs)   15:40, 23 November 2011

Breaks SideBarTest::testExpandMessages test when the wiki language is not English (some ordering issues may be present, too). It should be possible to reset the $instance of RequestContext::getMain() between tests.

#Comment by Hashar (talk | contribs)   10:42, 5 December 2011

Platonides, I could not reproduce that issue. Please give us a bit more details, resetting to new for now.

#Comment by Platonides (talk | contribs)   22:50, 7 December 2011

I set $wgLanguageCode = 'fr'; and run make databaseless

There was 1 failure:

1) SideBarTest::testExpandMessages
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
                 (
-                    [text] => Help
+                    [text] => Aide
                     [href] => /index.php/Help:Contents
                     [id] => n-help
                     [active] => 
                 )
 
         )
 
 )

It may depend on which order the tests are run. I think some other test is initialising RequestContext::getMain() to French (which? where?), and that's what makes this test fail.

Just php phpunit.php skins/SideBarTest.php works.

#Comment by IAlex (talk | contribs)   13:55, 11 December 2011

Fixed in r105796.

Status & tagging log