Some changes to the link tables. They now all use a key on cur_id for the *_from...
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
index 1876d93..af4e8a0 100644 (file)
@@ -27,8 +27,8 @@ function wfSpecialWhatlinkshere($par = NULL)
        $isredir = " (" . wfMsg( "isredirect" ) . ")\n";
 
        if ( 0 == $id ) {
-               $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='" .
-                 wfStrencode( $nt->getPrefixedDBkey() ) . "' LIMIT 500";
+               $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM brokenlinks,cur WHERE bl_to='" .
+                 wfStrencode( $nt->getPrefixedDBkey() ) . "' AND bl_from=cur_id LIMIT 500";
                $res = wfQuery( $sql, DB_READ, $fname );
 
                if ( 0 == wfNumRows( $res ) ) {
@@ -38,19 +38,16 @@ function wfSpecialWhatlinkshere($par = NULL)
                        $wgOut->addHTML( "\n<ul>" );
 
                        while ( $row = wfFetchObject( $res ) ) {
-                               $lid = $row->bl_from;
-                               $sql = "SELECT cur_namespace,cur_title,cur_is_redirect " .
-                                 "FROM cur WHERE cur_id={$lid}";
-                               $res2 = wfQuery( $sql, DB_READ, $fname );
-                               $s = wfFetchObject( $res2 );
-
-                               $n = Title::makeName( $s->cur_namespace, $s->cur_title );
-                               $link = $sk->makeKnownLink( $n, "", "redirect=no" );
+                               $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
+                               if( !$nt ) {
+                                       continue;
+                               }
+                               $link = $sk->makeKnownLinkObj( $nt, "", "redirect=no" );
                                $wgOut->addHTML( "<li>{$link}" );
 
-                               if ( 1 == $s->cur_is_redirect ) {
+                               if ( $row->cur_is_redirect ) {
                                        $wgOut->addHTML( $isredir );
-                                       wfShowIndirectLinks( 1, $lid );
+                                       wfShowIndirectLinks( 1, $row->cur_id );
                                }
                                $wgOut->addHTML( "</li>\n" );
                        }
@@ -67,7 +64,7 @@ function wfShowIndirectLinks( $level, $lid )
        global $wgOut, $wgUser;
        $fname = "wfShowIndirectLinks";
 
-       $sql = "SELECT l_from FROM links WHERE l_to={$lid} LIMIT 500";
+       $sql = "SELECT cur_id,cur_namespace,cur_title,cur_is_redirect FROM links,cur WHERE l_to={$lid} AND l_from=cur_id LIMIT 500";
        $res = wfQuery( $sql, DB_READ, $fname );
 
        if ( 0 == wfNumRows( $res ) ) {
@@ -84,34 +81,25 @@ function wfShowIndirectLinks( $level, $lid )
 
        $wgOut->addHTML( "<ul>" );
        while ( $row = wfFetchObject( $res ) ) {
-               $nt = Title::newFromDBkey( $row->l_from );
+               $nt = Title::makeTitle( $row->cur_namespace, $row->cur_title );
                if( !$nt ) {
                        $wgOut->addHTML( "<!-- bad backlink: " . htmlspecialchars( $row->l_from ) . " -->\n" );
                        continue;
                }
-               $ns = $nt->getNamespace();
-               $t = wfStrencode( $nt->getDBkey() );
-
-               # 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, DB_READ, $fname );
-               $s = wfFetchObject( $res2 );
-
-               if ( 1 == $s->cur_is_redirect ) {
+               if ( $row->cur_is_redirect ) {
                    $extra = "redirect=no";
                } else {
                    $extra = "";
                }
            
-               $link = $sk->makeKnownLink( $row->l_from, "", $extra );
+               $link = $sk->makeKnownLinkObj( $nt, "", $extra );
                $wgOut->addHTML( "<li>{$link}" );
 
-               if ( 1 == $s->cur_is_redirect ) {
+               if ( $row->cur_is_redirect ) {
                    $wgOut->addHTML( $isredir );
                    if ( $level < 2 ) {
-                       wfShowIndirectLinks( $level + 1, $s->cur_id );
+                       wfShowIndirectLinks( $level + 1, $row->cur_id );
                    }
                }
                $wgOut->addHTML( "</li>\n" );