- $id = $revision->getId();
- echo "$wgDBname $pageId [[$name]] latest time $latestTime, rev id $id\n";
- if( $fixit ) {
- $article = new Article( $title );
- $article->updateRevisionOn( $dbw, $revision );
+
+ public function execute() {
+ $this->output( "Looking for pages with page_latest set to 0...\n" );
+ $dbw = wfGetDB( DB_MASTER );
+ $result = $dbw->select( 'page',
+ array( 'page_id', 'page_namespace', 'page_title' ),
+ array( 'page_latest' => 0 ),
+ __METHOD__ );
+
+ $n = 0;
+ foreach ( $result as $row ) {
+ $pageId = intval( $row->page_id );
+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $name = $title->getPrefixedText();
+ $latestTime = $dbw->selectField( 'revision',
+ 'MAX(rev_timestamp)',
+ array( 'rev_page' => $pageId ),
+ __METHOD__ );
+ if ( !$latestTime ) {
+ $this->output( wfWikiID() . " $pageId [[$name]] can't find latest rev time?!\n" );
+ continue;
+ }
+
+ $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
+ if ( is_null( $revision ) ) {
+ $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
+ continue;
+ }
+ $id = $revision->getId();
+ $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, rev id $id\n" );
+ if ( $this->hasOption( 'fix' ) ) {
+ $article = new Article( $title );
+ $article->updateRevisionOn( $dbw, $revision );
+ }
+ $n++;
+ }
+ $this->output( "Done! Processed $n pages.\n" );
+ if ( !$this->hasOption( 'fix' ) ) {
+ $this->output( "This was a dry run; rerun with --fix to update page_latest.\n" );
+ }