From 18b624700fb6fd55ff2aab608f034146ffdff7e8 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Thu, 2 Oct 2008 21:49:20 +0000 Subject: [PATCH] Re-commit r41410 (parts of at least) with fixes (case problems). Passes all the tests brion mentioned. --- includes/Interwiki.php | 73 ++++++++++++++++++++++++++++++++++++++++-- includes/Title.php | 11 ++----- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/includes/Interwiki.php b/includes/Interwiki.php index 4c081ca6ab..a705591426 100644 --- a/includes/Interwiki.php +++ b/includes/Interwiki.php @@ -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 diff --git a/includes/Title.php b/includes/Title.php index 4fd382a12c..029938b7a2 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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); -- 2.20.1