Squid branch merge. Calls to purge functions in Article.php and special pages.
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
index f9d2a26..35dab26 100644 (file)
@@ -1,15 +1,24 @@
 <?
 
-function wfSpecialWhatlinkshere()
+function wfSpecialWhatlinkshere($par = NULL)
 {
        global $wgUser, $wgOut, $target;
        $fname = "wfSpecialWhatlinkshere";
 
+       if($par) {
+               $target = $par;
+       } else {
+               $target = wfCleanQueryVar( $_REQUEST['target'] );
+       }
        if ( "" == $target ) {
                $wgOut->errorpage( "notargettitle", "notargettext" );
                return;
        }
-       $nt = Title::newFromURL( wfCleanQueryVar( $target ) );
+       $nt = Title::newFromURL( $target );
+       if( !$nt ) {
+               $wgOut->errorpage( "notargettitle", "notargettext" );
+               return;
+       }
        $wgOut->setPagetitle( $nt->getPrefixedText() );
        $wgOut->setSubtitle( wfMsg( "linklistsub" ) );
 
@@ -18,9 +27,9 @@ function wfSpecialWhatlinkshere()
        $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
 
        if ( 0 == $id ) {
-               $sql = "SELECT DISTINCT bl_from FROM brokenlinks WHERE bl_to='" .
+               $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='" .
                  wfStrencode( $nt->getPrefixedDBkey() ) . "' LIMIT 500";
-               $res = wfQuery( $sql, $fname );
+               $res = wfQuery( $sql, DB_READ, $fname );
 
                if ( 0 == wfNumRows( $res ) ) {
                        $wgOut->addHTML( wfMsg( "nolinkshere" ) );
@@ -32,7 +41,7 @@ function wfSpecialWhatlinkshere()
                                $lid = $row->bl_from;
                                $sql = "SELECT cur_namespace,cur_title,cur_is_redirect " .
                                  "FROM cur WHERE cur_id={$lid}";
-                               $res2 = wfQuery( $sql, $fname );
+                               $res2 = wfQuery( $sql, DB_READ, $fname );
                                $s = wfFetchObject( $res2 );
 
                                $n = Title::makeName( $s->cur_namespace, $s->cur_title );
@@ -58,8 +67,8 @@ function wfShowIndirectLinks( $level, $lid )
        global $wgOut, $wgUser;
        $fname = "wfShowIndirectLinks";
 
-       $sql = "SELECT DISTINCT l_from FROM links WHERE l_to={$lid} LIMIT 500";
-       $res = wfQuery( $sql, $fname );
+       $sql = "SELECT l_from FROM links WHERE l_to={$lid} LIMIT 500";
+       $res = wfQuery( $sql, DB_READ, $fname );
 
        if ( 0 == wfNumRows( $res ) ) {
                if ( 0 == $level ) {
@@ -76,24 +85,36 @@ function wfShowIndirectLinks( $level, $lid )
        $wgOut->addHTML( "<ul>" );
        while ( $row = wfFetchObject( $res ) ) {
                $nt = Title::newFromDBkey( $row->l_from );
+               if( !$nt ) {
+                       $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
+                       continue;
+               }
                $ns = $nt->getNamespace();
                $t = wfStrencode( $nt->getDBkey() );
 
-               $link = $sk->makeKnownLink( $row->l_from, "", "redirect=no" );
-               $wgOut->addHTML( "<li>{$link}" );
-
+               # FIXME: this should be in a join above, or cached in the links table
+               
                $sql = "SELECT cur_id,cur_is_redirect FROM cur " .
                  "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
-               $res2 = wfQuery( $sql, $fname );
+               $res2 = wfQuery( $sql, DB_READ, $fname );
                $s = wfFetchObject( $res2 );
 
                if ( 1 == $s->cur_is_redirect ) {
-                       $wgOut->addHTML( $isredir );
-                       if ( $level < 2 ) {
-                               wfShowIndirectLinks( $level + 1, $s->cur_id );
-                       }
+                   $extra = "redirect=no";
+               } else {
+                   $extra = "";
+               }
+           
+               $link = $sk->makeKnownLink( $row->l_from, "", $extra );
+               $wgOut->addHTML( "<li>{$link}" );
+
+               if ( 1 == $s->cur_is_redirect ) {
+                   $wgOut->addHTML( $isredir );
+                   if ( $level < 2 ) {
+                       wfShowIndirectLinks( $level + 1, $s->cur_id );
+                   }
                }
-               $wgOut->addHTML( "</il>\n" );
+               $wgOut->addHTML( "</li>\n" );
        }
        $wgOut->addHTML( "</ul>\n" );
 }