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;
+ /** @var string The interwiki prefix, (e.g. "Meatball", or the language prefix "de") */
+ protected $mPrefix;
+
+ /** @var string The URL of the wiki, with "$1" as a placeholder for an article name. */
+ protected $mURL;
+
+ /** @var string The URL of the file api.php */
+ protected $mAPI;
+
+ /** @var string The name of the database (for a connection to be established
+ * with wfGetLB( 'wikiid' ))
+ */
+ protected $mWikiID;
+
+ /** @var bool whether the wiki is in this project */
+ protected $mLocal;
+
+ /** @var bool Whether interwiki transclusions are allowed */
+ protected $mTrans;
public function __construct( $prefix = null, $url = '', $api = '', $wikiId = '', $local = 0,
$trans = 0
*/
public static function isValidInterwiki( $prefix ) {
$result = self::fetch( $prefix );
+
return (bool)$result;
}
*/
public static function fetch( $prefix ) {
global $wgContLang;
+
if ( $prefix == '' ) {
return null;
}
+
$prefix = $wgContLang->lc( $prefix );
if ( isset( self::$smCache[$prefix] ) ) {
return self::$smCache[$prefix];
}
+
global $wgInterwikiCache;
if ( $wgInterwikiCache ) {
$iw = Interwiki::getInterwikiCached( $prefix );
$iw = false;
}
}
+
if ( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ) {
reset( self::$smCache );
unset( self::$smCache[key( self::$smCache )] );
}
+
self::$smCache[$prefix] = $iw;
+
return $iw;
}
} else {
$s = false;
}
+
return $s;
}
* Load the interwiki, trying first memcached then the DB
*
* @param string $prefix The interwiki prefix
- * @return bool If $prefix is valid
+ * @return Interwiki|bool Interwiki if $prefix is valid, otherwise false
*/
protected static function load( $prefix ) {
global $wgMemc, $wgInterwikiExpiry;
- $iwData = false;
+ $iwData = array();
if ( !wfRunHooks( 'InterwikiLoadPrefix', array( $prefix, &$iwData ) ) ) {
return Interwiki::loadFromArray( $iwData );
}
$key = wfMemcKey( 'interwiki', $prefix );
$iwData = $wgMemc->get( $key );
if ( $iwData === '!NONEXISTENT' ) {
- return false; // negative cache hit
+ // negative cache hit
+ return false;
}
}
- if ( $iwData && is_array( $iwData ) ) { // is_array is hack for old keys
+ // is_array is hack for old keys
+ if ( $iwData && is_array( $iwData ) ) {
$iw = Interwiki::loadFromArray( $iwData );
if ( $iw ) {
return $iw;
$db = wfGetDB( DB_SLAVE );
- $row = $db->fetchRow( $db->select( 'interwiki', self::selectFields(), array( 'iw_prefix' => $prefix ),
- __METHOD__ ) );
+ $row = $db->fetchRow( $db->select(
+ 'interwiki',
+ self::selectFields(),
+ array( 'iw_prefix' => $prefix ),
+ __METHOD__
+ ) );
+
$iw = Interwiki::loadFromArray( $row );
if ( $iw ) {
$mc = array(
'iw_trans' => $iw->mTrans
);
$wgMemc->add( $key, $mc, $wgInterwikiExpiry );
+
return $iw;
- } else {
- $wgMemc->add( $key, '!NONEXISTENT', $wgInterwikiExpiry ); // negative cache hit
}
+ // negative cache hit
+ $wgMemc->add( $key, '!NONEXISTENT', $wgInterwikiExpiry );
+
return false;
}
return $iw;
}
+
return false;
}
self::selectFields(),
$where, __METHOD__, array( 'ORDER BY' => 'iw_prefix' )
);
+
$retval = array();
foreach ( $res as $row ) {
$retval[] = (array)$row;
}
+
return $retval;
}
if ( $wgInterwikiCache ) {
return self::getAllPrefixesCached( $local );
- } else {
- return self::getAllPrefixesDB( $local );
}
+
+ return self::getAllPrefixesDB( $local );
}
/**
if ( $title !== null ) {
$url = str_replace( "$1", wfUrlencode( $title ), $url );
}
+
return $url;
}
*/
public function getName() {
$msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
+
return !$msg->exists() ? '' : $msg;
}
*/
public function getDescription() {
$msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
+
return !$msg->exists() ? '' : $msg;
}