Don't modify $wgHooks on language object construction
authorTim Starling <tstarling@wikimedia.org>
Thu, 28 Jan 2016 22:40:52 +0000 (09:40 +1100)
committerTim Starling <tstarling@wikimedia.org>
Fri, 29 Jan 2016 04:03:56 +0000 (15:03 +1100)
Previously various language objects would install a hook to update the
shared conversion table cache when the object was constructed. This is
not a good idea since language objects may be constructed even when they
are not the content language, but only the content language is
associated with variant conversion and the conversion cache.

Instead, have WikiPage call a method on $wgContLang directly. I put this
with message cache update since the logic is almost identical.

Change-Id: Ief9c0ef993e39645e74a6e158cb4e6e2139ce91d

12 files changed:
includes/page/WikiPage.php
languages/FakeConverter.php
languages/Language.php
languages/LanguageConverter.php
languages/classes/LanguageGan.php
languages/classes/LanguageIu.php
languages/classes/LanguageKk.php
languages/classes/LanguageKu.php
languages/classes/LanguageShi.php
languages/classes/LanguageSr.php
languages/classes/LanguageUz.php
languages/classes/LanguageZh.php

index c02f975..2e93cb5 100644 (file)
@@ -2200,7 +2200,7 @@ class WikiPage implements Page, IDBAccessObject {
         *   - 'no-change': don't update the article count, ever
         */
        public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
-               global $wgRCWatchCategoryMembership;
+               global $wgRCWatchCategoryMembership, $wgContLang;
 
                $options += array(
                        'changed' => true,
@@ -2329,6 +2329,10 @@ class WikiPage implements Page, IDBAccessObject {
                        }
 
                        MessageCache::singleton()->replace( $shortTitle, $msgtext );
+
+                       if ( $wgContLang->hasVariants() ) {
+                               $wgContLang->updateConversionTable( $this->mTitle );
+                       }
                }
 
                if ( $options['created'] ) {
@@ -3276,6 +3280,8 @@ class WikiPage implements Page, IDBAccessObject {
         * @param Title $title
         */
        public static function onArticleDelete( Title $title ) {
+               global $wgContLang;
+
                // Update existence markers on article/talk tabs...
                $other = $title->getOtherPage();
 
@@ -3291,6 +3297,10 @@ class WikiPage implements Page, IDBAccessObject {
                // Messages
                if ( $title->getNamespace() == NS_MEDIAWIKI ) {
                        MessageCache::singleton()->replace( $title->getDBkey(), false );
+
+                       if ( $wgContLang->hasVariants() ) {
+                               $wgContLang->updateConversionTable( $title );
+                       }
                }
 
                // Images
index 1b6e9d6..b953405 100644 (file)
@@ -114,4 +114,7 @@ class FakeConverter {
        function translate( $text, $variant ) {
                return $text;
        }
+
+       public function updateConversionTable( Title $title ) {
+       }
 }
index cb2d24f..0f10451 100644 (file)
@@ -4244,6 +4244,16 @@ class Language {
                return $this->mConverter->getParsedTitle();
        }
 
+       /**
+        * Refresh the cache of conversion tables when
+        * MediaWiki:Conversiontable* is updated.
+        *
+        * @param Title $titleobj The Title of the page being updated
+        */
+       public function updateConversionTable( Title $title ) {
+               $this->mConverter->updateConversionTable( $title );
+       }
+
        /**
         * Prepare external link text for conversion. When the text is
         * a URL, it shouldn't be converted, and it'll be wrapped in
index b00aa34..4eeba64 100644 (file)
@@ -1053,24 +1053,12 @@ class LanguageConverter {
        }
 
        /**
-        * Hook to refresh the cache of conversion tables when
+        * Refresh the cache of conversion tables when
         * MediaWiki:Conversiontable* is updated.
-        * @private
         *
-        * @param WikiPage $page
-        * @param User $user User object for the current user
-        * @param Content $content New page content
-        * @param string $summary Edit summary of the edit
-        * @param bool $isMinor Was the edit marked as minor?
-        * @param null $isWatch Unused.
-        * @param null $section Unused.
-        * @param int $flags Bitfield
-        * @param Revision|null $revision New Revision object or null
-        * @return bool True
+        * @param Title $titleobj The Title of the page being updated
         */
-       function OnPageContentSaveComplete( $page, $user, $content, $summary, $isMinor,
-                       $isWatch, $section, $flags, $revision ) {
-               $titleobj = $page->getTitle();
+       public function updateConversionTable( Title $titleobj ) {
                if ( $titleobj->getNamespace() == NS_MEDIAWIKI ) {
                        $title = $titleobj->getDBkey();
                        $t = explode( '/', $title, 3 );
@@ -1081,7 +1069,6 @@ class LanguageConverter {
                                }
                        }
                }
-               return true;
        }
 
        /**
index a012f59..3e57415 100644 (file)
@@ -82,7 +82,6 @@ class GanConverter extends LanguageConverter {
  */
 class LanguageGan extends LanguageZh {
        function __construct() {
-               global $wgHooks;
                parent::__construct();
 
                $variants = array( 'gan', 'gan-hans', 'gan-hant' );
@@ -99,8 +98,6 @@ class LanguageGan extends LanguageZh {
                        $variants, $variantfallbacks,
                        array(),
                        $ml );
-
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 
        /**
index db3a22c..3fc5260 100644 (file)
@@ -192,8 +192,6 @@ class IuConverter extends LanguageConverter {
  */
 class LanguageIu extends Language {
        function __construct() {
-               global $wgHooks;
-
                parent::__construct();
 
                $variants = array( 'iu', 'ike-cans', 'ike-latn' );
@@ -205,6 +203,5 @@ class LanguageIu extends Language {
 
                $flags = array();
                $this->mConverter = new IuConverter( $this, 'iu', $variants, $variantfallbacks, $flags );
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 }
index 0f60889..cae83c5 100644 (file)
@@ -395,7 +395,6 @@ class KkConverter extends LanguageConverter {
  */
 class LanguageKk extends LanguageKk_cyrl {
        function __construct() {
-               global $wgHooks;
                parent::__construct();
 
                $variants = array( 'kk', 'kk-cyrl', 'kk-latn', 'kk-arab', 'kk-kz', 'kk-tr', 'kk-cn' );
@@ -410,8 +409,6 @@ class LanguageKk extends LanguageKk_cyrl {
                );
 
                $this->mConverter = new KkConverter( $this, 'kk', $variants, $variantfallbacks );
-
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 
        /**
index 1fdebc2..ea339d7 100644 (file)
@@ -233,7 +233,6 @@ class KuConverter extends LanguageConverter {
 class LanguageKu extends LanguageKu_ku {
 
        function __construct() {
-               global $wgHooks;
                parent::__construct();
 
                $variants = array( 'ku', 'ku-arab', 'ku-latn' );
@@ -244,6 +243,5 @@ class LanguageKu extends LanguageKu_ku {
                );
 
                $this->mConverter = new KuConverter( $this, 'ku', $variants, $variantfallbacks );
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 }
index 105a3af..5c0a8be 100644 (file)
@@ -168,8 +168,6 @@ class ShiConverter extends LanguageConverter {
  */
 class LanguageShi extends Language {
        function __construct() {
-               global $wgHooks;
-
                parent::__construct();
 
                $variants = array( 'shi', 'shi-tfng', 'shi-latn' );
@@ -181,6 +179,5 @@ class LanguageShi extends Language {
 
                $flags = array();
                $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags );
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 }
index bdf1ec4..9ee8320 100644 (file)
@@ -200,8 +200,6 @@ class SrConverter extends LanguageConverter {
  */
 class LanguageSr extends Language {
        function __construct() {
-               global $wgHooks;
-
                parent::__construct();
 
                $variants = array( 'sr', 'sr-ec', 'sr-el' );
@@ -216,6 +214,5 @@ class LanguageSr extends Language {
                        'W' => 'W', 'реч' => 'W', 'reč' => 'W', 'ријеч' => 'W', 'riječ' => 'W'
                );
                $this->mConverter = new SrConverter( $this, 'sr', $variants, $variantfallbacks, $flags );
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 }
index 985de68..2f11e92 100644 (file)
@@ -134,7 +134,6 @@ class UzConverter extends LanguageConverter {
  */
 class LanguageUz extends Language {
        function __construct() {
-               global $wgHooks;
                parent::__construct();
 
                $variants = array( 'uz', 'uz-latn', 'uz-cyrl' );
@@ -145,6 +144,5 @@ class LanguageUz extends Language {
                );
 
                $this->mConverter = new UzConverter( $this, 'uz', $variants, $variantfallbacks );
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 }
index 0f47c38..225df94 100644 (file)
@@ -115,8 +115,6 @@ class ZhConverter extends LanguageConverter {
  */
 class LanguageZh extends LanguageZh_hans {
        function __construct() {
-               global $wgHooks;
-
                parent::__construct();
 
                $variants = array(
@@ -152,8 +150,6 @@ class LanguageZh extends LanguageZh_hans {
                                                                $variants, $variantfallbacks,
                                                                array(),
                                                                $ml );
-
-               $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
        }
 
        /**