MediaWiki  REL1_19
attachLatest.php
Go to the documentation of this file.
00001 <?php
00028 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
00029 
00030 class AttachLatest extends Maintenance {
00031 
00032         public function __construct() {
00033                 parent::__construct();
00034                 $this->addOption( "fix", "Actually fix the entries, will dry run otherwise" );
00035                 $this->mDescription = "Fix page_latest entries in the page table";
00036         }
00037 
00038         public function execute() {
00039                 $this->output( "Looking for pages with page_latest set to 0...\n" );
00040                 $dbw = wfGetDB( DB_MASTER );
00041                 $result = $dbw->select( 'page',
00042                         array( 'page_id', 'page_namespace', 'page_title' ),
00043                         array( 'page_latest' => 0 ),
00044                         __METHOD__ );
00045 
00046                 $n = 0;
00047                 foreach ( $result as $row ) {
00048                         $pageId = intval( $row->page_id );
00049                         $title = Title::makeTitle( $row->page_namespace, $row->page_title );
00050                         $name = $title->getPrefixedText();
00051                         $latestTime = $dbw->selectField( 'revision',
00052                                 'MAX(rev_timestamp)',
00053                                 array( 'rev_page' => $pageId ),
00054                                 __METHOD__ );
00055                         if ( !$latestTime ) {
00056                                 $this->output( wfWikiID() . " $pageId [[$name]] can't find latest rev time?!\n" );
00057                                 continue;
00058                         }
00059 
00060                         $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
00061                         if ( is_null( $revision ) ) {
00062                                 $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
00063                                 continue;
00064                         }
00065                         $id = $revision->getId();
00066                         $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, rev id $id\n" );
00067                         if ( $this->hasOption( 'fix' ) ) {
00068                                 $page = WikiPage::factory( $title );
00069                                 $page->updateRevisionOn( $dbw, $revision );
00070                         }
00071                         $n++;
00072                 }
00073                 $this->output( "Done! Processed $n pages.\n" );
00074                 if ( !$this->hasOption( 'fix' ) ) {
00075                         $this->output( "This was a dry run; rerun with --fix to update page_latest.\n" );
00076                 }
00077         }
00078 }
00079 
00080 $maintClass = "AttachLatest";
00081 require_once( RUN_MAINTENANCE_IF_MAIN );