The last checkin broke the wiki on installations where TMP is not set
[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 $wgDBuser = $wgDBadminuser;
9 $wgDBpassword = $wgDBadminpassword;
10
11
12 # That above is common code and should be hidden away :(
13
14 $n = 0;
15
16 echo "Checking for broken brokenlinks...\n";
17
18 $sql = "SELECT cur_namespace,cur_title,cur_id FROM cur";
19 $res = wfQuery( $sql, DB_WRITE );
20 while( $s = wfFetchObject( $res ) ) {
21 $n++;
22 if(($n % 500) == 0) {
23 echo "$n\n";
24 }
25 $title = Title::makeTitle( $s->cur_namespace, $s->cur_title );
26 if($title) {
27 $t = $title->getPrefixedDBKey();
28 $tt = wfStrencode( $t );
29 $any = false;
30 $sql2 = "SELECT bl_from,cur_id,cur_namespace,cur_title FROM brokenlinks,cur WHERE bl_to='$tt' AND cur_id=bl_from";
31 $res2 = wfQuery( $sql2, DB_WRITE );
32 while( $s = wfFetchObject( $res2 ) ) {
33 $from = Title::makeTitle( $s->cur_namespace, $s->cur_title );
34 $xt = $from->getPrefixedText();
35 echo "Found bad brokenlink to [[$t]] from page #$s->cur_id [[$xt]]!\n";
36 $any = true;
37 }
38 wfFreeResult( $res2 );
39 if($any) {
40 echo "Removing brokenlinks to [[$t]]...\n";
41 $sql3 = "DELETE FROM brokenlinks WHERE bl_to='$tt'";
42 $res3 = wfQuery( $sql3, DB_WRITE );
43 #echo "-- $sql3\n";
44 }
45 } else {
46 echo "Illegal title?! Namespace $s->cur_namespace, title '$s->cur_title'\n";
47 }
48 }
49 echo "Done at $n.\n\n";
50
51 echo "Clearing linkscc table...\n";
52 $sql4 = "DELETE FROM linkscc";
53 wfQuery( $sql4, DB_WRITE );
54
55 ?>