* (bug 2166) Fix partial categorylinks update so sortkeys are updated.
[lhc/web/wiklou.git] / maintenance / remove-brokenlinks.php
1 <?php
2 /**
3 * Remove spurious brokenlinks
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
7
8 /** */
9 require_once( "commandLine.inc" );
10 require_once( "./rebuildrecentchanges.inc" );
11 $wgTitle = Title::newFromText( "Rebuild brokenlinks script" );
12
13 $n = 0;
14
15 echo "Checking for broken brokenlinks...\n";
16
17 $dbw =& wfGetDB( DB_MASTER );
18 extract( $dbw->tableNames( 'brokenlinks', 'cur', 'linkscc' ) );
19
20 $res = $dbw->select( 'cur', array( 'cur_namespace', 'cur_title', 'cur_id' ), false );
21
22 while( $s = $dbw->fetchObject( $res ) ) {
23 $n++;
24 if(($n % 500) == 0) {
25 echo "$n\n";
26 }
27 $title = Title::makeTitle( $s->cur_namespace, $s->cur_title );
28 if($title) {
29 $t = $title->getPrefixedDBKey();
30 $tt = $dbw->strencode( $t );
31 $any = false;
32 $sql2 = "SELECT bl_from,cur_id,cur_namespace,cur_title FROM $brokenlinks,$cur " .
33 "WHERE bl_to='$tt' AND cur_id=bl_from";
34 $res2 = $dbw->query( $sql2 );
35 while( $s = $dbw->fetchObject( $res2 ) ) {
36 $from = Title::makeTitle( $s->cur_namespace, $s->cur_title );
37 $xt = $from->getPrefixedText();
38 echo "Found bad brokenlink to [[$t]] from page #$s->cur_id [[$xt]]!\n";
39 $any = true;
40 }
41 $dbw->freeResult( $res2 );
42 if($any) {
43 echo "Removing brokenlinks to [[$t]]...\n";
44 $sql3 = "DELETE FROM $brokenlinks WHERE bl_to='$tt'";
45 $res3 = $dbw->query( $sql3 );
46 #echo "-- $sql3\n";
47 }
48 } else {
49 echo "Illegal title?! Namespace $s->cur_namespace, title '$s->cur_title'\n";
50 }
51 }
52 echo "Done at $n.\n\n";
53
54 echo "Clearing linkscc table...\n";
55 $sql4 = "DELETE FROM $linkscc";
56 wfQuery( $sql4, DB_MASTER );
57
58 ?>