skins: Deprecate MediaWikiI18N::translate()
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 2 Feb 2018 20:54:02 +0000 (12:54 -0800)
committerKrinkle <krinklemail@gmail.com>
Fri, 2 Feb 2018 23:53:19 +0000 (23:53 +0000)
Remove all usage of $tpl->translator->translate() with wfMessage()->text(),
which does the same thing, given the deprecated $tpl->translator->set()
and $tpl->setTranslator() methods have no callers.

These new wfMessage() callers should probably be changed to context calls
via BaseTemplate::msg() or Skin::msg() at some point, but I'm reserving that
for a separate commit given wfMessage() is what MediaWikiI18N::translate()
currently does - to reduce risk of unrelated behaviour changes.

While `$tpl->setTranslator` and `MediaWikiI18N::set` ($tpl->translator->set)
have no known callers in Wikimedia Git, the `$tpl->translator->translate`
method does have a handful of calls (although less than three, and not in
bundled or WMF-deployed repos). As such, proceeding with hard-deprecation.

Bug: T186090
Change-Id: I93d503de5515298288852ec4c150959fd688786b

RELEASE-NOTES-1.31
includes/skins/BaseTemplate.php
includes/skins/MediaWikiI18N.php
includes/skins/QuickTemplate.php

index ba7b86c..576efe8 100644 (file)
@@ -196,6 +196,7 @@ changes to languages because of Phabricator reports.
   used for that. Rather, setRef() existed as memory optimisation for PHP 4.
 * QuickTemplate::setTranslator() was deprecated in favour of Skin::msg() parameters.
 * MediaWikiI18N::set() was deprecated in favour of Skin::msg() parameters.
+* MediaWikiI18N::translate() was deprecated in favour of Skin::msg() or wfMessage().
 * Passing false to ParserOptions::setWrapOutputClass() is deprecated. Use the
   'unwrap' transform to ParserOutput::getText() instead.
 * ParserOutput objects generated using a non-default value for
index bb1d8d0..08ab86a 100644 (file)
@@ -370,7 +370,7 @@ abstract class BaseTemplate extends QuickTemplate {
                if ( isset( $item['text'] ) ) {
                        $text = $item['text'];
                } else {
-                       $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
+                       $text = wfMessage( isset( $item['msg'] ) ? $item['msg'] : $key )->text();
                }
 
                $html = htmlspecialchars( $text );
@@ -541,8 +541,7 @@ abstract class BaseTemplate extends QuickTemplate {
                                $realAttrs = [
                                        'type' => 'submit',
                                        'name' => $mode,
-                                       'value' => $this->translator->translate(
-                                               $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
+                                       'value' => wfMessage( $mode == 'go' ? 'searcharticle' : 'searchbutton' )->text(),
                                ];
                                $realAttrs = array_merge(
                                        $realAttrs,
@@ -568,7 +567,7 @@ abstract class BaseTemplate extends QuickTemplate {
                                        'src' => $attrs['src'],
                                        'alt' => isset( $attrs['alt'] )
                                                ? $attrs['alt']
-                                               : $this->translator->translate( 'searchbutton' ),
+                                               : wfMessage( 'searchbutton' )->text(),
                                        'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
                                        'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
                                ];
index eeedaad..970290a 100644 (file)
@@ -37,7 +37,11 @@ class MediaWikiI18N {
                $this->context[$varName] = $value;
        }
 
+       /**
+        * @deprecate since 1.31 Use BaseTemplate::msg(), Skin::msg(), or wfMessage() instead.
+        */
        function translate( $value ) {
+               wfDeprecated( __METHOD__, '1.31' );
                // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
                $value = preg_replace( '/^string:/', '', $value );
 
index 7782e70..e8466dc 100644 (file)
@@ -136,18 +136,18 @@ abstract class QuickTemplate {
 
        /**
         * @private
-        * @param string $str
+        * @param string $msgKey
         */
-       function msg( $str ) {
-               echo htmlspecialchars( $this->translator->translate( $str ) );
+       function msg( $msgKey ) {
+               echo htmlspecialchars( wfMessage( $msgKey )->text() );
        }
 
        /**
         * @private
-        * @param string $str
+        * @param string $msgKey
         */
-       function msgHtml( $str ) {
-               echo $this->translator->translate( $str );
+       function msgHtml( $msgKey ) {
+               echo wfMessage( $msgKey )->text();
        }
 
        /**
@@ -155,10 +155,10 @@ abstract class QuickTemplate {
         * @private
         * @param string $str
         */
-       function msgWiki( $str ) {
+       function msgWiki( $msgKey ) {
                global $wgOut;
 
-               $text = $this->translator->translate( $str );
+               $text = wfMessage( $msgKey )->text();
                echo $wgOut->parse( $text );
        }
 
@@ -174,12 +174,12 @@ abstract class QuickTemplate {
        /**
         * @private
         *
-        * @param string $str
+        * @param string $msgKey
         * @return bool
         */
-       function haveMsg( $str ) {
-               $msg = $this->translator->translate( $str );
-               return ( $msg != '-' ) && ( $msg != '' ); # ????
+       function haveMsg( $msgKey ) {
+               $msg = wfMessage( $msgKey );
+               return $msg->exists() && !$msg->isDisabled();
        }
 
        /**