* (bug 13040) Gender-aware user namespace aliases
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Thu, 12 Feb 2009 19:54:32 +0000 (19:54 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Thu, 12 Feb 2009 19:54:32 +0000 (19:54 +0000)
No aliases in this commit

RELEASE-NOTES
includes/DefaultSettings.php
includes/Title.php
languages/Language.php
languages/messages/MessagesEn.php

index 41592c2..c89f537 100644 (file)
@@ -96,6 +96,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Localize time zone regions in Special:Preferences
 * Add NUMBEROFACTIVEUSERS magic word, which is like NUMBEROFUSERS, but uses
   the active users data from site_stats.
+* (bug 13040) Gender-aware user namespace aliases
 
 === Bug fixes in 1.15 ===
 * (bug 16968) Special:Upload no longer throws useless warnings.
index 093bf95..7399a70 100644 (file)
@@ -2644,6 +2644,12 @@ $wgExtraNamespaces = NULL;
  */
 $wgNamespaceAliases = array();
 
+/**
+ * Whether to check correct gender for all titles. If false, correct gender
+ * alias is only fetched for wgTitle.
+ */
+$wgSlowGenderAliases = true;
+
 /**
  * Limit images on image description pages to a user-selectable limit. In order
  * to reduce disk usage, limits can only be selected from a list.
index d7b57ef..649f764 100644 (file)
@@ -554,7 +554,7 @@ class Title {
         * @return \type{\string} Namespace text
         */
        public function getNsText() {
-               global $wgContLang, $wgCanonicalNamespaceNames;
+               global $wgCanonicalNamespaceNames;
 
                if ( '' != $this->mInterwiki ) {
                        // This probably shouldn't even happen. ohh man, oh yuck.
@@ -567,6 +567,35 @@ class Title {
                                return $wgCanonicalNamespaceNames[$this->mNamespace];
                        }
                }
+
+               return $this->getNsTextInternal( $this->mNamespace );
+       }
+
+       function getNsTextInternal( $namespace) {
+               global $wgContLang, $wgSlowGenderAliases, $wgTitle, $title;
+               if( $namespace === NS_USER || $namespace === NS_USER_TALK ) {
+                       static $gender = null;
+
+                       $name = $this->getBaseText();
+                       if( !isset($gender[$name] ) ) {
+                               $gender[$name] = User::getDefaultOption( 'gender' );
+
+                               // wgTitle may not be defined
+                               $mytitle = isset($wgTitle) ? $wgTitle: Title::newFromText($title);
+
+                               // Check stuff
+                               if ( $wgSlowGenderAliases ||
+                                    // Needs to be checked always to produce desired
+                                    // effect when viewing user pages
+                                    ($mytitle && $name === $mytitle->getBaseText()) ) {
+
+                                       $user = User::newFromName( $name );
+                                       if ( $user ) $gender[$name] = $user->getOption( 'gender' );
+                               }
+                       }
+
+                       return $wgContLang->getGenderNsText( $this->mNamespace, $gender[$name] );
+               }
                return $wgContLang->getNsText( $this->mNamespace );
        }
        /**
@@ -581,16 +610,14 @@ class Title {
         * @return \type{\string} Namespace text
         */
        public function getSubjectNsText() {
-               global $wgContLang;
-               return $wgContLang->getNsText( MWNamespace::getSubject( $this->mNamespace ) );
+               return $this->getNsTextInternal( MWNamespace::getSubject( $this->mNamespace ) );
        }
        /**
         * Get the namespace text of the talk page
         * @return \type{\string} Namespace text
         */
        public function getTalkNsText() {
-               global $wgContLang;
-               return( $wgContLang->getNsText( MWNamespace::getTalk( $this->mNamespace ) ) );
+               return $this->getNsTextInternal( MWNamespace::getTalk( $this->mNamespace ) );
        }
        /**
         * Could this title have a corresponding talk page?
index 427e7a9..9828383 100644 (file)
@@ -63,7 +63,7 @@ class Language {
                'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
                'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
                'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
-               'imageFiles'
+               'imageFiles', 'genderAliases'
        );
 
        static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
@@ -265,6 +265,18 @@ class Language {
                return isset( $ns[$index] ) ? $ns[$index] : false;
        }
 
+       /**
+        * Like getNsText, but looks first if there is custom alias for given gender
+        */
+       function getGenderNsText( $index, $gender ) {
+               $this->load();
+               if ( isset( $this->genderAliases[$index][$gender] ) ) {
+                       return $this->genderAliases[$index][$gender];
+               } else {
+                       return $this->getNsText( $index );
+               }
+       }
+
        /**
         * A convenience function that returns the same thing as
         * getNsText() except with '_' changed to ' ', useful for
@@ -2324,7 +2336,7 @@ class Language {
         *
         * @return array Dependencies, map of filenames to mtimes
         */
-       static function loadLocalisation( $code, $disableCache = false ) {
+       static function loadLocalisation( $code, $disableCache = true ) {
                static $recursionGuard = array();
                global $wgMemc, $wgEnableSerializedMessages, $wgCheckSerialized;
 
@@ -2592,6 +2604,12 @@ class Language {
                foreach ( $this->namespaceNames as $index => $name ) {
                        $this->mNamespaceIds[$this->lc($name)] = $index;
                }
+               # Add gender aliases to the normal aliases table automatically
+               foreach ( $this->genderAliases as $index => $aliases ) {
+                       foreach ( $aliases as $alias ) {
+                               $this->namespaceAliases[$alias] = $index;
+                       }
+               }
                if ( $this->namespaceAliases ) {
                        foreach ( $this->namespaceAliases as $name => $index ) {
                                if ( $index === NS_PROJECT_TALK ) {
index 62128bf..c5bb7bd 100644 (file)
@@ -98,6 +98,18 @@ $namespaceNames = array(
        NS_CATEGORY_TALK    => 'Category_talk',
 );
 
+/**
+ * Array of gender-based namespace aliases per namespace. Only NS_USER and
+ * NS_USER_TALK works.
+ *
+ * Example:
+       NS_USER => array(
+               'male'   => 'Male_user',
+               'female' => 'Female_user',
+       ),
+ */
+$genderAliases = array();
+
 /**
  * Array of namespace aliases, mapping from name to NS_xxx index
  */