useless call
[lhc/web/wiklou.git] / includes / Article.php
index 9b86e91..5d86ccf 100644 (file)
@@ -81,40 +81,33 @@ class Article {
         * @return Return the text of this revision
        */
        function getContent( $noredir ) {
-               global $wgRequest, $wgUser;
+               global $wgRequest, $wgUser, $wgOut;
 
                # Get variables from query string :P
                $action = $wgRequest->getText( 'action', 'view' );
                $section = $wgRequest->getText( 'section' );
                $preload = $wgRequest->getText( 'preload' );
-               $newpagetext = $wgRequest->getText('newpagetext');
 
                $fname =  'Article::getContent';
                wfProfileIn( $fname );
 
                if ( 0 == $this->getID() ) {
                        if ( 'edit' == $action ) {
-                               wfProfileOut( $fname );                         
-                               # Should we put something in the textarea?
-                               # if &preload=Pagename is set, we try to get
-                               # the revision text and put it in.
-                               if($preload) {
-                                       $preloadTitle=Title::newFromText($preload);
-                                       if($preloadTitle->userCanRead()) {
-                                               $rev=Revision::newFromTitle($preloadTitle);
-                                               if($rev) {
-                                               return $rev->getText();
-                                               }
-                                       }
-                               }
-                               # Don't preload anything.
-                               # We used to put MediaWiki:Newarticletext here.
+                               wfProfileOut( $fname );
+
+                               # If requested, preload some text.
+                               $text=$this->getPreloadedText($preload);
+
+                               # We used to put MediaWiki:Newarticletext here if
+                               # $text was empty at this point.
                                # This is now shown above the edit box instead.
-                               return ''; 
+                               return $text;
                        }
                        wfProfileOut( $fname );
+                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
                        
-                       return wfMsg( 'noarticletext' );
+                       $ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
+                       return "<div class='noarticletext'>$ret</div>";
                } else {
                        $this->loadContent( $noredir );
                        # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
@@ -129,7 +122,8 @@ class Article {
                                        if($section!='') {
                                                if($section=='new') {
                                                        wfProfileOut( $fname );
-                                                       return '';
+                                                       $text=$this->getPreloadedText($preload);
+                                                       return $text;
                                                }
 
                                                # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
@@ -145,6 +139,27 @@ 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. It respects
+               <includeonly>.
+       */
+       function getPreloadedText($preload) {
+               if($preload) {
+                       $preloadTitle=Title::newFromText($preload);
+                       if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
+                       $rev=Revision::newFromTitle($preloadTitle);
+                       if($rev) {
+                               $text=$rev->getText();
+                               $text=preg_replace('/<\/?includeonly>/i','',$text);
+                               return $text;
+                               }
+                       }
+               }
+               return '';
+       }
+
        /**
         * This function returns the text of a section, specified by a number ($section).
         * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
@@ -163,6 +178,7 @@ class Article {
                $striparray=array();
                $parser=new Parser();
                $parser->mOutputType=OT_WIKI;
+               $parser->mOptions = new ParserOptions();
                $striptext=$parser->strip($text, $striparray, true);
 
                # now that we can be sure that no pseudo-sections are in the source,
@@ -214,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
@@ -239,7 +245,7 @@ class Article {
                # Query variables :P
                $oldid = $wgRequest->getVal( 'oldid' );
                if ( isset( $oldid ) ) {
-                       $oldid = IntVal( $oldid );
+                       $oldid = intval( $oldid );
                        if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
                                $nextid = $this->mTitle->getNextRevisionID( $oldid );
                                if ( $nextid  ) {
@@ -319,7 +325,7 @@ class Article {
 
        function pageDataFromId( &$dbr, $id ) {
                return $this->pageData( $dbr, array(
-                       'page_id' => IntVal( $id ) ) );
+                       'page_id' => intval( $id ) ) );
        }
 
        /**
@@ -418,15 +424,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;
+                                               }
                                        }
                                }
                        }
@@ -476,11 +484,14 @@ class Article {
         * Get the database which should be used for reads
         */
        function &getDB() {
+               $ret =& wfGetDB( DB_MASTER );
+               return $ret;
                #if ( $this->mForUpdate ) {
-                       return wfGetDB( DB_MASTER );
+                       $ret =& wfGetDB( DB_MASTER );
                #} else {
-               #       return wfGetDB( DB_SLAVE );
+               #       $ret =& wfGetDB( DB_SLAVE );
                #}
+               return $ret;
        }
 
        /**
@@ -597,7 +608,7 @@ class Article {
 
        function getTimestamp() {
                $this->loadLastEdit();
-               return $this->mTimestamp;
+               return wfTimestamp(TS_MW, $this->mTimestamp);
        }
 
        function getUser() {
@@ -665,9 +676,9 @@ class Article {
         * the given title.
        */
        function view() {
-               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
-               global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
-               global $wgEnotif, $wgParser, $wgParserCache;
+               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
+               global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
+               global $wgParserCache, $wgUseTrackbacks;
                $sk = $wgUser->getSkin();
 
                $fname = 'Article::view';
@@ -687,7 +698,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();
@@ -743,15 +754,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 ) ) {
@@ -759,9 +777,11 @@ class Article {
                                        $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
                                        $s = wfMsg( 'redirectedfrom', $redir );
                                        $wgOut->setSubtitle( $s );
+                                       $wasRedirected = true;
                                }
                        }
-
+               }
+               if( !$outputDone ) {
                        # 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 (
@@ -772,12 +792,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));
@@ -786,6 +810,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
@@ -794,6 +819,7 @@ class Article {
                                if( !$this->isCurrent() ) {
                                        $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
                                }
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addWikiText( $text );
 
                                if( !$this->isCurrent() ) {
@@ -824,6 +850,10 @@ class Article {
                         );
                }
 
+               # Trackbacks
+               if ($wgUseTrackbacks)
+                       $this->addTrackbacks();
+
                # Put link titles into the link cache
                $wgOut->transformBuffer();
 
@@ -834,6 +864,100 @@ class Article {
                wfProfileOut( $fname );
        }
 
+       function addTrackbacks() {
+               global $wgOut, $wgUser;
+
+               $dbr =& wfGetDB(DB_SLAVE);
+               $tbs = $dbr->select(
+                               /* FROM   */ 'trackbacks',
+                               /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
+                               /* WHERE  */ array('tb_page' => $this->getID())
+               );
+
+               if (!$dbr->numrows($tbs))
+                       return;
+
+               $tbtext = "";
+               while ($o = $dbr->fetchObject($tbs)) {
+                       $rmvtxt = "";
+                       if ($wgUser->isSysop()) {
+                               $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid="
+                                               . $o->tb_id . "&token=" . $wgUser->editToken());
+                               $rmvtxt = wfMsg('trackbackremove', $delurl);
+                       }
+                       $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
+                                       $o->tb_title,
+                                       $o->tb_url,
+                                       $o->tb_ex,
+                                       $o->tb_name,
+                                       $rmvtxt);
+               }
+               $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
+       }
+
+       function deletetrackback() {
+               global $wgUser, $wgRequest, $wgOut, $wgTitle;
+
+               if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
+                       $wgOut->addWikitext(wfMsg('sessionfailure'));
+                       return;
+               }
+
+               if ((!$wgUser->isAllowed('delete'))) {
+                       $wgOut->sysopRequired();
+                       return;
+               }
+
+               if (wfReadOnly()) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+
+               $db =& wfGetDB(DB_MASTER);
+               $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
+               $wgTitle->invalidateCache();
+               $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
+       }
+
+       function render() {
+               global $wgOut;
+
+               $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.
         * This *must* be followed up by creating a revision
@@ -862,6 +986,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();
 
@@ -893,13 +1018,14 @@ class Article {
                        # An extra check against threads stepping on each other
                        $conditions['page_latest'] = $lastRevision;
                }
+
                $text = $revision->getText();
                $dbw->update( 'page',
                        array( /* SET */
                                'page_latest'      => $revision->getId(),
                                'page_touched'     => $dbw->timestamp(),
                                'page_is_new'      => ($lastRevision === 0) ? 1 : 0,
-                               'page_is_redirect' => Article::isRedirect( $text ),
+                               'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0,
                                'page_len'         => strlen( $text ),
                        ),
                        $conditions,
@@ -928,7 +1054,7 @@ class Article {
                                'page_latest=rev_id' ),
                        $fname );
                if( $row ) {
-                       if( $row->rev_timestamp >= $revision->getTimestamp() ) {
+                       if( wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp() ) {
                                wfProfileOut( $fname );
                                return false;
                        }
@@ -950,17 +1076,29 @@ class Article {
         * errors at some point.
         * @private
         */
-       function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false ) {
-               global $wgOut, $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
+       function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
+               global $wgOut, $wgUser, $wgUseSquid;
 
                $fname = 'Article::insertNewArticle';
+               wfProfileIn( $fname );
 
+               if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
+                       &$summary, &$isminor, &$watchthis, NULL ) ) ) {
+                       wfDebug( "$fname: ArticleSave hook aborted save!\n" );
+                       wfProfileOut( $fname );
+                       return false;
+               }
+               
                $this->mGoodAdjustment = $this->isCountable( $text );
                $this->mTotalAdjustment = 1;
 
                $ns = $this->mTitle->getNamespace();
                $ttl = $this->mTitle->getDBkey();
+
+               # If this is a comment, add the summary as headline
+               if($comment && $summary!="") {
+                       $text="== {$summary} ==\n\n".$text;
+               }
                $text = $this->preSaveTransform( $text );
                $isminor = ( $isminor && $wgUser->isLoggedIn() ) ? 1 : 0;
                $now = wfTimestampNow();
@@ -1010,11 +1148,25 @@ 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,
+                       $watchthis, NULL ) );
+               wfProfileOut( $fname );
        }
 
        function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
