Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -209,6 +209,8 @@ |
210 | 210 | 'WikiError' => 'includes/WikiError.php', |
211 | 211 | 'WikiErrorMsg' => 'includes/WikiError.php', |
212 | 212 | 'WikiExporter' => 'includes/Export.php', |
| 213 | + 'WikiMap' => 'includes/WikiMap.php', |
| 214 | + 'WikiReference' => 'includes/WikiReference.php', |
213 | 215 | 'WikiXmlError' => 'includes/WikiError.php', |
214 | 216 | 'XCacheBagOStuff' => 'includes/BagOStuff.php', |
215 | 217 | 'XmlDumpWriter' => 'includes/Export.php', |
Index: trunk/phase3/includes/WikiMap.php |
— | — | @@ -0,0 +1,112 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Helper tools for dealing with other locally-hosted wikis |
| 6 | + */ |
| 7 | + |
| 8 | +class WikiMap { |
| 9 | + static function getWiki( $wikiID ) { |
| 10 | + global $wgConf, $IP; |
| 11 | + static $initialiseSettingsDone = false; |
| 12 | + |
| 13 | + // This is a damn dirty hack |
| 14 | + if ( !$initialiseSettingsDone ) { |
| 15 | + $initialiseSettingsDone = true; |
| 16 | + if( file_exists( "$IP/InitialiseSettings.php" ) ) { |
| 17 | + require_once "$IP/InitialiseSettings.php"; |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + list( $major, $minor ) = $wgConf->siteFromDB( $wikiID ); |
| 22 | + if( isset( $major ) ) { |
| 23 | + $server = $wgConf->get( 'wgServer', $wikiID, $major, |
| 24 | + array( 'lang' => $minor, 'site' => $major ) ); |
| 25 | + $path = $wgConf->get( 'wgArticlePath', $wikiID, $major, |
| 26 | + array( 'lang' => $minor, 'site' => $major ) ); |
| 27 | + return new WikiReference( $major, $minor, $server, $path ); |
| 28 | + } else { |
| 29 | + return null; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + // Convenience functions from GlobalBlocking |
| 34 | + static function getWikiName( $wiki_id ) { |
| 35 | + // We can give more info than just the wiki id! |
| 36 | + $wiki = WikiMap::getWiki( $wiki_id ); |
| 37 | + |
| 38 | + if ($wiki) { |
| 39 | + return $wiki->getDisplayName(); |
| 40 | + } |
| 41 | + return $wiki_id; |
| 42 | + } |
| 43 | + |
| 44 | + static function foreignUserLink( $wiki_id, $user ) { |
| 45 | + return self::makeForeignLink( $wiki_id, "User:$user" ); |
| 46 | + } |
| 47 | + |
| 48 | + static function makeForeignLink( $wiki_id, $page, $text=null ) { |
| 49 | + global $wgUser; |
| 50 | + $sk = $wgUser->getSkin(); |
| 51 | + |
| 52 | + if (!$text) |
| 53 | + $text=$page; |
| 54 | + |
| 55 | + return $sk->makeExternalLink( self::getForeignURL( $wiki_id, $page ) , $text ); |
| 56 | + } |
| 57 | + |
| 58 | + static function getForeignURL( $wiki_id, $page ) { |
| 59 | + $wiki = WikiMap::getWiki( $wiki_id ); |
| 60 | + |
| 61 | + if ($wiki) |
| 62 | + return $wiki->getUrl( $page ); |
| 63 | + |
| 64 | + return false; |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +class WikiReference { |
| 69 | + private $mMinor; ///< 'en', 'meta', 'mediawiki', etc |
| 70 | + private $mMajor; ///< 'wiki', 'wiktionary', etc |
| 71 | + private $mServer; ///< server override, 'www.mediawiki.org' |
| 72 | + private $mPath; ///< path override, '/wiki/$1' |
| 73 | + |
| 74 | + function __construct( $major, $minor, $server, $path ) { |
| 75 | + $this->mMajor = $major; |
| 76 | + $this->mMinor = $minor; |
| 77 | + $this->mServer = $server; |
| 78 | + $this->mPath = $path; |
| 79 | + } |
| 80 | + |
| 81 | + function getHostname() { |
| 82 | + $prefixes = array( 'http://', 'https://' ); |
| 83 | + foreach ( $prefixes as $prefix ) { |
| 84 | + if ( substr( $this->mServer, 0, strlen( $prefix ) ) ) { |
| 85 | + return substr( $this->mServer, strlen( $prefix ) ); |
| 86 | + } |
| 87 | + } |
| 88 | + throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" ); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * pretty it up |
| 93 | + */ |
| 94 | + function getDisplayName() { |
| 95 | + $url = $this->getUrl( '' ); |
| 96 | + $url = preg_replace( '!^https?://!', '', $url ); |
| 97 | + $url = preg_replace( '!/index\.php(\?title=|/)$!', '/', $url ); |
| 98 | + $url = preg_replace( '!/wiki/$!', '/', $url ); |
| 99 | + $url = preg_replace( '!/$!', '', $url ); |
| 100 | + return $url; |
| 101 | + } |
| 102 | + |
| 103 | + private function getLocalUrl( $page ) { |
| 104 | + // FIXME: this may be generalized... |
| 105 | + return str_replace( '$1', wfUrlEncode( str_replace( ' ', '_', $page ) ), $this->mPath ); |
| 106 | + } |
| 107 | + |
| 108 | + function getUrl( $page ) { |
| 109 | + return |
| 110 | + $this->mServer . |
| 111 | + $this->getLocalUrl( $page ); |
| 112 | + } |
| 113 | +} |
Property changes on: trunk/phase3/includes/WikiMap.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 114 | + native |
Index: trunk/extensions/CentralAuth/WikiMap.php |
— | — | @@ -1,79 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Helper tools for dealing with other locally-hosted wikis |
6 | | - */ |
7 | | - |
8 | | -class WikiMap { |
9 | | - static function getWiki( $wikiID ) { |
10 | | - global $wgConf, $IP; |
11 | | - static $initialiseSettingsDone = false; |
12 | | - |
13 | | - // This is a damn dirty hack |
14 | | - if ( !$initialiseSettingsDone ) { |
15 | | - $initialiseSettingsDone = true; |
16 | | - if( file_exists( "$IP/InitialiseSettings.php" ) ) { |
17 | | - require_once "$IP/InitialiseSettings.php"; |
18 | | - } |
19 | | - } |
20 | | - |
21 | | - list( $major, $minor ) = $wgConf->siteFromDB( $wikiID ); |
22 | | - if( isset( $major ) ) { |
23 | | - $server = $wgConf->get( 'wgServer', $wikiID, $major, |
24 | | - array( 'lang' => $minor, 'site' => $major ) ); |
25 | | - $path = $wgConf->get( 'wgArticlePath', $wikiID, $major, |
26 | | - array( 'lang' => $minor, 'site' => $major ) ); |
27 | | - return new WikiReference( $major, $minor, $server, $path ); |
28 | | - } else { |
29 | | - return null; |
30 | | - } |
31 | | - |
32 | | - } |
33 | | -} |
34 | | - |
35 | | -class WikiReference { |
36 | | - private $mMinor; ///< 'en', 'meta', 'mediawiki', etc |
37 | | - private $mMajor; ///< 'wiki', 'wiktionary', etc |
38 | | - private $mServer; ///< server override, 'www.mediawiki.org' |
39 | | - private $mPath; ///< path override, '/wiki/$1' |
40 | | - |
41 | | - function __construct( $major, $minor, $server, $path ) { |
42 | | - $this->mMajor = $major; |
43 | | - $this->mMinor = $minor; |
44 | | - $this->mServer = $server; |
45 | | - $this->mPath = $path; |
46 | | - } |
47 | | - |
48 | | - function getHostname() { |
49 | | - $prefixes = array( 'http://', 'https://' ); |
50 | | - foreach ( $prefixes as $prefix ) { |
51 | | - if ( substr( $this->mServer, 0, strlen( $prefix ) ) ) { |
52 | | - return substr( $this->mServer, strlen( $prefix ) ); |
53 | | - } |
54 | | - } |
55 | | - throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" ); |
56 | | - } |
57 | | - |
58 | | - /** |
59 | | - * pretty it up |
60 | | - */ |
61 | | - function getDisplayName() { |
62 | | - $url = $this->getUrl( '' ); |
63 | | - $url = preg_replace( '!^https?://!', '', $url ); |
64 | | - $url = preg_replace( '!/index\.php(\?title=|/)$!', '/', $url ); |
65 | | - $url = preg_replace( '!/wiki/$!', '/', $url ); |
66 | | - $url = preg_replace( '!/$!', '', $url ); |
67 | | - return $url; |
68 | | - } |
69 | | - |
70 | | - private function getLocalUrl( $page ) { |
71 | | - // FIXME: this may be generalized... |
72 | | - return str_replace( '$1', wfUrlEncode( str_replace( ' ', '_', $page ) ), $this->mPath ); |
73 | | - } |
74 | | - |
75 | | - function getUrl( $page ) { |
76 | | - return |
77 | | - $this->mServer . |
78 | | - $this->getLocalUrl( $page ); |
79 | | - } |
80 | | -} |
Index: trunk/extensions/CentralAuth/CentralAuth.php |
— | — | @@ -138,8 +138,6 @@ |
139 | 139 | $wgAutoloadClasses['CentralAuthUser'] = "$caBase/CentralAuthUser.php"; |
140 | 140 | $wgAutoloadClasses['CentralAuthPlugin'] = "$caBase/CentralAuthPlugin.php"; |
141 | 141 | $wgAutoloadClasses['CentralAuthHooks'] = "$caBase/CentralAuthHooks.php"; |
142 | | -$wgAutoloadClasses['WikiMap'] = "$caBase/WikiMap.php"; |
143 | | -$wgAutoloadClasses['WikiReference'] = "$caBase/WikiMap.php"; |
144 | 142 | $wgAutoloadClasses['WikiSet'] = "$caBase/WikiSet.php"; |
145 | 143 | $wgAutoloadClasses['SpecialAutoLogin'] = "$caBase/SpecialAutoLogin.php"; |
146 | 144 | $wgAutoloadClasses['CentralAuthUserArray'] = "$caBase/CentralAuthUserArray.php"; |