Move up to date the parser test expectation.
[lhc/web/wiklou.git] / maintenance / attachLatest.php
1 <?php
2 /**
3 * quick hackjob to fix damages imports on wikisource
4 * page records have page_latest wrong
5 *
6 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
7 * http://www.mediawiki.org/
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @ingroup Maintenance
25 */
26
27 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
28
29 class AttachLatest extends Maintenance {
30
31 public function __construct() {
32 parent::__construct();
33 $this->addOption( "fix", "Actually fix the entries, will dry run otherwise" );
34 $this->mDescription = "Fix page_latest entries in the page table";
35 }
36
37 public function execute() {
38 $this->output( "Looking for pages with page_latest set to 0...\n" );
39 $dbw = wfGetDB( DB_MASTER );
40 $result = $dbw->select( 'page',
41 array( 'page_id', 'page_namespace', 'page_title' ),
42 array( 'page_latest' => 0 ),
43 __METHOD__ );
44
45 $n = 0;
46 foreach ( $result as $row ) {
47 $pageId = intval( $row->page_id );
48 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
49 $name = $title->getPrefixedText();
50 $latestTime = $dbw->selectField( 'revision',
51 'MAX(rev_timestamp)',
52 array( 'rev_page' => $pageId ),
53 __METHOD__ );
54 if ( !$latestTime ) {
55 $this->output( wfWikiID() . " $pageId [[$name]] can't find latest rev time?!\n" );
56 continue;
57 }
58
59 $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
60 if ( is_null( $revision ) ) {
61 $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, can't find revision id\n" );
62 continue;
63 }
64 $id = $revision->getId();
65 $this->output( wfWikiID() . " $pageId [[$name]] latest time $latestTime, rev id $id\n" );
66 if ( $this->hasOption( 'fix' ) ) {
67 $article = new Article( $title );
68 $article->updateRevisionOn( $dbw, $revision );
69 }
70 $n++;
71 }
72 $dbw->freeResult( $result );
73 $this->output( "Done! Processed $n pages.\n" );
74 if ( !$this->hasOption( 'fix' ) ) {
75 $this->output( "This was a dry run; rerun with --fix to update page_latest.\n" );
76 }
77 }
78 }
79
80 $maintClass = "AttachLatest";
81 require_once( DO_MAINTENANCE );