]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/Interwiki.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / Interwiki.php
index 3c71f6eeceb6d5edd0281c365cbdde9f3548ad9b..5a3b655643cc34bc1f0ad69630938d59547d901b 100644 (file)
@@ -7,7 +7,8 @@
 /**
  * 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 {
 
@@ -15,11 +16,13 @@ class Interwiki {
        protected static $smCache = array();
        const CACHE_LIMIT = 100; // 0 means unlimited, any other value is max number of entries.
 
-       protected $mPrefix, $mURL, $mLocal, $mTrans;
+       protected $mPrefix, $mURL, $mAPI, $mWikiID, $mLocal, $mTrans;
 
-       public function __construct( $prefix = null, $url = '', $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->mLocal = $local;
                $this->mTrans = $trans;
        }
@@ -61,7 +64,7 @@ class Interwiki {
                }
                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;
@@ -107,7 +110,7 @@ class Interwiki {
                        $db = CdbReader::open( $wgInterwikiCache );
                }
                /* Resolve site name */
-               if( $wgInterwikiScopes>=3 && !$site ) {
+               if( $wgInterwikiScopes >= 3 && !$site ) {
                        $site = $db->get( '__sites:' . wfWikiID() );
                        if ( $site == '' ) {
                                $site = $wgInterwikiFallbackSite;
@@ -123,8 +126,9 @@ class Interwiki {
                if ( $value == '' && $wgInterwikiScopes >= 2 ) {
                        $value = $db->get( "__global:{$prefix}" );
                }
-               if ( $value == 'undef' )
+               if ( $value == 'undef' ) {
                        $value = '';
+               }
 
                return $value;
        }
@@ -139,7 +143,7 @@ class Interwiki {
                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 );
                        if( $iw ) {
@@ -153,7 +157,12 @@ class Interwiki {
                        __METHOD__ ) );
                $iw = Interwiki::loadFromArray( $row );
                if ( $iw ) {
-                       $mc = array( 'iw_url' => $iw->mURL, '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;
                }
@@ -173,6 +182,9 @@ class Interwiki {
                        $iw->mURL = $mc['iw_url'];
                        $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;
@@ -180,7 +192,7 @@ class Interwiki {
 
        /**
         * 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
         */
@@ -192,6 +204,24 @@ class Interwiki {
                return $url;
        }
 
+       /**
+        * Get the API URL for this wiki
+        *
+        * @return String: the URL
+        */
+       public function getAPI() {
+               return $this->mAPI;
+       }
+
+       /**
+        * Get the DB name for this wiki
+        *
+        * @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