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