* (bug 13040) Gender-aware user namespace aliases
[lhc/web/wiklou.git] / includes / Title.php
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?