Index: trunk/phase3/includes/Interwiki.php |
— | — | @@ -26,12 +26,41 @@ |
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
| 30 | + * Check whether an interwiki prefix exists |
| 31 | + * |
| 32 | + * @return bool Whether it exists |
| 33 | + * @param $prefix string Interwiki prefix to use |
| 34 | + */ |
| 35 | + static public function isValidInterwiki( $prefix ){ |
| 36 | + global $wgContLang; |
| 37 | + $prefix = $wgContLang->lc( $prefix ); |
| 38 | + if( isset( self::$smCache[$prefix] ) ){ |
| 39 | + return true; |
| 40 | + } |
| 41 | + global $wgInterwikiCache; |
| 42 | + if ($wgInterwikiCache) { |
| 43 | + return Interwiki::isValidInterwikiCached( $key ); |
| 44 | + } |
| 45 | + $iw = new Interwiki; |
| 46 | + if( !$iw->load( $prefix ) ){ |
| 47 | + return false; |
| 48 | + } |
| 49 | + if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){ |
| 50 | + array_shift( self::$smCache ); |
| 51 | + } |
| 52 | + self::$smCache[$prefix] = &$iw; |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
30 | 57 | * Fetch an Interwiki object |
31 | 58 | * |
32 | 59 | * @return Interwiki Object, or null if not valid |
33 | 60 | * @param $prefix string Interwiki prefix to use |
34 | 61 | */ |
35 | 62 | static public function fetch( $prefix ) { |
| 63 | + global $wgContLang; |
| 64 | + $prefix = $wgContLang->lc( $prefix ); |
36 | 65 | if( isset( self::$smCache[$prefix] ) ){ |
37 | 66 | return self::$smCache[$prefix]; |
38 | 67 | } |
— | — | @@ -40,7 +69,9 @@ |
41 | 70 | return Interwiki::getInterwikiCached( $key ); |
42 | 71 | } |
43 | 72 | $iw = new Interwiki; |
44 | | - $iw->load( $prefix ); |
| 73 | + if( !$iw->load( $prefix ) ){ |
| 74 | + return false; |
| 75 | + } |
45 | 76 | if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){ |
46 | 77 | array_shift( self::$smCache ); |
47 | 78 | } |
— | — | @@ -54,7 +85,7 @@ |
55 | 86 | * @note More logic is explained in DefaultSettings. |
56 | 87 | * |
57 | 88 | * @param $key \type{\string} Database key |
58 | | - * @return \type{\string} URL of interwiki site |
| 89 | + * @return \type{\Interwiki} An interwiki object |
59 | 90 | */ |
60 | 91 | protected static function getInterwikiCached( $key ) { |
61 | 92 | global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite; |
— | — | @@ -91,7 +122,45 @@ |
92 | 123 | self::$smCache[$prefix] = &$s; |
93 | 124 | return $s; |
94 | 125 | } |
| 126 | + |
| 127 | + /** |
| 128 | + * Check whether an interwiki is in the cache |
| 129 | + * |
| 130 | + * @note More logic is explained in DefaultSettings. |
| 131 | + * |
| 132 | + * @param $key \type{\string} Database key |
| 133 | + * @return \type{\bool} Whether it exists |
| 134 | + */ |
| 135 | + protected static function isValidInterwikiCached( $key ) { |
| 136 | + global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite; |
| 137 | + static $db, $site; |
95 | 138 | |
| 139 | + if (!$db) |
| 140 | + $db=dba_open($wgInterwikiCache,'r','cdb'); |
| 141 | + /* Resolve site name */ |
| 142 | + if ($wgInterwikiScopes>=3 and !$site) { |
| 143 | + $site = dba_fetch('__sites:' . wfWikiID(), $db); |
| 144 | + if ($site=="") |
| 145 | + $site = $wgInterwikiFallbackSite; |
| 146 | + } |
| 147 | + $value = dba_fetch( wfMemcKey( $key ), $db); |
| 148 | + if ($value=='' and $wgInterwikiScopes>=3) { |
| 149 | + /* try site-level */ |
| 150 | + $value = dba_fetch("_{$site}:{$key}", $db); |
| 151 | + } |
| 152 | + if ($value=='' and $wgInterwikiScopes>=2) { |
| 153 | + /* try globals */ |
| 154 | + $value = dba_fetch("__global:{$key}", $db); |
| 155 | + } |
| 156 | + if ($value=='undef') |
| 157 | + $value=''; |
| 158 | + if ( $value != '' ) { |
| 159 | + return true; |
| 160 | + }else{ |
| 161 | + return false; |
| 162 | + } |
| 163 | + } |
| 164 | + |
96 | 165 | /** |
97 | 166 | * Clear all member variables in the current object. Does not clear |
98 | 167 | * the block from the DB. |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -2054,7 +2054,7 @@ |
2055 | 2055 | # Ordinary namespace |
2056 | 2056 | $dbkey = $m[2]; |
2057 | 2057 | $this->mNamespace = $ns; |
2058 | | - } elseif( new Interwiki( $p ) ) { |
| 2058 | + } elseif( Interwiki::isValidInterwiki( $p ) ) { |
2059 | 2059 | if( !$firstPass ) { |
2060 | 2060 | # Can't make a local interwiki link to an interwiki link. |
2061 | 2061 | # That's just crazy! |
— | — | @@ -2379,8 +2379,6 @@ |
2380 | 2380 | * @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure |
2381 | 2381 | */ |
2382 | 2382 | public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) { |
2383 | | - global $wgUser; |
2384 | | - |
2385 | 2383 | $errors = array(); |
2386 | 2384 | if( !$nt ) { |
2387 | 2385 | // Normally we'd add this to $errors, but we'll get |
— | — | @@ -2423,16 +2421,12 @@ |
2424 | 2422 | } |
2425 | 2423 | |
2426 | 2424 | if ( $auth ) { |
| 2425 | + global $wgUser; |
2427 | 2426 | $errors = wfArrayMerge($errors, |
2428 | 2427 | $this->getUserPermissionsErrors('move', $wgUser), |
2429 | 2428 | $this->getUserPermissionsErrors('edit', $wgUser), |
2430 | 2429 | $nt->getUserPermissionsErrors('move', $wgUser), |
2431 | 2430 | $nt->getUserPermissionsErrors('edit', $wgUser)); |
2432 | | - |
2433 | | - # Root userpage ? |
2434 | | - if ( $nt->getNamespace() == NS_USER && !$nt->isSubpage() && !$wgUser->isAllowed('move-rootuserpages') ) { |
2435 | | - $errors[] = array('moverootuserpagesnotallowed'); |
2436 | | - } |
2437 | 2431 | } |
2438 | 2432 | |
2439 | 2433 | $match = EditPage::matchSpamRegex( $reason ); |
— | — | @@ -2441,6 +2435,7 @@ |
2442 | 2436 | $errors[] = array('spamprotectiontext'); |
2443 | 2437 | } |
2444 | 2438 | |
| 2439 | + global $wgUser; |
2445 | 2440 | $err = null; |
2446 | 2441 | if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) { |
2447 | 2442 | $errors[] = array('hookaborted', $err); |