From f55ee65a08b7cae06b8cdf9b2990e9747c1ba439 Mon Sep 17 00:00:00 2001 From: "Mr. E23" Date: Mon, 5 Jan 2004 23:32:39 +0000 Subject: [PATCH] Added hooks for article create/delete/edit events and moved linkscc calls there --- includes/Article.php | 55 +++++++++++++++++++++--------------- includes/SpecialMovepage.php | 12 +++----- includes/SpecialUndelete.php | 9 ++---- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index da19b4f6ea..eab68b6988 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -369,7 +369,6 @@ class Article { /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis ) { global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir; - global $wgEnablePersistentLC; $fname = "Article::insertNewArticle"; @@ -399,10 +398,7 @@ class Article { $newid = wfInsertId(); $this->mTitle->resetArticleID( $newid ); - if ( $wgEnablePersistentLC ) { - // Purge related entries in links cache on new page, to heal broken links - LinkCache::linksccClearBrokenLinksTo( $ttl ); - } + Article::onArticleCreate( $this->mTitle ); $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," . "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," . @@ -530,11 +526,7 @@ class Article { "WHERE rc_cur_id=" . $this->getID(); wfQuery( $sql, DB_WRITE, $fname ); - global $wgEnablePersistentLC; - if ( $wgEnablePersistentLC ) { - // Purge link cache for this page - LinkCache::linksccClearPage( $this->getID() ); - } + Article::onArticleEdit( $this->mTitle ); } if( $wgDBtransactions ) { @@ -815,8 +807,7 @@ class Article { function doDeleteArticle( $title ) { - global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList, - $wgEnablePersistentLC; + global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList; $fname = "Article::doDeleteArticle"; wfDebug( "$fname\n" ); @@ -868,10 +859,7 @@ class Article { $t = wfStrencode( $title->getPrefixedDBkey() ); - if ( $wgEnablePersistentLC ) { - // Purge related entries in links cache on delete, - LinkCache::linksccClearLinksTo( $id ); - } + Article::onArticleDelete( $title ); $sql = "SELECT l_from FROM links WHERE l_to={$id}"; $res = wfQuery( $sql, DB_READ, $fname ); @@ -996,12 +984,8 @@ class Article { $wgOut->setRobotpolicy( "noindex,nofollow" ); $wgOut->addHTML( "

" . $newcomment . "

\n
\n" ); $this->updateArticle( Article::getRevisionText( $s ), $newcomment, 1, $this->mTitle->userIsWatching(), "", $bot ); - - global $wgEnablePersistentLC; - if ( $wgEnablePersistentLC ) { - LinkCache::linksccClearPage( $pid ); - } - + + Article::onArticleEdit( $this->mTitle ); $wgOut->returnToMain( false ); } @@ -1262,6 +1246,33 @@ class Article { } wfIgnoreSQLErrors( $oldignore ); } + + # The onArticle*() functions are supposed to be a kind of hooks + # which should be called whenever any of the specified actions + # are done. + # + # This is a good place to put code to clear caches, for instance. + + /* static */ function onArticleCreate($title_obj){ + global $wgEnablePersistentLC; + if ( $wgEnablePersistentLC ) { + LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() ); + } + } + + /* static */ function onArticleDelete($title_obj){ + global $wgEnablePersistentLC; + if ( $wgEnablePersistentLC ) { + LinkCache::linksccClearLinksTo( $title_obj->getArticleID() ); + } + } + + /* static */ function onArticleEdit($title_obj){ + global $wgEnablePersistentLC; + if ( $wgEnablePersistentLC ) { + LinkCache::linksccClearPage( $title_obj->getArticleID() ); + } + } } function wfReplaceSubstVar( $matches ) { diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index f72873983b..5ee03133c3 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -377,22 +377,18 @@ class MovePageForm { "old_namespace={$this->ons} AND old_title='{$this->odt}'"; wfQuery( $sql, DB_WRITE, $fname ); - $sql = "UPDATE recentchanges SET ". + $sql = "UPDATE recentchanges SET ". "rc_namespace={$this->nns}, rc_title='{$this->ndt}' WHERE ". "rc_namespace={$this->ons} AND rc_title='{$this->odt}'"; - wfQuery( $sql, DB_WRITE, $fname ); + wfQuery( $sql, DB_WRITE, $fname ); $sql = "INSERT INTO recentchanges (rc_namespace,rc_title, rc_comment,rc_user,rc_user_text,rc_timestamp, rc_cur_time,rc_cur_id,rc_new) VALUES ({$common},'{$now}',{$this->newid},1)"; - wfQuery( $sql, DB_WRITE, $fname ); + wfQuery( $sql, DB_WRITE, $fname ); - global $wgEnablePersistentLC; - if ( $wgEnablePersistentLC ) { - // Purge related entries in links cache on new page, to heal broken links - LinkCache::linksccClearBrokenLinksTo( $this->nft ); - } + Article::onArticleCreate( $this->nt ); $sql = "UPDATE links SET l_from='{$this->nft}' WHERE l_from='{$this->oft}'"; wfQuery( $sql, DB_WRITE, $fname ); diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index 7226c3c7dd..8111e2b9a3 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -178,12 +178,9 @@ function wfSpecialUndelete( $par ) $u = new LinksUpdate( $newid, $to->getPrefixedDBkey() ); array_push( $wgDeferredUpdateList, $u ); - - global $wgEnablePersistentLC; - if ( $wgEnablePersistentLC ) { - // Purge related entries in links cache on undelete, to heal broken links - LinkCache::linksccClearBrokenLinksTo( $to->getPrefixedDBkey() ); - } + + Article::onArticleCreate( $to ); + #TODO: SearchUpdate, etc. } -- 2.20.1