Dereckson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/337231 )

Change subject: Add support for namespaces aliases
......................................................................

Add support for namespaces aliases

This changes allows to fix namespaces translations without breaking
the current pages and links in the wiki, by adding former namespaces
names to wgNamespaceAliases. See for example T101634.

Bug: T155737
Change-Id: Ifce90f3570a6a984b3a11b02361001013283ad96
---
M ProofreadPage.namespaces.php
M includes/ProofreadPageInit.php
2 files changed, 32 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ProofreadPage 
refs/changes/31/337231/1

diff --git a/ProofreadPage.namespaces.php b/ProofreadPage.namespaces.php
index fc4f832..1ba9b94 100644
--- a/ProofreadPage.namespaces.php
+++ b/ProofreadPage.namespaces.php
@@ -6,8 +6,9 @@
  * @ingroup Extensions
  */
 
-global $proofreadPageNamespacesNames; // needed in order to be used inside of 
ProofreadPageInit
+global $proofreadPageNamespacesNames, $proofreadPageNamespacesAliases; // 
needed in order to be used inside of ProofreadPageInit
 $proofreadPageNamespacesNames = [];
+$proofreadPageNamespacesAliases = [];
 
 /** English (English) */
 $proofreadPageNamespacesNames['en'] = [
diff --git a/includes/ProofreadPageInit.php b/includes/ProofreadPageInit.php
index 711adee..94624f9 100644
--- a/includes/ProofreadPageInit.php
+++ b/includes/ProofreadPageInit.php
@@ -87,20 +87,48 @@
         * @return bool false if there is an error, true if not
         */
        protected static function createNamespace( $id, $key ) {
-               global $wgCanonicalNamespaceNames, $wgExtraNamespaces;
+               global $wgCanonicalNamespaceNames, $wgExtraNamespaces, 
$wgNamespaceAliases;
 
                if ( isset( $wgExtraNamespaces[$id] ) || isset( 
$wgExtraNamespaces[$id + 1] ) ) {
                        return false;
                }
 
+               $talkKey = $key . '_talk';
+
                $wgExtraNamespaces[$id] = self::getNamespaceName( $key );
-               $wgExtraNamespaces[$id + 1] = self::getNamespaceName( $key . 
'_talk' );
+               $wgExtraNamespaces[$id + 1] = self::getNamespaceName( $talkKey 
);
+
                $wgCanonicalNamespaceNames[$id] = $wgExtraNamespaces[$id]; // 
Very hugly but needed because initNamespaces() is called after the add of 
$wgExtraNamespaces into $wgCanonicalNamespaceNames
                $wgCanonicalNamespaceNames[$id + 1] = $wgExtraNamespaces[$id + 
1];
 
+               self::createNamespaceAliases( $key, $id );
+               self::createNamespaceAliases( $talkKey, $id + 1 );
+
                return true;
        }
 
+       private static function createNamespaceAliases ( $key, $id ) {
+               global $wgNamespaceAliases;
+
+               $aliases = self::getAliases ( $key );
+               foreach ( $aliases as $alias ) {
+                       $wgNamespaceAliases[$alias] = $id;
+               }
+       }
+
+       /**
+        * @return array
+        */
+       private static function getAliases ( $key ) {
+               global $proofreadPageNamespacesAliases, $wgLanguageCode;
+
+               if ( !isset( 
$proofreadPageNamespacesAliases[$wgLanguageCode][$key] ) ) {
+                       return [];
+               }
+
+               return $proofreadPageNamespacesAliases[$wgLanguageCode][$key];
+       }
+
        /**
         * Return the internationalized name of a namespace as set in 
proofreadPageNamespacesNames.
         * The english language is used as fallback.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifce90f3570a6a984b3a11b02361001013283ad96
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ProofreadPage
Gerrit-Branch: master
Gerrit-Owner: Dereckson <[email protected]>

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

Reply via email to