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 ) {
37 return self
::makeForeignLink( $wiki_id, "User:$user" );
40 static function makeForeignLink( $wiki_id, $page, $text=null ) {
42 $sk = $wgUser->getSkin();
47 return $sk->makeExternalLink( self
::getForeignURL( $wiki_id, $page ) , $text );
50 static function getForeignURL( $wiki_id, $page ) {
51 $wiki = WikiMap
::getWiki( $wiki_id );
54 return $wiki->getUrl( $page );
61 private $mMinor; ///< 'en', 'meta', 'mediawiki', etc
62 private $mMajor; ///< 'wiki', 'wiktionary', etc
63 private $mServer; ///< server override, 'www.mediawiki.org'
64 private $mPath; ///< path override, '/wiki/$1'
66 function __construct( $major, $minor, $server, $path ) {
67 $this->mMajor
= $major;
68 $this->mMinor
= $minor;
69 $this->mServer
= $server;
73 function getHostname() {
74 $prefixes = array( 'http://', 'https://' );
75 foreach ( $prefixes as $prefix ) {
76 if ( substr( $this->mServer
, 0, strlen( $prefix ) ) ) {
77 return substr( $this->mServer
, strlen( $prefix ) );
80 throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
86 function getDisplayName() {
87 $url = $this->getUrl( '' );
88 $url = preg_replace( '!^https?://!', '', $url );
89 $url = preg_replace( '!/index\.php(\?title=|/)$!', '/', $url );
90 $url = preg_replace( '!/wiki/$!', '/', $url );
91 $url = preg_replace( '!/$!', '', $url );
95 private function getLocalUrl( $page ) {
96 // FIXME: this may be generalized...
97 return str_replace( '$1', wfUrlEncode( str_replace( ' ', '_', $page ) ), $this->mPath
);
100 function getUrl( $page ) {
103 $this->getLocalUrl( $page );