-               $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
+               $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 );
+
                if ($section != '') {
                        if( is_null( $edittime ) ) {
                                $rev = Revision::newFromTitle( $this->mTitle );
@@ -1022,6 +1174,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') {
@@ -1034,6 +1191,7 @@ class Article {
                                $striparray=array();
                                $parser=new Parser();
                                $parser->mOutputType=OT_WIKI;
+                               $parser->mOptions = new ParserOptions();
                                $oldtext=$parser->strip($oldtext, $striparray, true);
 
                                # now that we can be sure that no pseudo-sections are in the source,
@@ -1092,6 +1250,7 @@ class Article {
                        }
 
                }
+               wfProfileOut( $fname );
                return $text;
        }
 
@@ -1103,13 +1262,21 @@ 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;
+               global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
+               global $wgPostCommitUpdateList, $wgUseFileCache;
 
                $fname = 'Article::updateArticle';
+               wfProfileIn( $fname );
                $good = true;
 
+               if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
+                       &$summary, &$minor,
+                       &$watchthis, &$sectionanchor ) ) ) {
+                       wfDebug( "$fname: ArticleSave hook aborted save!\n" );
+                       wfProfileOut( $fname );
+                       return false;
+               }
+
                $isminor = ( $minor && $wgUser->isLoggedIn() );
                if ( $this->isRedirect( $text ) ) {
                        # Remove all content but redirect
@@ -1156,6 +1323,9 @@ class Article {
                                'minor_edit' => $isminor,
                                'text'       => $text
                                ) );
