307916e1842c13026604887afb28a0e3b4c0feb8
4 * Helper tools for dealing with other locally-hosted wikis
8 static function getWiki( $wikiID ) {
11 $wgConf->loadFullData();
13 list( $major, $minor ) = $wgConf->siteFromDB( $wikiID );
14 if( isset( $major ) ) {
15 $server = $wgConf->get( 'wgServer', $wikiID, $major,
16 array( 'lang' => $minor, 'site' => $major ) );
17 $path = $wgConf->get( 'wgArticlePath', $wikiID, $major,
18 array( 'lang' => $minor, 'site' => $major ) );
19 return new WikiReference( $major, $minor, $server, $path );
25 // Convenience functions from GlobalBlocking
26 static function getWikiName( $wiki_id ) {
27 // We can give more info than just the wiki id!
28 $wiki = WikiMap
::getWiki( $wiki_id );
31 return $wiki->getDisplayName();
36 static function foreignUserLink( $wiki_id, $user, $text=null ) {
37 return self
::makeForeignLink( $wiki_id, "User:$user", $text );
40 static function makeForeignLink( $wiki_id, $page, $text=null ) {
42 $sk = $wgUser->getSkin();
47 $url = self
::getForeignURL( $wiki_id, $page );
51 return $sk->makeExternalLink( $url, $text );
54 static function getForeignURL( $wiki_id, $page ) {
55 $wiki = WikiMap
::getWiki( $wiki_id );
58 return $wiki->getUrl( $page );
65 private $mMinor; ///< 'en', 'meta', 'mediawiki', etc
66 private $mMajor; ///< 'wiki', 'wiktionary', etc
67 private $mServer; ///< server override, 'www.mediawiki.org'
68 private $mPath; ///< path override, '/wiki/$1'
70 function __construct( $major, $minor, $server, $path ) {
71 $this->mMajor
= $major;
72 $this->mMinor
= $minor;
73 $this->mServer
= $server;
77 function getHostname() {
78 $prefixes = array( 'http://', 'https://' );
79 foreach ( $prefixes as $prefix ) {
80 if ( substr( $this->mServer
, 0, strlen( $prefix ) ) ) {
81 return substr( $this->mServer
, strlen( $prefix ) );
84 throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
90 function getDisplayName() {
91 $url = $this->getUrl( '' );
92 $url = preg_replace( '!^https?://!', '', $url );
93 $url = preg_replace( '!/index\.php(\?title=|/)$!', '/', $url );
94 $url = preg_replace( '!/wiki/$!', '/', $url );
95 $url = preg_replace( '!/$!', '', $url );
99 private function getLocalUrl( $page ) {
100 // FIXME: this may be generalized...
101 return str_replace( '$1', wfUrlEncode( str_replace( ' ', '_', $page ) ), $this->mPath
);
104 function getUrl( $page ) {
107 $this->getLocalUrl( $page );