prefs toc styling
[lhc/web/wiklou.git] / maintenance / remove-brokenlinks.php
1 <?php
2
3 # Remove spurious brokenlinks
4
5 if ( ! is_readable( "../LocalSettings.php" ) ) {
6 print "A copy of your installation's LocalSettings.php\n" .
7 "must exist in the source directory.\n";
8 exit();
9 }
10
11 $wgCommandLineMode = true;
12 $DP = "../includes";
13 require_once( "../LocalSettings.php" );
14 require_once( "../AdminSettings.php" );
15
16 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
17 ini_set( "include_path", "$IP$sep$include_path" );
18
19 require_once( "Setup.php" );
20 require_once( "./rebuildrecentchanges.inc" );
21 $wgTitle = Title::newFromText( "Rebuild brokenlinks script" );
22 set_time_limit(0);
23
24 $wgDBuser = $wgDBadminuser;
25 $wgDBpassword = $wgDBadminpassword;
26
27
28 # That above is common code and should be hidden away :(
29
30 $n = 0;
31
32 echo "Checking for broken brokenlinks...\n";
33
34 $sql = "SELECT cur_namespace,cur_title,cur_id FROM cur";
35 $res = wfQuery( $sql, DB_WRITE );
36 while( $s = wfFetchObject( $res ) ) {
37 $n++;
38 if(($n % 500) == 0) {
39 echo "$n\n";
40 }
41 $title = Title::makeTitle( $s->cur_namespace, $s->cur_title );
42 if($title) {
43 $t = $title->getPrefixedDBKey();
44 $tt = wfStrencode( $t );
45 $any = false;
46 $sql2 = "SELECT bl_from,cur_id,cur_namespace,cur_title FROM brokenlinks,cur WHERE bl_to='$tt' AND cur_id=bl_from";
47 $res2 = wfQuery( $sql2, DB_WRITE );
48 while( $s = wfFetchObject( $res2 ) ) {
49 $from = Title::makeTitle( $s->cur_namespace, $s->cur_title );
50 $xt = $from->getPrefixedText();
51 echo "Found bad brokenlink to [[$t]] from page #$s->cur_id [[$xt]]!\n";
52 $any = true;
53 }
54 wfFreeResult( $res2 );
55 if($any) {
56 echo "Removing brokenlinks to [[$t]]...\n";
57 $sql3 = "DELETE FROM brokenlinks WHERE bl_to='$tt'";
58 $res3 = wfQuery( $sql3, DB_WRITE );
59 #echo "-- $sql3\n";
60 }
61 } else {
62 echo "Illegal title?! Namespace $s->cur_namespace, title '$s->cur_title'\n";
63 }
64 }
65 echo "Done at $n.\n\n";
66
67 echo "Clearing linkscc table...\n";
68 $sql4 = "DELETE FROM linkscc";
69 wfQuery( $sql4, DB_WRITE );
70
71 ?>