2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * If on the old non-unique indexes, check the cur table for duplicate
22 * entries and remove them...
25 * @subpackage Maintenance
28 $options = array( 'fix' );
30 require_once( "commandLine.inc" );
31 $wgTitle = Title
::newFromText( "Dupe cur entry cleanup script" );
33 checkDupes( isset( $options['fix'] ) );
35 function fixDupes( $fixthem = false) {
36 $dbw =& wfGetDB( DB_MASTER
);
37 $cur = $dbw->tableName( 'cur' );
38 $dbw->query( "LOCK TABLES $cur WRITE" );
39 echo "Checking for duplicate cur table entries... (this may take a while on a large wiki)\n";
40 $res = $dbw->query( <<<END
41 SELECT cur_namespace,cur_title,count(*) as c,min(cur_id) as id
43 GROUP BY cur_namespace,cur_title
47 $n = $dbw->numRows( $res );
48 echo "Found $n titles with duplicate entries.\n";
51 echo "Correcting...\n";
53 echo "Just a demo...\n";
55 while( $row = $dbw->fetchObject( $res ) ) {
56 $ns = IntVal( $row->cur_namespace
);
57 $title = $dbw->addQuotes( $row->cur_title
);
58 $id = IntVal( $row->id
);
59 echo "$ns:$row->cur_title (canonical ID $id)\n";
64 WHERE cur_namespace=$ns
72 $dbw->query( 'UNLOCK TABLES' );
76 echo "Run again with --fix option to delete the duplicates.\n";
80 function checkDupes( $fixthem = false ) {
81 $dbw =& wfGetDB( DB_MASTER
);
82 if( $dbw->indexExists( 'cur', 'name_title' ) &&
83 $dbw->indexUnique( 'cur', 'name_title' ) ) {
84 echo "Your cur table has the current unique index; no duplicate entries.\n";
86 echo "Your cur table has the old non-unique index and may have duplicate entries.\n";