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