Merge "Fix RequestContextTest screwing up $wgUser"
[lhc/web/wiklou.git] / includes / interwiki / Interwiki.php
index 3c237bf..09283f2 100644 (file)
@@ -31,7 +31,25 @@ class Interwiki {
        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
@@ -52,6 +70,7 @@ class Interwiki {
         */
        public static function isValidInterwiki( $prefix ) {
                $result = self::fetch( $prefix );
+
                return (bool)$result;
        }
 
@@ -63,13 +82,16 @@ class Interwiki {
         */
        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 );
@@ -79,11 +101,14 @@ class Interwiki {
                                $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;
        }
 
@@ -107,6 +132,7 @@ class Interwiki {
                } else {
                        $s = false;
                }
+
                return $s;
        }
 
@@ -160,12 +186,12 @@ class Interwiki {
         * 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 );
                }
@@ -174,11 +200,13 @@ class Interwiki {
                        $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;
@@ -187,8 +215,13 @@ class Interwiki {
 
                $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(
@@ -198,11 +231,13 @@ class Interwiki {
                                '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;
        }
 
@@ -223,6 +258,7 @@ class Interwiki {
 
                        return $iw;
                }
+
                return false;
        }
 
@@ -318,10 +354,12 @@ class Interwiki {
                        self::selectFields(),
                        $where, __METHOD__, array( 'ORDER BY' => 'iw_prefix' )
                );
+
                $retval = array();
                foreach ( $res as $row ) {
                        $retval[] = (array)$row;
                }
+
                return $retval;
        }
 
@@ -337,9 +375,9 @@ class Interwiki {
 
                if ( $wgInterwikiCache ) {
                        return self::getAllPrefixesCached( $local );
-               } else {
-                       return self::getAllPrefixesDB( $local );
                }
+
+               return self::getAllPrefixesDB( $local );
        }
 
        /**
@@ -356,6 +394,7 @@ class Interwiki {
                if ( $title !== null ) {
                        $url = str_replace( "$1", wfUrlencode( $title ), $url );
                }
+
                return $url;
        }
 
@@ -404,6 +443,7 @@ class Interwiki {
         */
        public function getName() {
                $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
+
                return !$msg->exists() ? '' : $msg;
        }
 
@@ -414,6 +454,7 @@ class Interwiki {
         */
        public function getDescription() {
                $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
+
                return !$msg->exists() ? '' : $msg;
        }