Index: trunk/extensions/CentralAuth/SpecialMergeAccount.php |
— | — | @@ -13,26 +13,101 @@ |
14 | 14 | |
15 | 15 | */ |
16 | 16 | |
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( |
23 | 29 | 'metawiki' => 'meta.wikimedia.org', |
24 | 30 | 'mediawikiwiki' => 'www.mediawiki.org', |
25 | | - 'enwikinews' => 'en.wikinews.org', |
26 | | - 'frwikisource' => 'fr.wikisource.org', |
27 | | - 'zhwiktionary' => 'zh.wiktionary.org', |
28 | 31 | ); |
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 ); |
30 | 44 | } |
| 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' |
31 | 51 | |
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; |
36 | 56 | } |
| 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 | + } |
37 | 112 | } |
38 | 113 | |
39 | 114 | class SpecialMergeAccount extends SpecialPage { |
— | — | @@ -104,9 +179,14 @@ |
105 | 180 | } |
106 | 181 | |
107 | 182 | 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(); |
109 | 189 | $userPageName = 'User:' . $this->mUserName; |
110 | | - $url = CentralAuth::foreignUrl( $dbname, $userPageName ); |
| 190 | + $url = $wiki->getUrl( $userPageName ); |
111 | 191 | return wfElement( 'a', |
112 | 192 | array( |
113 | 193 | 'href' => $url, |
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | |
33 | 33 | // For lists of wikis/accounts: |
34 | 34 | 'centralauth-list-merged' => |
35 | | - 'The accounts named "$1" on the following Wikimedia sites ' . |
| 35 | + 'The accounts named "$1" on the following sites ' . |
36 | 36 | 'have been automatically merged:', |
37 | 37 | 'centralauth-list-unmerged' => |
38 | 38 | 'Some accounts could not be automatically confirmed ' . |