Followup r78924: keep track of exception/warning comments separately, to prevent...
[lhc/web/wiklou.git] / includes / Article.php
index 7a99bef..d3673a3 100644 (file)
@@ -21,7 +21,6 @@ class Article {
        var $mContent;                    // !<
        var $mContentLoaded = false;      // !<
        var $mCounter = -1;               // !< Not loaded
-       var $mCurID = -1;                 // !< Not loaded
        var $mDataLoaded = false;         // !<
        var $mForUpdate = false;          // !<
        var $mGoodAdjustment = 0;         // !<
@@ -41,7 +40,7 @@ class Article {
        var $mTouched = '19700101000000'; // !<
        var $mUser = -1;                  // !< Not loaded
        var $mUserText = '';              // !< username from Revision if set
-       var $mParserOptions;              // !< ParserOptions object
+       var $mParserOptions;              // !< ParserOptions object for $wgUser articles
        var $mParserOutput;               // !< ParserCache object if set
        /**@}}*/
 
@@ -58,7 +57,7 @@ class Article {
 
        /**
         * Constructor from an page id
-        * @param $id The article ID to load
+        * @param $id Int article ID to load
         */
        public static function newFromID( $id ) {
                $t = Title::newFromID( $id );
@@ -119,14 +118,14 @@ class Article {
         */
        public function insertRedirect() {
                // recurse through to only get the final target
-               $retval = Title::newFromRedirectRecurse( $this->getContent() );
+               $retval = Title::newFromRedirectRecurse( $this->getRawText() );
                if ( !$retval ) {
                        return null;
                }
                $this->insertRedirectEntry( $retval );
                return $retval;
        }
-       
+
        /**
         * Insert or update the redirect table entry for this page to indicate
         * it redirects to $rt .
@@ -160,13 +159,13 @@ class Article {
         *
         * @param $text string article content containing redirect info
         * @return mixed false, Title of in-wiki target, or string with URL
-        * @deprecated
+        * @deprecated @since 1.17
         */
        public function followRedirectText( $text ) {
                // recurse through to only get the final target
                return $this->getRedirectURL( Title::newFromRedirectRecurse( $text ) );
        }
-       
+
        /**
         * Get the Title object or URL to use for a redirect. We use Title
         * objects for same-wiki, non-special redirects and URLs for everything
@@ -224,7 +223,7 @@ class Article {
                $this->mDataLoaded    = false;
                $this->mContentLoaded = false;
 
-               $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
+               $this->mUser = $this->mCounter = -1; # Not loaded
                $this->mRedirectedFrom = null; # Title object if set
                $this->mRedirectTarget = null; # Title object if set
                $this->mUserText =
@@ -401,9 +400,7 @@ class Article {
 
                wfProfileIn( __METHOD__ );
 
-               $oldid = $this->getOldID();
-               $this->mOldId = $oldid;
-               $this->fetchContent( $oldid );
+               $this->fetchContent( $this->getOldID() );
 
                wfProfileOut( __METHOD__ );
        }
@@ -470,8 +467,8 @@ class Article {
         */
        public function loadPageData( $data = 'fromdb' ) {
                if ( $data === 'fromdb' ) {
-                       $dbr = wfGetDB( DB_MASTER );
-                       $data = $this->pageDataFromId( $dbr, $this->getId() );
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
                }
 
                $lc = LinkCache::singleton();
@@ -508,8 +505,6 @@ class Article {
                        return $this->mContent;
                }
 
-               $dbr = wfGetDB( DB_MASTER );
-
                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
                $t = $this->mTitle->getPrefixedText();
@@ -523,28 +518,29 @@ class Article {
                                return false;
                        }
 
-                       $data = $this->pageDataFromId( $dbr, $revision->getPage() );
-
-                       if ( !$data ) {
-                               wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" );
-                               return false;
-                       }
-
-                       $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
-                       $this->loadPageData( $data );
-               } else {
-                       if ( !$this->mDataLoaded ) {
-                               $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
+                       if ( !$this->mDataLoaded || $this->getID() != $revision->getPage() ) {
+                               $data = $this->pageDataFromId( wfGetDB( DB_SLAVE ), $revision->getPage() );
 
                                if ( !$data ) {
-                                       wfDebug( __METHOD__ . " failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
+                                       wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" );
                                        return false;
                                }
 
+                               $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
                                $this->loadPageData( $data );
                        }
+               } else {
+                       if ( !$this->mDataLoaded ) {
+                               $this->loadPageData();
+                       }
+
+                       if ( $this->mLatest === false ) {
+                               wfDebug( __METHOD__ . " failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
+                               return false;
+                       }
+
                        $revision = Revision::newFromId( $this->mLatest );
-                       if (  $revision === null ) {
+                       if ( $revision === null ) {
                                wfDebug( __METHOD__ . " failed to retrieve current page, rev_id {$this->mLatest}\n" );
                                return false;
                        }
@@ -554,10 +550,9 @@ class Article {
                // We should instead work with the Revision object when we need it...
                $this->mContent   = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
 
-               $this->mUser      = $revision->getUser();
-               $this->mUserText  = $revision->getUserText();
-               $this->mComment   = $revision->getComment();
-               $this->mTimestamp = wfTimestamp( TS_MW, $revision->getTimestamp() );
+               if ( $revision->getId() == $this->mLatest ) {
+                       $this->setLastEdit( $revision );
+               }
 
                $this->mRevIdFetched = $revision->getId();
                $this->mContentLoaded = true;
@@ -669,18 +664,14 @@ class Article {
         */
        public function isRedirect( $text = false ) {
                if ( $text === false ) {
-                       if ( $this->mDataLoaded ) {
-                               return $this->mIsRedirect;
+                       if ( !$this->mDataLoaded ) {
+                               $this->loadPageData();
                        }
 
-                       // Apparently loadPageData was never called
-                       $this->loadContent();
-                       $titleObj = Title::newFromRedirectRecurse( $this->fetchContent() );
+                       return (bool)$this->mIsRedirect;
                } else {
-                       $titleObj = Title::newFromRedirect( $text );
+                       return Title::newFromRedirect( $text ) !== null;
                }
-
-               return $titleObj !== null;
        }
 
        /**
@@ -712,17 +703,25 @@ class Article {
                        return;
                }
 
-               $this->mLastRevision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id );
-               if ( !is_null( $this->mLastRevision ) ) {
-                       $this->mUser      = $this->mLastRevision->getUser();
-                       $this->mUserText  = $this->mLastRevision->getUserText();
-                       $this->mTimestamp = $this->mLastRevision->getTimestamp();
-                       $this->mComment   = $this->mLastRevision->getComment();
-                       $this->mMinorEdit = $this->mLastRevision->isMinor();
-                       $this->mRevIdFetched = $this->mLastRevision->getId();
+               $revision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id );
+               if ( !is_null( $revision ) ) {
+                       $this->setLastEdit( $revision );
                }
        }
 
+       /**
+        * Set the latest revision
+        */
+       protected function setLastEdit( Revision $revision ) {
+               $this->mLastRevision = $revision;
+               $this->mUser = $revision->getUser();
+               $this->mUserText = $revision->getUserText();
+               $this->mTimestamp = $revision->getTimestamp();
+               $this->mComment = $revision->getComment();
+               $this->mMinorEdit = $revision->isMinor();
+               $this->mRevIdFetched = $revision->getId();
+       }
+
        /**
         * @return string GMT timestamp of last article revision
         **/
@@ -893,6 +892,9 @@ class Article {
                        return;
                }
 
+               # Allow frames by default
+               $wgOut->allowClickjacking();
+
                if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
                        $parserOptions->setEditSection( false );
                }
@@ -966,11 +968,11 @@ class Article {
                                                if ( $oldid === $this->getLatest() && $this->useParserCache( false ) ) {
                                                        $this->mParserOutput = $parserCache->get( $this, $parserOptions );
                                                        if ( $this->mParserOutput ) {
-                                                               wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );                                                           
+                                                               wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );
                                                                $wgOut->addParserOutput( $this->mParserOutput );
                                                                $wgOut->setRevisionId( $this->mLatest );
                                                                $outputDone = true;
-                                                               break;                                                          
+                                                               break;
                                                        }
                                                }
                                        }
@@ -1002,10 +1004,9 @@ class Article {
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
-                                       $this->checkTouched();
                                        $key = $parserCache->getKey( $this, $parserOptions );
                                        $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
-                                       
+
                                        if ( !$poolArticleView->execute() ) {
                                                # Connection or timeout error
                                                wfProfileOut( __METHOD__ );
@@ -1180,7 +1181,7 @@ class Article {
         * merging of several policies using array_merge().
         * @param $policy Mixed, returns empty array on null/false/'', transparent
         *            to already-converted arrays, converts String.
-        * @return associative Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
+        * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
         */
        public static function formatRobotPolicy( $policy ) {
                if ( is_array( $policy ) ) {
@@ -1312,6 +1313,7 @@ class Article {
 
                $sk = $wgUser->getSkin();
                $token = $wgUser->editToken( $rcid );
+               $wgOut->preventClickjacking();
 
                $wgOut->addHTML(
                        "<div class='patrollink'>" .
@@ -1479,13 +1481,13 @@ class Article {
                $parserOptions->setIsPrintable( $wgOut->isPrintable() );
 
                # Don't show section-edit links on old revisions... this way lies madness.
-               if ( !$this->isCurrent() || $wgOut->isPrintable() ) {
+               if ( !$this->isCurrent() || $wgOut->isPrintable() || !$this->mTitle->quickUserCan( 'edit' ) ) {
                        $parserOptions->setEditSection( false );
                }
-               
+
                $useParserCache = $this->useParserCache( $oldid );
                $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
-               
+
                return true;
        }
 
@@ -1500,13 +1502,13 @@ class Article {
        public function tryDirtyCache() {
                global $wgOut;
                $parserCache = ParserCache::singleton();
-               $options = clone $this->getParserOptions();
-               
+               $options = $this->getParserOptions();
+
                if ( $wgOut->isPrintable() ) {
                        $options->setIsPrintable( true );
                        $options->setEditSection( false );
                }
-               
+
                $output = $parserCache->getDirty( $this, $options );
 
                if ( $output ) {
@@ -1529,7 +1531,7 @@ class Article {
        /**
         * View redirect
         *
-        * @param $target Title object or Array of destination(s) to redirect
+        * @param $target Title|Array of destination(s) to redirect
         * @param $appendSubtitle Boolean [optional]
         * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
         * @return string containing HMTL with redirect link
@@ -1570,7 +1572,7 @@ class Article {
                        }
                }
 
-               $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';              
+               $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
                return '<div class="redirectMsg">' .
                        Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
                        '<span class="redirectText">' . $link . '</span></div>';
@@ -1592,6 +1594,8 @@ class Article {
                        return;
                }
 
+               $wgOut->preventClickjacking();
+
                $tbtext = "";
                foreach ( $tbs as $o ) {
                        $rmvtxt = "";
@@ -1675,7 +1679,7 @@ class Article {
                        $form  = Html::openElement( 'form', $formParams );
                        $form .= Xml::submitButton( wfMsg( 'confirm_purge_button' ) );
                        $form .= Html::closeElement( 'form' );
-                       
+
                        $wgOut->addHTML( $form );
                        $wgOut->addWikiMsg( 'confirm-purge-bottom' );
 
@@ -1692,6 +1696,7 @@ class Article {
 
                // Invalidate the cache
                $this->mTitle->invalidateCache();
+               $this->clear();
 
                if ( $wgUseSquid ) {
                        // Commit the transaction before the purge is sent
@@ -1814,7 +1819,7 @@ class Article {
         * Add row to the redirect table if this is a redirect, remove otherwise.
         *
         * @param $dbw Database
-        * @param $redirectTitle a title object pointing to the redirect target,
+        * @param $redirectTitle Title object pointing to the redirect target,
         *                       or NULL if this is not a redirect
         * @param $lastRevIsRedirect If given, will optimize adding and
         *                           removing rows in redirect table.
@@ -1935,6 +1940,7 @@ class Article {
        /**
         * This function is not deprecated until somebody fixes the core not to use
         * it. Nevertheless, use Article::doEdit() instead.
+        * @deprecated @since 1.7
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC = false, $comment = false, $bot = false ) {
                $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
@@ -1966,7 +1972,7 @@ class Article {
        }
 
        /**
-        * @deprecated use Article::doEdit()
+        * @deprecated @since 1.7 use Article::doEdit()
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
                $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
@@ -2051,7 +2057,7 @@ class Article {
         * auto-detection due to MediaWiki's performance-optimised locking strategy.
         *
         * @param $baseRevId the revision ID this edit was based off, if any
-        * @param $user Optional user object, $wgUser will be used if not passed
+        * @param $user User (optional), $wgUser will be used if not passed
         *
         * @return Status object. Possible errors:
         *     edit-hook-aborted:       The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
@@ -2111,7 +2117,7 @@ class Article {
                        $summary = $this->getAutosummary( $oldtext, $text, $flags );
                }
 
-               $editInfo = $this->prepareTextForEdit( $text );
+               $editInfo = $this->prepareTextForEdit( $text, null, $user );
                $text = $editInfo->pst;
                $newsize = strlen( $text );
 
@@ -2152,6 +2158,7 @@ class Article {
                                        'parent_id'  => $this->mLatest,
                                        'user'       => $user->getId(),
                                        'user_text'  => $user->getName(),
+                                       'timestamp'  => $now
                                ) );
 
                                $dbw->begin();
@@ -2183,7 +2190,8 @@ class Article {
                                        # Update recentchanges
                                        if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                                # Mark as patrolled if the user can do so
-                                               $patrolled = $wgUseRCPatrol && $this->mTitle->userCan( 'autopatrol' );
+                                               $patrolled = $wgUseRCPatrol && !count(
+                                                       $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
                                                # Add RC row to the DB
                                                $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
                                                        $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
@@ -2222,7 +2230,7 @@ class Article {
                        # as a template. Partly deferred.
                        Article::onArticleEdit( $this->mTitle );
                        # Update links tables, site stats, etc.
-                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
+                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed, $user );
                } else {
                        # Create new article
                        $status->value['new'] = true;
@@ -2255,7 +2263,8 @@ class Article {
                                'text'       => $text,
                                'user'       => $user->getId(),
                                'user_text'  => $user->getName(),
-                               ) );
+                               'timestamp'  => $now
+                       ) );
                        $revisionId = $revision->insertOn( $dbw );
 
                        $this->mTitle->resetArticleID( $newid );
@@ -2270,7 +2279,8 @@ class Article {
                                global $wgUseRCPatrol, $wgUseNPPatrol;
 
                                # Mark as patrolled if the user can do so
-                               $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && $this->mTitle->userCan( 'autopatrol' );
+                               $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
+                                       $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
                                # Add RC row to the DB
                                $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
                                        '', strlen( $text ), $revisionId, $patrolled );
@@ -2284,7 +2294,7 @@ class Article {
                        $dbw->commit();
 
                        # Update links, etc.
-                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
+                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user );
 
                        # Clear caches
                        Article::onArticleCreate( $this->mTitle );
@@ -2308,14 +2318,6 @@ class Article {
                return $status;
        }
 
-       /**
-        * @deprecated wrapper for doRedirect
-        */
-       public function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
-               wfDeprecated( __METHOD__ );
-               $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
-       }
-
        /**
         * Output a redirect back to the article.
         * This is typically used after an edit.
@@ -2518,7 +2520,7 @@ class Article {
                $id = $this->mTitle->getArticleID();
 
                if ( $id <= 0 ) {
-                       wfDebug( "updateRestrictions failed: $id <= 0\n" );
+                       wfDebug( "updateRestrictions failed: article id $id <= 0\n" );
                        return false;
                }
 
@@ -3019,7 +3021,7 @@ class Article {
                wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
 
                if ( $wgUser->isAllowed( 'suppressrevision' ) ) {
-                       $suppress = "<tr id=\"wpDeleteSuppressRow\" name=\"wpDeleteSuppressRow\">
+                       $suppress = "<tr id=\"wpDeleteSuppressRow\">
                                        <td></td>
                                        <td class='mw-input'><strong>" .
                                                Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
@@ -3569,9 +3571,8 @@ class Article {
 
                # Don't update page view counters on views from bot users (bug 14044)
                if ( !$wgDisableCounters && !$wgUser->isAllowed( 'bot' ) && $this->getID() ) {
-                       Article::incViewCount( $this->getID() );
-                       $u = new SiteStatsUpdate( 1, 0, 0 );
-                       array_push( $wgDeferredUpdateList, $u );
+                       $wgDeferredUpdateList[] = new ViewCountUpdate( $this->getID() );
+                       $wgDeferredUpdateList[] = new SiteStatsUpdate( 1, 0, 0 );
                }
 
                # Update newtalk / watchlist notification status
@@ -3582,7 +3583,7 @@ class Article {
         * Prepare text which is about to be saved.
         * Returns a stdclass with source, pst and output members
         */
-       public function prepareTextForEdit( $text, $revid = null ) {
+       public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
                if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid ) {
                        // Already prepared
                        return $this->mPreparedEdit;
@@ -3593,10 +3594,10 @@ class Article {
                $edit = (object)array();
                $edit->revid = $revid;
                $edit->newText = $text;
-               $edit->pst = $this->preSaveTransform( $text );
-               $edit->popts = clone $this->getParserOptions();
+               $edit->pst = $this->preSaveTransform( $text, $user );
+               $edit->popts = $this->getParserOptions( true );
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
-               $edit->oldText = $this->getContent();
+               $edit->oldText = $this->getRawText();
 
                $this->mPreparedEdit = $edit;
 
@@ -3613,11 +3614,12 @@ class Article {
         * @param $text String: New text of the article
         * @param $summary String: Edit summary
         * @param $minoredit Boolean: Minor edit
-        * @param $timestamp_of_pagechange Timestamp associated with the page change
+        * @param $timestamp_of_pagechange String timestamp associated with the page change
         * @param $newid Integer: rev_id value of the new revision
         * @param $changed Boolean: Whether or not the content actually changed
+        * @param $user User object: User doing the edit
         */
-       public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
+       public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) {
                global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgEnableParserCache;
 
                wfProfileIn( __METHOD__ );
@@ -3626,7 +3628,7 @@ class Article {
                # Be careful not to double-PST: $text is usually already PST-ed once
                if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
                        wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" );
-                       $editInfo = $this->prepareTextForEdit( $text, $newid );
+                       $editInfo = $this->prepareTextForEdit( $text, $newid, $user );
                } else {
                        wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" );
                        $editInfo = $this->mPreparedEdit;
@@ -3868,13 +3870,20 @@ class Article {
         * so we can do things like signatures and links-in-context.
         *
         * @param $text String article contents
+        * @param $user User object: user doing the edit, $wgUser will be used if
+        *              null is given
         * @return string article contents with altered wikitext markup (signatures
         *      converted, {{subst:}}, templates, etc.)
         */
-       public function preSaveTransform( $text ) {
-               global $wgParser, $wgUser;
+       public function preSaveTransform( $text, User $user = null ) {
+               global $wgParser;
 
-               return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
+               if ( $user === null ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
+
+               return $wgParser->preSaveTransform( $text, $this->mTitle, $user, ParserOptions::newFromUser( $user ) );
        }
 
        /* Caching functions */
@@ -3920,7 +3929,7 @@ class Article {
                $cacheable = false;
 
                if ( HTMLFileCache::useFileCache() ) {
-                       $cacheable = $this->getID() && !$this->mRedirectedFrom;
+                       $cacheable = $this->getID() && !$this->mRedirectedFrom && !$this->mTitle->isRedirect();
                        // Extension may have reason to disable file caching on some pages.
                        if ( $cacheable ) {
                                $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
@@ -3995,73 +4004,6 @@ class Article {
        }
 
        /**
-        * Used to increment the view counter
-        *
-        * @param $id Integer: article id
-        */
-       public static function incViewCount( $id ) {
-               $id = intval( $id );
-
-               global $wgHitcounterUpdateFreq;
-
-               $dbw = wfGetDB( DB_MASTER );
-               $pageTable = $dbw->tableName( 'page' );
-               $hitcounterTable = $dbw->tableName( 'hitcounter' );
-               $acchitsTable = $dbw->tableName( 'acchits' );
-               $dbType = $dbw->getType();
-
-               if ( $wgHitcounterUpdateFreq <= 1 || $dbType == 'sqlite' ) {
-                       $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
-
-                       return;
-               }
-
-               # Not important enough to warrant an error page in case of failure
-               $oldignore = $dbw->ignoreErrors( true );
-
-               $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
-
-               $checkfreq = intval( $wgHitcounterUpdateFreq / 25 + 1 );
-               if ( ( rand() % $checkfreq != 0 ) or ( $dbw->lastErrno() != 0 ) ) {
-                       # Most of the time (or on SQL errors), skip row count check
-                       $dbw->ignoreErrors( $oldignore );
-
-                       return;
-               }
-
-               $res = $dbw->query( "SELECT COUNT(*) as n FROM $hitcounterTable" );
-               $row = $dbw->fetchObject( $res );
-               $rown = intval( $row->n );
-
-               if ( $rown >= $wgHitcounterUpdateFreq ) {
-                       wfProfileIn( 'Article::incViewCount-collect' );
-                       $old_user_abort = ignore_user_abort( true );
-
-                       $dbw->lockTables( array(), array( 'hitcounter' ), __METHOD__, false );
-                       $tabletype = $dbType == 'mysql' ? "ENGINE=HEAP " : '';
-                       $dbw->query( "CREATE TEMPORARY TABLE $acchitsTable $tabletype AS " .
-                               "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable " .
-                               'GROUP BY hc_id', __METHOD__ );
-                       $dbw->delete( 'hitcounter', '*', __METHOD__ );
-                       $dbw->unlockTables( __METHOD__ );
-
-                       if ( $dbType == 'mysql' ) {
-                               $dbw->query( "UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n " .
-                                       'WHERE page_id = hc_id', __METHOD__ );
-                       } else {
-                               $dbw->query( "UPDATE $pageTable SET page_counter=page_counter + hc_n " .
-                                       "FROM $acchitsTable WHERE page_id = hc_id", __METHOD__ );
-                       }
-                       $dbw->query( "DROP TABLE $acchitsTable", __METHOD__ );
-
-                       ignore_user_abort( $old_user_abort );
-                       wfProfileOut( 'Article::incViewCount-collect' );
-               }
-
-               $dbw->ignoreErrors( $oldignore );
-       }
-
-       /**#@+
         * The onArticle*() functions are supposed to be a kind of hooks
         * which should be called whenever any of the specified actions
         * are done.
@@ -4070,7 +4012,7 @@ class Article {
         *
         * This is called on page move and undelete, as well as edit
         *
-        * @param $title a title object
+        * @param $title Title object
         */
        public static function onArticleCreate( $title ) {
                # Update existence markers on article/talk tabs...
@@ -4327,12 +4269,12 @@ class Article {
        * Return an applicable autosummary if one exists for the given edit.
        * @param $oldtext String: the previous text of the page.
        * @param $newtext String: The submitted text of the page.
-       * @param $flags Bitmask: a bitmask of flags submitted for the edit.
+       * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
        * @return string An appropriate autosummary, or an empty string.
        */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
                global $wgContLang;
-               
+
                # Decide what kind of autosummary is needed.
 
                # Redirect autosummaries
@@ -4402,7 +4344,7 @@ class Article {
                global $wgParser, $wgEnableParserCache, $wgUseFileCache;
 
                if ( !$parserOptions ) {
-                       $parserOptions = clone $this->getParserOptions();
+                       $parserOptions = $this->getParserOptions();
                }
 
                $time = - wfTime();
@@ -4435,18 +4377,26 @@ class Article {
 
        /**
         * Get parser options suitable for rendering the primary article wikitext
+        * @param $canonical boolean Determines that the generated must not depend on user preferences (see bug 14404)
         * @return mixed ParserOptions object or boolean false
         */
-       public function getParserOptions() {
-               global $wgUser;
-
-               if ( !$this->mParserOptions ) {
-                       $this->mParserOptions = new ParserOptions( $wgUser );
-                       $this->mParserOptions->setTidy( true );
-                       $this->mParserOptions->enableLimitReport();
+       public function getParserOptions( $canonical = false ) {
+               global $wgUser, $wgLanguageCode;
+
+               if ( !$this->mParserOptions || $canonical ) {
+                       $user = !$canonical ? $wgUser : new User;
+                       $parserOptions = new ParserOptions( $user );
+                       $parserOptions->setTidy( true );
+                       $parserOptions->enableLimitReport();
+                       
+                       if ( $canonical ) {
+                               $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
+                               return $parserOptions;
+                       }
+                       $this->mParserOptions = $parserOptions;
                }
 
-               // Clone to allow modifications of the return value without affecting 
+               // Clone to allow modifications of the return value without affecting
                // the cache
                return clone $this->mParserOptions;
        }
@@ -4571,8 +4521,9 @@ class Article {
         * consider, so it's not appropriate to use there.
         *
         * @since 1.16 (r52326) for LiquidThreads
-        * 
+        *
         * @param $oldid mixed integer Revision ID or null
+        * @return ParserOutput
         */
        public function getParserOutput( $oldid = null ) {
                global $wgEnableParserCache, $wgUser;
@@ -4604,37 +4555,25 @@ class Article {
                }
        }
 
-       // Deprecated methods
-       /**
-        * Get the database which should be used for reads
-        *
-        * @return Database
-        * @deprecated - just call wfGetDB( DB_MASTER ) instead
-        */
-       function getDB() {
-               wfDeprecated( __METHOD__ );
-               return wfGetDB( DB_MASTER );
-       }
-
 }
 
 class PoolWorkArticleView extends PoolCounterWork {
        private $mArticle;
-       
+
        function __construct( $article, $key, $useParserCache, $parserOptions ) {
                parent::__construct( 'ArticleView', $key );
                $this->mArticle = $article;
                $this->cacheable = $useParserCache;
                $this->parserOptions = $parserOptions;
        }
-       
+
        function doWork() {
                return $this->mArticle->doViewParse();
        }
-       
+
        function getCachedWork() {
                global $wgOut;
-               
+
                $parserCache = ParserCache::singleton();
                $this->mArticle->mParserOutput = $parserCache->get( $this->mArticle, $this->parserOptions );
 
@@ -4648,21 +4587,21 @@ class PoolWorkArticleView extends PoolCounterWork {
                }
                return false;
        }
-       
+
        function fallback() {
                return $this->mArticle->tryDirtyCache();
        }
-       
+
        function error( $status ) {
                global $wgOut;
 
                $wgOut->clearHTML(); // for release() errors
                $wgOut->enableClientCache( false );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               
+
                $errortext = $status->getWikiText( false, 'view-pool-error' );
                $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
-               
+
                return false;
        }
 }