Remove some stuff marked as deprecated <= 1.16 unused
[lhc/web/wiklou.git] / includes / Article.php
index 8acfdfc..1f439cd 100644 (file)
@@ -17,7 +17,12 @@ class Article {
        /**@{{
         * @private
         */
-       var $mComment = '';               // !<
+
+       /**
+        * @var RequestContext
+        */
+       protected $mContext;
+
        var $mContent;                    // !<
        var $mContentLoaded = false;      // !<
        var $mCounter = -1;               // !< Not loaded
@@ -26,22 +31,50 @@ class Article {
        var $mGoodAdjustment = 0;         // !<
        var $mIsRedirect = false;         // !<
        var $mLatest = false;             // !<
-       var $mMinorEdit;                  // !<
        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 Title
+        */
        var $mRedirectUrl = false;        // !<
        var $mRevIdFetched = 0;           // !<
-       var $mRevision = null;            // !< 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 $mUser = -1;                  // !< Not loaded
-       var $mUserText = '';              // !< username from Revision if set
-       var $mParserOptions;              // !< ParserOptions object
-       var $mParserOutput;               // !< ParserCache object if set
+
+       /**
+        * @var ParserOptions
+        */
+       var $mParserOptions;
+
+       /**
+        * @var ParserOutput
+        */
+       var $mParserOutput;
+
        /**@}}*/
 
        /**
@@ -223,11 +256,11 @@ class Article {
                $this->mDataLoaded    = false;
                $this->mContentLoaded = false;
 
-               $this->mUser = $this->mCounter = -1; # Not loaded
+               $this->mCounter = -1; # Not loaded
                $this->mRedirectedFrom = null; # Title object if set
                $this->mRedirectTarget = null; # Title object if set
-               $this->mUserText =
-               $this->mTimestamp = $this->mComment = '';
+               $this->mLastRevision = null; # Latest revision
+               $this->mTimestamp = '';
                $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
                $this->mTouched = '19700101000000';
                $this->mForUpdate = false;
@@ -403,26 +436,34 @@ class Article {
                wfProfileOut( __METHOD__ );
        }
 
+       /**
+        * Return the list of revision fields that should be selected to create
+        * a new page.
+        */
+       public static function selectFields() {
+               return array(
+                       'page_id',
+                       'page_namespace',
+                       'page_title',
+                       'page_restrictions',
+                       'page_counter',
+                       'page_is_redirect',
+                       'page_is_new',
+                       'page_random',
+                       'page_touched',
+                       'page_latest',
+                       'page_len',
+               );
+       }
+
        /**
         * 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
         */
        protected function pageData( $dbr, $conditions ) {
-               $fields = array(
-                               'page_id',
-                               'page_namespace',
-                               'page_title',
-                               'page_restrictions',
-                               'page_counter',
-                               'page_is_redirect',
-                               'page_is_new',
-                               'page_random',
-                               'page_touched',
-                               'page_latest',
-                               'page_len',
-               );
+               $fields = self::selectFields();
 
                wfRunHooks( 'ArticlePageDataBefore', array( &$this, &$fields ) );
 
@@ -437,11 +478,11 @@ 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
         */
-       public function pageDataFromTitle( $dbr, $title ) {
+       protected function pageDataFromTitle( $dbr, $title ) {
                return $this->pageData( $dbr, array(
                        'page_namespace' => $title->getNamespace(),
                        'page_title'     => $title->getDBkey() ) );
@@ -450,8 +491,9 @@ 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
         */
        protected function pageDataFromId( $dbr, $id ) {
                return $this->pageData( $dbr, array( 'page_id' => $id ) );
@@ -461,7 +503,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' ) {
@@ -563,33 +605,16 @@ class Article {
 
        /**
         * Read/write accessor to select FOR UPDATE
+        * @deprecated since 1.18
         *
         * @param $x Mixed: FIXME
         * @return mixed value of $x, or value stored in Article::mForUpdate
         */
        public function forUpdate( $x = null ) {
+               wfDeprecated( __METHOD__ );
                return wfSetVar( $this->mForUpdate, $x );
        }
 
-       /**
-        * Get options for all SELECT statements
-        *
-        * @param $options Array: an optional options array which'll be appended to
-        *                       the default
-        * @return Array: options
-        */
-       protected function getSelectOptions( $options = '' ) {
-               if ( $this->mForUpdate ) {
-                       if ( is_array( $options ) ) {
-                               $options[] = 'FOR UPDATE';
-                       } else {
-                               $options = 'FOR UPDATE';
-                       }
-               }
-
-               return $options;
-       }
-
        /**
         * @return int Page ID
         */
@@ -630,8 +655,7 @@ class Article {
                                $this->mCounter = $dbr->selectField( 'page',
                                        'page_counter',
                                        array( 'page_id' => $id ),
-                                       __METHOD__,
-                                       $this->getSelectOptions()
+                                       __METHOD__
                                );
                        }
                }
@@ -691,8 +715,8 @@ class Article {
         * This isn't necessary for all uses, so it's only done if needed.
         */
        protected function loadLastEdit() {
-               if ( -1 != $this->mUser ) {
-                       return;
+               if ( $this->mLastRevision !== null ) {
+                       return; // already loaded
                }
 
                # New or non-existent articles have no user information
@@ -702,7 +726,7 @@ class Article {
                }
 
                $revision = Revision::loadFromPageId( wfGetDB( DB_MASTER ), $id );
-               if ( !is_null( $revision ) ) {
+               if ( $revision ) {
                        $this->setLastEdit( $revision );
                }
        }
@@ -712,11 +736,7 @@ class Article {
         */
        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();
        }
 
        /**
@@ -727,32 +747,55 @@ class Article {
                if ( !$this->mTimestamp ) {
                        $this->loadLastEdit();
                }
-
                return wfTimestamp( TS_MW, $this->mTimestamp );
        }
 
        /**
+        * @param $audience Integer: one of:
+        *      Revision::FOR_PUBLIC       to be displayed to all users
+        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::RAW              get the text regardless of permissions
         * @return int user ID for the user that made the last article revision
         */
-       public function getUser() {
+       public function getUser( $audience = Revision::FOR_PUBLIC ) {
                $this->loadLastEdit();
-               return $this->mUser;
+               if ( $this->mLastRevision ) {
+                       return $this->mLastRevision->getUser( $audience );
+               } else {
+                       return -1;
+               }
        }
 
        /**
+        * @param $audience Integer: one of:
+        *      Revision::FOR_PUBLIC       to be displayed to all users
+        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::RAW              get the text regardless of permissions
         * @return string username of the user that made the last article revision
         */
-       public function getUserText() {
+       public function getUserText( $audience = Revision::FOR_PUBLIC ) {
                $this->loadLastEdit();
-               return $this->mUserText;
+               if ( $this->mLastRevision ) {
+                       return $this->mLastRevision->getUserText( $audience );
+               } else {
+                       return '';
+               }
        }
 
        /**
+        * @param $audience Integer: one of:
+        *      Revision::FOR_PUBLIC       to be displayed to all users
+        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::RAW              get the text regardless of permissions
         * @return string Comment stored for the last article revision
         */
-       public function getComment() {
+       public function getComment( $audience = Revision::FOR_PUBLIC ) {
                $this->loadLastEdit();
-               return $this->mComment;
+               if ( $this->mLastRevision ) {
+                       return $this->mLastRevision->getComment( $audience );
+               } else {
+                       return '';
+               }
        }
 
        /**
@@ -762,7 +805,11 @@ class Article {
         */
        public function getMinorEdit() {
                $this->loadLastEdit();
-               return $this->mMinorEdit;
+               if ( $this->mLastRevision ) {
+                       return $this->mLastRevision->isMinor();
+               } else {
+                       return false;
+               }
        }
 
        /**
@@ -779,46 +826,54 @@ class Article {
        }
 
        /**
-        * FIXME: this does what?
-        * @param $limit Integer: default 0.
-        * @param $offset Integer: default 0.
-        * @return UserArrayFromResult object with User objects of article contributors for requested range
+        * 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
         */
-       public function getContributors( $limit = 0, $offset = 0 ) {
+       public function getContributors() {
                # FIXME: this is expensive; cache this info somewhere.
 
                $dbr = wfGetDB( DB_SLAVE );
-               $revTable = $dbr->tableName( 'revision' );
                $userTable = $dbr->tableName( 'user' );
 
-               $pageId = $this->getId();
-
-               $user = $this->getUser();
-
-               if ( $user ) {
-                       $excludeCond = "AND rev_user != $user";
+               if ( $dbr->implicitGroupby() ) {
+                       $realNameField = 'user_real_name';
                } else {
-                       $userText = $dbr->addQuotes( $this->getUserText() );
-                       $excludeCond = "AND rev_user_text != $userText";
+                       $realNameField = 'FIRST(user_real_name) AS user_real_name';
                }
 
-               $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden?
+               $tables = array( 'revision', 'user' );
 
-               $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp
-                       FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
-                       WHERE rev_page = $pageId
-                       $excludeCond
-                       AND $deletedBit = 0
-                       GROUP BY rev_user, rev_user_text
-                       ORDER BY timestamp DESC";
+               $fields = array(
+                       'rev_user as user_id',
+                       'rev_user_text AS user_name',
+                       $realNameField,
+                       'MAX(rev_timestamp) AS timestamp',
+               );
+
+               $conds = array( 'rev_page' => $this->getId() );
 
-               if ( $limit > 0 ) {
-                       $sql = $dbr->limitResult( $sql, $limit, $offset );
+               // The user who made the top revision gets credited as "this page was last edited by
+               // John, based on contributions by Tom, Dick and Harry", so don't include them twice.
+               $user = $this->getUser();
+               if ( $user ) {
+                       $conds[] = "rev_user != $user";
+               } else {
+                       $conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
                }
 
-               $sql .= ' ' . $this->getSelectOptions();
-               $res = $dbr->query( $sql, __METHOD__ );
+               $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0"; // username hidden?
 
+               $jconds = array(
+                       'user' => array( 'LEFT JOIN', 'rev_user = user_id' ),
+               );
+
+               $options = array(
+                       '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 );
        }
 
@@ -1211,7 +1266,7 @@ class Article {
         * @return boolean
         */
        public function showRedirectedFromHeader() {
-               global $wgOut, $wgUser, $wgRequest, $wgRedirectSources;
+               global $wgOut, $wgRequest, $wgRedirectSources;
 
                $rdfrom = $wgRequest->getVal( 'rdfrom' );
 
@@ -1219,7 +1274,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(),
@@ -1247,7 +1302,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 );
 
@@ -1310,7 +1365,6 @@ class Article {
                        return;
                }
 
-               $sk = $wgUser->getSkin();
                $token = $wgUser->editToken( $rcid );
                $wgOut->preventClickjacking();
 
@@ -1318,7 +1372,7 @@ class Article {
                        "<div class='patrollink'>" .
                                wfMsgHtml(
                                        'markaspatrolledlink',
-                                       $sk->link(
+                                       Linker::link(
                                                $this->mTitle,
                                                wfMsgHtml( 'markaspatrolledtext' ),
                                                array(),
@@ -1536,7 +1590,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 );
@@ -1548,14 +1602,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';
@@ -1564,9 +1617,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' ) );
                        }
                }
 
@@ -1658,32 +1711,7 @@ class Article {
         * Handle action=purge
         */
        public function purge() {
-               global $wgRequest, $wgOut;
-
-               if ( $wgOut->getUser()->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
-                       //FIXME: shouldn't this be in doPurge()?
-                       if ( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
-                               $this->doPurge();
-                               $this->view();
-                       }
-               } else {
-                       $formParams = array(
-                               'method' => 'post',
-                               'action' =>  $wgRequest->getRequestURL(),
-                       );
-
-                       $wgOut->addWikiMsg( 'confirm-purge-top' );
-
-                       $form  = Html::openElement( 'form', $formParams );
-                       $form .= Xml::submitButton( wfMsg( 'confirm_purge_button' ) );
-                       $form .= Html::closeElement( 'form' );
-
-                       $wgOut->addHTML( $form );
-                       $wgOut->addWikiMsg( 'confirm-purge-bottom' );
-
-                       $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               }
+               return Action::factory( 'purge', $this )->show();
        }
 
        /**
@@ -1692,6 +1720,10 @@ class Article {
        public function doPurge() {
                global $wgUseSquid;
 
+               if( !wfRunHooks( 'ArticlePurge', array( &$this ) ) ){
+                       return false;
+               }
+
                // Invalidate the cache
                $this->mTitle->invalidateCache();
                $this->clear();
@@ -1769,12 +1801,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();
@@ -1787,15 +1817,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 ),
                        ),
@@ -1814,7 +1840,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
@@ -2312,7 +2338,7 @@ class Article {
                if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
                        $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
                        $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
-                       $wgOut->returnToMain( false, $return );
+                       $wgOut->returnToMain( null, $return );
 
                        return;
                }
@@ -2326,32 +2352,15 @@ class Article {
                # Inform the user
                $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
                $wgOut->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
-               $wgOut->returnToMain( false, $return );
+               $wgOut->returnToMain( null, $return );
        }
 
        /**
         * User-interface handler for the "watch" action
+        * @deprecated since 1.18
         */
        public function watch() {
-               global $wgOut;
-
-               if ( $wgOut->getUser()->isAnon() ) {
-                       $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
-                       return;
-               }
-
-               if ( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
-               }
-
-               if ( $this->doWatch() ) {
-                       $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
-                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() );
-               }
-
-               $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
+               Action::factory( 'watch', $this )->show();
        }
 
        /**
@@ -2360,64 +2369,27 @@ class Article {
         * This is safe to be called multiple times
         *
         * @return bool true on successful watch operation
+        * @deprecated since 1.18
         */
        public function doWatch() {
-               global $wgUser;
-
-               if ( $wgUser->isAnon() ) {
-                       return false;
-               }
-
-               if ( wfRunHooks( 'WatchArticle', array( &$wgUser, &$this ) ) ) {
-                       $wgUser->addWatch( $this->mTitle );
-                       return wfRunHooks( 'WatchArticleComplete', array( &$wgUser, &$this ) );
-               }
-
-               return false;
+               return Action::factory( 'watch', $this )->execute();
        }
 
        /**
         * User interface handler for the "unwatch" action.
+        * @deprecated since 1.18
         */
        public function unwatch() {
-               global $wgOut;
-
-               if ( $wgOut->getUser()->isAnon() ) {
-                       $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
-                       return;
-               }
-
-               if ( wfReadOnly() ) {
-                       $wgOut->readOnlyPage();
-                       return;
-               }
-
-               if ( $this->doUnwatch() ) {
-                       $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
-                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() );
-               }
-
-               $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
+               Action::factory( 'unwatch', $this )->show();
        }
 
        /**
         * Stop watching a page
         * @return bool true on successful unwatch
+        * @deprecated since 1.18
         */
        public function doUnwatch() {
-               global $wgUser;
-
-               if ( $wgUser->isAnon() ) {
-                       return false;
-               }
-
-               if ( wfRunHooks( 'UnwatchArticle', array( &$wgUser, &$this ) ) ) {
-                       $wgUser->removeWatch( $this->mTitle );
-                       return wfRunHooks( 'UnwatchArticleComplete', array( &$wgUser, &$this ) );
-               }
-
-               return false;
+               return Action::factory( 'unwatch', $this )->execute();
        }
 
        /**
@@ -2837,12 +2809,11 @@ class Article {
                if ( $hasHistory && !$confirm ) {
                        global $wgLang;
 
-                       $skin = $wgOut->getSkin();
                        $revisions = $this->estimateRevisionCount();
                        //FIXME: lego
                        $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' ) ) .
@@ -2907,10 +2878,11 @@ class Article {
                                        'page_namespace' => $this->mTitle->getNamespace(),
                                        'page_title' => $this->mTitle->getDBkey(),
                                        'rev_page = page_id'
-                               ), __METHOD__, $this->getSelectOptions( array(
+                               ), __METHOD__,
+                               array(
                                        'ORDER BY' => 'rev_timestamp DESC',
                                        'LIMIT' => $num
-                               ) )
+                               )
                        );
 
                        if ( !$res ) {
@@ -2948,7 +2920,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' );
@@ -3025,9 +2997,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(),
@@ -3200,6 +3171,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 ) );
                }
 
@@ -3443,7 +3415,7 @@ class Article {
 
                                if ( $current->getComment() != '' ) {
                                        $wgOut->addWikiMsgArray( 'editcomment', array(
-                                               $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
+                                               Linker::formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
                                }
                        }
 
@@ -3482,12 +3454,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 );
 
@@ -3598,10 +3570,11 @@ class Article {
 
                                $dbw = wfGetDB( DB_MASTER );
                                $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
-                               $recentchanges = $dbw->tableName( 'recentchanges' );
-                               $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
-
-                               $dbw->query( $sql );
+                               $dbw->delete(
+                                       'recentchanges',
+                                       array( "rc_timestamp < '$cutoff'" ),
+                                       __METHOD__
+                               );
                        }
                }
 
@@ -3688,15 +3661,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(),
@@ -3705,7 +3679,7 @@ class Article {
                        );
                $curdiff = $current
                        ? wfMsgHtml( 'diff' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'diff' ),
                                array(),
@@ -3717,7 +3691,7 @@ class Article {
                        );
                $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
                $prevlink = $prev
-                       ? $sk->link(
+                       ? Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'previousrevision' ),
                                array(),
@@ -3729,7 +3703,7 @@ class Article {
                        )
                        : wfMsgHtml( 'previousrevision' );
                $prevdiff = $prev
-                       ? $sk->link(
+                       ? Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'diff' ),
                                array(),
@@ -3742,7 +3716,7 @@ class Article {
                        : wfMsgHtml( 'diff' );
                $nextlink = $current
                        ? wfMsgHtml( 'nextrevision' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'nextrevision' ),
                                array(),
@@ -3754,7 +3728,7 @@ class Article {
                        );
                $nextdiff = $current
                        ? wfMsgHtml( 'diff' )
-                       : $sk->link(
+                       : Linker::link(
                                $this->mTitle,
                                wfMsgHtml( 'diff' ),
                                array(),
@@ -3771,20 +3745,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'
@@ -3981,6 +3955,8 @@ class Article {
 
        /**
         * Clears caches when article is deleted
+        *
+        * @param $title Title
         */
        public static function onArticleDelete( $title ) {
                # Update existence markers on article/talk tabs...
@@ -4081,7 +4057,7 @@ class Article {
                                $msg = $wgUser->isLoggedIn()
                                        ? 'noarticletext'
                                        : 'noarticletextanon';
-                               $wgOut->addHTML( wfMsgExt( $msg, 'parse' ) );
+                               $wgOut->addWikiMsg( $msg );
                        }
 
                        $wgOut->addHTML( '</div>' );
@@ -4094,8 +4070,7 @@ class Article {
                                'watchlist',
                                'COUNT(*)',
                                $wl_clause,
-                               __METHOD__,
-                               $this->getSelectOptions() );
+                               __METHOD__ );
 
                        $pageInfo = $this->pageCountInfo( $page );
                        $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
@@ -4139,15 +4114,13 @@ class Article {
                        'revision',
                        'COUNT(rev_page)',
                        $rev_clause,
-                       __METHOD__,
-                       $this->getSelectOptions()
+                       __METHOD__
                );
                $authors = $dbr->selectField(
                        'revision',
                        'COUNT(DISTINCT rev_user_text)',
                        $rev_clause,
-                       __METHOD__,
-                       $this->getSelectOptions()
+                       __METHOD__
                );
 
                return array( 'edits' => $edits, 'authors' => $authors );
@@ -4324,26 +4297,33 @@ class Article {
 
        /**
         * Get parser options suitable for rendering the primary article wikitext
-        * @return mixed ParserOptions object or boolean false
+        * @return ParserOptions object
         */
        public function getParserOptions() {
                global $wgUser;
-
                if ( !$this->mParserOptions ) {
-                       $this->mParserOptions = new ParserOptions( $wgUser );
-                       $this->mParserOptions->setTidy( true );
-                       $this->mParserOptions->enableLimitReport();
+                       $this->mParserOptions = $this->makeParserOptions( $wgUser );
                }
-
-               // 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() ) {
@@ -4500,9 +4480,38 @@ class Article {
                return $this->getOutputFromWikitext( $text, $useParserCache );
        }
 
+       /**
+        * Sets the context this Article is executed in
+        *
+        * @param $context RequestContext
+        * @since 1.18
+        */
+       public function setContext( $context ) {
+               $this->mContext = $context;
+       }
+
+       /**
+        * Gets the context this Article is executed in
+        *
+        * @return RequestContext
+        * @since 1.18
+        */
+       public function getContext() {
+               if ( $this->mContext instanceof RequestContext ) {
+                       return $this->mContext;
+               } else {
+                       wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
+                       return RequestContext::getMain();
+               }
+       }
+
 }
 
 class PoolWorkArticleView extends PoolCounterWork {
+
+       /**
+        * @var Article
+        */
        private $mArticle;
 
        function __construct( $article, $key, $useParserCache, $parserOptions ) {
@@ -4537,6 +4546,9 @@ class PoolWorkArticleView extends PoolCounterWork {
                return $this->mArticle->tryDirtyCache();
        }
 
+       /**
+        * @param  $status Status
+        */
        function error( $status ) {
                global $wgOut;