Merge "Show descriptive error message on invalid title instead of showing an empty...
authorBrion VIBBER <brion@wikimedia.org>
Tue, 8 May 2012 20:47:59 +0000 (20:47 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 8 May 2012 20:47:59 +0000 (20:47 +0000)
includes/api/ApiBlock.php
includes/api/ApiUnblock.php
includes/filerepo/file/LocalFile.php
includes/objectcache/SqlBagOStuff.php
includes/tidy.conf
maintenance/backupTextPass.inc
maintenance/dumpBackup.php
maintenance/dumpTextPass.php

index 7d3a40b..c566a5c 100644 (file)
@@ -149,7 +149,10 @@ class ApiBlock extends ApiBase {
                                ApiBase::PARAM_REQUIRED => true
                        ),
                        'token' => null,
-                       'gettoken' => false,
+                       'gettoken' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
                        'expiry' => 'never',
                        'reason' => null,
                        'anononly' => false,
@@ -166,7 +169,7 @@ class ApiBlock extends ApiBase {
        public function getParamDescription() {
                return array(
                        'user' => 'Username, IP address or IP range you want to block',
-                       'token' => 'A block token previously obtained through the gettoken parameter or prop=info',
+                       'token' => 'A block token previously obtained through prop=info',
                        'gettoken' => 'If set, a block token will be returned, and no other action will be taken',
                        'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.',
                        'reason' => 'Reason for block (optional)',
index e599e32..32e0d88 100644 (file)
@@ -98,7 +98,10 @@ class ApiUnblock extends ApiBase {
                        ),
                        'user' => null,
                        'token' => null,
-                       'gettoken' => false,
+                       'gettoken' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
                        'reason' => null,
                );
        }
@@ -108,7 +111,7 @@ class ApiUnblock extends ApiBase {
                return array(
                        'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
                        'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
-                       'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
+                       'token' => "An unblock token previously obtained through prop=info",
                        'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
                        'reason' => 'Reason for unblock (optional)',
                );
index 215de38..467bf1b 100644 (file)
@@ -1246,19 +1246,18 @@ class LocalFile extends File {
                }
 
                wfDebugLog( 'imagemove', "Got request to move {$this->name} to " . $target->getText() );
-               $this->lock(); // begin
-
                $batch = new LocalFileMoveBatch( $this, $target );
+
+               $this->lock(); // begin
                $batch->addCurrent();
                $batch->addOlds();
-
                $status = $batch->execute();
+               $this->unlock(); // done
+
                wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
 
                $this->purgeEverything();
-               $this->unlock(); // done
-
-               if ( $status->isOk() ) {
+               if ( $status->isOK() ) {
                        // Now switch the object
                        $this->title = $target;
                        // Force regeneration of the name and hashpath
@@ -1288,31 +1287,33 @@ class LocalFile extends File {
                        return $this->readOnlyFatalStatus();
                }
 
-               $this->lock(); // begin
-
+               $dbw = $this->repo->getMasterDB();
                $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
-               $batch->addCurrent();
+               $archiveNames = array();
 
+               $this->lock(); // begin
+               $batch->addCurrent();
                # Get old version relative paths
-               $dbw = $this->repo->getMasterDB();
                $result = $dbw->select( 'oldimage',
                        array( 'oi_archive_name' ),
                        array( 'oi_name' => $this->getName() ) );
                foreach ( $result as $row ) {
                        $batch->addOld( $row->oi_archive_name );
-                       $this->purgeOldThumbnails( $row->oi_archive_name );
+                       $archiveNames[] = $row->oi_archive_name;
                }
                $status = $batch->execute();
-
                if ( $status->isOK() ) {
                        // Update site_stats
                        $site_stats = $dbw->tableName( 'site_stats' );
                        $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", __METHOD__ );
-                       $this->purgeEverything();
                }
-
                $this->unlock(); // done
 
+               $this->purgeEverything();
+               foreach ( $archiveNames as $archiveName ) {
+                       $this->purgeOldThumbnails( $archiveName );
+               }
+
                return $status;
        }
 
@@ -1368,25 +1369,21 @@ class LocalFile extends File {
                        return $this->readOnlyFatalStatus();
                }
 
-               $this->lock(); // begin
-
                $batch = new LocalFileRestoreBatch( $this, $unsuppress );
 
+               $this->lock(); // begin
                if ( !$versions ) {
                        $batch->addAll();
                } else {
                        $batch->addIds( $versions );
                }
-
                $status = $batch->execute();
-
                if ( $status->isGood() ) {
                        $cleanupStatus = $batch->cleanup();
                        $cleanupStatus->successCount = 0;
                        $cleanupStatus->failCount = 0;
                        $status->merge( $cleanupStatus );
                }
-
                $this->unlock(); // done
 
                return $status;
@@ -2186,7 +2183,7 @@ class LocalFileRestoreBatch {
 class LocalFileMoveBatch {
 
        /**
-        * @var File
+        * @var LocalFile
         */
        var $file;
 
@@ -2281,17 +2278,17 @@ class LocalFileMoveBatch {
                        return $statusMove;
                }
 
-               $this->db->begin( __METHOD__ );
+               $this->file->lock(); // begin
                $statusDb = $this->doDBUpdates();
                wfDebugLog( 'imagemove', "Renamed {$this->file->getName()} in database: {$statusDb->successCount} successes, {$statusDb->failCount} failures" );
                if ( !$statusDb->isGood() ) {
-                       $this->db->rollback( __METHOD__ );
+                       $this->file->unlockAndRollback();
                        // Something went wrong with the DB updates, so remove the target files
                        $this->cleanupTarget( $triplets );
                        $statusDb->ok = false;
                        return $statusDb;
                }
-               $this->db->commit( __METHOD__ );
+               $this->file->unlock(); // done
 
                // Everything went ok, remove the source files
                $this->cleanupSource( $triplets );
index b244b07..54a67e0 100644 (file)
@@ -139,40 +139,64 @@ class SqlBagOStuff extends BagOStuff {
        }
 
        public function get( $key ) {
-               # expire old entries if any
-               $this->garbageCollect();
-               $db = $this->getDB();
-               $tableName = $this->getTableByKey( $key );
-               $row = $db->selectRow( $tableName, array( 'value', 'exptime' ),
-                       array( 'keyname' => $key ), __METHOD__ );
+               $values = $this->getBatch( array( $key ) );
+               return $values[$key];
+       }
 
-               if ( !$row ) {
-                       $this->debug( 'get: no matching rows' );
-                       return false;
+       public function getBatch( array $keys ) {
+               $values = array(); // array of (key => value)
+
+               $keysByTableName = array();
+               foreach ( $keys as $key ) {
+                       $tableName = $this->getTableByKey( $key );
+                       if ( !isset( $keysByTableName[$tableName] ) ) {
+                               $keysByTableName[$tableName] = array();
+                       }
+                       $keysByTableName[$tableName][] = $key;
                }
 
-               $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
+               $db = $this->getDB();
+               $this->garbageCollect(); // expire old entries if any
 
-               if ( $this->isExpired( $row->exptime ) ) {
-                       $this->debug( "get: key has expired, deleting" );
-                       try {
-                               $db->begin( __METHOD__ );
-                               # Put the expiry time in the WHERE condition to avoid deleting a
-                               # newly-inserted value
-                               $db->delete( $tableName,
-                                       array(
-                                               'keyname' => $key,
-                                               'exptime' => $row->exptime
-                                       ), __METHOD__ );
-                               $db->commit( __METHOD__ );
-                       } catch ( DBQueryError $e ) {
-                               $this->handleWriteError( $e );
+               $dataRows = array();
+               foreach ( $keysByTableName as $tableName => $tableKeys ) {
+                       $res = $db->select( $tableName,
+                               array( 'keyname', 'value', 'exptime' ),
+                               array( 'keyname' => $tableKeys ),
+                               __METHOD__ );
+                       foreach ( $res as $row ) {
+                               $dataRows[$row->keyname] = $row;
                        }
+               }
 
-                       return false;
+               foreach ( $keys as $key ) {
+                       if ( isset( $dataRows[$key] ) ) { // HIT?
+                               $row = $dataRows[$key];
+                               $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
+                               if ( $this->isExpired( $row->exptime ) ) { // MISS
+                                       $this->debug( "get: key has expired, deleting" );
+                                       try {
+                                               $db->begin( __METHOD__ );
+                                               # Put the expiry time in the WHERE condition to avoid deleting a
+                                               # newly-inserted value
+                                               $db->delete( $this->getTableByKey( $key ),
+                                                       array( 'keyname' => $key, 'exptime' => $row->exptime ),
+                                                       __METHOD__ );
+                                               $db->commit( __METHOD__ );
+                                       } catch ( DBQueryError $e ) {
+                                               $this->handleWriteError( $e );
+                                       }
+                                       $values[$key] = false;
+                               } else { // HIT
+                                       $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) );
+                               }
+                       } else { // MISS
+                               $values[$key] = false;
+                               $this->debug( 'get: no matching rows' );
+                       }
                }
 
-               return $this->unserialize( $db->decodeBlob( $row->value ) );
+               return $values;
        }
 
        public function set( $key, $value, $exptime = 0 ) {
@@ -349,7 +373,7 @@ class SqlBagOStuff extends BagOStuff {
                                        if ( $maxExpTime !== false ) {
                                                $conds[] = 'exptime > ' . $db->addQuotes( $maxExpTime );
                                        }
-                                       $rows = $db->select( 
+                                       $rows = $db->select(
                                                $this->getTableByShard( $i ),
                                                array( 'keyname', 'exptime' ),
                                                $conds,
@@ -373,7 +397,7 @@ class SqlBagOStuff extends BagOStuff {
                                        $db->begin( __METHOD__ );
                                        $db->delete(
                                                $this->getTableByShard( $i ),
-                                               array( 
+                                               array(
                                                        'exptime >= ' . $db->addQuotes( $minExpTime ),
                                                        'exptime < ' . $db->addQuotes( $dbTimestamp ),
                                                        'keyname' => $keys
@@ -385,12 +409,12 @@ class SqlBagOStuff extends BagOStuff {
                                                if ( intval( $totalSeconds ) === 0 ) {
                                                        $percent = 0;
                                                } else {
-                                                       $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp ) 
+                                                       $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
                                                                - wfTimestamp( TS_UNIX, $maxExpTime );
                                                        if ( $remainingSeconds > $totalSeconds ) {
                                                                $totalSeconds = $remainingSeconds;
                                                        }
-                                                       $percent = ( $i + $remainingSeconds / $totalSeconds ) 
+                                                       $percent = ( $i + $remainingSeconds / $totalSeconds )
                                                                / $this->shards * 100;
                                                }
                                                call_user_func( $progressCallback, $percent );
index 09412f0..479083e 100644 (file)
@@ -16,3 +16,4 @@ quiet: yes
 quote-nbsp: yes
 fix-backslash: no
 fix-uri: no
+new-inline-tags: video,audio,source,track
index 717f21b..3846ef5 100644 (file)
@@ -24,6 +24,7 @@
  * @ingroup Maintenance
  */
 
+require_once( dirname( __FILE__ ) . '/backup.inc' );
 
 /**
  * @ingroup Maintenance
index e05f43c..4638468 100644 (file)
@@ -30,7 +30,7 @@ $originalDir = getcwd();
 $optionsWithArgs = array( 'pagelist', 'start', 'end', 'revstart', 'revend');
 
 require_once( dirname( __FILE__ ) . '/commandLine.inc' );
-require_once( 'backup.inc' );
+require_once( dirname( __FILE__ ) . '/backup.inc' );
 
 $dumper = new BackupDumper( $argv );
 
index 7a5a5f6..41a7a68 100644 (file)
@@ -27,8 +27,7 @@
 $originalDir = getcwd();
 
 require_once( dirname( __FILE__ ) . '/commandLine.inc' );
-require_once( 'backup.inc' );
-require_once( 'backupTextPass.inc' );
+require_once( dirname( __FILE__ ) . '/backupTextPass.inc' );
 
 
 $dumper = new TextPassDumper( $argv );