Added hooks for article create/delete/edit events and moved linkscc calls there
authorMr. E23 <e23@users.mediawiki.org>
Mon, 5 Jan 2004 23:32:39 +0000 (23:32 +0000)
committerMr. E23 <e23@users.mediawiki.org>
Mon, 5 Jan 2004 23:32:39 +0000 (23:32 +0000)
includes/Article.php
includes/SpecialMovepage.php
includes/SpecialUndelete.php

index da19b4f..eab68b6 100644 (file)
@@ -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( "<h2>" . $newcomment . "</h2>\n<hr>\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 ) {
index f728739..5ee0313 100644 (file)
@@ -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 );
index 7226c3c..8111e2b 100644 (file)
@@ -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.
                }