catch exceptions while generating auto delete reason
[lhc/web/wiklou.git] / includes / Article.php
index fe68ddd..5470dbc 100644 (file)
@@ -37,7 +37,8 @@ class Article extends Page {
         */
        public $mParserOptions;
 
-       var $mContent;                    // !<
+       var $mContent;                    // !< #BC cruft
+    var $mContentObject;              // !<
        var $mContentLoaded = false;      // !<
        var $mOldId;                      // !<
 
@@ -112,13 +113,14 @@ class Article extends Page {
                if ( !$page ) {
                        switch( $title->getNamespace() ) {
                                case NS_FILE:
-                                       $page = new ImagePage( $title );
+                                       $page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler
                                        break;
                                case NS_CATEGORY:
-                                       $page = new CategoryPage( $title );
+                                       $page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler
                                        break;
                                default:
-                                       $page = new Article( $title );
+                    $handler = ContentHandler::getForTitle( $title );
+                                       $page = $handler->createArticle( $title );
                        }
                }
                $page->setContext( $context );
@@ -150,12 +152,23 @@ class Article extends Page {
 
        /**
         * Get the title object of the article
+        *
         * @return Title object of this page
         */
        public function getTitle() {
                return $this->mPage->getTitle();
        }
 
+       /**
+        * Get the WikiPage object of this instance
+        *
+        * @since 1.19
+        * @return WikiPage
+        */
+       public function getPage() {
+               return $this->mPage;
+       }
+
        /**
         * Clear the object
         */
@@ -172,14 +185,31 @@ class Article extends Page {
        /**
         * Note that getContent/loadContent do not follow redirects anymore.
         * If you need to fetch redirectable content easily, try
-        * the shortcut in Article::followRedirect()
+        * the shortcut in WikiPage::getRedirectTarget()
         *
         * This function has side effects! Do not use this function if you
         * only want the real revision text if any.
         *
         * @return Return the text of this revision
+     * @deprecated in 1.20; use getContentObject() instead
         */
        public function getContent() {
+        wfDeprecated( __METHOD__, '1.20' );
+        $content = $this->getContentObject();
+        return ContentHandler::getContentText( $content );
+    }
+
+    /**
+     * Note that getContent/loadContent do not follow redirects anymore.
+     * If you need to fetch redirectable content easily, try
+     * the shortcut in WikiPage::getRedirectTarget()
+     *
+     * This function has side effects! Do not use this function if you
+     * only want the real revision text if any.
+     *
+     * @return Return the content of this revision
+     */
+   public function getContentObject() {
                global $wgUser;
 
                wfProfileIn( __METHOD__ );
@@ -197,12 +227,12 @@ class Article extends Page {
                        }
                        wfProfileOut( __METHOD__ );
 
-                       return $text;
+                       return ContentHandler::makeContent( $text, $this->getTitle() );
                } else {
-                       $this->fetchContent();
+                       $this->fetchContentObject();
                        wfProfileOut( __METHOD__ );
 
-                       return $this->mContent;
+                       return $this->mContentObject;
                }
        }
 
@@ -251,6 +281,7 @@ class Article extends Page {
                        $nextid = $this->getTitle()->getNextRevisionID( $oldid );
                        if ( $nextid ) {
                                $oldid = $nextid;
+                               $this->mRevision = null;
                        } else {
                                $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
                        }
@@ -258,6 +289,7 @@ class Article extends Page {
                        $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
                        if ( $previd ) {
                                $oldid = $previd;
+                               $this->mRevision = null;
                        }
                }
 
@@ -270,6 +302,7 @@ class Article extends Page {
         * @deprecated in 1.19; use fetchContent()
         */
        function loadContent() {
+               wfDeprecated( __METHOD__, '1.19' );
                $this->fetchContent();
        }
 
@@ -278,67 +311,96 @@ class Article extends Page {
         * Does *NOT* follow redirects.
         *
         * @return mixed string containing article contents, or false if null
+     * @deprecated in 1.20, use getContentObject() instead
         */
-       function fetchContent() {
-               if ( $this->mContentLoaded ) {
+       protected function fetchContent() { #BC cruft!
+        wfDeprecated( __METHOD__, '1.20' );
+
+               if ( $this->mContentLoaded && $this->mContent ) {
                        return $this->mContent;
                }
 
                wfProfileIn( __METHOD__ );
 
-               $this->mContentLoaded = true;
+        $content = $this->fetchContentObject();
 
-               $oldid = $this->getOldID();
+        $this->mContent = ContentHandler::getContentText( $content ); #FIXME: get rid of mContent everywhere!
+               wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); #BC cruft!
 
-               # Pre-fill content with error message so that if something
-               # fails we'll have something telling us what we intended.
-               $t = $this->getTitle()->getPrefixedText();
-               $d = $oldid ? wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
-               $this->mContent = wfMsgNoTrans( 'missing-article', $t, $d ) ;
+               wfProfileOut( __METHOD__ );
 
-               if ( $oldid ) {
-                       # $this->mRevision might already be fetched by getOldIDFromRequest()
-                       if ( !$this->mRevision ) {
-                               $this->mRevision = Revision::newFromId( $oldid );
-                               if ( !$this->mRevision ) {
-                                       wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
-                                       wfProfileOut( __METHOD__ );
-                                       return false;
-                               }
-                       }
-               } else {
-                       if ( !$this->mPage->getLatest() ) {
-                               wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
-                               wfProfileOut( __METHOD__ );
-                               return false;
-                       }
+               return $this->mContent;
+       }
 
-                       $this->mRevision = $this->mPage->getRevision();
-                       if ( !$this->mRevision ) {
-                               wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n" );
-                               wfProfileOut( __METHOD__ );
-                               return false;
-                       }
-               }
 
-               // @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 = $this->mRevision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
-               $this->mRevIdFetched = $this->mRevision->getId();
+    /**
+     * Get text content object
+     * Does *NOT* follow redirects.
+     *
+     * @return Content object containing article contents, or null
+     */
+    protected function fetchContentObject() {
+        if ( $this->mContentLoaded ) {
+            return $this->mContentObject;
+        }
 
-               wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
+        wfProfileIn( __METHOD__ );
 
-               wfProfileOut( __METHOD__ );
+        $this->mContentLoaded = true;
+        $this->mContent = null;
 
-               return $this->mContent;
-       }
+        $oldid = $this->getOldID();
+
+        # Pre-fill content with error message so that if something
+        # fails we'll have something telling us what we intended.
+        $t = $this->getTitle()->getPrefixedText();
+        $d = $oldid ? wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
+        $this->mContentObject = new MessageContent( 'missing-article', array($t, $d), array() ) ;
+
+        if ( $oldid ) {
+            # $this->mRevision might already be fetched by getOldIDFromRequest()
+            if ( !$this->mRevision ) {
+                $this->mRevision = Revision::newFromId( $oldid );
+                if ( !$this->mRevision ) {
+                    wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
+                    wfProfileOut( __METHOD__ );
+                    return false;
+                }
+            }
+        } else {
+            if ( !$this->mPage->getLatest() ) {
+                wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
+                wfProfileOut( __METHOD__ );
+                return false;
+            }
+
+            $this->mRevision = $this->mPage->getRevision();
+
+            if ( !$this->mRevision ) {
+                wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n" );
+                wfProfileOut( __METHOD__ );
+                return false;
+            }
+        }
+
+        // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
+        // We should instead work with the Revision object when we need it...
+        $this->mContentObject = $this->mRevision->getContent( Revision::FOR_THIS_USER ); // Loads if user is allowed
+        $this->mRevIdFetched = $this->mRevision->getId();
+
+        wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) ); #FIXME: register new hook
+
+        wfProfileOut( __METHOD__ );
+
+        return $this->mContentObject;
+    }
 
        /**
         * No-op
         * @deprecated since 1.18
         */
        public function forUpdate() {
-               wfDeprecated( __METHOD__ );
+               wfDeprecated( __METHOD__, '1.18' );
        }
 
        /**
@@ -355,6 +417,19 @@ class Article extends Page {
                return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
        }
 
+       /**
+        * Get the fetched Revision object depending on request parameters or null
+        * on failure.
+        *
+        * @since 1.19
+        * @return Revision|null
+        */
+       public function getRevisionFetched() {
+               $this->fetchContentObject();
+
+               return $this->mRevision;
+       }
+
        /**
         * Use this to fetch the rev ID used on page views
         *
@@ -374,7 +449,7 @@ class Article extends Page {
         */
        public function view() {
                global $wgUser, $wgOut, $wgRequest, $wgParser;
-               global $wgUseFileCache, $wgUseETag;
+               global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
 
                wfProfileIn( __METHOD__ );
 
@@ -429,7 +504,7 @@ class Article extends Page {
                }
 
                # Try client and file cache
-               if ( $oldid === 0 && $this->mPage->checkTouched() ) {
+               if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
                        if ( $wgUseETag ) {
                                $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
                        }
@@ -445,7 +520,7 @@ class Article extends Page {
                                wfDebug( __METHOD__ . ": done file cache\n" );
                                # tell wgOut that output is taken care of
                                $wgOut->disable();
-                               $this->mPage->viewUpdates();
+                               $this->mPage->doViewUpdates( $wgUser );
                                wfProfileOut( __METHOD__ );
 
                                return;
@@ -453,7 +528,7 @@ class Article extends Page {
                }
 
                # Should the parser cache be used?
-               $useParserCache = $this->mPage->isParserCacheUsed( $wgUser, $oldid );
+               $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
                wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
                if ( $wgUser->getStubThreshold() ) {
                        wfIncrStats( 'pcache_miss_stub' );
@@ -497,17 +572,19 @@ class Article extends Page {
                                                        # Ensure that UI elements requiring revision ID have
                                                        # the correct version information.
                                                        $wgOut->setRevisionId( $this->mPage->getLatest() );
-                                                       $outputDone = true;
                                                        # Preload timestamp to avoid a DB hit
-                                                       if ( isset( $this->mParserOutput->mTimestamp ) ) {
-                                                               $this->mPage->setTimestamp( $this->mParserOutput->mTimestamp );
+                                                       $cachedTimestamp = $this->mParserOutput->getTimestamp();
+                                                       if ( $cachedTimestamp !== null ) {
+                                                               $wgOut->setRevisionTimestamp( $cachedTimestamp );
+                                                               $this->mPage->setTimestamp( $cachedTimestamp );
                                                        }
+                                                       $outputDone = true;
                                                }
                                        }
                                        break;
                                case 3:
                                        # This will set $this->mRevision if needed
-                                       $this->fetchContent();
+                                       $this->fetchContentObject();
 
                                        # Are we looking at an old revision
                                        if ( $oldid && $this->mRevision ) {
@@ -523,24 +600,30 @@ class Article extends Page {
                                        # Ensure that UI elements requiring revision ID have
                                        # the correct version information.
                                        $wgOut->setRevisionId( $this->getRevIdFetched() );
+                                       # Preload timestamp to avoid a DB hit
+                                       $wgOut->setRevisionTimestamp( $this->getTimestamp() );
 
                                        # Pages containing custom CSS or JavaScript get special treatment
                                        if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
+                        #FIXME: use ContentHandler for specialized actions insetad.
                                                wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
                                                $this->showCssOrJsPage();
                                                $outputDone = true;
-                                       } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
+                    } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) { #FIXME: document new hook!
+                        # Allow extensions do their own custom view for certain pages
+                        $outputDone = true;
+                                       } elseif( Hooks::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated! #FIXME: deprecate hook!
                                                # Allow extensions do their own custom view for certain pages
                                                $outputDone = true;
                                        } else {
-                                               $text = $this->getContent();
-                                               $rt = Title::newFromRedirectArray( $text );
+                                               $content = $this->getContentObject();
+                                               $rt = $content->getRedirectChain();
                                                if ( $rt ) {
                                                        wfDebug( __METHOD__ . ": showing redirect=no page\n" );
                                                        # Viewing a redirect page (e.g. with parameter redirect=no)
                                                        $wgOut->addHTML( $this->viewRedirect( $rt ) );
                                                        # Parse just to get categories, displaytitle, etc.
-                                                       $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(), $parserOptions );
+                                                       $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions );
                                                        $wgOut->addParserOutputNoText( $this->mParserOutput );
                                                        $outputDone = true;
                                                }
@@ -550,16 +633,34 @@ class Article extends Page {
                                        # Run the parse, protected by a pool counter
                                        wfDebug( __METHOD__ . ": doing uncached parse\n" );
 
-                                       $key = $parserCache->getKey( $this, $parserOptions );
-                                       $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
+                                       $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
+                                               $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
 
                                        if ( !$poolArticleView->execute() ) {
+                                               $error = $poolArticleView->getError();
+                                               if ( $error ) {
+                                                       $wgOut->clearHTML(); // for release() errors
+                                                       $wgOut->enableClientCache( false );
+                                                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
+
+                                                       $errortext = $error->getWikiText( false, 'view-pool-error' );
+                                                       $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
+                                               }
                                                # Connection or timeout error
                                                wfProfileOut( __METHOD__ );
                                                return;
-                                       } else {
-                                               $outputDone = true;
                                        }
+
+                                       $this->mParserOutput = $poolArticleView->getParserOutput();
+                                       $wgOut->addParserOutput( $this->mParserOutput );
+
+                                       # Don't cache a dirty ParserOutput object
+                                       if ( $poolArticleView->getIsDirty() ) {
+                                               $wgOut->setSquidMaxage( 0 );
+                                               $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
+                                       }
+
+                                       $outputDone = true;
                                        break;
                                # Should be unreachable, but just in case...
                                default:
@@ -595,7 +696,7 @@ class Article extends Page {
                $wgOut->setFollowPolicy( $policy['follow'] );
 
                $this->showViewFooter();
-               $this->mPage->viewUpdates();
+               $this->mPage->doViewUpdates( $wgUser );
 
                wfProfileOut( __METHOD__ );
        }
@@ -627,14 +728,16 @@ class Article extends Page {
                $unhide = $wgRequest->getInt( 'unhide' ) == 1;
                $oldid = $this->getOldID();
 
-               $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
+        $contentHandler = ContentHandler::getForTitle( $this->getTitle() );
+               $de = $contentHandler->getDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
+
                // DifferenceEngine directly fetched the revision:
                $this->mRevIdFetched = $de->mNewid;
                $de->showDiffPage( $diffOnly );
 
                if ( $diff == 0 || $diff == $this->mPage->getLatest() ) {
                        # Run view updates for current revision only
-                       $this->mPage->viewUpdates();
+                       $this->mPage->doViewUpdates( $wgUser );
                }
        }
 
@@ -648,20 +751,16 @@ class Article extends Page {
        protected function showCssOrJsPage() {
                global $wgOut;
 
-               $dir = $this->getContext()->getLang()->getDir();
-               $lang = $this->getContext()->getLang()->getCode();
+               $dir = $this->getContext()->getLanguage()->getDir();
+               $lang = $this->getContext()->getLanguage()->getCode();
 
                $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
                        'clearyourcache' );
 
                // Give hooks a chance to customise the output
-               if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
-                       // Wrap the whole lot in a <pre> and don't parse
-                       $m = array();
-                       preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
-                       $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
-                       $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
-                       $wgOut->addHTML( "\n</pre>\n" );
+               if ( !Hooks::isRegistered('ShowRawCssJs') || wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated
+            $po = $this->mContentObject->getParserOutput();
+                       $wgOut->addHTML( $po->getText() );
                }
        }
 
@@ -805,6 +904,9 @@ class Article extends Page {
                                        'href' => $this->getTitle()->getLocalURL() )
                                );
 
+                               // Tell $wgOut the user arrived at this article through a redirect
+                               $wgOut->setRedirectedFrom( $this->mRedirectedFrom );
+
                                return true;
                        }
                } elseif ( $rdfrom ) {
@@ -839,7 +941,7 @@ class Article extends Page {
         * Show the footer section of an ordinary page view
         */
        public function showViewFooter() {
-               global $wgOut, $wgUseTrackbacks;
+               global $wgOut;
 
                # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
                if ( $this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid( $this->getTitle()->getText() ) ) {
@@ -850,11 +952,6 @@ class Article extends Page {
                # chance to mark this new article as patrolled.
                $this->showPatrolFooter();
 
-               # Trackbacks
-               if ( $wgUseTrackbacks ) {
-                       $this->addTrackbacks();
-               }
-
                wfRunHooks( 'ArticleViewFooter', array( $this ) );
 
        }
@@ -873,7 +970,7 @@ class Article extends Page {
                        return;
                }
 
-               $token = $wgUser->editToken( $rcid );
+               $token = $wgUser->getEditToken( $rcid );
                $wgOut->preventClickjacking();
 
                $wgOut->addHTML(
@@ -901,7 +998,7 @@ class Article extends Page {
         * namespace, show the default message text. To be called from Article::view().
         */
        public function showMissingArticle() {
-               global $wgOut, $wgRequest, $wgUser;
+               global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
 
                # Show info in user (talk) namespace. Does the user exist? Is he blocked?
                if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) {
@@ -910,7 +1007,7 @@ class Article extends Page {
                        $user = User::newFromName( $rootPart, false /* allow IP users*/ );
                        $ip = User::isIP( $rootPart );
 
-                       if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
+                       if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
                                $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
                                        array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
                        } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
@@ -963,7 +1060,7 @@ class Article extends Page {
                }
                $text = "<div class='noarticletext'>\n$text\n</div>";
 
-               if ( !$this->mPage->hasViewableContent() ) {
+               if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
                        // If there's no backing content, send a 404 Not Found
                        // for better machine handling of broken links.
                        $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
@@ -1126,21 +1223,8 @@ class Article extends Page {
                                array( 'known', 'noclasses' )
                        );
 
-               $cdel = '';
-
-               // User can delete revisions or view deleted revisions...
-               $canHide = $wgUser->isAllowed( 'deleterevision' );
-               if ( $canHide || ( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
-                       if ( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
-                               $cdel = Linker::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
-                       } else {
-                               $query = array(
-                                       'type'   => 'revision',
-                                       'target' => $this->getTitle()->getPrefixedDbkey(),
-                                       'ids'    => $oldid
-                               );
-                               $cdel = Linker::revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
-                       }
+               $cdel = Linker::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
+               if ( $cdel !== '' ) {
                        $cdel .= ' ';
                }
 
@@ -1149,67 +1233,6 @@ class Article extends Page {
                        $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
        }
 
-       /**
-        * Execute the uncached parse for action=view
-        * @return bool
-        */
-       public function doViewParse() {
-               global $wgOut;
-
-               $oldid = $this->getOldID();
-               $parserOptions = $this->getParserOptions();
-
-               # Render printable version, use printable version cache
-               $parserOptions->setIsPrintable( $wgOut->isPrintable() );
-
-               # Don't show section-edit links on old revisions... this way lies madness.
-               if ( !$this->isCurrent() || $wgOut->isPrintable() || !$this->getTitle()->quickUserCan( 'edit' ) ) {
-                       $parserOptions->setEditSection( false );
-               }
-
-               $useParserCache = $this->useParserCache( $oldid );
-               $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
-
-               return true;
-       }
-
-       /**
-        * Try to fetch an expired entry from the parser cache. If it is present,
-        * output it and return true. If it is not present, output nothing and
-        * return false. This is used as a callback function for
-        * PoolCounter::executeProtected().
-        *
-        * @return boolean
-        */
-       public function tryDirtyCache() {
-               global $wgOut;
-               $parserCache = ParserCache::singleton();
-               $options = $this->getParserOptions();
-
-               if ( $wgOut->isPrintable() ) {
-                       $options->setIsPrintable( true );
-                       $options->setEditSection( false );
-               }
-
-               $output = $parserCache->getDirty( $this, $options );
-
-               if ( $output ) {
-                       wfDebug( __METHOD__ . ": sending dirty output\n" );
-                       wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
-                       $wgOut->setSquidMaxage( 0 );
-                       $this->mParserOutput = $output;
-                       $wgOut->addParserOutput( $output );
-                       $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
-
-                       return true;
-               } else {
-                       wfDebugLog( 'dirty', "dirty missing\n" );
-                       wfDebug( __METHOD__ . ": no dirty cache\n" );
-
-                       return false;
-               }
-       }
-
        /**
         * View redirect
         *
@@ -1263,46 +1286,6 @@ class Article extends Page {
                        '<span class="redirectText">' . $link . '</span></div>';
        }
 
-       /**
-        * Builds trackback links for article display if $wgUseTrackbacks is set to true
-        */
-       public function addTrackbacks() {
-               global $wgOut;
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $tbs = $dbr->select( 'trackbacks',
-                       array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
-                       array( 'tb_page' => $this->mPage->getID() )
-               );
-
-               if ( !$dbr->numRows( $tbs ) ) {
-                       return;
-               }
-
-               $wgOut->preventClickjacking();
-
-               $tbtext = "";
-               foreach ( $tbs as $o ) {
-                       $rmvtxt = "";
-
-                       if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
-                               $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
-                                       $o->tb_id . "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
-                               $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
-                       }
-
-                       $tbtext .= "\n";
-                       $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex ) ? 'trackbackexcerpt' : 'trackback',
-                                       $o->tb_title,
-                                       $o->tb_url,
-                                       $o->tb_ex,
-                                       $o->tb_name,
-                                       $rmvtxt );
-               }
-
-               $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
-       }
-
        /**
         * Handle action=render
         */
@@ -1369,18 +1352,6 @@ class Article extends Page {
                        return;
                }
 
-               # Hack for big sites
-               $bigHistory = $this->mPage->isBigDeletion();
-               if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
-                       global $wgDeleteRevisionsLimit;
-
-                       $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
-                       $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
-                               array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
-
-                       return;
-               }
-
                $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
                $deleteReason = $wgRequest->getText( 'wpReason' );
 
@@ -1413,12 +1384,18 @@ class Article extends Page {
                // Generate deletion reason
                $hasHistory = false;
                if ( !$reason ) {
-                       $reason = $this->generateReason( $hasHistory );
+            try {
+                $reason = $this->generateReason( $hasHistory );
+            } catch (MWException $e) {
+                # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
+                wfDebug("Error while building auto delete summary: $e");
+                $reason = '';
+            }
                }
 
                // If the page has a history, insert a warning
                if ( $hasHistory ) {
-                       $revisions = $this->mPage->estimateRevisionCount();
+                       $revisions = $this->mTitle->estimateRevisionCount();
                        // @todo FIXME: i18n issue/patchwork message
                        $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
                                wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
@@ -1429,7 +1406,7 @@ class Article extends Page {
                                '</strong>'
                        );
 
-                       if ( $bigHistory ) {
+                       if ( $this->mTitle->isBigDeletion() ) {
                                global $wgDeleteRevisionsLimit;
                                $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
                                        array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
@@ -1524,7 +1501,7 @@ class Article extends Page {
                        </tr>" .
                        Xml::closeElement( 'table' ) .
                        Xml::closeElement( 'fieldset' ) .
-                       Html::hidden( 'wpEditToken', $user->editToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
+                       Html::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
                        Xml::closeElement( 'form' );
 
                        if ( $user->isAllowed( 'editinterface' ) ) {
@@ -1553,10 +1530,8 @@ class Article extends Page {
        public function doDelete( $reason, $suppress = false ) {
                global $wgOut;
 
-               $id = $this->getTitle()->getArticleID( Title::GAID_FOR_UPDATE );
-
                $error = '';
-               if ( $this->mPage->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
+               if ( $this->mPage->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
                        $deleted = $this->getTitle()->getPrefixedText();
 
                        $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
@@ -1641,25 +1616,6 @@ class Article extends Page {
 
        /**#@-*/
 
-       /**
-        * Add the primary page-view wikitext to the output buffer
-        * Saves the text into the parser cache if possible.
-        * Updates templatelinks if it is out of date.
-        *
-        * @param $text String
-        * @param $cache Boolean
-        * @param $parserOptions mixed ParserOptions object, or boolean false
-        */
-       public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
-               global $wgOut;
-
-               $this->mParserOutput = $this->getOutputFromWikitext( $text, $cache, $parserOptions );
-
-               $this->doCascadeProtectionUpdates( $this->mParserOutput );
-
-               $wgOut->addParserOutput( $this->mParserOutput );
-       }
-
        /**
         * Lightweight method to get the parser output for a page, checking the parser cache
         * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
@@ -1672,93 +1628,12 @@ class Article extends Page {
         * @return ParserOutput or false if the given revsion ID is not found
         */
        public function getParserOutput( $oldid = null, User $user = null ) {
-               global $wgEnableParserCache, $wgUser;
-               $user = is_null( $user ) ? $wgUser : $user;
-
-               wfProfileIn( __METHOD__ );
-               // Should the parser cache be used?
-               $useParserCache = $wgEnableParserCache &&
-                       $user->getStubThreshold() == 0 &&
-                       $this->mPage->exists() &&
-                       $oldid === null;
-
-               wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
-
-               if ( $user->getStubThreshold() ) {
-                       wfIncrStats( 'pcache_miss_stub' );
-               }
-
-               if ( $useParserCache ) {
-                       $options = $this->mPage->makeParserOptions( $user );
-                       $parserOutput = ParserCache::singleton()->get( $this, $options );
-                       if ( $parserOutput !== false ) {
-                               wfProfileOut( __METHOD__ );
-                               return $parserOutput;
-                       }
-               }
-
-               // Cache miss; parse and output it.
-               if ( $oldid === null ) {
-                       $text = $this->mPage->getRawText();
-               } else {
-                       $rev = Revision::newFromTitle( $this->getTitle(), $oldid );
-                       if ( $rev === null ) {
-                               wfProfileOut( __METHOD__ );
-                               return false;
-                       }
-                       $text = $rev->getText();
-               }
-
-               $output = $this->getOutputFromWikitext( $text, $useParserCache );
-               wfProfileOut( __METHOD__ );
-               return $output;
-       }
-
-       /**
-        * This does all the heavy lifting for outputWikitext, except it returns the parser
-        * output instead of sending it straight to $wgOut. Makes things nice and simple for,
-        * say, embedding thread pages within a discussion system (LiquidThreads)
-        *
-        * @param $text string
-        * @param $cache boolean
-        * @param $parserOptions parsing options, defaults to false
-        * @return ParserOutput
-        */
-       public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
-               global $wgParser, $wgEnableParserCache, $wgUseFileCache;
-
-               if ( !$parserOptions ) {
-                       $parserOptions = $this->getParserOptions();
-               }
-
-               $time = - wfTime();
-               $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(),
-                       $parserOptions, true, true, $this->getRevIdFetched() );
-               $time += wfTime();
-
-               # Timing hack
-               if ( $time > 3 ) {
-                       wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
-                               $this->getTitle()->getPrefixedDBkey() ) );
-               }
-
-               if ( $wgEnableParserCache && $cache && $this->mParserOutput->isCacheable() ) {
-                       $parserCache = ParserCache::singleton();
-                       $parserCache->save( $this->mParserOutput, $this, $parserOptions );
-               }
-
-               // Make sure file cache is not used on uncacheable content.
-               // Output that has magic words in it can still use the parser cache
-               // (if enabled), though it will generally expire sooner.
-               if ( !$this->mParserOutput->isCacheable() || $this->mParserOutput->containsOldMagic() ) {
-                       $wgUseFileCache = false;
-               }
+               global $wgUser;
 
-               if ( $this->isCurrent() ) {
-                       $this->mPage->doCascadeProtectionUpdates( $this->mParserOutput );
-               }
+               $user = is_null( $user ) ? $wgUser : $user;
+               $parserOptions = $this->mPage->makeParserOptions( $user );
 
-               return $this->mParserOutput;
+               return $this->mPage->getParserOutput( $parserOptions, $oldid );
        }
 
        /**
@@ -1799,19 +1674,12 @@ class Article extends Page {
                }
        }
 
-       /**
-        * Removes trackback record for current article from trackbacks table
-        * @deprecated since 1.18
-        */
-       public function deletetrackback() {
-               return Action::factory( 'deletetrackback', $this )->show();
-       }
-
        /**
         * Info about this page
         * @deprecated since 1.19
         */
        public function info() {
+               wfDeprecated( __METHOD__, '1.19' );
                Action::factory( 'info', $this )->show();
        }
 
@@ -1820,6 +1688,7 @@ class Article extends Page {
         * @deprecated since 1.18
         */
        public function markpatrolled() {
+               wfDeprecated( __METHOD__, '1.18' );
                Action::factory( 'markpatrolled', $this )->show();
        }
 
@@ -1836,6 +1705,7 @@ class Article extends Page {
         * @deprecated since 1.19
         */
        public function revert() {
+               wfDeprecated( __METHOD__, '1.19' );
                Action::factory( 'revert', $this )->show();
        }
 
@@ -1844,6 +1714,7 @@ class Article extends Page {
         * @deprecated since 1.19
         */
        public function rollback() {
+               wfDeprecated( __METHOD__, '1.19' );
                Action::factory( 'rollback', $this )->show();
        }
 
@@ -1853,6 +1724,7 @@ class Article extends Page {
         * @deprecated since 1.18
         */
        public function watch() {
+               wfDeprecated( __METHOD__, '1.18' );
                Action::factory( 'watch', $this )->show();
        }
 
@@ -1866,6 +1738,7 @@ class Article extends Page {
         */
        public function doWatch() {
                global $wgUser;
+               wfDeprecated( __METHOD__, '1.18' );
                return WatchAction::doWatch( $this->getTitle(), $wgUser );
        }
 
@@ -1875,6 +1748,7 @@ class Article extends Page {
         * @deprecated since 1.18
         */
        public function unwatch() {
+               wfDeprecated( __METHOD__, '1.18' );
                Action::factory( 'unwatch', $this )->show();
        }
 
@@ -1885,6 +1759,7 @@ class Article extends Page {
         */
        public function doUnwatch() {
                global $wgUser;
+               wfDeprecated( __METHOD__, '1.18' );
                return WatchAction::doUnwatch( $this->getTitle(), $wgUser );
        }
 
@@ -1898,7 +1773,7 @@ class Article extends Page {
         * @param $extraQuery String: extra query params
         */
        public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
-               wfDeprecated( __METHOD__ );
+               wfDeprecated( __METHOD__, '1.18' );
                global $wgOut;
 
                if ( $noRedir ) {
@@ -1962,6 +1837,18 @@ class Article extends Page {
 
        // ****** B/C functions to work-around PHP silliness with __call and references ****** //
 
+       /**
+        * @param $limit array
+        * @param $expiry array
+        * @param $cascade bool
+        * @param $reason string
+        * @param $user User
+        * @return Status
+        */
+       public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User $user ) {
+               return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
+       }
+
        /**
         * @param $limit array
         * @param $reason string
@@ -2019,7 +1906,9 @@ class Article extends Page {
         * @return mixed
         */
        public function generateReason( &$hasHistory ) {
-               return $this->mPage->getAutoDeleteReason( $hasHistory );
+        $title = $this->mPage->getTitle();
+        $handler = ContentHandler::getForTitle( $title );
+               return $handler->getAutoDeleteReason( $title, $hasHistory );
        }
 
        // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
@@ -2057,74 +1946,10 @@ class Article extends Page {
         * @param $newtext
         * @param $flags
         * @return string
+     * @deprecated since 1.20, use ContentHandler::getAutosummary() instead
         */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
                return WikiPage::getAutosummary( $oldtext, $newtext, $flags );
        }
        // ******
 }
-
-class PoolWorkArticleView extends PoolCounterWork {
-
-       /**
-        * @var Article
-        */
-       private $mArticle;
-
-       function __construct( $article, $key, $useParserCache, $parserOptions ) {
-               parent::__construct( 'ArticleView', $key );
-               $this->mArticle = $article;
-               $this->cacheable = $useParserCache;
-               $this->parserOptions = $parserOptions;
-       }
-
-       /**
-        * @return bool
-        */
-       function doWork() {
-               return $this->mArticle->doViewParse();
-       }
-
-       /**
-        * @return bool
-        */
-       function getCachedWork() {
-               global $wgOut;
-
-               $parserCache = ParserCache::singleton();
-               $this->mArticle->mParserOutput = $parserCache->get( $this->mArticle, $this->parserOptions );
-
-               if ( $this->mArticle->mParserOutput !== false ) {
-                       wfDebug( __METHOD__ . ": showing contents parsed by someone else\n" );
-                       $wgOut->addParserOutput( $this->mArticle->mParserOutput );
-                       # Ensure that UI elements requiring revision ID have
-                       # the correct version information.
-                       $wgOut->setRevisionId( $this->mArticle->getLatest() );
-                       return true;
-               }
-               return false;
-       }
-
-       /**
-        * @return bool
-        */
-       function fallback() {
-               return $this->mArticle->tryDirtyCache();
-       }
-
-       /**
-        * @param $status Status
-        */
-       function error( $status ) {
-               global $wgOut;
-
-               $wgOut->clearHTML(); // for release() errors
-               $wgOut->enableClientCache( false );
-               $wgOut->setRobotPolicy( 'noindex,nofollow' );
-
-               $errortext = $status->getWikiText( false, 'view-pool-error' );
-               $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
-
-               return false;
-       }
-}