Consolidate a bit of the link update code from movepage into linksupdate
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 5 Jul 2003 08:12:04 +0000 (08:12 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 5 Jul 2003 08:12:04 +0000 (08:12 +0000)
(specifically, turning brokenlinks on a new page into live links), which
should also fix the old code not touching the cache timestamps for pages
linking to the 'new' title after a move.

includes/LinksUpdate.php
includes/SpecialMovepage.php

index bf181ad..4f1ebbb 100644 (file)
@@ -9,21 +9,25 @@ class LinksUpdate {
        {
                $this->mId = $id;
                $this->mTitle = $title;
+               $this->mTitleEnc = wfStrencode( $title );
        }
 
        function doUpdate()
        {
+               /* Update link tables with outgoing links from an updated article */
+               /* Currently this is 'dumb', removing all links and putting them back. */
+               
+               /* Relies on the 'link cache' to be filled out */
                global $wgLinkCache, $wgDBtransactions;
                $fname = "LinksUpdate::doUpdate";
                wfProfileIn( $fname );
-               $t = wfStrencode( $this->mTitle );
 
                if( $wgDBtransactions ) {
                        $sql = "BEGIN";
                        wfQuery( $sql, $fname );
                }
                
-               $sql = "DELETE FROM links WHERE l_from='{$t}'";
+               $sql = "DELETE FROM links WHERE l_from='{$this->mTitleEnc}'";
                wfQuery( $sql, $fname );
 
                $a = $wgLinkCache->getGoodLinks();
@@ -35,7 +39,7 @@ class LinksUpdate {
                                if ( ! $first ) { $sql .= ","; }
                                $first = false;
 
-                               $sql .= "('{$t}',{$lid})";
+                               $sql .= "('{$this->mTitleEnc}',{$lid})";
                        }
                }
                if ( "" != $sql ) { wfQuery( $sql, $fname ); }
@@ -76,7 +80,20 @@ class LinksUpdate {
                }
                if ( "" != $sql ) { wfQuery( $sql, $fname ); }
 
-               $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$t}'";
+               $this->fixBrokenLinks();
+
+               if( $wgDBtransactions ) {
+                       $sql = "COMMIT";
+                       wfQuery( $sql, $fname );
+               }
+               wfProfileOut();
+       }
+       
+       function fixBrokenLinks() {
+               /* Update any brokenlinks *to* this page */
+               /* Call for a newly created page, or just to make sure state is consistent */
+               
+               $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
                $res = wfQuery( $sql, $fname );
                if ( 0 == wfNumRows( $res ) ) { return; }
 
@@ -96,15 +113,10 @@ class LinksUpdate {
                wfQuery( $sql, $fname );
                wfQuery( $sql2, $fname );
 
-               $sql = "DELETE FROM brokenlinks WHERE bl_to='{$t}'";
+               $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->mTitleEnc}'";
                wfQuery( $sql, $fname );
-
-               if( $wgDBtransactions ) {
-                       $sql = "COMMIT";
-                       wfQuery( $sql, $fname );
-               }
-               wfProfileOut();
        }
+       
 }
 
 ?>
index 245d537..eb8fbc2 100644 (file)
@@ -1,4 +1,5 @@
 <?
+include_once( "LinksUpdate.php" );
 
 function wfSpecialMovepage()
 {
@@ -380,18 +381,8 @@ class MovePageForm {
 
                # Non-existent target may have had broken links to it; these must
                # now be removed and made into good links.
-
-               $sql = "SELECT bl_from FROM brokenlinks WHERE bl_to='{$this->nft}'";
-               $res = wfQuery( $sql, $fname );
-
-               while ( $rec = wfFetchObject( $res ) ) {
-                       $lid = $rec->bl_from;
-                       $lt = wfStrencode( Article::nameOf( $lid ) );
-                       $sql = "INSERT INTO links (l_from,l_to) VALUES ('{$lt}',$this->oldid)";
-                       wfQuery( $sql, $fname );
-               }
-               $sql = "DELETE FROM brokenlinks WHERE bl_to='{$this->nft}'";
-               wfQuery( $sql, $fname );
+               $update = new LinksUpdate( $this->oldid, $this->nft );
+               $update->fixBrokenLinks();
 
                $sql = "UPDATE imagelinks SET il_from='{$this->nft}' WHERE il_from='{$this->oft}'";
                wfQuery( $sql, $fname );