diff options
author | Alexandre Emsenhuber <ialex@users.mediawiki.org> | 2010-01-12 21:49:47 +0000 |
---|---|---|
committer | Alexandre Emsenhuber <ialex@users.mediawiki.org> | 2010-01-12 21:49:47 +0000 |
commit | 5fc268d803740f0da842c9848e100ae8fcb94816 (patch) | |
tree | 9a3d20d63eb14b3761ada6e65a02ba63fbe2c3a9 /includes/WikiMap.php | |
parent | 28ca5b8bb69421088ae60d79893c2fb84d0e2613 (diff) | |
download | mediawikicore-5fc268d803740f0da842c9848e100ae8fcb94816.tar.gz mediawikicore-5fc268d803740f0da842c9848e100ae8fcb94816.zip |
document a bit
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/60988
Diffstat (limited to 'includes/WikiMap.php')
-rw-r--r-- | includes/WikiMap.php | 106 |
1 files changed, 79 insertions, 27 deletions
diff --git a/includes/WikiMap.php b/includes/WikiMap.php index 307916e1842c..e68a232f8e9b 100644 --- a/includes/WikiMap.php +++ b/includes/WikiMap.php @@ -3,11 +3,17 @@ /** * Helper tools for dealing with other locally-hosted wikis */ - class WikiMap { - static function getWiki( $wikiID ) { + + /** + * Get a WikiReference object for $wikiID + * + * @param $wikiID String: wiki'd id (generally database name) + * @return WikiReference object or null if the wiki was not found + */ + public static function getWiki( $wikiID ) { global $wgConf, $IP; - + $wgConf->loadFullData(); list( $major, $minor ) = $wgConf->siteFromDB( $wikiID ); @@ -22,59 +28,90 @@ class WikiMap { } } - // Convenience functions from GlobalBlocking - static function getWikiName( $wiki_id ) { - // We can give more info than just the wiki id! - $wiki = WikiMap::getWiki( $wiki_id ); - - if ($wiki) { + /** + * Convenience to get the wiki's display name + * + * @todo We can give more info than just the wiki id! + * @param $wikiID String: wiki'd id (generally database name) + * @return Wiki's name or $wiki_id if the wiki was not found + */ + public static function getWikiName( $wikiID ) { + $wiki = WikiMap::getWiki( $wikiID ); + + if ( $wiki ) { return $wiki->getDisplayName(); } return $wiki_id; } - - static function foreignUserLink( $wiki_id, $user, $text=null ) { - return self::makeForeignLink( $wiki_id, "User:$user", $text ); + + /** + * Convenience to get a link to a user page on a foreign wiki + * + * @param $wikiID String: wiki'd id (generally database name) + * @param $user String: user name (must be normalised before calling this function!) + * @param $text String: link's text; optional, default to "User:$user" + * @return String: HTML link or false if the wiki was not found + */ + public static function foreignUserLink( $wikiID, $user, $text=null ) { + return self::makeForeignLink( $wikiID, "User:$user", $text ); } - - static function makeForeignLink( $wiki_id, $page, $text=null ) { + + /** + * Convenience to get a link to a page on a foreign wiki + * + * @param $wikiID String: wiki'd id (generally database name) + * @param $page String: page name (must be normalised before calling this function!) + * @param $text String: link's text; optional, default to $page + * @return String: HTML link or false if the wiki was not found + */ + public static function makeForeignLink( $wikiID, $page, $text=null ) { global $wgUser; $sk = $wgUser->getSkin(); if ( !$text ) - $text=$page; + $text = $page; - $url = self::getForeignURL( $wiki_id, $page ); + $url = self::getForeignURL( $wikiID, $page ); if ( $url === false ) return false; return $sk->makeExternalLink( $url, $text ); } - - static function getForeignURL( $wiki_id, $page ) { - $wiki = WikiMap::getWiki( $wiki_id ); + + /** + * Convenience to get a url to a page on a foreign wiki + * + * @param $wikiID String: wiki'd id (generally database name) + * @param $page String: page name (must be normalised before calling this function!) + * @return String: URL or false if the wiki was not found + */ + public static function getForeignURL( $wikiID, $page ) { + $wiki = WikiMap::getWiki( $wikiID ); - if ($wiki) + if ( $wiki ) return $wiki->getUrl( $page ); return false; } } +/** + * Reference to a locally-hosted wiki + */ class WikiReference { private $mMinor; ///< 'en', 'meta', 'mediawiki', etc private $mMajor; ///< 'wiki', 'wiktionary', etc private $mServer; ///< server override, 'www.mediawiki.org' private $mPath; ///< path override, '/wiki/$1' - function __construct( $major, $minor, $server, $path ) { + public function __construct( $major, $minor, $server, $path ) { $this->mMajor = $major; $this->mMinor = $minor; $this->mServer = $server; $this->mPath = $path; } - function getHostname() { + public function getHostname() { $prefixes = array( 'http://', 'https://' ); foreach ( $prefixes as $prefix ) { if ( substr( $this->mServer, 0, strlen( $prefix ) ) ) { @@ -85,9 +122,12 @@ class WikiReference { } /** - * pretty it up + * Get the the URL in a way to de displayed to the user + * More or less Wikimedia specific + * + * @return String */ - function getDisplayName() { + public function getDisplayName() { $url = $this->getUrl( '' ); $url = preg_replace( '!^https?://!', '', $url ); $url = preg_replace( '!/index\.php(\?title=|/)$!', '/', $url ); @@ -96,14 +136,26 @@ class WikiReference { return $url; } + /** + * Helper function for getUrl() + * + * @todo FIXME: this may be generalized... + * @param $page String: page name (must be normalised before calling this function!) + * @return String: Url fragment + */ private function getLocalUrl( $page ) { - // FIXME: this may be generalized... return str_replace( '$1', wfUrlEncode( str_replace( ' ', '_', $page ) ), $this->mPath ); } - function getUrl( $page ) { + /** + * Get a URL to a page on this foreign wiki + * + * @param $page String: page name (must be normalised before calling this function!) + * @return String: Url + */ + public function getUrl( $page ) { return - $this->mServer . + $this->mServer . $this->getLocalUrl( $page ); } } |