r17728 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17727‎ | r17728 | r17729 >
Date:20:48, 16 November 2006
Author:brion
Status:old
Tags:
Comment:
poke poke
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.i18n.php (modified) (history)
  • /trunk/extensions/CentralAuth/SpecialMergeAccount.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/SpecialMergeAccount.php
@@ -13,26 +13,101 @@
1414
1515 */
1616
17 -class CentralAuth {
18 - static function foreignHostname( $dbname ) {
19 - $map = array(
20 - 'enwiki' => 'en.wikipedia.org',
21 - 'enwikisource' => 'en.wikisource.org',
22 - 'frwiki' => 'fr.wikipedia.org',
 17+global $wgSecureUrlHost;
 18+$wgSecureUrlHost = 'secure.wikimedia.org';
 19+
 20+class WikiMap {
 21+ function byDatabase( $dbname ) {
 22+ $suffixes = array(
 23+ 'wiki' => 'wikipedia',
 24+ 'wikisource' => 'wikisource',
 25+ 'wikinews' => 'wikinews',
 26+ 'wiktionary' => 'wiktionary',
 27+ );
 28+ $overrides = array(
2329 'metawiki' => 'meta.wikimedia.org',
2430 'mediawikiwiki' => 'www.mediawiki.org',
25 - 'enwikinews' => 'en.wikinews.org',
26 - 'frwikisource' => 'fr.wikisource.org',
27 - 'zhwiktionary' => 'zh.wiktionary.org',
2831 );
29 - return $map[$dbname];
 32+ foreach( $suffixes as $suffix => $family ) {
 33+ if( substr( $dbname, -strlen( $suffix ) ) == $suffix ) {
 34+ $major = $family;
 35+ $minor = substr( $dbname, 0, strlen( $dbname ) - strlen( $suffix ) );
 36+ break;
 37+ }
 38+ }
 39+ if( !isset( $major ) ) {
 40+ return null;
 41+ }
 42+ $hostname = @$overrides[$dbname];
 43+ return new WikiReference( $major, $minor, $hostname );
3044 }
 45+}
 46+
 47+class WikiReference {
 48+ private $mMinor; ///< 'en', 'meta', 'mediawiki', etc
 49+ private $mMajor; ///< 'wiki', 'wiktionary', etc
 50+ private $mHostname; ///< hostname override, 'www.mediawiki.org'
3151
32 - static function foreignUrl( $dbname, $title ) {
33 - $host = self::foreignHostname( $dbname );
34 - return "http://$host/wiki/" .
35 - wfUrlencode( $title );
 52+ function __construct( $major, $minor, $hostname=null ) {
 53+ $this->mMajor = $major;
 54+ $this->mMinor = $minor;
 55+ $this->mHostname = $hostname;
3656 }
 57+
 58+ function getHostname() {
 59+ if( $this->mHostname ) {
 60+ return $this->mHostname;
 61+ } else {
 62+ return $this->mMinor .
 63+ '.' .
 64+ $this->mMajor .
 65+ '.org';
 66+ }
 67+ }
 68+
 69+ private function getLocalUrl( $page ) {
 70+ // FIXME: this may be generalized...
 71+ return '/wiki/' . urlencode( $page );
 72+ }
 73+
 74+ function getCanonicalUrl( $page ) {
 75+ return
 76+ 'http://' .
 77+ $this->getHostname() .
 78+ $this->getLocalUrl( $page );
 79+ }
 80+
 81+ function getSecureUrl( $page ) {
 82+ global $wgSecureUrlHost;
 83+ if( $wgSecureUrlHost ) {
 84+ // For the current secure.wikimedia.org hack
 85+ // In the future we'll want to move to a nice
 86+ // clean https://en.wikipedia.org/ etc
 87+ return
 88+ 'https://' .
 89+ $wgSecureUrlHost .
 90+ '/' . $this->mMajor .
 91+ '/' . $this->mMinor .
 92+ $this->getLocalUrl( $page );
 93+ } else {
 94+ return
 95+ 'https://' .
 96+ $this->getHostname() .
 97+ $this->getLocalUrl( $page );
 98+ }
 99+ }
 100+
 101+ /**
 102+ * If the current user is coming over HTTPS, return
 103+ * the secure URL to match...
 104+ */
 105+ function getUrl( $page ) {
 106+ if( isset( $_SERVER['HTTPS'] ) ) {
 107+ return $this->getSecureUrl( $page );
 108+ } else {
 109+ return $this->getCanonicalUrl( $page );
 110+ }
 111+ }
37112 }
38113
39114 class SpecialMergeAccount extends SpecialPage {
@@ -104,9 +179,14 @@
105180 }
106181
107182 function foreignUserLink( $dbname ) {
108 - $hostname = CentralAuth::foreignHostname( $dbname );
 183+ $wiki = WikiMap::byDatabase( $dbname );
 184+ if( !$wiki ) {
 185+ throw new MWException( "no wiki for $dbname" );
 186+ }
 187+
 188+ $hostname = $wiki->getHostname();
109189 $userPageName = 'User:' . $this->mUserName;
110 - $url = CentralAuth::foreignUrl( $dbname, $userPageName );
 190+ $url = $wiki->getUrl( $userPageName );
111191 return wfElement( 'a',
112192 array(
113193 'href' => $url,
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php
@@ -31,7 +31,7 @@
3232
3333 // For lists of wikis/accounts:
3434 'centralauth-list-merged' =>
35 - 'The accounts named "$1" on the following Wikimedia sites ' .
 35+ 'The accounts named "$1" on the following sites ' .
3636 'have been automatically merged:',
3737 'centralauth-list-unmerged' =>
3838 'Some accounts could not be automatically confirmed ' .