r41569 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41568‎ | r41569 | r41570 >
Date:21:49, 2 October 2008
Author:mattj
Status:old (Comments)
Tags:
Comment:
Re-commit r41410 (parts of at least) with fixes (case problems). Passes all the tests brion mentioned.
Modified paths:
  • /trunk/phase3/includes/Interwiki.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Interwiki.php
@@ -26,12 +26,41 @@
2727 }
2828
2929 /**
 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+ /**
3057 * Fetch an Interwiki object
3158 *
3259 * @return Interwiki Object, or null if not valid
3360 * @param $prefix string Interwiki prefix to use
3461 */
3562 static public function fetch( $prefix ) {
 63+ global $wgContLang;
 64+ $prefix = $wgContLang->lc( $prefix );
3665 if( isset( self::$smCache[$prefix] ) ){
3766 return self::$smCache[$prefix];
3867 }
@@ -40,7 +69,9 @@
4170 return Interwiki::getInterwikiCached( $key );
4271 }
4372 $iw = new Interwiki;
44 - $iw->load( $prefix );
 73+ if( !$iw->load( $prefix ) ){
 74+ return false;
 75+ }
4576 if( self::CACHE_LIMIT && count( self::$smCache ) >= self::CACHE_LIMIT ){
4677 array_shift( self::$smCache );
4778 }
@@ -54,7 +85,7 @@
5586 * @note More logic is explained in DefaultSettings.
5687 *
5788 * @param $key \type{\string} Database key
58 - * @return \type{\string} URL of interwiki site
 89+ * @return \type{\Interwiki} An interwiki object
5990 */
6091 protected static function getInterwikiCached( $key ) {
6192 global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
@@ -91,7 +122,45 @@
92123 self::$smCache[$prefix] = &$s;
93124 return $s;
94125 }
 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;
95138
 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+
96165 /**
97166 * Clear all member variables in the current object. Does not clear
98167 * the block from the DB.
Index: trunk/phase3/includes/Title.php
@@ -2054,7 +2054,7 @@
20552055 # Ordinary namespace
20562056 $dbkey = $m[2];
20572057 $this->mNamespace = $ns;
2058 - } elseif( new Interwiki( $p ) ) {
 2058+ } elseif( Interwiki::isValidInterwiki( $p ) ) {
20592059 if( !$firstPass ) {
20602060 # Can't make a local interwiki link to an interwiki link.
20612061 # That's just crazy!
@@ -2379,8 +2379,6 @@
23802380 * @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure
23812381 */
23822382 public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
2383 - global $wgUser;
2384 -
23852383 $errors = array();
23862384 if( !$nt ) {
23872385 // Normally we'd add this to $errors, but we'll get
@@ -2423,16 +2421,12 @@
24242422 }
24252423
24262424 if ( $auth ) {
 2425+ global $wgUser;
24272426 $errors = wfArrayMerge($errors,
24282427 $this->getUserPermissionsErrors('move', $wgUser),
24292428 $this->getUserPermissionsErrors('edit', $wgUser),
24302429 $nt->getUserPermissionsErrors('move', $wgUser),
24312430 $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 - }
24372431 }
24382432
24392433 $match = EditPage::matchSpamRegex( $reason );
@@ -2441,6 +2435,7 @@
24422436 $errors[] = array('spamprotectiontext');
24432437 }
24442438
 2439+ global $wgUser;
24452440 $err = null;
24462441 if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) {
24472442 $errors[] = array('hookaborted', $err);

Follow-up revisions

RevisionCommit summaryAuthorDate
r41595Better implementation of r41465 (Adding a new right, move-rootuserpages.) whi...nicdumz10:20, 3 October 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41410* Add Linker::link flag for using article path...mattj01:56, 30 September 2008

Comments

#Comment by Tim Starling (talk | contribs)   13:57, 11 October 2008

My comments on r41377 still apply.

#Comment by Brion VIBBER (talk | contribs)   21:42, 15 October 2008

Issues resolved in r42022, r42023, r42041, r42046 follow-ups.

Status & tagging log