Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/273576

Change subject: Use IContextSource::msg instead of wfMessage where available
......................................................................

Use IContextSource::msg instead of wfMessage where available

A Message object returned by ICOntextSource::msg (and equivalents)
should be preferred when using interface messages as they've the information
provided by the context (Title, Language, ...), according to [1].

[1] 
https://www.mediawiki.org/wiki/Manual:Messages_API#Additional_methods_of_printing_messages

Change-Id: I440767d7d500b135f5fbd4f69f4b150413263f8e
---
M includes/MobileFrontend.skin.hooks.php
M includes/skins/MinervaTemplate.php
M includes/skins/MinervaTemplateBeta.php
M includes/skins/SkinMinerva.php
M includes/specials/SpecialMobileMenu.php
M includes/specials/SpecialMobilePreferences.php
M includes/specials/SpecialNearby.php
7 files changed, 36 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/76/273576/1

diff --git a/includes/MobileFrontend.skin.hooks.php 
b/includes/MobileFrontend.skin.hooks.php
index ce573fe..7df881e 100644
--- a/includes/MobileFrontend.skin.hooks.php
+++ b/includes/MobileFrontend.skin.hooks.php
@@ -135,7 +135,9 @@
         * @param Title $title
         * @param WebRequest $req
         */
-       public static function desktopFooter( $sk, $tpl, $ctx, $title, $req ) {
+       public static function desktopFooter( Skin $sk, QuickTemplate $tpl, 
MobileContext $ctx,
+               Title $title, WebRequest $req
+       ) {
                $footerlinks = $tpl->data['footerlinks'];
                $args = $req->getQueryValues();
                // avoid title being set twice
@@ -147,7 +149,7 @@
 
                $link = Html::element( 'a',
                        array( 'href' => $mobileViewUrl, 'class' => 'noprint 
stopMobileRedirectToggle' ),
-                       wfMessage( 'mobile-frontend-view' )->text()
+                       $ctx->msg( 'mobile-frontend-view' )->text()
                );
                $tpl->set( 'mobileview', $link );
                $footerlinks['places'][] = 'mobileview';
@@ -163,7 +165,9 @@
         * @param WebRequest $req
         * @return QuickTemplate
         */
-       protected static function mobileFooter( $sk, $tpl, $ctx, $title, $req ) 
{
+       protected static function mobileFooter( Skin $sk, QuickTemplate $tpl, 
MobileContext $ctx,
+               Title $title, WebRequest $req
+       ) {
                $url = $sk->getOutput()->getProperty( 'desktopUrl' );
                if ( $url ) {
                        $url = wfAppendQuery( $url, 
'mobileaction=toggle_view_desktop' );
@@ -176,8 +180,8 @@
                        $ctx->getDesktopUrl( wfExpandUrl( $url, PROTO_RELATIVE 
) )
                );
 
-               $desktop = wfMessage( 'mobile-frontend-view-desktop' 
)->escaped();
-               $mobile = wfMessage( 'mobile-frontend-view-mobile' )->escaped();
+               $desktop = $ctx->msg( 'mobile-frontend-view-desktop' 
)->escaped();
+               $mobile = $ctx->msg( 'mobile-frontend-view-mobile' )->escaped();
 
                $sitename = self::getSitename( true );
                $switcherHtml = <<<HTML
@@ -228,12 +232,13 @@
         * @return string
         */
        public static function getSitename( $withPossibleTrademark = false ) {
-               $config = MobileContext::singleton()->getMFConfig();
+               $ctx = MobileContext::singleton();
+               $config = $ctx->getMFConfig();
                $customLogos = $config->get( 'MFCustomLogos' );
                $trademarkSymbol = $config->get( 'MFTrademarkSitename' );
                $suffix = '';
 
-               $footerSitename = wfMessage( 'mobile-frontend-footer-sitename' 
)->text();
+               $footerSitename = $ctx->msg( 'mobile-frontend-footer-sitename' 
)->text();
 
                // Add a trademark symbol if needed
                if ( $withPossibleTrademark ) {
diff --git a/includes/skins/MinervaTemplate.php 
b/includes/skins/MinervaTemplate.php
index 0e52000..aa9266d 100644
--- a/includes/skins/MinervaTemplate.php
+++ b/includes/skins/MinervaTemplate.php
@@ -89,7 +89,7 @@
                        'autocomplete' => 'off',
                        // The placeholder gets fed to HTML::element later 
which escapes all
                        // attribute values, so need to escape the string here.
-                       'placeholder' => wfMessage( 
'mobile-frontend-placeholder' )->escaped(),
+                       'placeholder' => $this->getMsg( 
'mobile-frontend-placeholder' )->escaped(),
                );
                return $searchBox;
        }
@@ -189,7 +189,7 @@
                                        'class' => 'languageSelector',
                                        'href' => $languageUrl,
                                ),
-                               'label' => wfMessage( 
'mobile-frontend-language-article-heading' )->text()
+                               'label' => $this->getMsg( 
'mobile-frontend-language-article-heading' )->text()
                        );
                }
 
diff --git a/includes/skins/MinervaTemplateBeta.php 
b/includes/skins/MinervaTemplateBeta.php
index 0fd1639..a7c7e0b 100644
--- a/includes/skins/MinervaTemplateBeta.php
+++ b/includes/skins/MinervaTemplateBeta.php
@@ -14,7 +14,7 @@
         */
        protected function getSearchAttributes() {
                $searchBox = parent::getSearchAttributes();
-               $searchBox['placeholder'] = wfMessage( 
'mobile-frontend-placeholder-beta' )->escaped();
+               $searchBox['placeholder'] = $this->getMsg( 
'mobile-frontend-placeholder-beta' )->escaped();
                return $searchBox;
        }
 
@@ -39,7 +39,7 @@
                                        // be removed in categories/init.js)
                                        'class' => 'category-button hidden',
                                ),
-                               'label' => wfMessage( 'categories' )->text()
+                               'label' => $this->getMsg( 'categories' )->text()
                        ),
                );
        }
