Merge "jquery.makeCollapsible: clean up the handler toggling logic"
[lhc/web/wiklou.git] / maintenance / Maintenance.php
index 45df0e9..a13453d 100644 (file)
@@ -342,7 +342,7 @@ abstract class Maintenance {
         */
        protected function error( $err, $die = 0 ) {
                $this->outputChanneled( false );
-               if ( php_sapi_name() == 'cli' ) {
+               if ( PHP_SAPI == 'cli' ) {
                        fwrite( STDERR, $err . "\n" );
                } else {
                        print $err;
@@ -513,8 +513,11 @@ abstract class Maintenance {
                define( 'MEDIAWIKI', true );
 
                $wgCommandLineMode = true;
+
                # Turn off output buffering if it's on
-               @ob_end_flush();
+               while( ob_get_level() > 0 ) {
+                       ob_end_flush();
+               }
 
                $this->validateParamsAndArgs();
        }
@@ -920,7 +923,7 @@ abstract class Maintenance {
                if ( !is_readable( $settingsFile ) ) {
                        $this->error( "A copy of your installation's LocalSettings.php\n" .
                                                "must exist and be readable in the source directory.\n" .
-                                               "Use --conf to specify it." , true );
+                                               "Use --conf to specify it.", true );
                }
                $wgCommandLineMode = true;
                return $settingsFile;
@@ -936,13 +939,9 @@ abstract class Maintenance {
                $dbw = $this->getDB( DB_MASTER );
                $dbw->begin( __METHOD__ );
 
-               $tbl_arc = $dbw->tableName( 'archive' );
-               $tbl_rev = $dbw->tableName( 'revision' );
-               $tbl_txt = $dbw->tableName( 'text' );
-
                # Get "active" text records from the revisions table
                $this->output( 'Searching for active text records in revisions table...' );
-               $res = $dbw->query( "SELECT DISTINCT rev_text_id FROM $tbl_rev" );
+               $res = $dbw->select( 'revision', 'rev_text_id', array(), __METHOD__, array( 'DISTINCT' ) );
                foreach ( $res as $row ) {
                        $cur[] = $row->rev_text_id;
                }
@@ -950,7 +949,7 @@ abstract class Maintenance {
 
                # Get "active" text records from the archive table
                $this->output( 'Searching for active text records in archive table...' );
-               $res = $dbw->query( "SELECT DISTINCT ar_text_id FROM $tbl_arc" );
+               $res = $dbw->select( 'archive', 'ar_text_id', array(), __METHOD__, array( 'DISTINCT' ) );
                foreach ( $res as $row ) {
                        # old pre-MW 1.5 records can have null ar_text_id's.
                        if ( $row->ar_text_id !== null ) {
@@ -961,8 +960,8 @@ abstract class Maintenance {
 
                # Get the IDs of all text records not in these sets
                $this->output( 'Searching for inactive text records...' );
-               $set = implode( ', ', $cur );
-               $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" );
+               $cond = 'old_id NOT IN ( ' . $dbw->makeList( $cur ) . ' )';
+               $res = $dbw->select( 'text', 'old_id', array( $cond ), __METHOD__, array( 'DISTINCT' ) );
                $old = array();
                foreach ( $res as $row ) {
                        $old[] = $row->old_id;
@@ -976,8 +975,7 @@ abstract class Maintenance {
                # Delete as appropriate
                if ( $delete && $count ) {
                        $this->output( 'Deleting...' );
-                       $set = implode( ', ', $old );
-                       $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" );
+                       $dbw->delete( 'text', array( 'old_id' => $old ), __METHOD__ );
                        $this->output( "done.\n" );
                }
 
@@ -1210,7 +1208,7 @@ abstract class Maintenance {
                        $encPrompt = wfEscapeShellArg( $prompt );
                        $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
                        $encCommand = wfEscapeShellArg( $command );
-                       $line = wfShellExec( "$bash -c $encCommand", $retval );
+                       $line = wfShellExec( "$bash -c $encCommand", $retval, array(), array( 'walltime' => 0 ) );
 
                        if ( $retval == 0 ) {
                                return $line;