+                       
+                       $dbw->immediateCommit();
+                       $dbw->begin();
                        $revisionId = $revision->insertOn( $dbw );
 
                        # Update page
@@ -1164,6 +1334,7 @@ class Article {
                        if( !$ok ) {
                                /* Belated edit conflict! Run away!! */
                                $good = false;
+                               $dbw->rollback();
                        } else {
                                # Update recentchanges and purge cache and whatnot
                                $bot = (int)($wgUser->isBot() || $forceBot);
@@ -1171,6 +1342,7 @@ class Article {
                                        $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
                                        $revisionId );
                                Article::onArticleEdit( $this->mTitle );
+                               $dbw->commit();
                        }
                }
 
@@ -1180,10 +1352,18 @@ class Article {
 
                if ( $good ) {
                        if ($watchthis) {
-                               if (!$this->mTitle->userIsWatching()) $this->watch();
+                               if (!$this->mTitle->userIsWatching()) {
+                                       $dbw->immediateCommit();
+                                       $dbw->begin();
+                                       $this->watch();
+                                       $dbw->commit();
+                               }
                        } else {
                                if ( $this->mTitle->userIsWatching() ) {
+                                       $dbw->immediateCommit();
+                                       $dbw->begin();
                                        $this->unwatch();
+                                       $dbw->commit();
                                }
                        }
                        # standard deferred updates
@@ -1210,8 +1390,19 @@ class Article {
                                array_push( $wgPostCommitUpdateList, $u );
                        }
 
-                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
+                       # File cache
+                       if ( $wgUseFileCache ) {
+                               $cm = new CacheManager($this->mTitle);
+                               @unlink($cm->fileCacheName());
+                       }
+
+                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
                }
+               wfRunHooks( 'ArticleSaveComplete',
+                       array( &$this, &$wgUser, $text,
+                       $summary, $minor,
+                       $watchthis, $sectionanchor ) );
+               wfProfileOut( $fname );
                return $good;
        }
 
