quick hackjob to fix damages imports on wikisource
[lhc/web/wiklou.git] / maintenance / attachLatest.php
1 <?php
2 // quick hackjob to fix damages imports on wikisource
3 // page records have page_latest wrong
4
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 *
24 * @package MediaWiki
25 * @subpackage Maintenance
26 */
27
28 require_once( 'commandLine.inc' );
29
30 $fixit = isset( $options['fix'] );
31 $fname = 'attachLatest';
32
33 echo "Looking for pages with page_latest set to 0...\n";
34 $dbw =& wfGetDB( DB_MASTER );
35 $result = $dbw->select( 'page',
36 array( 'page_id', 'page_namespace', 'page_title' ),
37 array( 'page_latest' => 0 ),
38 $fname );
39
40 $n = 0;
41 while( $row = $dbw->fetchObject( $result ) ) {
42 $pageId = intval( $row->page_id );
43 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
44 $name = $title->getPrefixedText();
45 $latestTime = $dbw->selectField( 'revision',
46 'MAX(rev_timestamp)',
47 array( 'rev_page' => $pageId ),
48 $fname );
49 if( !$latestTime ) {
50 echo "$wgDBname $pageId [[$name]] can't find latest rev time?!\n";
51 continue;
52 }
53
54 $revision = Revision::loadFromTimestamp( $dbw, $title, $latestTime );
55 if( is_null( $revision ) ) {
56 echo "$wgDBname $pageId [[$name]] latest time $latestTime, can't find revision id\n";
57 continue;
58 }
59 $id = $revision->getId();
60 echo "$wgDBname $pageId [[$name]] latest time $latestTime, rev id $id\n";
61 if( $fixit ) {
62 $article = new Article( $title );
63 $article->updateRevisionOn( $dbw, $revision );
64 }
65 $n++;
66 }
67 $dbw->freeResult( $result );
68 echo "Done! Processed $n pages.\n";
69 if( !$fixit ) {
70 echo "This was a dry run; rerun with --fix to update page_latest.\n";
71 }
72
73 ?>