r47196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47195‎ | r47196 | r47197 >
Date:19:54, 12 February 2009
Author:nikerabbit
Status:reverted (Comments)
Tags:
Comment:
* (bug 13040) Gender-aware user namespace aliases
No aliases in this commit
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -554,7 +554,7 @@
555555 * @return \type{\string} Namespace text
556556 */
557557 public function getNsText() {
558 - global $wgContLang, $wgCanonicalNamespaceNames;
 558+ global $wgCanonicalNamespaceNames;
559559
560560 if ( '' != $this->mInterwiki ) {
561561 // This probably shouldn't even happen. ohh man, oh yuck.
@@ -567,6 +567,35 @@
568568 return $wgCanonicalNamespaceNames[$this->mNamespace];
569569 }
570570 }
 571+
 572+ return $this->getNsTextInternal( $this->mNamespace );
 573+ }
 574+
 575+ function getNsTextInternal( $namespace) {
 576+ global $wgContLang, $wgSlowGenderAliases, $wgTitle, $title;
 577+ if( $namespace === NS_USER || $namespace === NS_USER_TALK ) {
 578+ static $gender = null;
 579+
 580+ $name = $this->getBaseText();
 581+ if( !isset($gender[$name] ) ) {
 582+ $gender[$name] = User::getDefaultOption( 'gender' );
 583+
 584+ // wgTitle may not be defined
 585+ $mytitle = isset($wgTitle) ? $wgTitle: Title::newFromText($title);
 586+
 587+ // Check stuff
 588+ if ( $wgSlowGenderAliases ||
 589+ // Needs to be checked always to produce desired
 590+ // effect when viewing user pages
 591+ ($mytitle && $name === $mytitle->getBaseText()) ) {
 592+
 593+ $user = User::newFromName( $name );
 594+ if ( $user ) $gender[$name] = $user->getOption( 'gender' );
 595+ }
 596+ }
 597+
 598+ return $wgContLang->getGenderNsText( $this->mNamespace, $gender[$name] );
 599+ }
571600 return $wgContLang->getNsText( $this->mNamespace );
572601 }
573602 /**
@@ -581,16 +610,14 @@
582611 * @return \type{\string} Namespace text
583612 */
584613 public function getSubjectNsText() {
585 - global $wgContLang;
586 - return $wgContLang->getNsText( MWNamespace::getSubject( $this->mNamespace ) );
 614+ return $this->getNsTextInternal( MWNamespace::getSubject( $this->mNamespace ) );
587615 }
588616 /**
589617 * Get the namespace text of the talk page
590618 * @return \type{\string} Namespace text
591619 */
592620 public function getTalkNsText() {
593 - global $wgContLang;
594 - return( $wgContLang->getNsText( MWNamespace::getTalk( $this->mNamespace ) ) );
 621+ return $this->getNsTextInternal( MWNamespace::getTalk( $this->mNamespace ) );
595622 }
596623 /**
597624 * Could this title have a corresponding talk page?
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2645,6 +2645,12 @@
26462646 $wgNamespaceAliases = array();
26472647
26482648 /**
 2649+ * Whether to check correct gender for all titles. If false, correct gender
 2650+ * alias is only fetched for wgTitle.
 2651+ */
 2652+$wgSlowGenderAliases = true;
 2653+
 2654+/**
26492655 * Limit images on image description pages to a user-selectable limit. In order
26502656 * to reduce disk usage, limits can only be selected from a list.
26512657 * The user preference is saved as an array offset in the database, by default
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -99,6 +99,18 @@
100100 );
101101
102102 /**
 103+ * Array of gender-based namespace aliases per namespace. Only NS_USER and
 104+ * NS_USER_TALK works.
 105+ *
 106+ * Example:
 107+ NS_USER => array(
 108+ 'male' => 'Male_user',
 109+ 'female' => 'Female_user',
 110+ ),
 111+ */
 112+$genderAliases = array();
 113+
 114+/**
103115 * Array of namespace aliases, mapping from name to NS_xxx index
104116 */
105117 $namespaceAliases = array();
Index: trunk/phase3/languages/Language.php
@@ -63,7 +63,7 @@
6464 'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
6565 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
6666 'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
67 - 'imageFiles'
 67+ 'imageFiles', 'genderAliases'
6868 );
6969
7070 static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
@@ -266,6 +266,18 @@
267267 }
268268
269269 /**
 270+ * Like getNsText, but looks first if there is custom alias for given gender
 271+ */
 272+ function getGenderNsText( $index, $gender ) {
 273+ $this->load();
 274+ if ( isset( $this->genderAliases[$index][$gender] ) ) {
 275+ return $this->genderAliases[$index][$gender];
 276+ } else {
 277+ return $this->getNsText( $index );
 278+ }
 279+ }
 280+
 281+ /**
270282 * A convenience function that returns the same thing as
271283 * getNsText() except with '_' changed to ' ', useful for
272284 * producing output.
@@ -2324,7 +2336,7 @@
23252337 *
23262338 * @return array Dependencies, map of filenames to mtimes
23272339 */
2328 - static function loadLocalisation( $code, $disableCache = false ) {
 2340+ static function loadLocalisation( $code, $disableCache = true ) {
23292341 static $recursionGuard = array();
23302342 global $wgMemc, $wgEnableSerializedMessages, $wgCheckSerialized;
23312343
@@ -2592,6 +2604,12 @@
25932605 foreach ( $this->namespaceNames as $index => $name ) {
25942606 $this->mNamespaceIds[$this->lc($name)] = $index;
25952607 }
 2608+ # Add gender aliases to the normal aliases table automatically
 2609+ foreach ( $this->genderAliases as $index => $aliases ) {
 2610+ foreach ( $aliases as $alias ) {
 2611+ $this->namespaceAliases[$alias] = $index;
 2612+ }
 2613+ }
25962614 if ( $this->namespaceAliases ) {
25972615 foreach ( $this->namespaceAliases as $name => $index ) {
25982616 if ( $index === NS_PROJECT_TALK ) {
Index: trunk/phase3/RELEASE-NOTES
@@ -96,6 +96,7 @@
9797 * Localize time zone regions in Special:Preferences
9898 * Add NUMBEROFACTIVEUSERS magic word, which is like NUMBEROFUSERS, but uses
9999 the active users data from site_stats.
 100+* (bug 13040) Gender-aware user namespace aliases
100101
101102 === Bug fixes in 1.15 ===
102103 * (bug 16968) Special:Upload no longer throws useless warnings.

Follow-up revisions

RevisionCommit summaryAuthorDate
r47219bug 17477 and fix for r47196: Don't use global $title; this can work when exe...ialex17:50, 13 February 2009
r47391Revert r47196, r47219 "* (bug 13040) Gender-aware user namespace aliases" and...brion23:00, 17 February 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r46246* (bug 13040) Gender switch in user preferencesnikerabbit09:41, 26 January 2009
r46247* (bug 13040) {{GENDER:}} magic word for interface messagesnikerabbit09:48, 26 January 2009

Comments

#Comment by Brion VIBBER (talk | contribs)   22:56, 17 February 2009

What's this $wgTitle and $title stuff? Code makes no sense; needs revert.

#Comment by Nikerabbit (talk | contribs)   07:17, 18 February 2009

I'd imagine querying the user id for every user page link is not desirable.

#Comment by Brion VIBBER (talk | contribs)   23:01, 17 February 2009

Reverted in r47391

Status & tagging log