* schema updates etc, which aren't wiki-related)
*/
class Interwiki {
-
// Cache - removes oldest entry when it hits limit
protected static $smCache = array();
const CACHE_LIMIT = 100; // 0 means unlimited, any other value is max number of entries.
protected $mPrefix, $mURL, $mAPI, $mWikiID, $mLocal, $mTrans;
- public function __construct( $prefix = null, $url = '', $api = '', $wikiId = '', $local = 0, $trans = 0 ) {
+ public function __construct( $prefix = null, $url = '', $api = '', $wikiId = '', $local = 0,
+ $trans = 0
+ ) {
$this->mPrefix = $prefix;
$this->mURL = $url;
$this->mAPI = $api;
/**
* Check whether an interwiki prefix exists
*
- * @param $prefix String: interwiki prefix to use
- * @return Boolean: whether it exists
+ * @param string $prefix Interwiki prefix to use
+ * @return bool Whether it exists
*/
static public function isValidInterwiki( $prefix ) {
$result = self::fetch( $prefix );
/**
* Fetch an Interwiki object
*
- * @param $prefix String: interwiki prefix to use
+ * @param string $prefix Interwiki prefix to use
* @return Interwiki|null|bool
*/
static public function fetch( $prefix ) {
global $wgContLang;
- if( $prefix == '' ) {
+ if ( $prefix == '' ) {
return null;
}
$prefix = $wgContLang->lc( $prefix );
- if( isset( self::$smCache[$prefix] ) ) {
+ if ( isset( self::$smCache[$prefix] ) ) {
return self::$smCache[$prefix];
}
global $wgInterwikiCache;
- if( $wgInterwikiCache ) {
+ if ( $wgInterwikiCache ) {
$iw = Interwiki::getInterwikiCached( $prefix );
} else {
$iw = Interwiki::load( $prefix );
- if( !$iw ) {
+ if ( !$iw ) {
$iw = false;
}
}
- if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ) {
+ if ( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ) {
reset( self::$smCache );
unset( self::$smCache[key( self::$smCache )] );
}
*
* @note More logic is explained in DefaultSettings.
*
- * @param $prefix String: interwiki prefix
+ * @param string $prefix Interwiki prefix
* @return Interwiki object
*/
protected static function getInterwikiCached( $prefix ) {
*
* @note More logic is explained in DefaultSettings.
*
- * @param $prefix String: database key
- * @return String: the entry
+ * @param string $prefix Database key
+ * @return string The interwiki entry
*/
protected static function getInterwikiCacheEntry( $prefix ) {
global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
static $db, $site;
wfDebug( __METHOD__ . "( $prefix )\n" );
- if( !$db ) {
+ if ( !$db ) {
$db = CdbReader::open( $wgInterwikiCache );
}
/* Resolve site name */
- if( $wgInterwikiScopes >= 3 && !$site ) {
+ if ( $wgInterwikiScopes >= 3 && !$site ) {
$site = $db->get( '__sites:' . wfWikiID() );
if ( $site == '' ) {
$site = $wgInterwikiFallbackSite;
$value = '';
}
-
return $value;
}
/**
* Load the interwiki, trying first memcached then the DB
*
- * @param $prefix string The interwiki prefix
- * @return Boolean: the prefix is valid
+ * @param string $prefix The interwiki prefix
+ * @return bool If $prefix is valid
*/
protected static function load( $prefix ) {
global $wgMemc, $wgInterwikiExpiry;
}
}
- if( $iwData && is_array( $iwData ) ) { // is_array is hack for old keys
+ if ( $iwData && is_array( $iwData ) ) { // is_array is hack for old keys
$iw = Interwiki::loadFromArray( $iwData );
- if( $iw ) {
+ if ( $iw ) {
return $iw;
}
}
/**
* Fill in member variables from an array (e.g. memcached result, Database::fetchRow, etc)
*
- * @param $mc array Associative array: row from the interwiki table
- * @return Boolean|Interwiki whether everything was there
+ * @param array $mc Associative array: row from the interwiki table
+ * @return Interwiki|bool Interwiki object or false if $mc['iw_url'] is not set
*/
protected static function loadFromArray( $mc ) {
- if( isset( $mc['iw_url'] ) ) {
+ if ( isset( $mc['iw_url'] ) ) {
$iw = new Interwiki();
$iw->mURL = $mc['iw_url'];
$iw->mLocal = isset( $mc['iw_local'] ) ? $mc['iw_local'] : 0;
/**
* Fetch all interwiki prefixes from interwiki cache
*
- * @param $local null|string If not null, limits output to local/non-local interwikis
- * @return Array List of prefixes
+ * @param null|string $local If not null, limits output to local/non-local interwikis
+ * @return array List of prefixes
* @since 1.19
*/
protected static function getAllPrefixesCached( $local ) {
static $db, $site;
wfDebug( __METHOD__ . "()\n" );
- if( !$db ) {
+ if ( !$db ) {
$db = CdbReader::open( $wgInterwikiCache );
}
/* Resolve site name */
- if( $wgInterwikiScopes >= 3 && !$site ) {
+ if ( $wgInterwikiScopes >= 3 && !$site ) {
$site = $db->get( '__sites:' . wfWikiID() );
if ( $site == '' ) {
$site = $wgInterwikiFallbackSite;
$data = array();
- foreach( $sources as $source ) {
+ foreach ( $sources as $source ) {
$list = $db->get( "__list:{$source}" );
foreach ( explode( ' ', $list ) as $iw_prefix ) {
$row = $db->get( "{$source}:{$iw_prefix}" );
- if( !$row ) {
+ if ( !$row ) {
continue;
}
$data[$iw_prefix] = array(
'iw_prefix' => $iw_prefix,
- 'iw_url' => $iw_url,
- 'iw_local' => $iw_local,
+ 'iw_url' => $iw_url,
+ 'iw_local' => $iw_local,
);
}
}
/**
* Fetch all interwiki prefixes from DB
*
- * @param $local string|null If not null, limits output to local/non-local interwikis
- * @return Array List of prefixes
+ * @param string|null $local If not null, limits output to local/non-local interwikis
+ * @return array List of prefixes
* @since 1.19
*/
protected static function getAllPrefixesDB( $local ) {
/**
* Returns all interwiki prefixes
*
- * @param $local string|null If set, limits output to local/non-local interwikis
- * @return Array List of prefixes
+ * @param string|null $local If set, limits output to local/non-local interwikis
+ * @return array List of prefixes
* @since 1.19
*/
public static function getAllPrefixes( $local = null ) {
/**
* Get the URL for a particular title (or with $1 if no title given)
*
- * @param $title String: what text to put for the article name
- * @return String: the URL
+ * @param string $title What text to put for the article name
+ * @return string The URL
* @note Prior to 1.19 The getURL with an argument was broken.
* If you if you use this arg in an extension that supports MW earlier
* than 1.19 please wfUrlencode and substitute $1 on your own.
*/
public function getURL( $title = null ) {
$url = $this->mURL;
- if( $title !== null ) {
+ if ( $title !== null ) {
$url = str_replace( "$1", wfUrlencode( $title ), $url );
}
return $url;
/**
* Get the API URL for this wiki
*
- * @return String: the URL
+ * @return string The URL
*/
public function getAPI() {
return $this->mAPI;
/**
* Get the DB name for this wiki
*
- * @return String: the DB name
+ * @return string The DB name
*/
public function getWikiID() {
return $this->mWikiID;
* Is this a local link from a sister project, or is
* it something outside, like Google
*
- * @return Boolean
+ * @return bool
*/
public function isLocal() {
return $this->mLocal;
* Can pages from this wiki be transcluded?
* Still requires $wgEnableScaryTransclusion
*
- * @return Boolean
+ * @return bool
*/
public function isTranscludable() {
return $this->mTrans;
/**
* Get the name for the interwiki site
*
- * @return String
+ * @return string
*/
public function getName() {
$msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
/**
* Get a description for this interwiki
*
- * @return String
+ * @return string
*/
public function getDescription() {
$msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
/**
* Return the list of interwiki fields that should be selected to create
- * a new interwiki object.
- * @return array
+ * a new Interwiki object.
+ * @return string[]
*/
public static function selectFields() {
return array(