Some changes to the link tables. They now all use a key on cur_id for the *_from...
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 11 Mar 2004 09:06:13 +0000 (09:06 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 11 Mar 2004 09:06:13 +0000 (09:06 +0000)
This saves trouble in a number of places where we can now do joins with the link tables to get other info (such as cur_is_redirect!) as well as the name, and fewer bits need to be juggled on page renaming, as outgoing links no longer have to be changed (cur_id remains the same when a page is renamed).

rebuildLinks.inc and some of the tools in the 'maintenance page' still need to be updated to work with the new setup. (Special:Maintenance needs a *lot* of cleanup in general. It's kind of a catch-all of vaguely defined features which suck performance like a hydroelectric dam.)

Also I've slipped in some extra debug code. And, I think 'indexes.sql' is a big waste of time and should all be moved into tables.sql. Building indexes separately doesn't help on InnoDB and won't do anything on MyISAM either if you're just going to replace the table after it's built with an imported one from a dump which creates it with indexes.

18 files changed:
includes/Article.php
includes/Database.php
includes/ImagePage.php
includes/LinkCache.php
includes/LinksUpdate.php
includes/Parser.php
includes/ParserCache.php
includes/SpecialDeadendpages.php
includes/SpecialMaintenance.php
includes/SpecialMovepage.php
includes/SpecialRecentchangeslinked.php
includes/SpecialWhatlinkshere.php
includes/SquidUpdate.php
maintenance/archives/patch-linktables.sql [new file with mode: 0644]
maintenance/archives/patch-list.txt
maintenance/indexes.sql
maintenance/rebuildlinks.inc
maintenance/tables.sql

index 7e83b96..9d49d75 100644 (file)
@@ -843,11 +843,11 @@ class Article {
                        wfPurgeSquidServers($urlArr);
 
                        /* prepare the list of urls to purge */
-                       $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
+                       $sql = "SELECT cur_namespace,cur_title FROM links,cur WHERE l_to={$id} and l_from=cur_id" ;
                        $res = wfQuery ( $sql, DB_READ ) ;
                        while ( $BL = wfFetchObject ( $res ) )
                        {
-                               $tobj = Title::newFromDBkey( $BL->l_from) ; 
+                               $tobj = Title::MakeTitle( $BL->cur_namespace, $BL->cur_title ) ; 
                                $blurlArr[] = $tobj->getInternalURL();
                        }
                        wfFreeResult ( $res ) ;
@@ -899,18 +899,15 @@ class Article {
                        $res = wfQuery( $sql, DB_READ, $fname );
 
                        $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
-                       $now = wfTimestampNow();
+                       $now = wfTimestampNow();
                        $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
                        $first = true;
 
                        while ( $s = wfFetchObject( $res ) ) {
-                               $nt = Title::newFromDBkey( $s->l_from );
-                               $lid = $nt->getArticleID();
-
                                if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
                                $first = false;
-                               $sql .= "({$lid},'{$t}')";
-                               $sql2 .= "{$lid}";
+                               $sql .= "({$s->l_from},'{$t}')";
+                               $sql2 .= "{$s->l_from}";
                        }
                        $sql2 .= ")";
                        if ( ! $first ) {
@@ -922,10 +919,10 @@ class Article {
                        $sql = "DELETE FROM links WHERE l_to={$id}";
                        wfQuery( $sql, DB_WRITE, $fname );
 
-                       $sql = "DELETE FROM links WHERE l_from='{$t}'";
+                       $sql = "DELETE FROM links WHERE l_from={$id}";
                        wfQuery( $sql, DB_WRITE, $fname );
 
-                       $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
+                       $sql = "DELETE FROM imagelinks WHERE il_from={$d}";
                        wfQuery( $sql, DB_WRITE, $fname );
 
                        $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
index 8acd3d7..99422a3 100644 (file)
@@ -186,8 +186,21 @@ class Database {
        }
        
        function freeResult( $res ) { mysql_free_result( $res ); }
-       function fetchObject( $res ) { return mysql_fetch_object( $res ); }
-       function numRows( $res ) { return mysql_num_rows( $res ); }
+       function fetchObject( $res ) {
+               @$row = mysql_fetch_object( $res );
+               # FIXME: HACK HACK HACK HACK debug
+               if( mysql_errno() ) {
+                       wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( mysql_error() ) );
+               }
+               return $row;
+       }
+       function numRows( $res ) {
+               @$n = mysql_num_rows( $res ); 
+               if( mysql_errno() ) {
+                       wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( mysql_error() ) );
+               }
+               return $n;
+       }
        function numFields( $res ) { return mysql_num_fields( $res ); }
        function fieldName( $res, $n ) { return mysql_field_name( $res, $n ); }
        function insertId() { return mysql_insert_id( $this->mConn ); }
index 4eef270..b3630fc 100644 (file)
@@ -95,8 +95,8 @@ class ImagePage extends Article {
 
                $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
 
-               $sql = "SELECT il_from FROM imagelinks WHERE il_to='" .
-                 wfStrencode( $this->mTitle->getDBkey() ) . "'";
+               $sql = "SELECT cur_namespace,cur_title FROM imagelinks,cur WHERE il_to='" .
+                 wfStrencode( $this->mTitle->getDBkey() ) . "' AND il_from=cur_id";
                $res = wfQuery( $sql, DB_READ, "Article::imageLinks" );
 
                if ( 0 == wfNumRows( $res ) ) {
@@ -107,8 +107,8 @@ class ImagePage extends Article {
 
                $sk = $wgUser->getSkin();
                while ( $s = wfFetchObject( $res ) ) {
-                       $name = $s->il_from;
-                       $link = $sk->makeKnownLink( $name, "" );
+                       $name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
+                       $link = $sk->makeKnownLinkObj( $name, "" );
                        $wgOut->addHTML( "<li>{$link}</li>\n" );
                }
                $wgOut->addHTML( "</ul>\n" );
index f4c50c0..93721af 100644 (file)
@@ -148,17 +148,26 @@ class LinkCache {
                $fname = "LinkCache::preFill";
                wfProfileIn( $fname );
                # Note -- $fromtitle is a Title *object*
-               $dbkeyfrom = wfStrencode( $fromtitle->getPrefixedDBKey() );
 
+               $this->suspend();
+               $id = $fromtitle->getArticleID();
+               $this->resume();
+               
+               if( $id == 0 ) {
+                       wfDebug( "$fname - got id 0 for title '" . $fromtitle->getPrefixedDBkey() . "'\n" );
+                       wfProfileOut( $fname );
+                       return;
+               }
+               
                if ( $wgEnablePersistentLC ) {
-                       if( $this->fillFromLinkscc( $dbkeyfrom ) ){
+                       if( $this->fillFromLinkscc( $id ) ){
                                return;
                        }
                }
 
                $sql = "SELECT cur_id,cur_namespace,cur_title
                        FROM cur,links
-                       WHERE cur_id=l_to AND l_from='{$dbkeyfrom}'";
+                       WHERE cur_id=l_to AND l_from=$id";
                $res = wfQuery( $sql, DB_READ, $fname );
                while( $s = wfFetchObject( $res ) ) {
                        $this->addGoodLink( $s->cur_id,
@@ -166,16 +175,6 @@ class LinkCache {
                                );
                }
                
-               $this->suspend();
-               $id = $fromtitle->getArticleID();
-               $this->resume();
-               
-               if( $id == 0 ) {
-                       wfDebug( "$fname - got id 0 for title '" . $fromtitle->getPrefixedDBkey() . "'\n" );
-                       wfProfileOut( $fname );
-                       return;
-               }
-               
                $sql = "SELECT bl_to
                        FROM brokenlinks
                        WHERE bl_from='{$id}'";
@@ -264,8 +263,9 @@ class LinkCache {
                $this->mImageLinks = array();
        }
 
-       /* private */ function fillFromLinkscc( $dbkeyfrom ){ 
-               $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_title = '{$dbkeyfrom}'", 
+       /* private */ function fillFromLinkscc( $id ){ 
+               $id = IntVal( $id );
+               $res = wfQuery("SELECT lcc_cacheobj FROM linkscc WHERE lcc_pageid = $id", 
                        DB_READ);
                $row = wfFetchObject( $res );
                if( $row == FALSE)
@@ -297,15 +297,15 @@ class LinkCache {
                } else {
                        $ser = wfStrencode( serialize( $this ) );
                }
-               wfQuery("REPLACE INTO linkscc(lcc_pageid,lcc_title,lcc_cacheobj) " .
-                       "VALUES({$pid}, '{$dbkeyfrom}', '{$ser}')", DB_WRITE);
+               wfQuery("REPLACE INTO linkscc(lcc_pageid,lcc_cacheobj) " .
+                       "VALUES({$pid}, '{$ser}')", DB_WRITE);
        }
 
        # $pid is a page id
        /* static */ function linksccClearLinksTo( $pid ){
                $pid = intval( $pid );
                wfQuery("DELETE linkscc FROM linkscc,links ".
-                       "WHERE lcc_title=links.l_from AND l_to={$pid}", DB_WRITE);
+                       "WHERE lcc_pageid=links.l_from AND l_to={$pid}", DB_WRITE);
                wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
        }
 
index aebadd7..fe39d36 100644 (file)
@@ -38,13 +38,13 @@ class LinksUpdate {
                if ( $wgLinkCache->incrementalSetup( LINKCACHE_GOOD, $del, $add ) ) {
                        # Delete where necessary
                        if ( count( $del ) ) {
-                               $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}' AND l_to IN(".
+                               $sql = "DELETE FROM links WHERE l_from={$this->mId} AND l_to IN(".
                                        implode( ",", $del ) . ")";
                                wfQuery( $sql, DB_WRITE, $fname );
                        }
                } else {
                        # Delete everything
-                       $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
+                       $sql = "DELETE FROM links WHERE l_from={$this->mId}";
                        wfQuery( $sql, DB_WRITE, $fname );
                        
                        # Get the addition list
@@ -61,7 +61,7 @@ class LinksUpdate {
                                if ( ! $first ) { $sql .= ","; }
                                $first = false;
 
-                               $sql .= "('{$this->mTitleEnc}',{$lid})";
+                               $sql .= "({$this->mId},{$lid})";
                        }
                }
                if ( "" != $sql ) { 
@@ -106,7 +106,7 @@ class LinksUpdate {
 
                #------------------------------------------------------------------------------
                # Image links
-               $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
+               $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mId}'";
                wfQuery( $sql, DB_WRITE, $fname );
                
                # Get addition list
@@ -128,7 +128,7 @@ class LinksUpdate {
                                if ( ! $first ) { $sql .= ","; }
                                $first = false;
 
-                               $sql .= "('{$this->mTitleEnc}','{$iname}')";
+                               $sql .= "({$this->mId},'{$iname}')";
                        }
                }
                if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
@@ -156,7 +156,7 @@ class LinksUpdate {
                        wfQuery( $sql, DB_WRITE, $fname );
                }
                
-               $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
+               $sql = "DELETE FROM links WHERE l_from={$this->mId}";
                wfQuery( $sql, DB_WRITE, $fname );
 
                $a = $wgLinkCache->getGoodLinks();
@@ -168,7 +168,7 @@ class LinksUpdate {
                                if ( ! $first ) { $sql .= ","; }
                                $first = false;
 
-                               $sql .= "('{$this->mTitleEnc}',{$lid})";
+                               $sql .= "({$this->mId},{$lid})";
                        }
                }
                if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
@@ -191,7 +191,7 @@ class LinksUpdate {
                }
                if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
                
-               $sql = "DELETE FROM imagelinks WHERE il_from='{$this->mTitleEnc}'";
+               $sql = "DELETE FROM imagelinks WHERE il_from={$this->mId}";
                wfQuery( $sql, DB_WRITE, $fname );
 
                $a = $wgLinkCache->getImageLinks();
@@ -204,7 +204,7 @@ class LinksUpdate {
                                if ( ! $first ) { $sql .= ","; }
                                $first = false;
 
-                               $sql .= "('{$this->mTitleEnc}','{$iname}')";
+                               $sql .= "({$this->mId},'{$iname}')";
                        }
                }
                if ( "" != $sql ) { wfQuery( $sql, DB_WRITE, $fname ); }
@@ -234,9 +234,8 @@ class LinksUpdate {
                while ( $row = wfFetchObject( $res ) ) {
                        if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
                        $first = false;
-                       $nl = wfStrencode( Title::nameOf( $row->bl_from ) );
 
-                       $sql .= "('{$nl}',{$this->mId})";
+                       $sql .= "({$row->bl_from},{$this->mId})";
                        $sql2 .= $row->bl_from;
                }
                $sql2 .= ")";
index 435b406..360c126 100644 (file)
@@ -200,7 +200,7 @@ class Parser
 
                $doesexist = false ;
                if ( $doesexist ) {
-                       $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
+                       $sql = "SELECT cur_title,cur_namespace FROM cur,links WHERE l_to={$id} AND l_from=cur_id";
                } else {
                        $sql = "SELECT cur_title,cur_namespace FROM cur,brokenlinks WHERE bl_to={$id} AND bl_from=cur_id" ;
                }
@@ -211,13 +211,9 @@ class Parser
                #  $t = new Title ; 
                #  $t->newFromDBkey ( $x->l_from ) ;
                #  $t = $t->getText() ;
-                       if ( $doesexist ) {
-                               $t = $x->l_from ;
-                       } else {
-                               $t = $wgLang->getNsText ( $x->cur_namespace ) ;
-                               if ( $t != "" ) $t .= ":" ;
-                               $t .= $x->cur_title ;
-                       }
+                       $t = $wgLang->getNsText ( $x->cur_namespace ) ;
+                       if ( $t != "" ) $t .= ":" ;
+                       $t .= $x->cur_title ;
 
                        $y = explode ( ":" , $t , 2 ) ;
                        if ( count ( $y ) == 2 && $y[0] == $cat ) {
index c7d934b..70b9943 100644 (file)
@@ -44,7 +44,7 @@ class ParserCache
        function clearLinksTo( $pid ){
                $pid = intval( $pid );
                wfQuery("DELETE parsercache FROM parsercache,links ".
-                       "WHERE pc_title=links.l_from AND l_to={$pid}", DB_WRITE);
+                       "WHERE pc_pageid=links.l_from AND l_to={$pid}", DB_WRITE);
                wfQuery("DELETE FROM parsercache WHERE pc_pageid='{$pid}'", DB_WRITE);
        }
 
index 08d16c9..34105db 100644 (file)
@@ -16,7 +16,7 @@ class DeadendPagesPage extends PageQueryPage {
     
     function getSQL( $offset, $limit ) {
        return "SELECT cur_title " . 
-         "FROM cur LEFT JOIN links ON cur_title = l_from " .
+         "FROM cur LEFT JOIN links ON cur_id = l_from " .
          "WHERE l_from IS NULL " .
          "AND cur_namespace = 0 " .
          "ORDER BY cur_title " . 
index dc8a9fe..7b8fc49 100644 (file)
@@ -95,7 +95,9 @@ function wfSpecialDisambiguations()
        list( $limit, $offset ) = wfCheckLimits();
 
        $dp = wfStrencode( wfMsg("disambiguationspage") );
-
+       
+       die( "wfSpecialDisambiguation is broken. Link tables have changed...\n" );
+       
        $sql = "SELECT la.l_from,la.l_to,"
                . " lb.l_from AS source,lb.l_to AS dest,"
                . " c.cur_id, c.cur_title AS dt"
@@ -142,6 +144,7 @@ function wfSpecialDoubleRedirects()
 
        list( $limit, $offset ) = wfCheckLimits();
 
+       die( "wfSpecialDoubleRedirects() is broken for now; link tables are changed." );
        $sql = "SELECT l_from,l_to,cb.cur_text AS rt,cb.cur_title AS ti FROM links,cur AS ca, cur AS cb WHERE ca.cur_is_redirect=1 AND cb.cur_is_redirect=1 AND l_to=cb.cur_id AND l_from=ca.cur_title AND ca.cur_namespace=0 LIMIT {$offset}, {$limit}" ;
 
        $res = wfQuery( $sql, DB_READ, $fname );
index 6ac9d34..ad66cb1 100644 (file)
@@ -340,32 +340,29 @@ class MovePageForm {
                
                RecentChange::notifyMove( $now, $this->ot, $this->nt, $wgUser, $mt );
 
-               # The only link from here should be the old redirect
-
-               $sql = "DELETE FROM links WHERE l_from='{$this->nft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-
-               $sql = "UPDATE links SET l_from='{$this->nft}' WHERE l_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-
                # Swap links.  Using MAXINT as a temp; if there's ever an article
                # with id 4294967295, this will fail, but I think that's pretty safe
 
+               # FIXME: LOCK TABLE
+               # Reassign links to the old title to LIMBO
                $sql = "UPDATE links SET l_to=4294967295 WHERE l_to={$this->oldid}";
                wfQuery( $sql, DB_WRITE, $fname );
 
+               # Reassign links to the new title to the old title
                $sql = "UPDATE links SET l_to={$this->oldid} WHERE l_to={$this->newid}";
                wfQuery( $sql, DB_WRITE, $fname );
 
+               # Reassign links from LIMBO to the new title. Ah, clear as mud!
                $sql = "UPDATE links SET l_to={$this->newid} WHERE l_to=4294967295";
                wfQuery( $sql, DB_WRITE, $fname );
 
                # Note: the insert below must be after the updates above!
 
-               $sql = "INSERT INTO links (l_from,l_to) VALUES ('{$this->oft}',{$this->oldid})";
+               # Now, we record the link from the redirect to the new title.
+               # It should have no other outgoing links...
+               $sql = "DELETE FROM links WHERE l_from={$this->newid}";
                wfQuery( $sql, DB_WRITE, $fname );
-
-               $sql = "UPDATE imagelinks SET il_from='{$this->nft}' WHERE il_from='{$this->oft}'";
+               $sql = "INSERT INTO links (l_from,l_to) VALUES ({$this->newid},{$this->oldid})";
                wfQuery( $sql, DB_WRITE, $fname );
        }
 
@@ -406,22 +403,18 @@ class MovePageForm {
                RecentChange::notifyMove( $now, $this->ot, $this->nt, $wgUser, $comment );
                Article::onArticleCreate( $this->nt );
 
-               $sql = "UPDATE links SET l_from='{$this->nft}' WHERE l_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-
+               # Any text links to the old title must be reassigned to the redirect
                $sql = "UPDATE links SET l_to={$this->newid} WHERE l_to={$this->oldid}";
                wfQuery( $sql, DB_WRITE, $fname );
 
-               $sql = "INSERT INTO links (l_from,l_to) VALUES ('{$this->oft}',{$this->oldid})";
+               # Record the just-created redirect's linking to the page
+               $sql = "INSERT INTO links (l_from,l_to) VALUES ({$this->newid},{$this->oldid})";
                wfQuery( $sql, DB_WRITE, $fname );
 
                # Non-existent target may have had broken links to it; these must
                # now be removed and made into good links.
                $update = new LinksUpdate( $this->oldid, $this->nft );
                $update->fixBrokenLinks();
-
-               $sql = "UPDATE imagelinks SET il_from='{$this->nft}' WHERE il_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
        }
 
        function updateWatchlists()
index ddb66ac..1a50588 100644 (file)
@@ -18,6 +18,12 @@ function wfSpecialRecentchangeslinked( $par = NULL )
                return;
        }
        $nt = Title::newFromURL( $target );
+       if( !$nt ) {
+               $wgOut->errorpage( "notargettitle", "notargettext" );
+               return;
+       }
+       $id = $nt->getArticleId();
+       
        $wgOut->setSubtitle( wfMsg( "rclsub", $nt->getPrefixedText() ) );
 
        if ( ! $days ) {
@@ -44,9 +50,8 @@ function wfSpecialRecentchangeslinked( $par = NULL )
 
        $sql = "SELECT cur_id,cur_namespace,cur_title,cur_user,cur_comment," .
          "cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new FROM links, cur " .
-         "WHERE cur_timestamp > '{$cutoff}' {$cmq} AND l_to=cur_id AND l_from='" .
-      wfStrencode( $nt->getPrefixedDBkey() ) . "' GROUP BY cur_id " .
-         "ORDER BY inverse_timestamp LIMIT {$limit}";
+         "WHERE cur_timestamp > '{$cutoff}' {$cmq} AND l_to=cur_id AND l_from=$id " .
+      "GROUP BY cur_id ORDER BY inverse_timestamp LIMIT {$limit}";
        $res = wfQuery( $sql, DB_READ, $fname );
 
        $note = wfMsg( "rcnote", $limit, $days );
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" );
index 45e4883..27ee985 100644 (file)
@@ -2,31 +2,29 @@
 # See deferred.doc
 
 class SquidUpdate {
-
-       function SquidUpdate( $title, $urlArr = Array() )
-       {
+       var $title, $urlArr;
+       
+       function SquidUpdate( $title, $urlArr = Array() ) {
                $this->title = $title;
                $this->urlArr = $urlArr;
        }
 
 
-       function doUpdate()
-       {
-               if (count( $this->urlArr ) == 0) { // newly created Article
-                       /* prepare the list of urls to purge */
+       function doUpdate() {
+               if( count( $this->urlArr ) == 0) {
+                       # newly created Article
+                       # prepare the list of urls to purge
                        $id= $this->title->getArticleID();
-                       $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
-                       $res = wfQuery ( $sql, DB_READ ) ;
-                       while ( $BL = wfFetchObject ( $res ) )
-                       {
-                               $t = Title::newFromDBkey( $BL->l_from) ; 
-                               $this->urlArr[] = $t->getInternalURL() ;
+                       $sql = "SELECT cur_namespace,cur_title FROM links,cur WHERE l_to={$id} AND l_from=cur_id" ;
+                       $res = wfQuery( $sql, DB_READ );
+                       while( $row = wfFetchObject ( $res ) ) {
+                               $t = Title::MakeTitle( $row->cur_namespace, $row->cur_title );
+                               $this->urlArr[] = $t->getInternalURL();
                        }
-                       wfFreeResult ( $res ) ;
-
+                       wfFreeResult( $res );
                }
 
-               wfPurgeSquidServers($this->urlArr);
+               wfPurgeSquidServers( $this->urlArr );
        }
 }
 
diff --git a/maintenance/archives/patch-linktables.sql b/maintenance/archives/patch-linktables.sql
new file mode 100644 (file)
index 0000000..5293411
--- /dev/null
@@ -0,0 +1,48 @@
+--
+-- Track links that do exist
+-- l_from and l_to key to cur_id
+--
+DROP TABLE IF EXISTS links;
+CREATE TABLE links (
+  l_from int(8) unsigned NOT NULL default '0',
+  l_to int(8) unsigned NOT NULL default '0',
+  UNIQUE KEY l_from(l_from,l_to),
+  KEY (l_to)
+);
+
+--
+-- Track links to pages that don't yet exist.
+-- bl_from keys to cur_id
+-- bl_to is a text link (namespace:title)
+--
+DROP TABLE IF EXISTS brokenlinks;
+CREATE TABLE brokenlinks (
+  bl_from int(8) unsigned NOT NULL default '0',
+  bl_to varchar(255) binary NOT NULL default '',
+  UNIQUE KEY bl_from(bl_from,bl_to),
+  KEY (bl_to)
+);
+
+--
+-- Track links to images *used inline*
+-- il_from keys to cur_id, il_to keys to image_name.
+-- We don't distinguish live from broken links.
+--
+DROP TABLE IF EXISTS imagelinks;
+CREATE TABLE imagelinks (
+  il_from int(8) unsigned NOT NULL default '0',
+  il_to varchar(255) binary NOT NULL default '',
+  UNIQUE KEY il_from(il_from,il_to),
+  KEY (il_to)
+);
+
+--
+-- Stores (possibly gzipped) serialized objects with
+-- cache arrays to reduce database load slurping up
+-- from links and brokenlinks.
+--
+DROP TABLE IF EXISTS linkscc;
+CREATE TABLE linkscc (
+  lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
+  lcc_cacheobj MEDIUMBLOB NOT NULL
+);
index 9e8b82b..dc2d13a 100644 (file)
@@ -163,3 +163,8 @@ patch-rc-newindex.sql
 * 2004-02-14: Adds the ipb_expiry field to ipblocks
 patch-ipb_expiry.sql
 
+
+* 2004-03-11: Recreate links tables to avoid duplicating titles
+everywhere. **Rebuild your links after this with refreshLinks.php**
+
+patch-linktables.sql
index 90155c0..ffa0782 100644 (file)
@@ -1,3 +1,7 @@
+-- This file should be phased out.
+-- It's useless importing dumps that already have indexes in their definitions.
+--
+
 -- SQL to add non-unique indexes to Wikipedia database tables.
 -- This is read and executed by the install script; you should
 -- never have to run it by itself.
@@ -27,18 +31,6 @@ ALTER TABLE old
   ADD INDEX user_timestamp (old_user,inverse_timestamp),
   ADD INDEX usertext_timestamp (old_user_text,inverse_timestamp);
 
-ALTER TABLE links
-  ADD INDEX l_from (l_from),
-  ADD INDEX l_to (l_to);
-
-ALTER TABLE brokenlinks
-  ADD INDEX bl_from (bl_from),
-  ADD INDEX bl_to (bl_to);
-
-ALTER TABLE imagelinks
-  ADD INDEX il_from (il_from(10)),
-  ADD INDEX il_to (il_to(10));
-
 ALTER TABLE ipblocks
   ADD INDEX ipb_address (ipb_address),
   ADD INDEX ipb_user (ipb_user);
index f75f615..3aba4d0 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+die( "rebuildLinks.inc needs to be updated for the new schema\n" );
+
 # Functions for rebuilding the link tracking tables; must
 # be included within a script that also includes the Setup.
 # See rebuildlinks.php, for example.
index d9a034a..96aa781 100644 (file)
@@ -2,12 +2,7 @@
 -- This is read and executed by the install script; you should
 -- never have to run it by itself.
 --
--- Only UNIQUE keys are defined here; the rest are added by
--- indexes.sql.
---
--- If you change the main development branch version of this 
--- file, please add an appropriate ALTER TABLE to update.php, 
--- and increment the version number in Version.php.
+-- Indexes should be defined here; please import the rest from indexes.sql.
 
 DROP TABLE IF EXISTS user;
 CREATE TABLE user (
@@ -20,13 +15,13 @@ CREATE TABLE user (
   user_options blob NOT NULL default '',  
   user_touched char(14) binary NOT NULL default '',
   UNIQUE KEY user_id (user_id)
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
        
 DROP TABLE IF EXISTS user_newtalk;
 CREATE TABLE user_newtalk (
   user_id int(5) NOT NULL default '0',
   user_ip varchar(40) NOT NULL default ''
-) TYPE=MyISAM;
+);
 
 DROP TABLE IF EXISTS cur;
 CREATE TABLE cur (
@@ -47,7 +42,7 @@ CREATE TABLE cur (
   cur_touched char(14) binary NOT NULL default '',
   inverse_timestamp char(14) binary NOT NULL default '',
   UNIQUE KEY cur_id (cur_id)
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS old;
 CREATE TABLE old (
@@ -63,7 +58,7 @@ CREATE TABLE old (
   old_flags tinyblob NOT NULL default '',
   inverse_timestamp char(14) binary NOT NULL default '',
   UNIQUE KEY old_id (old_id)
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS archive;
 CREATE TABLE archive (
@@ -76,32 +71,56 @@ CREATE TABLE archive (
   ar_timestamp char(14) binary NOT NULL default '',
   ar_minor_edit tinyint(1) NOT NULL default '0',
   ar_flags tinyblob NOT NULL default ''
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
+--
+-- Track links that do exist
+-- l_from and l_to key to cur_id
+--
 DROP TABLE IF EXISTS links;
 CREATE TABLE links (
-  l_from varchar(255) binary NOT NULL default '',
-  l_to int(8) unsigned NOT NULL default '0'
-) TYPE=MyISAM;
+  l_from int(8) unsigned NOT NULL default '0',
+  l_to int(8) unsigned NOT NULL default '0',
+  UNIQUE KEY l_from(l_from,l_to),
+  KEY (l_to)
+);
 
+--
+-- Track links to pages that don't yet exist.
+-- bl_from keys to cur_id
+-- bl_to is a text link (namespace:title)
+--
 DROP TABLE IF EXISTS brokenlinks;
 CREATE TABLE brokenlinks (
   bl_from int(8) unsigned NOT NULL default '0',
-  bl_to varchar(255) binary NOT NULL default ''
-) TYPE=MyISAM;
+  bl_to varchar(255) binary NOT NULL default '',
+  UNIQUE KEY bl_from(bl_from,bl_to),
+  KEY (bl_to)
+);
+
+--
+-- Track links to images *used inline*
+-- il_from keys to cur_id, il_to keys to image_name.
+-- We don't distinguish live from broken links.
+--
+DROP TABLE IF EXISTS imagelinks;
+CREATE TABLE imagelinks (
+  il_from int(8) unsigned NOT NULL default '0',
+  il_to varchar(255) binary NOT NULL default '',
+  UNIQUE KEY il_from(il_from,il_to),
+  KEY (il_to)
+);
 
+--
+-- Stores (possibly gzipped) serialized objects with
+-- cache arrays to reduce database load slurping up
+-- from links and brokenlinks.
+--
 DROP TABLE IF EXISTS linkscc;
 CREATE TABLE linkscc (
   lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
-  lcc_title VARCHAR(255) binary NOT NULL UNIQUE KEY,
   lcc_cacheobj MEDIUMBLOB NOT NULL
-) TYPE=MyISAM;
-
-DROP TABLE IF EXISTS imagelinks;
-CREATE TABLE imagelinks (
-  il_from varchar(255) binary NOT NULL default '',
-  il_to varchar(255) binary NOT NULL default ''
-) TYPE=MyISAM;
+);
 
 DROP TABLE IF EXISTS site_stats;
 CREATE TABLE site_stats (
@@ -110,7 +129,7 @@ CREATE TABLE site_stats (
   ss_total_edits bigint(20) unsigned default '0',
   ss_good_articles bigint(20) unsigned default '0',
   UNIQUE KEY ss_row_id (ss_row_id)
-) TYPE=MyISAM;
+);
 
 DROP TABLE IF EXISTS hitcounter;
 CREATE TABLE hitcounter (
@@ -128,7 +147,7 @@ CREATE TABLE ipblocks (
   ipb_auto tinyint(1) NOT NULL default '0',
   ipb_expiry char(14) binary NOT NULL default '',
   UNIQUE KEY ipb_id (ipb_id)
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS image;
 CREATE TABLE image (
@@ -138,7 +157,7 @@ CREATE TABLE image (
   img_user int(5) unsigned NOT NULL default '0',
   img_user_text varchar(255) binary NOT NULL default '',
   img_timestamp char(14) binary NOT NULL default ''
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS oldimage;
 CREATE TABLE oldimage (
@@ -149,7 +168,7 @@ CREATE TABLE oldimage (
   oi_user int(5) unsigned NOT NULL default '0',
   oi_user_text varchar(255) binary NOT NULL default '',
   oi_timestamp char(14) binary NOT NULL default ''
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS recentchanges;
 CREATE TABLE recentchanges (
@@ -169,7 +188,7 @@ CREATE TABLE recentchanges (
   rc_type tinyint(3) unsigned NOT NULL default '0',
   rc_moved_to_ns tinyint(3) unsigned NOT NULL default '0',
   rc_moved_to_title varchar(255) binary NOT NULL default ''
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS watchlist;
 CREATE TABLE watchlist (
@@ -177,7 +196,7 @@ CREATE TABLE watchlist (
   wl_namespace tinyint(2) unsigned NOT NULL default '0',
   wl_title varchar(255) binary NOT NULL default '',
   UNIQUE KEY (wl_user, wl_namespace, wl_title)
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS math;
 CREATE TABLE math (
@@ -187,7 +206,7 @@ CREATE TABLE math (
   math_html text,
   math_mathml text,
   UNIQUE KEY math_inputhash (math_inputhash)
-) TYPE=MyISAM;
+);
 
 
 -- Table searchindex must be MyISAM for fulltext support
@@ -198,7 +217,7 @@ CREATE TABLE searchindex (
   si_title varchar(255) NOT NULL default '',
   si_text mediumtext NOT NULL default '',
   UNIQUE KEY (si_page)
-) TYPE=MyISAM PACK_KEYS=1;
+) PACK_KEYS=1;
 
 DROP TABLE IF EXISTS interwiki;
 CREATE TABLE interwiki (