Hooks! Hoooooks!
[lhc/web/wiklou.git] / includes / Article.php
index 9aa9092..792fd7e 100644 (file)
@@ -142,7 +142,8 @@ class Article {
        /**
                This function accepts a title string as parameter
                ($preload). If this string is non-empty, it attempts
-               to fetch the current revision text.
+               to fetch the current revision text. It respects
+               <includeonly>.
        */
        function getPreloadedText($preload) {
                if($preload) {
@@ -150,7 +151,9 @@ class Article {
                        if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
                        $rev=Revision::newFromTitle($preloadTitle);
                        if($rev) {
-                               return $rev->getText();
+                               $text=$rev->getText();
+                               $text=preg_replace('/<\/?includeonly>/i','',$text);
+                               return $text;
                                }
                        }
                }
@@ -227,16 +230,6 @@ class Article {
 
        }
 
-       /**
-        * Return an array of the columns of the "cur"-table
-        */
-       function getContentFields() {
-               return $wgArticleContentFields = array(
-                 'old_text','old_flags',
-                 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
-                 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
-       }
-
        /**
         * Return the oldid of the article that is to be shown.
         * For requests with a "direction", this is not the oldid of the
@@ -307,8 +300,7 @@ class Article {
         * @access private
         */
        function pageData( &$dbr, $conditions ) {
-               return $dbr->selectRow( 'page',
-                       array(
+               $fields = array(
                                'page_id',
                                'page_namespace',
                                'page_title',
@@ -319,9 +311,14 @@ class Article {
                                'page_random',
                                'page_touched',
                                'page_latest',
-                               'page_len' ),
+                               'page_len' ) ;
+               wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) )       ;
+               $row = $dbr->selectRow( 'page',
+                       $fields,
                        $conditions,
                        'Article::pageData' );
+               wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) )   ;
+               return $row ;
        }
 
        function pageDataFromTitle( &$dbr, $title ) {
@@ -431,15 +428,17 @@ class Article {
                                                return false;
                                        }
                                }
-                               $redirData = $this->pageDataFromTitle( $dbr, $rt );
-                               if( $redirData ) {
-                                       $redirRev = Revision::newFromId( $redirData->page_latest );
-                                       if( !is_null( $redirRev ) ) {
-                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                               $this->mTitle = $rt;
-                                               $data = $redirData;
-                                               $this->loadPageData( $data );
-                                               $revision = $redirRev;
+                               if( $rt->getInterwiki() == '' ) {
+                                       $redirData = $this->pageDataFromTitle( $dbr, $rt );
+                                       if( $redirData ) {
+                                               $redirRev = Revision::newFromId( $redirData->page_latest );
+                                               if( !is_null( $redirRev ) ) {
+                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                                       $this->mTitle = $rt;
+                                                       $data = $redirData;
+                                                       $this->loadPageData( $data );
+                                                       $revision = $redirRev;
+                                               }
                                        }
                                }
                        }
@@ -681,9 +680,9 @@ class Article {
         * the given title.
        */
        function view() {
-               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
-               global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
-               global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
+               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
+               global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
+               global $wgParserCache, $wgUseTrackbacks;
                $sk = $wgUser->getSkin();
 
                $fname = 'Article::view';
@@ -703,7 +702,7 @@ class Article {
                        require_once( 'DifferenceEngine.php' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
 
-                       $de = new DifferenceEngine( $oldid, $diff, $rcid );
+                       $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
                        // DifferenceEngine directly fetched the revision:
                        $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage();
@@ -759,15 +758,22 @@ class Article {
                                $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
                                $wgOut->setRobotpolicy( 'noindex,follow' );
                        }
+                       $wasRedirected = false;
                        if ( '' != $this->mRedirectedFrom ) {
-                               $sk = $wgUser->getSkin();
-                               $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '',
-                                 'redirect=no' );
-                               $s = wfMsg( 'redirectedfrom', $redir );
-                               $wgOut->setSubtitle( $s );
-
-                               # Can't cache redirects
-                               $pcache = false;
+                               if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
+                                       $sk = $wgUser->getSkin();
+                                       $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '', 'redirect=no' );
+                                       $s = wfMsg( 'redirectedfrom', $redir );
+                                       $wgOut->setSubtitle( $s );
+                                       
+                                       // Check the parser cache again, for the target page
+                                       if( $pcache ) {
+                                               if( $wgOut->tryParserCache( $this, $wgUser ) ) {
+                                                       $outputDone = true;
+                                               }
+                                       }
+                                       $wasRedirected = true;
+                               }
                        } elseif ( !empty( $rdfrom ) ) {
                                global $wgRedirectSources;
                                if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
@@ -775,9 +781,12 @@ class Article {
                                        $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
                                        $s = wfMsg( 'redirectedfrom', $redir );
                                        $wgOut->setSubtitle( $s );
+                                       $wasRedirected = true;
                                }
                        }
-
+               }
+               if( !$outputDone ) {
+                       wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
                        # wrap user css and user js in pre and don't parse
                        # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
                        if (
@@ -788,12 +797,16 @@ class Article {
                                $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
                        } else if ( $rt = Title::newFromRedirect( $text ) ) {
                                # Display redirect
-                               $imageUrl = $wgStylePath.'/common/images/redirect.png';
+                               $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+                               $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
+                               if( !$wasRedirected ) {
+                                       $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
+                               }
                                $targetUrl = $rt->escapeLocalURL();
                                $titleText = htmlspecialchars( $rt->getPrefixedText() );
                                $link = $sk->makeLinkObj( $rt );
 
-                               $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
+                               $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
                                  '<span class="redirectText">'.$link.'</span>' );
 
                                $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
@@ -802,6 +815,7 @@ class Article {
                                $skin = $wgUser->getSkin();
                        } else if ( $pcache ) {
                                # Display content and save to parser cache
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addPrimaryWikiText( $text, $this );
                        } else {
                                # Display content, don't attempt to save to parser cache
@@ -810,6 +824,7 @@ class Article {
                                if( !$this->isCurrent() ) {
                                        $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
                                }
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addWikiText( $text );
 
                                if( !$this->isCurrent() ) {
@@ -844,9 +859,6 @@ class Article {
                if ($wgUseTrackbacks)
                        $this->addTrackbacks();
 
-               # Put link titles into the link cache
-               $wgOut->transformBuffer();
-
                # Add link titles as META keywords
                $wgOut->addMetaTags() ;
 
@@ -915,6 +927,38 @@ class Article {
                $wgOut->setArticleBodyOnly(true);
                $this->view();
        }
+       
+       function purge() {
+               global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
+
+               if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() ) {
+                       // Invalidate the cache
+                       $this->mTitle->invalidateCache();
+
+                       if ( $wgUseSquid ) {
+                               // Commit the transaction before the purge is sent
+                               $dbw = wfGetDB( DB_MASTER );
+                               $dbw->immediateCommit();
+
+                               // Send purge
+                               $update = SquidUpdate::newSimplePurge( $this->mTitle );
+                               $update->doUpdate();
+                       }
+                       $this->view();
+               } else {
+                       $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
+                       $action = $this->mTitle->escapeLocalURL( 'action=purge' );
+                       $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
+                       $msg = str_replace( '$1', 
+                               "<form method=\"post\" action=\"$action\">\n" .
+                               "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
+                               "</form>\n", $msg );
+
+                       $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->addHTML( $msg );
+               }
+       }
 
        /**
         * Insert a new empty page record for this article.
@@ -944,6 +988,7 @@ class Article {
                        'page_random'       => wfRandom(),
                        'page_touched'      => $dbw->timestamp(),
                        'page_latest'       => 0, # Fill this in shortly...
+                       'page_len'          => 0, # Fill this in shortly...
                ), $fname );
                $newid = $dbw->insertId();
 
@@ -1034,8 +1079,7 @@ class Article {
         * @private
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
-               global $wgOut, $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
+               global $wgOut, $wgUser, $wgUseSquid;
 
                $fname = 'Article::insertNewArticle';
                wfProfileIn( $fname );
@@ -1106,7 +1150,7 @@ class Article {
                $this->editUpdates( $text, $summary, $isminor, $now );
 
                $oldid = 0; # new article
-               $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
+               $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid, $revisionId );
 
                wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
                        $summary, $isminor,
@@ -1118,6 +1162,9 @@ class Article {
                $this->replaceSection( $section, $text, $summary, $edittime );
        }
 
+       /**
+        * @return string Complete article text, or null if error
+        */
        function replaceSection($section, $text, $summary = '', $edittime = NULL) {
                $fname = 'Article::replaceSection';
                wfProfileIn( $fname );
@@ -1129,6 +1176,11 @@ class Article {
                                $dbw =& wfGetDB( DB_MASTER );
                                $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
                        }
+                       if( is_null( $rev ) ) {
+                               wfDebug( "Article::replaceSection asked for bogus section (page: " .
+                                       $this->getId() . "; section: $section; edittime: $edittime)\n" );
+                               return null;
+                       }
                        $oldtext = $rev->getText();
 
                        if($section=='new') {
@@ -1212,9 +1264,8 @@ class Article {
         * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               global $wgOut, $wgUser;
-               global $wgDBtransactions, $wgMwRedir;
-               global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
+               global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
+               global $wgPostCommitUpdateList, $wgUseFileCache;
 
                $fname = 'Article::updateArticle';
                wfProfileIn( $fname );
@@ -1258,6 +1309,7 @@ class Article {
                $oldsize = strlen( $oldtext );
                $newsize = strlen( $text );
                $lastRevision = 0;
+               $revisionId = 0;
 
                if ( 0 != strcmp( $text, $oldtext ) ) {
                        $this->mGoodAdjustment = $this->isCountable( $text )
@@ -1292,8 +1344,10 @@ class Article {
                                RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
                                        $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
                                        $revisionId );
-                               Article::onArticleEdit( $this->mTitle );
                                $dbw->commit();
+                               
+                               // Update caches outside the main transaction
+                               Article::onArticleEdit( $this->mTitle );
                        }
                }
 
@@ -1321,33 +1375,7 @@ class Article {
                        $this->editUpdates( $text, $summary, $minor, $now );
 
 
-                       $urls = array();
-                       # Template namespace
-                       # Purge all articles linking here
-                       if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
-                               $titles = $this->mTitle->getLinksTo();
-                               Title::touchArray( $titles );
-                               if ( $wgUseSquid ) {
-                                               foreach ( $titles as $title ) {
-                                                       $urls[] = $title->getInternalURL();
-                                               }
-                               }
-                       }
-
-                       # Squid updates
-                       if ( $wgUseSquid ) {
-                               $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
-                               $u = new SquidUpdate( $urls );
-                               array_push( $wgPostCommitUpdateList, $u );
-                       }
-
-                       # File cache
-                       if ( $wgUseFileCache ) {
-                               $cm = new CacheManager($this->mTitle);
-                               @unlink($cm->fileCacheName());
-                       }
-
-                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
+                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
                }
                wfRunHooks( 'ArticleSaveComplete',
                        array( &$this, &$wgUser, $text,
@@ -1361,8 +1389,8 @@ class Article {
         * After we've either updated or inserted the article, update
         * the link tables and redirect to the new page.
         */
-       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
-               global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
+       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
+               global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache;
                global $wgUseEnotif;
 
                $fname = 'Article::showArticle';
@@ -1378,14 +1406,11 @@ class Article {
                        }
                }
 
-               # Parse the text and replace links with placeholders
+               # Parse the text and save it to the parser cache
                $wgOut = new OutputPage();
-
-               # Pass the current title along in case we're creating a wiki page
-               # which is different than the currently displayed one (e.g. image
-               # pages created on file uploads); otherwise, link updates will
-               # go wrong.
-               $wgOut->addWikiTextWithTitle( $text, $this->mTitle );
+               $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
+               $wgOut->setRevisionId( $newid );
+               $wgOut->addPrimaryWikiText( $text, $this );
 
                if ( !$wgUseDumbLinkUpdate ) {
                        # Move the current links back to the second register
@@ -1405,13 +1430,7 @@ class Article {
                else
                        $r = '';
                $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
-
-               if ( $wgUseEnotif  ) {
-                       # this would be better as an extension hook
-                       include_once( "UserMailer.php" );
-                       $wgEnotif = new EmailNotification ();
-                       $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid );
-               }
+               
                wfProfileOut( $fname );
        }
 
@@ -1649,7 +1668,7 @@ class Article {
                        $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
                }
 
-               $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
+               $confirm = htmlspecialchars( wfMsg( 'protectpage' ) );
                $token = htmlspecialchars( $wgUser->editToken() );
 
                $wgOut->addHTML( "
@@ -1699,7 +1718,7 @@ class Article {
         * UI entry point for page deletion
         */
        function delete() {
-               global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
+               global $wgUser, $wgOut, $wgRequest;
                $fname = 'Article::delete';
                $confirm = $wgRequest->wasPosted() &&
                        $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
@@ -1825,7 +1844,7 @@ class Article {
 
                $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
 
-               $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
+               $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
                $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
                $token = htmlspecialchars( $wgUser->editToken() );
 
@@ -1887,9 +1906,8 @@ class Article {
         * Returns success
         */
        function doDeleteArticle( $reason ) {
-               global $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
-               global $wgUseTrackbacks;
+               global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
+               global $wgPostCommitUpdateList, $wgUseTrackbacks;
 
                $fname = 'Article::doDeleteArticle';
                wfDebug( $fname."\n" );
@@ -2071,15 +2089,17 @@ class Article {
                        );
                }
 
-               # Save it!
+               # Get the edit summary
                $target = Revision::newFromId( $s->rev_id );
-               $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+               $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+               $newComment = $wgRequest->getText( 'summary', $newComment );
 
+               # Save it!
                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
-               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
+               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
 
-               $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
+               $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
                Article::onArticleEdit( $this->mTitle );
 
                $dbw->commit();
@@ -2092,7 +2112,7 @@ class Article {
         * @private
         */
        function viewUpdates() {
-               global $wgDeferredUpdateList, $wgUseEnotif;
+               global $wgDeferredUpdateList;
 
                if ( 0 != $this->getID() ) {
                        global $wgDisableCounters;
@@ -2103,24 +2123,9 @@ class Article {
                        }
                }
 
-               # Update newtalk status if user is reading their own
-               # talk page
-
+               # Update newtalk / watchlist notification status
                global $wgUser;
-               if ($this->mTitle->getNamespace() == NS_USER_TALK &&
-                       $this->mTitle->getText() == $wgUser->getName())
-               {
-                       if ( $wgUseEnotif ) {
-                               require_once( 'UserTalkUpdate.php' );
-                               $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false );
-                       } else {
-                               $wgUser->setNewtalk(0);
-                               $wgUser->saveNewtalk();
-                       }
-               } elseif ( $wgUseEnotif ) {
-                       $wgUser->clearNotification( $this->mTitle );
-               }
-
+               $wgUser->clearNotification( $this->mTitle );
        }
 
        /**
@@ -2130,23 +2135,22 @@ class Article {
         * @param string $text
         */
        function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
-               global $wgDeferredUpdateList, $wgDBname, $wgMemc;
-               global $wgMessageCache, $wgUser, $wgUseEnotif;
-
-               wfSeedRandom();
-               if ( 0 == mt_rand( 0, 999 ) ) {
-                       # Periodically flush old entries from the recentchanges table.
-                       global $wgRCMaxAge;
-                       $dbw =& wfGetDB( DB_MASTER );
-                       $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
-                       $recentchanges = $dbw->tableName( 'recentchanges' );
-                       $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
-                       //$dbw->query( $sql ); // HACK: disabled for now, slowness
-
-                       // re-enabled for commit of unrelated live changes -- TS
-                       $dbw->query( $sql );
+               global $wgDeferredUpdateList, $wgMessageCache, $wgUser;
+
+               if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
+                       wfSeedRandom();
+                       if ( 0 == mt_rand( 0, 999 ) ) {
+                               # Periodically flush old entries from the recentchanges table.
+                               global $wgRCMaxAge;
+                               
+                               $dbw =& wfGetDB( DB_MASTER );
+                               $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
+                               $recentchanges = $dbw->tableName( 'recentchanges' );
+                               $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
+                               $dbw->query( $sql );
+                       }
                }
-               
+
                $id = $this->getID();
                $title = $this->mTitle->getPrefixedDBkey();
                $shortTitle = $this->mTitle->getDBkey();
@@ -2162,21 +2166,14 @@ class Article {
                        # If this is another user's talk page, update newtalk
 
                        if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
-                               if ( $wgUseEnotif ) {
-                                       require_once( 'UserTalkUpdate.php' );
-                                       $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary,
-                                         $minoredit, $timestamp_of_pagechange);
-                               } else {
-                                       $other = User::newFromName( $shortTitle );
-                                       if( is_null( $other ) && User::isIP( $shortTitle ) ) {
-                                               // An anonymous user
-                                               $other = new User();
-                                               $other->setName( $shortTitle );
-                                       }
-                                       if( $other ) {
-                                               $other->setNewtalk(1);
-                                               $other->saveNewtalk();
-                                       }
+                               $other = User::newFromName( $shortTitle );
+                               if( is_null( $other ) && User::isIP( $shortTitle ) ) {
+                                       // An anonymous user
+                                       $other = new User();
+                                       $other->setName( $shortTitle );
+                               }
+                               if( $other ) {
+                                       $other->setNewtalk( true );
                                }
                        }
 
@@ -2410,9 +2407,38 @@ class Article {
                }
        }
 
-       function onArticleEdit($title_obj) {
-               // This would be an appropriate place to purge caches.
-               // Why's this not in here now?
+       /**
+        * Purge caches on page update etc
+        */
+       function onArticleEdit( $title ) {
+               global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
+               
+               $urls = array();
+               
+               // Template namespace? Purge all articles linking here.
+               // FIXME: When a templatelinks table arrives, use it for all includes.
+               if ( $title->getNamespace() == NS_TEMPLATE) {
+                       $titles = $title->getLinksTo();
+                       Title::touchArray( $titles );
+                       if ( $wgUseSquid ) {
+                               foreach ( $titles as $link ) {
+                                       $urls[] = $link->getInternalURL();
+                               }
+                       }
+               }
+
+               # Squid updates
+               if ( $wgUseSquid ) {
+                       $urls = array_merge( $urls, $title->getSquidURLs() );
+                       $u = new SquidUpdate( $urls );
+                       array_push( $wgPostCommitUpdateList, $u );
+               }
+
+               # File cache
+               if ( $wgUseFileCache ) {
+                       $cm = new CacheManager( $title );
+                       @unlink( $cm->fileCacheName() );
+               }
        }
 
        /**#@-*/