Re-commit r41410 (parts of at least) with fixes (case problems). Passes all the tests...
authorMatt Johnston <mattj@users.mediawiki.org>
Thu, 2 Oct 2008 21:49:20 +0000 (21:49 +0000)
committerMatt Johnston <mattj@users.mediawiki.org>
Thu, 2 Oct 2008 21:49:20 +0000 (21:49 +0000)
includes/Interwiki.php
includes/Title.php

index 4c081ca..a705591 100644 (file)
@@ -25,6 +25,33 @@ class Interwiki {
                $this->mTrans = $trans;
        }
 
+       /**
+        * Check whether an interwiki prefix exists
+        * 
+        * @return bool Whether it exists
+        * @param $prefix string Interwiki prefix to use
+        */
+       static public function isValidInterwiki( $prefix ){
+               global $wgContLang;
+               $prefix = $wgContLang->lc( $prefix );
+               if( isset( self::$smCache[$prefix] ) ){
+                       return true;
+               }
+               global $wgInterwikiCache;
+               if ($wgInterwikiCache) {
+                       return Interwiki::isValidInterwikiCached( $key );
+               }
+               $iw = new Interwiki;
+               if( !$iw->load( $prefix ) ){
+                       return false;
+               }
+               if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
+                       array_shift( self::$smCache );
+               }
+               self::$smCache[$prefix] = &$iw;
+               return true;
+       }
+
        /**
         * Fetch an Interwiki object
         * 
@@ -32,6 +59,8 @@ class Interwiki {
         * @param $prefix string Interwiki prefix to use
         */
        static public function fetch( $prefix ) {
+               global $wgContLang;
+               $prefix = $wgContLang->lc( $prefix );
                if( isset( self::$smCache[$prefix] ) ){
                        return self::$smCache[$prefix];
                }
@@ -40,7 +69,9 @@ class Interwiki {
                        return Interwiki::getInterwikiCached( $key );
                }
                $iw = new Interwiki;
-               $iw->load( $prefix );
+               if( !$iw->load( $prefix ) ){
+                       return false;
+               }
                if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
                        array_shift( self::$smCache );
                }
@@ -54,7 +85,7 @@ class Interwiki {
         * @note More logic is explained in DefaultSettings.
         *
         * @param $key \type{\string} Database key
-        * @return \type{\string} URL of interwiki site
+        * @return \type{\Interwiki} An interwiki object
         */
        protected static function getInterwikiCached( $key ) {
                global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
@@ -91,6 +122,44 @@ class Interwiki {
                self::$smCache[$prefix] = &$s;
                return $s;
        }
+       
+       /**
+        * Check whether an interwiki is in the cache
+        *
+        * @note More logic is explained in DefaultSettings.
+        *
+        * @param $key \type{\string} Database key
+        * @return \type{\bool} Whether it exists
+        */
+       protected static function isValidInterwikiCached( $key ) {
+               global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
+               static $db, $site;
+
+               if (!$db)
+                       $db=dba_open($wgInterwikiCache,'r','cdb');
+               /* Resolve site name */
+               if ($wgInterwikiScopes>=3 and !$site) {
+                       $site = dba_fetch('__sites:' . wfWikiID(), $db);
+                       if ($site=="")
+                               $site = $wgInterwikiFallbackSite;
+               }
+               $value = dba_fetch( wfMemcKey( $key ), $db);
+               if ($value=='' and $wgInterwikiScopes>=3) {
+                       /* try site-level */
+                       $value = dba_fetch("_{$site}:{$key}", $db);
+               }
+               if ($value=='' and $wgInterwikiScopes>=2) {
+                       /* try globals */
+                       $value = dba_fetch("__global:{$key}", $db);
+               }
+               if ($value=='undef')
+                       $value='';
+               if ( $value != '' ) {
+                       return true;
+               }else{
+                       return false;
+               }
+       }
 
        /**
         * Clear all member variables in the current object. Does not clear
index 4fd382a..029938b 100644 (file)
@@ -2054,7 +2054,7 @@ class Title {
                                        # Ordinary namespace
                                        $dbkey = $m[2];
                                        $this->mNamespace = $ns;
-                               } elseif( new Interwiki( $p ) ) {
+                               } elseif( Interwiki::isValidInterwiki( $p ) ) {
                                        if( !$firstPass ) {
                                                # Can't make a local interwiki link to an interwiki link.
                                                # That's just crazy!
@@ -2379,8 +2379,6 @@ class Title {
         * @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure
         */
        public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
-               global $wgUser;
-
                $errors = array();      
                if( !$nt ) {
                        // Normally we'd add this to $errors, but we'll get
@@ -2423,16 +2421,12 @@ class Title {
                }
 
                if ( $auth ) {
+                       global $wgUser;
                        $errors = wfArrayMerge($errors, 
                                        $this->getUserPermissionsErrors('move', $wgUser),
                                        $this->getUserPermissionsErrors('edit', $wgUser),
                                        $nt->getUserPermissionsErrors('move', $wgUser),
                                        $nt->getUserPermissionsErrors('edit', $wgUser));
-
-                       # Root userpage ?
-                       if ( $nt->getNamespace() == NS_USER && !$nt->isSubpage() && !$wgUser->isAllowed('move-rootuserpages') ) {
-                                       $errors[] = array('moverootuserpagesnotallowed');
-                       }
                }
 
                $match = EditPage::matchSpamRegex( $reason );
@@ -2441,6 +2435,7 @@ class Title {
                        $errors[] = array('spamprotectiontext');
                }
                
+               global $wgUser;
                $err = null;
                if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) {
                        $errors[] = array('hookaborted', $err);