Braces and spaces
[lhc/web/wiklou.git] / maintenance / deleteRevision.php
index 980b0c3..485cb86 100644 (file)
@@ -20,7 +20,7 @@
  * @ingroup Maintenance
  */
 
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class DeleteRevision extends Maintenance {
        
@@ -30,11 +30,11 @@ class DeleteRevision extends Maintenance {
        }
        
        public function execute() {
-               if( count( $this->mArgs ) == 0 ) {
+               if ( count( $this->mArgs ) == 0 ) {
                        $this->error( "No revisions specified", true );
                }
 
-               $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) . 
+               $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) .
                                                " from " . wfWikiID() . "...\n" );
                $dbw = wfGetDB( DB_MASTER );
                
@@ -63,7 +63,14 @@ class DeleteRevision extends Maintenance {
                                $this->output( "Revision $revID not found\n" );
                        } else {
                                $affected += $dbw->affectedRows();
+                               $pageID = $dbw->selectField( 'revision', 'rev_page', array( 'rev_id' => $revID ), __METHOD__ );
+                               $pageLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), __METHOD__ );
                                $dbw->delete( 'revision', array( 'rev_id' => $revID ) );
+                               if ( $pageLatest == $revID ) {
+                                       // Database integrity
+                                       $newLatest = $dbw->selectField( 'revision', 'rev_id', array( 'rev_page' => $pageID ), __METHOD__, array( 'ORDER BY' => 'rev_timestamp DESC' ) );
+                                       $dbw->update( 'page', array( 'page_latest' => $newLatest ), array( 'page_id' => $pageID ), __METHOD__ );
+                               }
                        }
                }
                $this->output( "Deleted $affected revisions\n" );