/**
* The interwiki class
* All information is loaded on creation when called by Interwiki::fetch( $prefix ).
- * All work is done on slave, because this should *never* change (except during schema updates etc, which arent wiki-related)
+ * All work is done on slave, because this should *never* change (except during
+ * schema updates etc, which aren't wiki-related)
*/
class Interwiki {
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;
- $this->mWikiID = $wikiid;
+ $this->mWikiID = $wikiId;
$this->mLocal = $local;
$this->mTrans = $trans;
}
}
if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ) {
reset( self::$smCache );
- unset( self::$smCache[ key( self::$smCache ) ] );
+ unset( self::$smCache[key( self::$smCache )] );
}
self::$smCache[$prefix] = $iw;
return $iw;
$db = CdbReader::open( $wgInterwikiCache );
}
/* Resolve site name */
- if( $wgInterwikiScopes>=3 && !$site ) {
+ if( $wgInterwikiScopes >= 3 && !$site ) {
$site = $db->get( '__sites:' . wfWikiID() );
if ( $site == '' ) {
$site = $wgInterwikiFallbackSite;
if ( $value == '' && $wgInterwikiScopes >= 2 ) {
$value = $db->get( "__global:{$prefix}" );
}
- if ( $value == 'undef' )
+ if ( $value == 'undef' ) {
$value = '';
+ }
return $value;
}
*/
protected static function load( $prefix ) {
global $wgMemc, $wgInterwikiExpiry;
- $key = wfMemcKey( 'interwiki', $prefix );
- $mc = $wgMemc->get( $key );
- $iw = false;
- if( $mc && is_array( $mc ) ) { // is_array is hack for old keys
- $iw = Interwiki::loadFromArray( $mc );
+
+ $iwData = false;
+ if ( !wfRunHooks( 'InterwikiLoadPrefix', array( $prefix, &$iwData ) ) ) {
+ return Interwiki::loadFromArray( $iwData );
+ }
+
+ if ( !$iwData ) {
+ $key = wfMemcKey( 'interwiki', $prefix );
+ $iwData = $wgMemc->get( $key );
+ }
+
+ if( $iwData && is_array( $iwData ) ) { // is_array is hack for old keys
+ $iw = Interwiki::loadFromArray( $iwData );
if( $iw ) {
return $iw;
}
__METHOD__ ) );
$iw = Interwiki::loadFromArray( $row );
if ( $iw ) {
- $mc = array( 'iw_url' => $iw->mURL, 'iw_api' => $iw->mAPI, 'iw_local' => $iw->mLocal, 'iw_trans' => $iw->mTrans );
+ $mc = array(
+ 'iw_url' => $iw->mURL,
+ 'iw_api' => $iw->mAPI,
+ 'iw_local' => $iw->mLocal,
+ 'iw_trans' => $iw->mTrans
+ );
$wgMemc->add( $key, $mc, $wgInterwikiExpiry );
return $iw;
}
* @return Boolean: whether everything was there
*/
protected static function loadFromArray( $mc ) {
- if( isset( $mc['iw_url'] ) && isset( $mc['iw_api'] ) && isset( $mc['iw_wikiid'] )
- && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) {
+ if( isset( $mc['iw_url'] ) && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) {
$iw = new Interwiki();
$iw->mURL = $mc['iw_url'];
- $iw->mAPI = $mc['iw_api'];
- $iw->mWikiID = $mc['iw_wikiid'];
$iw->mLocal = $mc['iw_local'];
$iw->mTrans = $mc['iw_trans'];
+ $iw->mAPI = isset( $mc['iw_api'] ) ? $mc['iw_api'] : '';
+ $iw->mWikiID = isset( $mc['iw_wikiid'] ) ? $mc['iw_wikiid'] : '';
+
return $iw;
}
return false;
/**
* 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
*/
/**
* Get the API URL for this wiki
- *
+ *
* @return String: the URL
*/
- public function getAPI( ) {
+ public function getAPI() {
return $this->mAPI;
}
/**
* Get the DB name for this wiki
- *
+ *
* @return String: the DB name
*/
- public function getWikiID( ) {
+ public function getWikiID() {
return $this->mWikiID;
}
* @return String
*/
public function getName() {
- $key = 'interwiki-name-' . $this->mPrefix;
- $msg = wfMsgForContent( $key );
- return wfEmptyMsg( $key, $msg ) ? '' : $msg;
+ $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
+ return !$msg->exists() ? '' : $msg;
}
/**
* @return String
*/
public function getDescription() {
- $key = 'interwiki-desc-' . $this->mPrefix;
- $msg = wfMsgForContent( $key );
- return wfEmptyMsg( $key, $msg ) ? '' : $msg;
+ $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
+ return !$msg->exists() ? '' : $msg;
}
}