@@ -1219,10 +1410,13 @@ 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 ) {
+       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
                global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
                global $wgUseEnotif;
 
+               $fname = 'Article::showArticle';
+               wfProfileIn( $fname );
+
                $wgLinkCache = new LinkCache();
 
                if ( !$wgUseDumbLinkUpdate ) {
@@ -1233,14 +1427,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
@@ -1267,6 +1458,7 @@ class Article {
                        $wgEnotif = new EmailNotification ();
                        $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid );
                }
+               wfProfileOut( $fname );
        }
 
        /**
@@ -1469,8 +1661,7 @@ class Article {
                        }
                        return;
                } else {
-                       $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
-                       return $this->confirmProtect( '', $reason, $limit );
+                       return $this->confirmProtect( '', '', $limit );
                }
        }
 
@@ -1482,7 +1673,7 @@ class Article {
 
                wfDebug( "Article::confirmProtect\n" );
 
-               $sub = $this->mTitle->getPrefixedText();
+               $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
                $check = '';
@@ -1504,7 +1695,7 @@ class Article {
                        $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
                }
 
-               $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
+               $confirm = htmlspecialchars( wfMsg( 'protectpage' ) );
                $token = htmlspecialchars( $wgUser->editToken() );
 
                $wgOut->addHTML( "
@@ -1554,7 +1745,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' ) );
@@ -1606,7 +1797,7 @@ class Article {
                }
 
                # Fetch cur_text
-               $rev =& Revision::newFromTitle( $this->mTitle );
+               $rev = Revision::newFromTitle( $this->mTitle );
 
                # Fetch name(s) of contributors
                $rev_name = '';
@@ -1638,7 +1829,7 @@ class Article {
                        # this should not happen, since it is not possible to store an empty, new
                        # page. Let's insert a standard text in case it does, though
                        if( $length == 0 && $reason === '' ) {
-                               $reason = wfMsg( 'exblank' );
+                               $reason = wfMsgForContent( 'exblank' );
                        }
 
                        if( $length < 500 && $reason === '' ) {
@@ -1652,12 +1843,12 @@ class Article {
 
                                if( !$blanked ) {
                                        if( !$all_same_user ) {
-                                               $reason = wfMsg( 'excontent', $text );
+                                               $reason = wfMsgForContent( 'excontent', $text );
                                        } else {
-                                               $reason = wfMsg( 'excontentauthor', $text, $rev_name );
+                                               $reason = wfMsgForContent( 'excontentauthor', $text, $rev_name );
                                        }
                                } else {
-                                       $reason = wfMsg( 'exbeforeblank', $text );
+                                       $reason = wfMsgForContent( 'exbeforeblank', $text );
                                }
                        }
                }
@@ -1680,7 +1871,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() );
 
@@ -1742,8 +1933,8 @@ class Article {
         * Returns success
         */
        function doDeleteArticle( $reason ) {
-               global $wgUser;
-               global  $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
+               global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
+               global $wgPostCommitUpdateList, $wgUseTrackbacks;
 
                $fname = 'Article::doDeleteArticle';
                wfDebug( $fname."\n" );
@@ -1809,6 +2000,9 @@ class Article {
                $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
                $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
 
+               if ($wgUseTrackbacks)
+                       $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
+
                # Clean up recentchanges entries...
                $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
 
@@ -1875,7 +2069,7 @@ class Article {
 
                $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
                if( $from != $current->getUserText() ) {
-                       $wgOut->setPageTitle(wfmsg('rollbackfailed'));
+                       $wgOut->setPageTitle( wfMsg('rollbackfailed') );
                        $wgOut->addWikiText( wfMsg( 'alreadyrolled',
                                htmlspecialchars( $this->mTitle->getPrefixedText()),
                                htmlspecialchars( $from ),
@@ -1889,7 +2083,7 @@ class Article {
                }
 
                # Get the last edit not by this guy
-               $user = IntVal( $current->getUser() );
+               $user = intval( $current->getUser() );
                $user_text = $dbw->addQuotes( $current->getUserText() );
                $s = $dbw->selectRow( 'revision',
                        array( 'rev_id', 'rev_timestamp' ),
@@ -1922,15 +2116,17 @@ class Article {
                        );
                }
 
-               # Save it!
+               # Get the edit summary
                $target = Revision::newFromId( $s->rev_id );
-               $newcomment = wfMsg( '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();
@@ -1981,19 +2177,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 );
+               global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgUseEnotif;
+
+               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();
@@ -2014,8 +2213,13 @@ class Article {
                                        $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary,
                                          $minoredit, $timestamp_of_pagechange);
                                } else {
-                                       $other = User::newFromName($shortTitle);
-                                       if ($other) {
+                                       $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();
                                        }
@@ -2242,8 +2446,14 @@ class Article {
                }
        }
 
-       function onArticleDelete($title_obj) {
-               $title_obj->touchLinks();
+       function onArticleDelete( $title ) {
+               global $wgMessageCache;
+               
+               $title->touchLinks();
+               
+               if( $title->getNamespace() == NS_MEDIAWIKI) {
+                       $wgMessageCache->replace( $title->getDBkey(), false );
+               }
        }
 
        function onArticleEdit($title_obj) {
@@ -2260,7 +2470,7 @@ class Article {
         * @access public
         */
        function info() {
-               global $wgLang, $wgOut, $wgAllowPageInfo;
+               global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
                $fname = 'Article::info';
 
                if ( !$wgAllowPageInfo ) {
@@ -2276,7 +2486,7 @@ class Article {
                # first, see if the page exists at all.
                $exists = $page->getArticleId() != 0;
                if( !$exists ) {
-                       $wgOut->addHTML( wfMsg('noarticletext') );
+                       $wgOut->addHTML( wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) );
                } else {
                        $dbr =& $this->getDB( DB_SLAVE );
                        $wl_clause = array(
@@ -2369,9 +2579,6 @@ class Article {
                $db->freeResult( $res );
                return $result;
        }
-
-
 }
 
-
 ?>