@@ -57,7 +57,7 @@
                                'attributes' => array(
                                        'href' => $donationUrl,
                                ),
-                               'label' => wfMessage( 
'mobile-frontend-donate-button-label' )->text()
+                               'label' => $this->getMsg( 
'mobile-frontend-donate-button-label' )->text()
                        );
                }
 
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 37537af..715c8f7 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -102,7 +102,7 @@
                        }
                        $tpl->set( 'subject-page', Linker::link(
                                $title->getSubjectPage(),
-                               wfMessage( $msg, $title->getText() ),
+                               $this->msg( $msg, $title->getText() 
)->escaped(),
                                array( 'class' => 'return-link' )
                        ) );
                }
@@ -138,11 +138,11 @@
                if ( $this->isAllowedPageAction( 'edit' ) ) {
                        $additionalClass = $noJsEdit?' nojs-edit':'';
                        $lang = wfGetLangObj( $lang );
-                       $message = wfMessage( 'mobile-frontend-editor-edit' 
)->inLanguage( $lang )->text();
+                       $message = $this->msg( 'mobile-frontend-editor-edit' 
)->inLanguage( $lang )->text();
                        $html = Html::openElement( 'span' );
                        $html .= Html::element( 'a', array(
                                'href' =>  $this->getTitle()->getLocalUrl( 
array( 'action' => 'edit', 'section' => $section ) ),
-                               'title' => wfMessage( 'editsectionhint', 
$tooltip )->inLanguage( $lang )->text(),
+                               'title' => $this->msg( 'editsectionhint', 
$tooltip )->inLanguage( $lang )->text(),
                                'data-section' => $section,
                                // Note visibility of the edit section link 
button is controlled by .edit-page in ui.less so
                                // we default to enabled even though this may 
not be true.
@@ -271,7 +271,7 @@
                // notifications archive, show the notifications icon in the 
header.
                if ( $this->useEcho() && $user->isLoggedIn() ) {
                        $notificationsTitle = SpecialPage::getTitleFor( 
'Notifications' );
-                       $notificationsMsg = wfMessage( 
'mobile-frontend-user-button-tooltip' );
+                       $notificationsMsg = $this->msg( 
'mobile-frontend-user-button-tooltip' )->text();
                        if ( $currentTitle->getPrefixedText() !== 
$notificationsTitle->getPrefixedText() ) {
                                $count = MWEchoNotifUser::newFromUser( $user 
)->getNotificationCount();
                                $isZero = $count === 0;
@@ -279,7 +279,7 @@
                        }
                } elseif ( !empty( $newtalks ) ) {
                        $notificationsTitle = SpecialPage::getTitleFor( 
'Mytalk' );
-                       $notificationsMsg = wfMessage( 
'mobile-frontend-user-newmessages' )->text();
+                       $notificationsMsg = $this->msg( 
'mobile-frontend-user-newmessages' )->text();
                }
 
                if ( $notificationsTitle ) {
@@ -342,7 +342,7 @@
 
                $menu->insert( 'watchlist', $isJSOnly = true )
                        ->addComponent(
-                               wfMessage( 
'mobile-frontend-main-menu-watchlist' )->escaped(),
+                               $this->msg( 
'mobile-frontend-main-menu-watchlist' )->escaped(),
                                $this->getPersonalUrl(
                                        $watchTitle,
                                        'mobile-frontend-watchlist-purpose',
@@ -358,7 +358,7 @@
                        // Settings link
                        $menu->insert( 'settings' )
                                ->addComponent(
-                                       wfMessage( 
'mobile-frontend-main-menu-settings' )->escaped(),
+                                       $this->msg( 
'mobile-frontend-main-menu-settings' )->escaped(),
                                        SpecialPage::getTitleFor( 
'MobileOptions' )->
                                                getLocalUrl( array( 'returnto' 
=> $returnToTitle ) ),
                                        MobileUI::iconClass( 'mobileoptions', 
'before' ),
@@ -371,7 +371,7 @@
                        // Preferences link
                        $menu->insert( 'preferences' )
                                ->addComponent(
-                                       wfMessage( 'preferences' )->escaped(),
+                                       $this->msg( 'preferences' )->escaped(),
                                        $this->getPersonalUrl(
                                                SpecialPage::getTitleFor( 
'Preferences' ),
                                                'prefsnologintext2'
@@ -419,7 +419,7 @@
                // Home link
                $menu->insert( 'home' )
                        ->addComponent(
-                               wfMessage( 'mobile-frontend-home-button' 
)->escaped(),
+                               $this->msg( 'mobile-frontend-home-button' 
)->escaped(),
                                Title::newMainPage()->getLocalUrl(),
                                MobileUI::iconClass( 'home', 'before' ),
                                array( 'data-event-name' => 'home' )
@@ -428,7 +428,7 @@
                // Random link
                $menu->insert( 'random' )
                        ->addComponent(
-                               wfMessage( 'mobile-frontend-random-button' 
)->escaped(),
+                               $this->msg( 'mobile-frontend-random-button' 
)->escaped(),
                                SpecialPage::getTitleFor( 'Randompage',
                                        MWNamespace::getCanonicalName( 
$config->get( 'MFContentNamespace' ) ) )->getLocalUrl() .
                                                '#/random',
@@ -446,7 +446,7 @@
                ) {
                        $menu->insert( 'nearby', $isJSOnly = true )
                                ->addComponent(
-                                       wfMessage( 
'mobile-frontend-main-menu-nearby' )->escaped(),
+                                       $this->msg( 
'mobile-frontend-main-menu-nearby' )->escaped(),
                                        SpecialPage::getTitleFor( 'Nearby' 
)->getLocalURL(),
                                        MobileUI::iconClass( 'nearby', 
'before', 'nearby' ),
                                        array( 'data-event-name' => 'nearby' )
@@ -515,7 +515,7 @@
                                        array( 'data-event-name' => 'profile' )
                                )
                                ->addComponent(
-                                       wfMessage( 
'mobile-frontend-main-menu-logout' )->escaped(),
+                                       $this->msg( 
'mobile-frontend-main-menu-logout' )->escaped(),
                                        $url,
                                        MobileUI::iconClass(
                                                'secondary-logout', 'element', 
'secondary-action truncated-text' ),
@@ -531,7 +531,7 @@
                        $url = $this->getLoginUrl( $query );
                        $menu->insert( 'auth', $isJSOnly = true )
                                ->addComponent(
-                                       wfMessage( 
'mobile-frontend-main-menu-login' )->escaped(),
+                                       $this->msg( 
'mobile-frontend-main-menu-login' )->escaped(),
                                        $url,
                                        MobileUI::iconClass( 'anonymous-white', 
'before' ),
                                        array( 'data-event-name' => 'login' )
@@ -627,7 +627,7 @@
                                $templateParser->processTemplate( 
'user_page_links', $data ) );
                } elseif ( $title->isMainPage() ) {
                        if ( $user->isLoggedIn() ) {
-                               $pageTitle = wfMessage(
+                               $pageTitle = $this->msg(
                                        
'mobile-frontend-logged-in-homepage-notification', $user->getName() )->text();
                        } else {
                                $pageTitle = '';
diff --git a/includes/specials/SpecialMobileMenu.php 
b/includes/specials/SpecialMobileMenu.php
index 2692a2d..49bff53 100644
--- a/includes/specials/SpecialMobileMenu.php
+++ b/includes/specials/SpecialMobileMenu.php
@@ -29,7 +29,7 @@
        public function executeWhenAvailable( $par = '' ) {
                $this->setHeaders();
                $out = $this->getOutput();
-               $out->setPageTitle( wfMessage( 
'mobile-frontend-main-menu-page-title' )->text() );
+               $out->setPageTitle( $this->msg( 
'mobile-frontend-main-menu-page-title' ) );
                $out->setProperty( 'bodyClassName', 'navigation-enabled 
navigation-full-screen' );
                $out->addModuleStyles(
                        array(
diff --git a/includes/specials/SpecialMobilePreferences.php 
b/includes/specials/SpecialMobilePreferences.php
index e1f5634..268ab65 100644
--- a/includes/specials/SpecialMobilePreferences.php
+++ b/includes/specials/SpecialMobilePreferences.php
@@ -63,7 +63,7 @@
                $this->checkReadOnly();
 
                if ( $this->getRequest()->getCheck( 'success' ) ) {
-                       $out->addHtml( MobileUI::successBox( wfMessage( 
'savedprefs' ) ) );
+                       $out->addHtml( MobileUI::successBox( $this->msg( 
'savedprefs' )->escaped() ) );
                }
 
                // combine our valid tabs array with all available tabs on the 
preferences form
diff --git a/includes/specials/SpecialNearby.php 
b/includes/specials/SpecialNearby.php
index fc03bad..ec597c2 100644
--- a/includes/specials/SpecialNearby.php
+++ b/includes/specials/SpecialNearby.php
@@ -29,7 +29,7 @@
 
                // set config
                $output->addJsConfigVars( 'wgMFNearbyRange', 
$this->getMFConfig()->get( 'MFNearbyRange' ) );
-               $output->setPageTitle( wfMessage( 
'mobile-frontend-nearby-title' )->escaped() );
+               $output->setPageTitle( $this->msg( 
'mobile-frontend-nearby-title' ) );
 
                $html =
                        Html::openElement( 'div',
@@ -41,9 +41,9 @@
                        MobileUI::contentElement(
                                MobileUI::errorBox(
                                        Html::element( 'h2', array(),
-                                               wfMessage( 
'mobile-frontend-nearby-requirements' ) ) .
+                                               $this->msg( 
'mobile-frontend-nearby-requirements' )->text() ) .
                                        Html::element( 'p', array(),
-                                               wfMessage( 
'mobile-frontend-nearby-requirements-guidance' ) )
+                                               $this->msg( 
'mobile-frontend-nearby-requirements-guidance' )->text() )
                                ),
                                'noscript'
                        ) .

-- 
To view, visit https://gerrit.wikimedia.org/r/273576
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I440767d7d500b135f5fbd4f69f4b150413263f8e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to