Simplify a bit by using getRawText() instead of creating a Revision object
[lhc/web/wiklou.git] / includes / Article.php
index 67c8f91..d66795d 100644 (file)
@@ -17,50 +17,115 @@ class Article {
        /**@{{
         * @private
         */
-       protected $mContext;              // !< RequestContext
+
+       /**
+        * @var RequestContext
+        */
+       protected $mContext;
 
        var $mContent;                    // !<
        var $mContentLoaded = false;      // !<
        var $mCounter = -1;               // !< Not loaded
        var $mDataLoaded = false;         // !<
-       var $mForUpdate = false;          // !<
-       var $mGoodAdjustment = 0;         // !<
        var $mIsRedirect = false;         // !<
        var $mLatest = false;             // !<
        var $mOldId;                      // !<
-       var $mPreparedEdit = false;       // !< Title object if set
-       var $mRedirectedFrom = null;      // !< Title object if set
-       var $mRedirectTarget = null;      // !< Title object if set
+       var $mPreparedEdit = false;
+
+       /**
+        * @var Title
+        */
+       var $mRedirectedFrom = null;
+
+       /**
+        * @var Title
+        */
+       var $mRedirectTarget = null;
+
+       /**
+        * @var mixed: boolean false or URL string
+        */
        var $mRedirectUrl = false;        // !<
        var $mRevIdFetched = 0;           // !<
-       var $mLastRevision = null;                // !< Latest revision if set
-       var $mRevision = null;            // !< Loaded revision object if set
+
+       /**
+        * @var Revision
+        */
+       var $mLastRevision = null;
+
+       /**
+        * @var Revision
+        */
+       var $mRevision = null;
+
        var $mTimestamp = '';             // !<
        var $mTitle;                      // !< Title object
-       var $mTotalAdjustment = 0;        // !<
        var $mTouched = '19700101000000'; // !<
-       var $mParserOptions;              // !< ParserOptions object
-       var $mParserOutput;               // !< ParserCache object if set
+
+       /**
+        * @var ParserOptions: ParserOptions object for $wgUser articles
+        */
+       var $mParserOptions;
+
+       /**
+        * @var ParserOutput
+        */
+       var $mParserOutput;
+
        /**@}}*/
 
        /**
         * Constructor and clear the article
-        * @param $title Reference to a Title object.
+        * @param $title Title Reference to a Title object.
         * @param $oldId Integer revision ID, null to fetch from request, zero for current
         */
        public function __construct( Title $title, $oldId = null ) {
-               // FIXME: does the reference play any role here?
+               // @todo FIXME: Does the reference play any role here?
                $this->mTitle =& $title;
                $this->mOldId = $oldId;
        }
 
+       /**
+        * Create an Article object of the appropriate class for the given page.
+        *
+        * @param $title Title
+        * @param $context RequestContext
+        * @return Article object
+        */
+       public static function newFromTitle( $title, RequestContext $context ) {
+               if ( NS_MEDIA == $title->getNamespace() ) {
+                       // FIXME: where should this go?
+                       $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
+               }
+
+               $article = null;
+               wfRunHooks( 'ArticleFromTitle', array( &$title, &$article ) );
+               if ( $article ) {
+                       $article->setContext( $context );
+                       return $article;
+               }
+
+               switch( $title->getNamespace() ) {
+                       case NS_FILE:
+                               $page = new ImagePage( $title );
+                               break;
+                       case NS_CATEGORY:
+                               $page = new CategoryPage( $title );
+                               break;
+                       default:
+                               $page = new Article( $title );
+               }
+               $page->setContext( $context );
+               return $page;
+       }
+
        /**
         * Constructor from an page id
         * @param $id Int article ID to load
         */
        public static function newFromID( $id ) {
                $t = Title::newFromID( $id );
-               # FIXME: doesn't inherit right
+               # @todo FIXME: Doesn't inherit right
                return $t == null ? null : new self( $t );
                # return $t == null ? null : new static( $t ); // PHP 5.3
        }
@@ -79,7 +144,7 @@ class Article {
         *
         * The target will be fetched from the redirect table if possible.
         * If this page doesn't have an entry there, call insertRedirect()
-        * @return mixed Title object, or null if this page is not a redirect
+        * @return Title|mixed object, or null if this page is not a redirect
         */
        public function getRedirectTarget() {
                if ( !$this->mTitle->isRedirect() ) {
@@ -215,7 +280,7 @@ class Article {
 
        /**
         * Clear the object
-        * FIXME: shouldn't this be public?
+        * @todo FIXME: Shouldn't this be public?
         * @private
         */
        public function clear() {
@@ -227,9 +292,7 @@ class Article {
                $this->mRedirectTarget = null; # Title object if set
                $this->mLastRevision = null; # Latest revision
                $this->mTimestamp = '';
-               $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
                $this->mTouched = '19700101000000';
-               $this->mForUpdate = false;
                $this->mIsRedirect = false;
                $this->mRevIdFetched = 0;
                $this->mRedirectUrl = false;
@@ -291,23 +354,6 @@ class Article {
                return $text;
        }
 
-       /**
-        * 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
-        * the first section before any such heading (section 0).
-        *
-        * If a section contains subsections, these are also returned.
-        *
-        * @param $text String: text to look in
-        * @param $section Integer: section number
-        * @return string text of the requested section
-        * @deprecated
-        */
-       public function getSection( $text, $section ) {
-               global $wgParser;
-               return $wgParser->getSection( $text, $section );
-       }
-
        /**
         * Get the text that needs to be saved in order to undo all revisions
         * between $undo and $undoafter. Revisions must belong to the same page,
@@ -317,13 +363,12 @@ class Article {
         * @return mixed string on success, false on failure
         */
        public function getUndoText( Revision $undo, Revision $undoafter = null ) {
-               $currentRev = Revision::newFromTitle( $this->mTitle );
-               if ( !$currentRev ) {
+               $cur_text = $this->getRawText();
+               if ( $cur_text === false ) {
                        return false; // no page
                }
                $undo_text = $undo->getText();
                $undoafter_text = $undoafter->getText();
-               $cur_text = $currentRev->getText();
 
                if ( $cur_text == $undo_text ) {
                        # No use doing a merge if it's just a straight revert.
@@ -424,7 +469,7 @@ class Article {
 
        /**
         * Fetch a page record with the given conditions
-        * @param $dbr Database object
+        * @param $dbr DatabaseBase object
         * @param $conditions Array
         * @return mixed Database result resource, or false on failure
         */
@@ -444,7 +489,7 @@ class Article {
         * Fetch a page record matching the Title object's namespace and title
         * using a sanitized title string
         *
-        * @param $dbr Database object
+        * @param $dbr DatabaseBase object
         * @param $title Title object
         * @return mixed Database result resource, or false on failure
         */
@@ -457,7 +502,7 @@ class Article {
        /**
         * Fetch a page record matching the requested ID
         *
-        * @param $dbr Database
+        * @param $dbr DatabaseBase
         * @param $id Integer
         * @return mixed Database result resource, or false on failure
         */
@@ -469,7 +514,7 @@ class Article {
         * Set the general counter, title etc data loaded from
         * some source.
         *
-        * @param $data Database row object or "fromdb"
+        * @param $data Object|String $res->fetchObject() object or the string "fromdb" to reload
         */
        public function loadPageData( $data = 'fromdb' ) {
                if ( $data === 'fromdb' ) {
@@ -552,7 +597,7 @@ class Article {
                        }
                }
 
-               // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
+               // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
                // 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
 
@@ -570,15 +615,11 @@ class Article {
        }
 
        /**
-        * Read/write accessor to select FOR UPDATE
-        * @FIXME: remove, does nothing
-        *
-        * @param $x Mixed: FIXME
-        * @return mixed value of $x, or value stored in Article::mForUpdate
+        * No-op
+        * @deprecated since 1.18
         */
-       public function forUpdate( $x = null ) {
+       public function forUpdate() {
                wfDeprecated( __METHOD__ );
-               return wfSetVar( $this->mForUpdate, $x );
        }
 
        /**
@@ -633,15 +674,43 @@ class Article {
         * Determine whether a page would be suitable for being counted as an
         * article in the site_stats table based on the title & its content
         *
-        * @param $text String: text to analyze
-        * @return bool
+        * @param $editInfo Object or false: object returned by prepareTextForEdit(),
+        *        if false, the current database state will be used
+        * @return Boolean
         */
-       public function isCountable( $text ) {
-               global $wgUseCommaCount;
+       public function isCountable( $editInfo = false ) {
+               global $wgArticleCountMethod;
 
-               $token = $wgUseCommaCount ? ',' : '[[';
+               if ( !$this->mTitle->isContentPage() ) {
+                       return false;
+               }
+
+               $text = $editInfo ? $editInfo->pst : false;
 
-               return $this->mTitle->isContentPage() && !$this->isRedirect( $text ) && in_string( $token, $text );
+               if ( $this->isRedirect( $text ) ) {
+                       return false;
+               }
+
+               switch ( $wgArticleCountMethod ) {
+               case 'any':
+                       return true;
+               case 'comma':
+                       if ( $text === false ) {
+                               $text = $this->getRawText();
+                       }
+                       return strpos( $text,  ',' ) !== false;
+               case 'link':
+                       if ( $editInfo ) {
+                               // ParserOutput::getLinks() is a 2D array of page links, so
+                               // to be really correct we would need to recurse in the array
+                               // but the main array should only have items in it if there are
+                               // links.
+                               return (bool)count( $editInfo->output->getLinks() );
+                       } else {
+                               return (bool)wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1,
+                                       array( 'pl_from' => $this->getId() ), __METHOD__ );
+                       }
+               }
        }
 
        /**
@@ -794,19 +863,25 @@ class Article {
        /**
         * Get a list of users who have edited this article, not including the user who made
         * the most recent revision, which you can get from $article->getUser() if you want it
-        * @return UserArray
+        * @return UserArrayFromResult
         */
        public function getContributors() {
-               # FIXME: this is expensive; cache this info somewhere.
+               # @todo FIXME: This is expensive; cache this info somewhere.
 
                $dbr = wfGetDB( DB_SLAVE );
-               $userTable = $dbr->tableName( 'user' );
+
+               if ( $dbr->implicitGroupby() ) {
+                       $realNameField = 'user_real_name';
+               } else {
+                       $realNameField = 'FIRST(user_real_name) AS user_real_name';
+               }
 
                $tables = array( 'revision', 'user' );
 
                $fields = array(
-                       "$userTable.*",
+                       'rev_user as user_id',
                        'rev_user_text AS user_name',
+                       $realNameField,
                        'MAX(rev_timestamp) AS timestamp',
                );
 
@@ -831,7 +906,7 @@ class Article {
                        'GROUP BY' => array( 'rev_user', 'rev_user_text' ),
                        'ORDER BY' => 'timestamp DESC',
                );
-               
+
                $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $jconds );
                return new UserArrayFromResult( $res );
        }
@@ -881,7 +956,7 @@ class Article {
                if ( $wgOut->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
                        $parserOptions->setEditSection( false );
-               } else if ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
+               } elseif ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
                        $parserOptions->setEditSection( false );
                }
 
@@ -898,7 +973,7 @@ class Article {
 
                                return;
                        # Try file cache
-                       } else if ( $wgUseFileCache && $this->tryFileCache() ) {
+                       } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
                                wfDebug( __METHOD__ . ": done file cache\n" );
                                # tell wgOut that output is taken care of
                                $wgOut->disable();
@@ -1225,7 +1300,7 @@ class Article {
         * @return boolean
         */
        public function showRedirectedFromHeader() {
-               global $wgOut, $wgUser, $wgRequest, $wgRedirectSources;
+               global $wgOut, $wgRequest, $wgRedirectSources;
 
                $rdfrom = $wgRequest->getVal( 'rdfrom' );
 
@@ -1233,7 +1308,7 @@ class Article {
                        // This is an internally redirected page view.
                        // We'll need a backlink to the source page for navigation.
                        if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
-                               $redir = $wgUser->getSkin()->link(
+                               $redir = Linker::link(
                                        $this->mRedirectedFrom,
                                        null,
                                        array(),
@@ -1261,7 +1336,7 @@ class Article {
                        // This is an externally redirected view, from some other wiki.
                        // If it was reported from a trusted site, supply a backlink.
                        if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
-                               $redir = $wgUser->getSkin()->makeExternalLink( $rdfrom, $rdfrom );
+                               $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
                                $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
                                $wgOut->setSubtitle( $s );
 
@@ -1324,7 +1399,6 @@ class Article {
                        return;
                }
 
-               $sk = $wgUser->getSkin();
                $token = $wgUser->editToken( $rcid );
                $wgOut->preventClickjacking();
 
@@ -1332,7 +1406,7 @@ class Article {
                        "<div class='patrollink'>" .
                                wfMsgHtml(
                                        'markaspatrolledlink',
-                                       $sk->link(
+                                       Linker::link(
                                                $this->mTitle,
                                                wfMsgHtml( 'markaspatrolledtext' ),
                                                array(),
@@ -1364,8 +1438,8 @@ class Article {
 
                        if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
                                $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
-                                       array( 'userpage-userdoesnotexist-view', $rootPart ) );
-                       } else if ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
+                                       array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
+                       } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
                                LogEventsList::showLogExtract(
                                        $wgOut,
                                        'block',
@@ -1445,7 +1519,7 @@ class Article {
 
                        return false;
                // If the user needs to confirm that they want to see it...
-               } else if ( $wgRequest->getInt( 'unhide' ) != 1 ) {
+               } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
                        # Give explanation and add a link to view the revision...
                        $oldid = intval( $this->getOldID() );
                        $link = $this->mTitle->getFullUrl( "oldid={$oldid}&unhide=1" );
@@ -1550,7 +1624,7 @@ class Article {
         * @return string containing HMTL with redirect link
         */
        public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
-               global $wgOut, $wgContLang, $wgStylePath, $wgUser;
+               global $wgOut, $wgContLang, $wgStylePath;
 
                if ( !is_array( $target ) ) {
                        $target = array( $target );
@@ -1562,14 +1636,13 @@ class Article {
                        $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
                }
 
-               $sk = $wgUser->getSkin();
                // the loop prepends the arrow image before the link, so the first case needs to be outside
                $title = array_shift( $target );
 
                if ( $forceKnown ) {
-                       $link = $sk->linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
+                       $link = Linker::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
                } else {
-                       $link = $sk->link( $title, htmlspecialchars( $title->getFullText() ) );
+                       $link = Linker::link( $title, htmlspecialchars( $title->getFullText() ) );
                }
 
                $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
@@ -1578,9 +1651,9 @@ class Article {
                foreach ( $target as $rt ) {
                        $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
                        if ( $forceKnown ) {
-                               $link .= $sk->linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
+                               $link .= Linker::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
                        } else {
-                               $link .= $sk->link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
+                               $link .= Linker::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
                        }
                }
 
@@ -1632,29 +1705,10 @@ class Article {
 
        /**
         * Removes trackback record for current article from trackbacks table
+        * @deprecated since 1.19
         */
        public function deletetrackback() {
-               global $wgRequest, $wgOut;
-
-               if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
-                       $wgOut->addWikiMsg( 'sessionfailure' );
-
-                       return;
-               }
-
-               $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
-
-               if ( count( $permission_errors ) ) {
-                       $wgOut->showPermissionsErrorPage( $permission_errors );
-
-                       return;
-               }
-
-               $db = wfGetDB( DB_MASTER );
-               $db->delete( 'trackbacks', array( 'tb_id' => $wgRequest->getInt( 'tbid' ) ) );
-
-               $wgOut->addWikiMsg( 'trackbackdeleteok' );
-               $this->mTitle->invalidateCache();
+               return Action::factory( 'deletetrackback', $this )->show();
        }
 
        /**
@@ -1710,6 +1764,78 @@ class Article {
                }
        }
 
+       /**
+        * Mark this particular edit/page as patrolled
+        * @deprecated since 1.19
+        */
+       public function markpatrolled() {
+               Action::factory( 'markpatrolled', $this )->show();
+       }
+
+       /**
+        * User-interface handler for the "watch" action.
+        * Requires Request to pass a token as of 1.19.
+        * @deprecated since 1.18
+        */
+       public function watch() {
+               Action::factory( 'watch', $this )->show();
+       }
+
+       /**
+        * Add this page to $wgUser's watchlist
+        *
+        * This is safe to be called multiple times
+        *
+        * @return bool true on successful watch operation
+        * @deprecated since 1.18
+        */
+       public function doWatch() {
+               global $wgUser;
+               return WatchAction::doWatch( $this->mTitle, $wgUser );
+       }
+
+       /**
+        * User interface handler for the "unwatch" action.
+        * Requires Request to pass a token as of 1.19.
+        * @deprecated since 1.18
+        */
+       public function unwatch() {
+               Action::factory( 'unwatch', $this )->show();
+       }
+
+       /**
+        * Stop watching a page
+        * @return bool true on successful unwatch
+        * @deprecated since 1.18
+        */
+       public function doUnwatch() {
+               global $wgUser;
+               return WatchAction::doUnwatch( $this->mTitle, $wgUser );
+       }
+
+       /**
+        * action=protect handler
+        */
+       public function protect() {
+               $form = new ProtectionForm( $this );
+               $form->execute();
+       }
+
+       /**
+        * action=unprotect handler (alias)
+        */
+       public function unprotect() {
+               $this->protect();
+       }
+
+       /**
+        * Info about this page
+        * Called for ?action=info when $wgAllowPageInfo is on.
+        */
+       public function info() {
+               Action::factory( 'info', $this )->show();
+       }
+
        /**
         * Insert a new empty page record for this article.
         * This *must* be followed up by creating a revision
@@ -1717,7 +1843,7 @@ class Article {
         * or else the record will be left in a funky state.
         * Best if all done inside a transaction.
         *
-        * @param $dbw Database
+        * @param $dbw DatabaseBase
         * @return int The newly created page_id key, or false if the title already existed
         * @private
         */
@@ -1762,12 +1888,10 @@ class Article {
         *                      on.
         * @param $lastRevIsRedirect Boolean: if given, will optimize adding and
         *                           removing rows in redirect table.
-        * @param $setNewFlag Boolean: Set to true if a page flag should be set
-        *                    Needed when $lastRevision has to be set to sth. !=0
         * @return bool true on success, false on failure
         * @private
         */
-       public function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null, $setNewFlag = false ) {
+       public function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
                wfProfileIn( __METHOD__ );
 
                $text = $revision->getText();
@@ -1780,15 +1904,11 @@ class Article {
                        $conditions['page_latest'] = $lastRevision;
                }
 
-               if ( !$setNewFlag ) {
-                       $setNewFlag = ( $lastRevision === 0 );
-               }
-
                $dbw->update( 'page',
                        array( /* SET */
                                'page_latest'      => $revision->getId(),
                                'page_touched'     => $dbw->timestamp(),
-                               'page_is_new'      => $setNewFlag,
+                               'page_is_new'      => ( $lastRevision === 0 ) ? 1 : 0,
                                'page_is_redirect' => $rt !== null ? 1 : 0,
                                'page_len'         => strlen( $text ),
                        ),
@@ -1807,7 +1927,7 @@ class Article {
        /**
         * Add row to the redirect table if this is a redirect, remove otherwise.
         *
-        * @param $dbw Database
+        * @param $dbw DatabaseBase
         * @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
@@ -2057,10 +2177,6 @@ class Article {
                        $changed = ( strcmp( $text, $oldtext ) != 0 );
 
                        if ( $changed ) {
-                               $this->mGoodAdjustment = (int)$this->isCountable( $text )
-                                 - (int)$this->isCountable( $oldtext );
-                               $this->mTotalAdjustment = 0;
-
                                if ( !$this->mLatest ) {
                                        # Article gone missing
                                        wfDebug( __METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n" );
@@ -2155,12 +2271,6 @@ class Article {
                        # Create new article
                        $status->value['new'] = true;
 
-                       # Set statistics members
-                       # We work out if it's countable after PST to avoid counter drift
-                       # when articles are created with {{subst:}}
-                       $this->mGoodAdjustment = (int)$this->isCountable( $text );
-                       $this->mTotalAdjustment = 1;
-
                        $dbw->begin();
 
                        # Add the page record; stake our claim on this title!
@@ -2188,7 +2298,8 @@ class Article {
                        $revisionId = $revision->insertOn( $dbw );
 
                        $this->mTitle->resetArticleID( $newid );
-                       # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached (FIXME?)
+                       # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached
+                       # @todo FIXME?
                        LinkCache::singleton()->addGoodLinkObj( $newid, $this->mTitle, strlen( $text ), (bool)Title::newFromRedirect( $text ), $revisionId );
 
                        # Update the page record with revision data
@@ -2216,7 +2327,7 @@ class Article {
                        $dbw->commit();
 
                        # Update links, etc.
-                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user );
+                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true, $user, true );
 
                        # Clear caches
                        Article::onArticleCreate( $this->mTitle );
@@ -2244,11 +2355,13 @@ class Article {
         * Output a redirect back to the article.
         * This is typically used after an edit.
         *
+        * @deprecated in 1.19; call $wgOut->redirect() directly
         * @param $noRedir Boolean: add redirect=no
         * @param $sectionAnchor String: section to redirect to, including "#"
         * @param $extraQuery String: extra query params
         */
        public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
+               wfDeprecated( __METHOD__ );
                global $wgOut;
 
                if ( $noRedir ) {
@@ -2262,118 +2375,6 @@ class Article {
                $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $sectionAnchor );
        }
 
-       /**
-        * Mark this particular edit/page as patrolled
-        */
-       public function markpatrolled() {
-               global $wgOut, $wgRequest;
-
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
-
-               # If we haven't been given an rc_id value, we can't do anything
-               $rcid = (int) $wgRequest->getVal( 'rcid' );
-
-               if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
-                       $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
-                       return;
-               }
-
-               $rc = RecentChange::newFromId( $rcid );
-
-               if ( is_null( $rc ) ) {
-                       $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
-                       return;
-               }
-
-               # It would be nice to see where the user had actually come from, but for now just guess
-               $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
-               $return = SpecialPage::getTitleFor( $returnto );
-
-               $errors = $rc->doMarkPatrolled();
-
-               if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
-                       $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
-
-                       return;
-               }
-
-               if ( in_array( array( 'hookaborted' ), $errors ) ) {
-                       // The hook itself has handled any output
-                       return;
-               }
-
-               if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
-                       $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
-                       $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
-                       $wgOut->returnToMain( false, $return );
-
-                       return;
-               }
-
-               if ( !empty( $errors ) ) {
-                       $wgOut->showPermissionsErrorPage( $errors );
-
-                       return;
-               }
-
-               # Inform the user
-               $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
-               $wgOut->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
-               $wgOut->returnToMain( false, $return );
-       }
-
-       /**
-        * User-interface handler for the "watch" action
-        * @deprecated since 1.18
-        */
-       public function watch() {
-               Action::factory( 'watch', $this )->show();
-       }
-
-       /**
-        * Add this page to $wgUser's watchlist
-        *
-        * This is safe to be called multiple times
-        *
-        * @return bool true on successful watch operation
-        * @deprecated since 1.18
-        */
-       public function doWatch() {
-               return Action::factory( 'watch', $this )->execute();
-       }
-
-       /**
-        * User interface handler for the "unwatch" action.
-        * @deprecated since 1.18
-        */
-       public function unwatch() {
-               Action::factory( 'unwatch', $this )->show();
-       }
-
-       /**
-        * Stop watching a page
-        * @return bool true on successful unwatch
-        * @deprecated since 1.18
-        */
-       public function doUnwatch() {
-               return Action::factory( 'unwatch', $this )->execute();
-       }
-
-       /**
-        * action=protect handler
-        */
-       public function protect() {
-               $form = new ProtectionForm( $this );
-               $form->execute();
-       }
-
-       /**
-        * action=unprotect handler (alias)
-        */
-       public function unprotect() {
-               $this->protect();
-       }
-
        /**
         * Update the article's restriction field, and leave a log entry.
         *
@@ -2412,7 +2413,7 @@ class Article {
                // Take this opportunity to purge out expired restrictions
                Title::purgeExpiredRestrictions();
 
-               # FIXME: Same limitations as described in ProtectionForm.php (line 37);
+               # @todo FIXME: Same limitations as described in ProtectionForm.php (line 37);
                # we expect a single selection, but the schema allows otherwise.
                $current = array();
                $updated = Article::flattenRestrictions( $limit );
@@ -2677,7 +2678,7 @@ class Article {
        }
 
 
-       /*
+       /**
         * UI entry point for page deletion
         */
        public function delete() {
@@ -2730,7 +2731,8 @@ class Article {
                                Html::rawElement(
                                        'div',
                                        array( 'class' => 'error mw-error-cannotdelete' ),
-                                       wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
+                                       wfMsgExt( 'cannotdelete', array( 'parse' ),
+                                               wfEscapeWikiText( $this->mTitle->getPrefixedText() ) )
                                )
                        );
                        $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
@@ -2776,12 +2778,11 @@ class Article {
                if ( $hasHistory && !$confirm ) {
                        global $wgLang;
 
-                       $skin = $wgOut->getSkin();
                        $revisions = $this->estimateRevisionCount();
-                       //FIXME: lego
+                       // @todo FIXME: i18n issue/patchwork message
                        $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
                                wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
-                               wfMsgHtml( 'word-separator' ) . $skin->link( $this->mTitle,
+                               wfMsgHtml( 'word-separator' ) . Linker::link( $this->mTitle,
                                        wfMsgHtml( 'history' ),
                                        array( 'rel' => 'archives' ),
                                        array( 'action' => 'history' ) ) .
@@ -2880,7 +2881,7 @@ class Article {
 
        /**
         * Output deletion confirmation dialog
-        * FIXME: Move to another file?
+        * @todo FIXME: Move to another file?
         * @param $reason String: prefilled reason
         */
        public function confirmDelete( $reason ) {
@@ -2888,7 +2889,7 @@ class Article {
 
                wfDebug( "Article::confirmDelete\n" );
 
-               $deleteBackLink = $wgOut->getSkin()->linkKnown( $this->mTitle );
+               $deleteBackLink = Linker::linkKnown( $this->mTitle );
                $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addWikiMsg( 'confirmdeletetext' );
@@ -2965,9 +2966,8 @@ class Article {
                        Xml::closeElement( 'form' );
 
                        if ( $wgOut->getUser()->isAllowed( 'editinterface' ) ) {
-                               $skin = $wgOut->getSkin();
                                $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
-                               $link = $skin->link(
+                               $link = Linker::link(
                                        $title,
                                        wfMsgHtml( 'delete-edit-reasonlist' ),
                                        array(),
@@ -3000,7 +3000,7 @@ class Article {
 
                        $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
 
-                       $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
+                       $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
                        $wgOut->returnToMain( false );
                } else {
                        if ( $error == '' ) {
@@ -3008,7 +3008,8 @@ class Article {
                                        Html::rawElement(
                                                'div',
                                                array( 'class' => 'error mw-error-cannotdelete' ),
-                                               wfMsgExt( 'cannotdelete', array( 'parse' ), $this->mTitle->getPrefixedText() )
+                                               wfMsgExt( 'cannotdelete', array( 'parse' ),
+                                                       wfEscapeWikiText( $this->mTitle->getPrefixedText() ) )
                                        )
                                );
 
@@ -3056,7 +3057,7 @@ class Article {
                        return false;
                }
 
-               $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable( $this->getRawText() ), -1 );
+               $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 );
                array_push( $wgDeferredUpdateList, $u );
 
                // Bitfields to further suppress the content
@@ -3140,6 +3141,7 @@ class Article {
                        $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
                        $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
                        $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
+                       $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ) );
                        $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
                }
 
@@ -3276,7 +3278,7 @@ class Article {
                if ( $s === false ) {
                        # No one else ever edited this page
                        return array( array( 'cantrollback' ) );
-               } else if ( $s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER ) {
+               } elseif ( $s->rev_deleted & Revision::DELETED_TEXT || $s->rev_deleted & Revision::DELETED_USER ) {
                        # Only admins can see this text
                        return array( array( 'notvisiblerev' ) );
                }
@@ -3383,7 +3385,7 @@ class Article {
 
                                if ( $current->getComment() != '' ) {
                                        $wgOut->addWikiMsgArray( 'editcomment', array(
-                                               $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
+                                               Linker::formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
                                }
                        }
 
@@ -3422,12 +3424,12 @@ class Article {
                if ( $current->getUserText() === '' ) {
                        $old = wfMsg( 'rev-deleted-user' );
                } else {
-                       $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
-                               . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
+                       $old = Linker::userLink( $current->getUser(), $current->getUserText() )
+                               . Linker::userToolLinks( $current->getUser(), $current->getUserText() );
                }
 
-               $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
-                       . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
+               $new = Linker::userLink( $target->getUser(), $target->getUserText() )
+                       . Linker::userToolLinks( $target->getUser(), $target->getUserText() );
                $wgOut->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
                $wgOut->returnToMain( false, $this->mTitle );
 
@@ -3479,7 +3481,7 @@ class Article {
                $edit->revid = $revid;
                $edit->newText = $text;
                $edit->pst = $this->preSaveTransform( $text, $user, $popts );
-               $edit->popts = $this->getParserOptions();
+               $edit->popts = $this->getParserOptions( true );
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
                $edit->oldText = $this->getRawText();
 
@@ -3502,8 +3504,11 @@ class Article {
         * @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
+        * @param $created Boolean: Whether the edit created the page
         */
-       public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) {
+       public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid,
+               $changed = true, User $user = null, $created = false )
+       {
                global $wgDeferredUpdateList, $wgUser, $wgEnableParserCache;
 
                wfProfileIn( __METHOD__ );
@@ -3555,10 +3560,19 @@ class Article {
                        return;
                }
 
-               $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment );
-               array_push( $wgDeferredUpdateList, $u );
-               $u = new SearchUpdate( $id, $title, $text );
-               array_push( $wgDeferredUpdateList, $u );
+               if ( !$changed ) {
+                       $good = 0;
+                       $total = 0;
+               } elseif ( $created ) {
+                       $good = (int)$this->isCountable( $editInfo );
+                       $total = 1;
+               } else {
+                       $good = (int)$this->isCountable( $editInfo ) - (int)$this->isCountable();
+                       $total = 0;
+               }
+
+               $wgDeferredUpdateList[] = new SiteStatsUpdate( 0, 1, $good, $total );
+               $wgDeferredUpdateList[] = new SearchUpdate( $id, $title, $text );
 
                # If this is another user's talk page, update newtalk
                # Don't do this if $changed = false otherwise some idiot can null-edit a
@@ -3599,10 +3613,8 @@ class Article {
         * anymore.
         */
        public function createUpdates( $rev ) {
-               $this->mGoodAdjustment = $this->isCountable( $rev->getText() );
-               $this->mTotalAdjustment = 1;
                $this->editUpdates( $rev->getText(), $rev->getComment(),
-                       $rev->isMinor(), wfTimestamp(), $rev->getId(), true );
+                       $rev->isMinor(), wfTimestamp(), $rev->getId(), true, null, true );
        }
 
        /**
@@ -3629,15 +3641,16 @@ class Article {
                }
 
                $revision = Revision::newFromId( $oldid );
+               $timestamp = $revision->getTimestamp();
 
                $current = ( $oldid == $this->mLatest );
-               $td = $wgLang->timeanddate( $this->mTimestamp, true );
-               $tddate = $wgLang->date( $this->mTimestamp, true );
-               $tdtime = $wgLang->time( $this->mTimestamp, true );
-               $sk = $wgUser->getSkin();
+               $td = $wgLang->timeanddate( $timestamp, true );
+               $tddate = $wgLang->date( $timestamp, true );
+               $tdtime = $wgLang->time( $timestamp, true );
+
                $lnk = $current
                        ? wfMsgHtml( 'currentrevisionlink' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'currentrevisionlink' ),
                                array(),
@@ -3646,7 +3659,7 @@ class Article {
                        );
                $curdiff = $current
                        ? wfMsgHtml( 'diff' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'diff' ),
                                array(),
@@ -3658,7 +3671,7 @@ class Article {
                        );
                $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
                $prevlink = $prev
-                       ? $sk->link(
+                       ? Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'previousrevision' ),
                                array(),
@@ -3670,7 +3683,7 @@ class Article {
                        )
                        : wfMsgHtml( 'previousrevision' );
                $prevdiff = $prev
-                       ? $sk->link(
+                       ? Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'diff' ),
                                array(),
@@ -3683,7 +3696,7 @@ class Article {
                        : wfMsgHtml( 'diff' );
                $nextlink = $current
                        ? wfMsgHtml( 'nextrevision' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'nextrevision' ),
                                array(),
@@ -3695,7 +3708,7 @@ class Article {
                        );
                $nextdiff = $current
                        ? wfMsgHtml( 'diff' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'diff' ),
                                array(),
@@ -3712,20 +3725,20 @@ class Article {
                $canHide = $wgUser->isAllowed( 'deleterevision' );
                if ( $canHide || ( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
                        if ( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
-                               $cdel = $sk->revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
+                               $cdel = Linker::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
                        } else {
                                $query = array(
                                        'type'   => 'revision',
                                        'target' => $this->mTitle->getPrefixedDbkey(),
                                        'ids'    => $oldid
                                );
-                               $cdel = $sk->revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
+                               $cdel = Linker::revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
                        }
                        $cdel .= ' ';
                }
 
                # Show user links if allowed to see them. If hidden, then show them only if requested...
-               $userlinks = $sk->revUserTools( $revision, !$unhide );
+               $userlinks = Linker::revUserTools( $revision, !$unhide );
 
                $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
                        ? 'revision-info-current'
@@ -3922,6 +3935,8 @@ class Article {
 
        /**
         * Clears caches when article is deleted
+        *
+        * @param $title Title
         */
        public static function onArticleDelete( $title ) {
                # Update existence markers on article/talk tabs...
@@ -3994,103 +4009,6 @@ class Article {
                $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
        }
 
-       /**
-        * Info about this page
-        * Called for ?action=info when $wgAllowPageInfo is on.
-        */
-       public function info() {
-               global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
-
-               if ( !$wgAllowPageInfo ) {
-                       $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
-                       return;
-               }
-
-               $page = $this->mTitle->getSubjectPage();
-
-               $wgOut->setPagetitle( $page->getPrefixedText() );
-               $wgOut->setPageTitleActionText( wfMsg( 'info_short' ) );
-               $wgOut->setSubtitle( wfMsgHtml( 'infosubtitle' ) );
-
-               if ( !$this->mTitle->exists() ) {
-                       $wgOut->addHTML( '<div class="noarticletext">' );
-                       if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                               // This doesn't quite make sense; the user is asking for
-                               // information about the _page_, not the message... -- RC
-                               $wgOut->addHTML( htmlspecialchars( $this->mTitle->getDefaultMessageText() ) );
-                       } else {
-                               $msg = $wgUser->isLoggedIn()
-                                       ? 'noarticletext'
-                                       : 'noarticletextanon';
-                               $wgOut->addHTML( wfMsgExt( $msg, 'parse' ) );
-                       }
-
-                       $wgOut->addHTML( '</div>' );
-               } else {
-                       $dbr = wfGetDB( DB_SLAVE );
-                       $wl_clause = array(
-                               'wl_title'     => $page->getDBkey(),
-                               'wl_namespace' => $page->getNamespace() );
-                       $numwatchers = $dbr->selectField(
-                               'watchlist',
-                               'COUNT(*)',
-                               $wl_clause,
-                               __METHOD__ );
-
-                       $pageInfo = $this->pageCountInfo( $page );
-                       $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
-
-
-                       //FIXME: unescaped messages
-                       $wgOut->addHTML( "<ul><li>" . wfMsg( "numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
-                       $wgOut->addHTML( "<li>" . wfMsg( 'numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>' );
-
-                       if ( $talkInfo ) {
-                               $wgOut->addHTML( '<li>' . wfMsg( "numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>' );
-                       }
-
-                       $wgOut->addHTML( '<li>' . wfMsg( "numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
-
-                       if ( $talkInfo ) {
-                               $wgOut->addHTML( '<li>' . wfMsg( 'numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
-                       }
-
-                       $wgOut->addHTML( '</ul>' );
-               }
-       }
-
-       /**
-        * Return the total number of edits and number of unique editors
-        * on a given page. If page does not exist, returns false.
-        *
-        * @param $title Title object
-        * @return mixed array or boolean false
-        */
-       public function pageCountInfo( $title ) {
-               $id = $title->getArticleId();
-
-               if ( $id == 0 ) {
-                       return false;
-               }
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $rev_clause = array( 'rev_page' => $id );
-               $edits = $dbr->selectField(
-                       'revision',
-                       'COUNT(rev_page)',
-                       $rev_clause,
-                       __METHOD__
-               );
-               $authors = $dbr->selectField(
-                       'revision',
-                       'COUNT(DISTINCT rev_user_text)',
-                       $rev_clause,
-                       __METHOD__
-               );
-
-               return array( 'edits' => $edits, 'authors' => $authors );
-       }
-
        /**
         * Return a list of templates used by this article.
         * Uses the templatelinks table
@@ -4262,26 +4180,44 @@ class Article {
 
        /**
         * Get parser options suitable for rendering the primary article wikitext
+        * @param $canonical boolean Determines that the generated options 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
-               // the cache
+               // Clone to allow modifications of the return value without affecting cache
                return clone $this->mParserOptions;
        }
 
+       /**
+       * Get parser options suitable for rendering the primary article wikitext
+       * @param User $user
+       * @return ParserOptions
+       */
+       public function makeParserOptions( User $user ) {
+               $options = ParserOptions::newFromUser( $user );
+               $options->enableLimitReport(); // show inclusion/loop reports
+               $options->setTidy( true ); // fix bad HTML
+               return $options;
+       }
+
        /**
         * Updates cascading protections
         *
-        * @param $parserOutput mixed ParserOptions object, or boolean false
+        * @param $parserOutput ParserOutput object, or boolean false
         **/
        protected function doCascadeProtectionUpdates( $parserOutput ) {
                if ( !$this->isCurrent() || wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
@@ -4466,6 +4402,10 @@ class Article {
 }
 
 class PoolWorkArticleView extends PoolCounterWork {
+
+       /**
+        * @var Article
+        */
        private $mArticle;
 
        function __construct( $article, $key, $useParserCache, $parserOptions ) {
@@ -4500,6 +4440,9 @@ class PoolWorkArticleView extends PoolCounterWork {
                return $this->mArticle->tryDirtyCache();
        }
 
+       /**
+        * @param  $status Status
+        */
        function error( $status ) {
                global $wgOut;