3 # Remove spurious brokenlinks
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";
11 $wgCommandLineMode = true;
13 include_once( "../LocalSettings.php" );
14 include_once( "../AdminSettings.php" );
16 $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ?
";" : ":";
17 ini_set( "include_path", "$IP$sep$include_path" );
19 include_once( "Setup.php" );
20 include_once( "./rebuildrecentchanges.inc" );
21 $wgTitle = Title
::newFromText( "Rebuild brokenlinks script" );
24 $wgDBuser = $wgDBadminuser;
25 $wgDBpassword = $wgDBadminpassword;
28 # That above is common code and should be hidden away :(
32 echo "Checking for broken brokenlinks...\n";
34 $sql = "SELECT cur_namespace,cur_title,cur_id FROM cur";
35 $res = wfQuery( $sql, DB_WRITE
);
36 while( $s = wfFetchObject( $res ) ) {
41 $title = Title
::makeTitle( $s->cur_namespace
, $s->cur_title
);
43 $t = $title->getPrefixedDBKey();
44 $tt = wfStrencode( $t );
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";
54 wfFreeResult( $res2 );
56 echo "Removing brokenlinks to [[$t]]...\n";
57 $sql3 = "DELETE FROM brokenlinks WHERE bl_to='$tt'";
58 $res3 = wfQuery( $sql3, DB_WRITE
);
62 echo "Illegal title?! Namespace $s->cur_namespace, title '$s->cur_title'\n";
65 echo "Done at $n.\n\n";
67 echo "Clearing linkscc table...\n";
68 $sql4 = "DELETE FROM linkscc";
69 wfQuery( $sql4, DB_WRITE
);