Use local context to get messages
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Mon, 7 May 2012 04:38:51 +0000 (06:38 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Wed, 9 May 2012 18:18:30 +0000 (20:18 +0200)
Change-Id: Ieb3564e5532e421b4b803ed6c327d6a75ed0103c

includes/specials/SpecialSearch.php

index a6d75bb..079130f 100644 (file)
@@ -233,13 +233,13 @@ class SpecialSearch extends SpecialPage {
                        } else {
                                $out->addHTML(
                                        Xml::openElement( 'fieldset' ) .
-                                       Xml::element( 'legend', null, wfMsg( 'search-external' ) ) .
-                                       Xml::element( 'p', array( 'class' => 'mw-searchdisabled' ), wfMsg( 'searchdisabled' ) ) .
-                                       wfMsg( 'googlesearch',
+                                       Xml::element( 'legend', null, $this->msg( 'search-external' )->text() ) .
+                                       Xml::element( 'p', array( 'class' => 'mw-searchdisabled' ), $this->msg( 'searchdisabled' )->text() ) .
+                                       $this->msg( 'googlesearch' )->rawParams(
                                                htmlspecialchars( $term ),
-                                               htmlspecialchars( 'UTF-8' ),
-                                               htmlspecialchars( wfMsg( 'searchbutton' ) )
-                                       ) .
+                                               'UTF-8',
+                                               $this->msg( 'searchbutton' )->escaped()
+                                       )->text() .
                                        Xml::closeElement( 'fieldset' )
                                );
                        }
@@ -286,7 +286,7 @@ class SpecialSearch extends SpecialPage {
                                $stParams
                        );
 
-                       $this->didYouMeanHtml = '<div class="searchdidyoumean">'.wfMsg('search-suggest',$suggestLink).'</div>';
+                       $this->didYouMeanHtml = '<div class="searchdidyoumean">' . $this->msg( 'search-suggest' )->rawParams( $suggestLink )->text() . '</div>';
                }
                // start rendering the page
                $out->addHtml(
@@ -584,13 +584,8 @@ class SpecialSearch extends SpecialPage {
                                $redirectText = null;
 
                        $redirect = "<span class='searchalttitle'>" .
-                               wfMsg(
-                                       'search-redirect',
-                                       Linker::linkKnown(
-                                               $redirectTitle,
-                                               $redirectText
-                                       )
-                               ) .
+                               $this->msg( 'search-redirect' )->rawParams(
+                                       Linker::linkKnown( $redirectTitle, $redirectText ) )->text() .
                                "</span>";
                }
 
@@ -601,12 +596,8 @@ class SpecialSearch extends SpecialPage {
                                $sectionText = null;
 
                        $section = "<span class='searchalttitle'>" .
-                               wfMsg(
-                                       'search-section', Linker::linkKnown(
-                                               $sectionTitle,
-                                               $sectionText
-                                       )
-                               ) .
+                               $this->msg( 'search-section' )->rawParams(
+                                       Linker::linkKnown( $sectionTitle, $sectionText ) )->text() .
                                "</span>";
                }
 
@@ -621,7 +612,7 @@ class SpecialSearch extends SpecialPage {
                        $score = '';
                } else {
                        $percent = sprintf( '%2.1f', $result->getScore() * 100 );
-                       $score = wfMsg( 'search-result-score', $lang->formatNum( $percent ) )
+                       $score = $this->msg( 'search-result-score' )->numParams( $percent )->text()
                                . ' - ';
                }
 
@@ -629,25 +620,17 @@ class SpecialSearch extends SpecialPage {
                $byteSize = $result->getByteSize();
                $wordCount = $result->getWordCount();
                $timestamp = $result->getTimestamp();
-               $size = wfMsgExt(
-                       'search-result-size',
-                       array( 'parsemag', 'escape' ),
-                       $lang->formatSize( $byteSize ),
-                       $lang->formatNum( $wordCount )
-               );
+               $size = $this->msg( 'search-result-size', $lang->formatSize( $byteSize ) )
+                       ->numParams( $wordCount )->escaped();
 
                if( $t->getNamespace() == NS_CATEGORY ) {
                        $cat = Category::newFromTitle( $t );
-                       $size = wfMsgExt(
-                               'search-result-category-size',
-                               array( 'parsemag', 'escape' ),
-                               $lang->formatNum( $cat->getPageCount() ),
-                               $lang->formatNum( $cat->getSubcatCount() ),
-                               $lang->formatNum( $cat->getFileCount() )
-                       );
+                       $size = $this->msg( 'search-result-category-size' )
+                               ->numParams( $cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount() )
+                               ->escaped();
                }
 
-               $date = $lang->timeanddate( $timestamp );
+               $date = $lang->userTimeAndDate( $timestamp, $this->getUser() );
 
                // link to related articles if supported
                $related = '';
@@ -656,14 +639,15 @@ class SpecialSearch extends SpecialPage {
                        $stParams = array_merge(
                                $this->powerSearchOptions(),
                                array(
-                                       'search' => wfMsgForContent( 'searchrelated' ) . ':' . $t->getPrefixedText(),
-                                       'fulltext' => wfMsg( 'search' )
+                                       'search' => $this->msg( 'searchrelated' )->inContentLanguage()->text() .
+                                               ':' . $t->getPrefixedText(),
+                                       'fulltext' => $this->msg( 'search' )->text()
                                )
                        );
 
                        $related = ' -- ' . Linker::linkKnown(
                                $st,
-                               wfMsg('search-relatedarticle'),
+                               $this->msg( 'search-relatedarticle' )->text(),
                                array(),
                                $stParams
                        );
@@ -675,7 +659,7 @@ class SpecialSearch extends SpecialPage {
                        if( $img ) {
                                $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
                                if( $thumb ) {
-                                       $desc = wfMsg( 'parentheses', $img->getShortDesc() );
+                                       $desc = $this->msg( 'parentheses' )->rawParams( $img->getShortDesc() )->escaped();
                                        wfProfileOut( __METHOD__ );
                                        // Float doesn't seem to interact well with the bullets.
                                        // Table messes up vertical alignment of the bullets.
@@ -719,12 +703,12 @@ class SpecialSearch extends SpecialPage {
                $terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
 
                $out = "<div id='mw-search-interwiki'><div id='mw-search-interwiki-caption'>".
-                       wfMsg('search-interwiki-caption')."</div>\n";
+                       $this->msg( 'search-interwiki-caption' )->text()  . "</div>\n";
                $out .= "<ul class='mw-search-iwresults'>\n";
 
                // work out custom project captions
                $customCaptions = array();
-               $customLines = explode("\n",wfMsg('search-interwiki-custom')); // format per line <iwprefix>:<caption>
+               $customLines = explode( "\n", $this->msg( 'search-interwiki-custom' )->text() ); // format per line <iwprefix>:<caption>
                foreach($customLines as $line) {
                        $parts = explode(":",$line,2);
                        if(count($parts) == 2) // validate line
@@ -787,13 +771,8 @@ class SpecialSearch extends SpecialPage {
                                $redirectText = null;
 
                        $redirect = "<span class='searchalttitle'>" .
-                               wfMsg(
-                                       'search-redirect',
-                                       Linker::linkKnown(
-                                               $redirectTitle,
-                                               $redirectText
-                                       )
-                               ) .
+                               $this->msg( 'search-redirect' )->rawParams(
+                                       Linker::linkKnown( $redirectTitle, $redirectText ) )->text() .
                                "</span>";
                }
 
@@ -807,13 +786,13 @@ class SpecialSearch extends SpecialPage {
                                // default is to show the hostname of the other wiki which might suck
                                // if there are many wikis on one hostname
                                $parsed = wfParseUrl( $t->getFullURL() );
-                               $caption = wfMsg('search-interwiki-default', $parsed['host']);
+                               $caption = $this->msg( 'search-interwiki-default', $parsed['host'] )->text();
                        }
                        // "more results" link (special page stuff could be localized, but we might not know target lang)
                        $searchTitle = Title::newFromText($t->getInterwiki().":Special:Search");
                        $searchLink = Linker::linkKnown(
                                $searchTitle,
-                               wfMsg('search-interwiki-more'),
+                               $this->msg( 'search-interwiki-more' )->text(),
                                array(),
                                array(
                                        'search' => $query,
@@ -866,7 +845,7 @@ class SpecialSearch extends SpecialPage {
                        }
                        $name = str_replace( '_', ' ', $name );
                        if( $name == '' ) {
-                               $name = wfMsg( 'blanknamespace' );
+                               $name = $this->msg( 'blanknamespace' )->text();
                        }
                        $rows[$subject] .=
                                Xml::openElement(
@@ -902,7 +881,7 @@ class SpecialSearch extends SpecialPage {
                // Show redirects check only if backend supports it
                if( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
                        $showSections['redirects'] =
-                               Xml::checkLabel( wfMsg( 'powersearch-redir' ), 'redirs', 'redirs', $this->searchRedirects );
+                               Xml::checkLabel( $this->msg( 'powersearch-redir' )->text(), 'redirs', 'redirs', $this->searchRedirects );
                }
 
                wfRunHooks( 'SpecialSearchPowerBox', array( &$showSections, $term, $opts ) );
@@ -918,18 +897,18 @@ class SpecialSearch extends SpecialPage {
                                'fieldset',
                                array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
                        ) .
-                       Xml::element( 'legend', null, wfMsg('powersearch-legend') ) .
-                       Xml::tags( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) ) .
+                       Xml::element( 'legend', null, $this->msg('powersearch-legend' )->text() ) .
+                       Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() ) .
                        Xml::tags(
                                'div',
                                array( 'id' => 'mw-search-togglebox' ),
-                               Xml::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
+                               Xml::label( $this->msg( 'powersearch-togglelabel' )->text(), 'mw-search-togglelabel' ) .
                                        Xml::element(
                                                'input',
                                                array(
                                                        'type'=>'button',
                                                        'id' => 'mw-search-toggleall',
-                                                       'value' => wfMsg( 'powersearch-toggleall' )
+                                                       'value' => $this->msg( 'powersearch-toggleall' )->text()
                                                )
                                        ) .
                                        Xml::element(
@@ -937,7 +916,7 @@ class SpecialSearch extends SpecialPage {
                                                array(
                                                        'type'=>'button',
                                                        'id' => 'mw-search-togglenone',
-                                                       'value' => wfMsg( 'powersearch-togglenone' )
+                                                       'value' => $this->msg( 'powersearch-togglenone' )->text()
                                                )
                                        )
                        ) .
@@ -1035,8 +1014,8 @@ class SpecialSearch extends SpecialPage {
                                $this->makeSearchLink(
                                        $bareterm,
                                        array(),
-                                       wfMsg( $profile['message'] ),
-                                       wfMsg( $profile['tooltip'], $tooltipParam ),
+                                       $this->msg( $profile['message'] )->text(),
+                                       $this->msg( $profile['tooltip'], $tooltipParam )->text(),
                                        $profile['parameters']
                                )
                        );
@@ -1047,24 +1026,19 @@ class SpecialSearch extends SpecialPage {
                // Results-info
                if ( $resultsShown > 0 ) {
                        if ( $totalNum > 0 ){
-                               $top = wfMsgExt( 'showingresultsheader', array( 'parseinline' ),
-                                       $lang->formatNum( $this->offset + 1 ),
-                                       $lang->formatNum( $this->offset + $resultsShown ),
-                                       $lang->formatNum( $totalNum ),
-                                       wfEscapeWikiText( $term ),
-                                       $lang->formatNum( $resultsShown )
-                               );
+                               $top = $this->msg( 'showingresultsheader' )
+                                       ->numParams( $this->offset + 1, $this->offset + $resultsShown, $totalNum )
+                                       ->params( wfEscapeWikiText( $term ) )
+                                       ->numParams( $resultsShown )
+                                       ->parse();
                        } elseif ( $resultsShown >= $this->limit ) {
-                               $top = wfMsgExt( 'showingresults', array( 'parseinline' ),
-                                       $lang->formatNum( $this->limit ),
-                                       $lang->formatNum( $this->offset + 1 )
-                               );
+                               $top = $this->msg( 'showingresults' )
+                                       ->numParams( $this->limit, $this->offset + 1 )
+                                       ->parse();
                        } else {
-                               $top =  wfMsgExt( 'showingresultsnum', array( 'parseinline' ),
-                                       $lang->formatNum( $this->limit ),
-                                       $lang->formatNum( $this->offset + 1 ),
-                                       $lang->formatNum( $resultsShown )
-                               );
+                               $top = $this->msg( 'showingresultsnum' )
+                                       ->numParams( $this->limit, $this->offset + 1, $resultsShown )
+                                       ->parse();
                        }
                        $out .= Xml::tags( 'div', array( 'class' => 'results-info' ),
                                Xml::tags( 'ul', null, Xml::tags( 'li', null, $top ) )
@@ -1091,7 +1065,7 @@ class SpecialSearch extends SpecialPage {
                        'autofocus'
                ) ) . "\n";
                $out .= Html::hidden( 'fulltext', 'Search' ) . "\n";
-               $out .= Xml::submitButton( wfMsg( 'searchbutton' ) ) . "\n";
+               $out .= Xml::submitButton( $this->msg( 'searchbutton' )->text() ) . "\n";
                return $out . $this->didYouMeanHtml;
        }
 
@@ -1115,7 +1089,7 @@ class SpecialSearch extends SpecialPage {
                $stParams = array_merge(
                        array(
                                'search' => $term,
-                               'fulltext' => wfMsg( 'search' )
+                               'fulltext' => $this->msg( 'search' )->text()
                        ),
                        $opt
                );
@@ -1153,7 +1127,7 @@ class SpecialSearch extends SpecialPage {
         */
        protected function startsWithAll( $term ) {
 
-               $allkeyword = wfMsgForContent('searchall');
+               $allkeyword = $this->msg( 'searchall' )->inContentLanguage()->text();
 
                $p = explode( ':', $term );
                if( count( $p ) > 1 ) {