From 6dff569b099d53f336dd65de57bd1a5091871892 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 5 Jul 2003 08:12:04 +0000 Subject: [PATCH] Consolidate a bit of the link update code from movepage into linksupdate (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 | 34 +++++++++++++++++++++++----------- includes/SpecialMovepage.php | 15 +++------------ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index bf181ad6a5..4f1ebbb3b4 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -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(); } + } ?> diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 245d53704e..eb8fbc2eac 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -1,4 +1,5 @@ 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 ); -- 2.20.1