X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FArticle.php;h=d98fc1e55fe7e610772507908017a1a898d28907;hb=0abb52ae76adfadefdc5e37ee754eb6fc4c4c2fc;hp=71d65993f34e43b052695957eb809035da0cdd83;hpb=2b78de3f023660acec4fa20c8123768722c87b72;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Article.php b/includes/Article.php index 71d65993f3..d98fc1e55f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -126,6 +126,19 @@ class Article extends Page { return $page; } + /** + * Create an Article object of the appropriate class for the given page. + * + * @param $page WikiPage + * @param $context IContextSource + * @return Article object + */ + public static function newFromWikiPage( WikiPage $page, IContextSource $context ) { + $article = self::newFromTitle( $page->getTitle(), $context ); + $article->mPage = $page; // override to keep process cached vars + return $article; + } + /** * Tell the page view functions that this view was redirected * from another page on the wiki. @@ -137,12 +150,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 */ @@ -159,12 +183,12 @@ 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 + * @return string Return the text of this revision */ public function getContent() { global $wgUser; @@ -186,7 +210,7 @@ class Article extends Page { return $text; } else { - $this->loadContent(); + $this->fetchContent(); wfProfileOut( __METHOD__ ); return $this->mContent; @@ -215,27 +239,43 @@ class Article extends Page { $this->mRedirectUrl = false; - $oldid = $wgRequest->getVal( 'oldid' ); + $oldid = $wgRequest->getIntOrNull( 'oldid' ); - if ( isset( $oldid ) ) { - $oldid = intval( $oldid ); - if ( $wgRequest->getVal( 'direction' ) == 'next' ) { - $nextid = $this->getTitle()->getNextRevisionID( $oldid ); - if ( $nextid ) { - $oldid = $nextid; - } else { - $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' ); - } - } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) { - $previd = $this->getTitle()->getPreviousRevisionID( $oldid ); - if ( $previd ) { - $oldid = $previd; + if ( $oldid === null ) { + return 0; + } + + if ( $oldid !== 0 ) { + # Load the given revision and check whether the page is another one. + # In that case, update this instance to reflect the change. + if ( $oldid === $this->mPage->getLatest() ) { + $this->mRevision = $this->mPage->getRevision(); + } else { + $this->mRevision = Revision::newFromId( $oldid ); + if ( $this->mRevision !== null ) { + // Revision title doesn't match the page title given? + if ( $this->mPage->getID() != $this->mRevision->getPage() ) { + $function = array( get_class( $this->mPage ), 'newFromID' ); + $this->mPage = call_user_func( $function, $this->mRevision->getPage() ); + } } } } - if ( !$oldid ) { - $oldid = 0; + if ( $wgRequest->getVal( 'direction' ) == 'next' ) { + $nextid = $this->getTitle()->getNextRevisionID( $oldid ); + if ( $nextid ) { + $oldid = $nextid; + $this->mRevision = null; + } else { + $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' ); + } + } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) { + $previd = $this->getTitle()->getPreviousRevisionID( $oldid ); + if ( $previd ) { + $oldid = $previd; + $this->mRevision = null; + } } return $oldid; @@ -243,31 +283,31 @@ class Article extends Page { /** * Load the revision (including text) into this object + * + * @deprecated in 1.19; use fetchContent() */ function loadContent() { - if ( $this->mContentLoaded ) { - return; - } - - wfProfileIn( __METHOD__ ); - - $this->fetchContent( $this->getOldID() ); - - wfProfileOut( __METHOD__ ); + wfDeprecated( __METHOD__, '1.19' ); + $this->fetchContent(); } /** * Get text of an article from database * Does *NOT* follow redirects. * - * @param $oldid Int: 0 for whatever the latest revision is * @return mixed string containing article contents, or false if null */ - function fetchContent( $oldid = 0 ) { + function fetchContent() { if ( $this->mContentLoaded ) { return $this->mContent; } + wfProfileIn( __METHOD__ ); + + $this->mContentLoaded = true; + + $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(); @@ -275,43 +315,39 @@ class Article extends Page { $this->mContent = wfMsgNoTrans( 'missing-article', $t, $d ) ; if ( $oldid ) { - $revision = Revision::newFromId( $oldid ); - if ( !$revision ) { - wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" ); - return false; - } - // Revision title doesn't match the page title given? - if ( $this->mPage->getID() != $revision->getPage() ) { - $function = array( get_class( $this->mPage ), 'newFromID' ); - $this->mPage = call_user_func( $function, $revision->getPage() ); - if ( !$this->mPage->getId() ) { - wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" ); + # $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; } - $revision = $this->mPage->getRevision(); - if ( !$revision ) { + $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 = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed - - $this->mRevIdFetched = $revision->getId(); - $this->mContentLoaded = true; - $this->mRevision =& $revision; + $this->mContent = $this->mRevision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed + $this->mRevIdFetched = $this->mRevision->getId(); wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); + wfProfileOut( __METHOD__ ); + return $this->mContent; } @@ -320,7 +356,7 @@ class Article extends Page { * @deprecated since 1.18 */ public function forUpdate() { - wfDeprecated( __METHOD__ ); + wfDeprecated( __METHOD__, '1.18' ); } /** @@ -337,6 +373,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->fetchContent(); + + return $this->mRevision; + } + /** * Use this to fetch the rev ID used on page views * @@ -356,14 +405,25 @@ class Article extends Page { */ public function view() { global $wgUser, $wgOut, $wgRequest, $wgParser; - global $wgUseFileCache, $wgUseETag; + global $wgUseFileCache, $wgUseETag, $wgDebugToolbar; wfProfileIn( __METHOD__ ); # Get variables from query string + # As side effect this will load the revision and update the title + # in a revision ID is passed in the request, so this should remain + # the first call of this method even if $oldid is used way below. $oldid = $this->getOldID(); - # getOldID may want us to redirect somewhere else + # Another whitelist check in case getOldID() is altering the title + $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser ); + if ( count( $permErrors ) ) { + wfDebug( __METHOD__ . ": denied on secondary read check\n" ); + wfProfileOut( __METHOD__ ); + throw new PermissionsError( 'read', $permErrors ); + } + + # getOldID() may as well want us to redirect somewhere else if ( $this->mRedirectUrl ) { $wgOut->redirect( $this->mRedirectUrl ); wfDebug( __METHOD__ . ": redirecting due to oldid\n" ); @@ -372,9 +432,6 @@ class Article extends Page { return; } - # Set page title (may be overridden by DISPLAYTITLE) - $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() ); - # If we got diff in the query, we want to see a diff page instead of the article. if ( $wgRequest->getCheck( 'diff' ) ) { wfDebug( __METHOD__ . ": showing diff page\n" ); @@ -384,6 +441,9 @@ class Article extends Page { return; } + # Set page title (may be overridden by DISPLAYTITLE) + $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() ); + $wgOut->setArticleFlag( true ); # Allow frames by default $wgOut->allowClickjacking(); @@ -395,12 +455,12 @@ class Article extends Page { if ( $wgOut->isPrintable() ) { $parserOptions->setIsPrintable( true ); $parserOptions->setEditSection( false ); - } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) { + } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) { $parserOptions->setEditSection( false ); } # 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 ) ); } @@ -416,19 +476,15 @@ 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; } } - if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) { - $parserOptions->setEditSection( false ); - } - # Should the parser cache be used? - $useParserCache = $this->useParserCache( $oldid ); + $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid ); wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" ); if ( $wgUser->getStubThreshold() ) { wfIncrStats( 'pcache_miss_stub' ); @@ -449,43 +505,45 @@ class Article extends Page { wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) ); break; case 2: + # Early abort if the page doesn't exist + if ( !$this->mPage->exists() ) { + wfDebug( __METHOD__ . ": showing missing article\n" ); + $this->showMissingArticle(); + wfProfileOut( __METHOD__ ); + return; + } + # Try the parser cache if ( $useParserCache ) { $this->mParserOutput = $parserCache->get( $this, $parserOptions ); if ( $this->mParserOutput !== false ) { - wfDebug( __METHOD__ . ": showing parser cache contents\n" ); + if ( $oldid ) { + wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" ); + $this->setOldSubtitle( $oldid ); + } else { + wfDebug( __METHOD__ . ": showing parser cache contents\n" ); + } $wgOut->addParserOutput( $this->mParserOutput ); # 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: - $text = $this->getContent(); - if ( $text === false || $this->mPage->getID() == 0 ) { - wfDebug( __METHOD__ . ": showing missing article\n" ); - $this->showMissingArticle(); - wfProfileOut( __METHOD__ ); - return; - } - - # Another whitelist check in case oldid is altering the title - $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser ); - if ( count( $permErrors ) ) { - wfDebug( __METHOD__ . ": denied on secondary read check\n" ); - wfProfileOut( __METHOD__ ); - throw new PermissionsError( 'read', $permErrors ); - } + # This will set $this->mRevision if needed + $this->fetchContent(); # Are we looking at an old revision - if ( $oldid && !is_null( $this->mRevision ) ) { + if ( $oldid && $this->mRevision ) { $this->setOldSubtitle( $oldid ); if ( !$this->showDeletedRevisionHeader() ) { @@ -493,23 +551,13 @@ class Article extends Page { wfProfileOut( __METHOD__ ); return; } - - # If this "old" version is the current, then try the parser cache... - if ( $oldid === $this->mPage->getLatest() && $this->useParserCache( false ) ) { - $this->mParserOutput = $parserCache->get( $this, $parserOptions ); - if ( $this->mParserOutput ) { - wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" ); - $wgOut->addParserOutput( $this->mParserOutput ); - $wgOut->setRevisionId( $this->mPage->getLatest() ); - $outputDone = true; - break; - } - } } # 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() ) { @@ -520,6 +568,7 @@ class Article extends Page { # Allow extensions do their own custom view for certain pages $outputDone = true; } else { + $text = $this->getContent(); $rt = Title::newFromRedirectArray( $text ); if ( $rt ) { wfDebug( __METHOD__ . ": showing redirect=no page\n" ); @@ -536,16 +585,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->getContent() ); 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( '
' . $errortext . '
' ); + } # 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( "\n" ); + } + + $outputDone = true; break; # Should be unreachable, but just in case... default: @@ -581,7 +648,7 @@ class Article extends Page { $wgOut->setFollowPolicy( $policy['follow'] ); $this->showViewFooter(); - $this->mPage->viewUpdates(); + $this->mPage->doViewUpdates( $wgUser ); wfProfileOut( __METHOD__ ); } @@ -620,7 +687,7 @@ class Article extends Page { if ( $diff == 0 || $diff == $this->mPage->getLatest() ) { # Run view updates for current revision only - $this->mPage->viewUpdates(); + $this->mPage->doViewUpdates( $wgUser ); } } @@ -634,8 +701,8 @@ 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( "
\n$1\n
", 'clearyourcache' ); @@ -791,6 +858,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 ) { @@ -825,7 +895,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() ) ) { @@ -836,11 +906,6 @@ class Article extends Page { # chance to mark this new article as patrolled. $this->showPatrolFooter(); - # Trackbacks - if ( $wgUseTrackbacks ) { - $this->addTrackbacks(); - } - wfRunHooks( 'ArticleViewFooter', array( $this ) ); } @@ -859,7 +924,7 @@ class Article extends Page { return; } - $token = $wgUser->editToken( $rcid ); + $token = $wgUser->getEditToken( $rcid ); $wgOut->preventClickjacking(); $wgOut->addHTML( @@ -887,7 +952,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 ) { @@ -896,7 +961,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( "
\n\$1\n
", array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) ); } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked @@ -927,6 +992,18 @@ class Article extends Page { 'msgKey' => array( 'moveddeleted-notice' ) ) ); + 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" ); + } + + $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) ); + + if ( ! $hookResult ) { + return; + } + # Show error message $oldid = $this->getOldID(); if ( $oldid ) { @@ -949,12 +1026,6 @@ class Article extends Page { } $text = "
\n$text\n
"; - if ( !$this->mPage->hasViewableContent() ) { - // 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" ); - } - $wgOut->addWikiText( $text ); } @@ -1000,64 +1071,131 @@ class Article extends Page { } /** - * Execute the uncached parse for action=view - * @return bool + * Generate the navigation links when browsing through an article revisions + * It shows the information as: + * Revision as of \; view current revision + * \<- Previous version | Next Version -\> + * + * @param $oldid String: revision ID of this article revision */ - public function doViewParse() { - global $wgOut; + public function setOldSubtitle( $oldid = 0 ) { + global $wgLang, $wgOut, $wgUser, $wgRequest; - $oldid = $this->getOldID(); - $parserOptions = $this->getParserOptions(); + if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) { + return; + } - # Render printable version, use printable version cache - $parserOptions->setIsPrintable( $wgOut->isPrintable() ); + $unhide = $wgRequest->getInt( 'unhide' ) == 1; - # 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 ); + # Cascade unhide param in links for easy deletion browsing + $extraParams = array(); + if ( $unhide ) { + $extraParams['unhide'] = 1; } - $useParserCache = $this->useParserCache( $oldid ); - $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions ); + if ( $this->mRevision && $this->mRevision->getId() === $oldid ) { + $revision = $this->mRevision; + } else { + $revision = Revision::newFromId( $oldid ); + } - return true; - } + $timestamp = $revision->getTimestamp(); - /** - * 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(); + $current = ( $oldid == $this->mPage->getLatest() ); + $td = $wgLang->timeanddate( $timestamp, true ); + $tddate = $wgLang->date( $timestamp, true ); + $tdtime = $wgLang->time( $timestamp, true ); - if ( $wgOut->isPrintable() ) { - $options->setIsPrintable( true ); - $options->setEditSection( false ); - } + # Show user links if allowed to see them. If hidden, then show them only if requested... + $userlinks = Linker::revUserTools( $revision, !$unhide ); - $output = $parserCache->getDirty( $this, $options ); + $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled() + ? 'revision-info-current' + : 'revision-info'; - 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( "\n" ); + $wgOut->addSubtitle( "
" . wfMessage( $infomsg, + $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate, + $tdtime, $revision->getUser() )->parse() . "
" ); - return true; - } else { - wfDebugLog( 'dirty', "dirty missing\n" ); - wfDebug( __METHOD__ . ": no dirty cache\n" ); + $lnk = $current + ? wfMsgHtml( 'currentrevisionlink' ) + : Linker::link( + $this->getTitle(), + wfMsgHtml( 'currentrevisionlink' ), + array(), + $extraParams, + array( 'known', 'noclasses' ) + ); + $curdiff = $current + ? wfMsgHtml( 'diff' ) + : Linker::link( + $this->getTitle(), + wfMsgHtml( 'diff' ), + array(), + array( + 'diff' => 'cur', + 'oldid' => $oldid + ) + $extraParams, + array( 'known', 'noclasses' ) + ); + $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ; + $prevlink = $prev + ? Linker::link( + $this->getTitle(), + wfMsgHtml( 'previousrevision' ), + array(), + array( + 'direction' => 'prev', + 'oldid' => $oldid + ) + $extraParams, + array( 'known', 'noclasses' ) + ) + : wfMsgHtml( 'previousrevision' ); + $prevdiff = $prev + ? Linker::link( + $this->getTitle(), + wfMsgHtml( 'diff' ), + array(), + array( + 'diff' => 'prev', + 'oldid' => $oldid + ) + $extraParams, + array( 'known', 'noclasses' ) + ) + : wfMsgHtml( 'diff' ); + $nextlink = $current + ? wfMsgHtml( 'nextrevision' ) + : Linker::link( + $this->getTitle(), + wfMsgHtml( 'nextrevision' ), + array(), + array( + 'direction' => 'next', + 'oldid' => $oldid + ) + $extraParams, + array( 'known', 'noclasses' ) + ); + $nextdiff = $current + ? wfMsgHtml( 'diff' ) + : Linker::link( + $this->getTitle(), + wfMsgHtml( 'diff' ), + array(), + array( + 'diff' => 'next', + 'oldid' => $oldid + ) + $extraParams, + array( 'known', 'noclasses' ) + ); - return false; + $cdel = Linker::getRevDeleteLink( $wgUser, $revision, $this->getTitle() ); + if ( $cdel !== '' ) { + $cdel .= ' '; } + + $wgOut->addSubtitle( "
" . $cdel . + wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ), + $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "
" ); } /** @@ -1114,122 +1252,17 @@ class Article extends Page { } /** - * Builds trackback links for article display if $wgUseTrackbacks is set to true + * Handle action=render */ - public function addTrackbacks() { + public function render() { 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( "
\n$1\n
\n", array( 'trackbackbox', $tbtext ) ); + $wgOut->setArticleBodyOnly( true ); + $this->view(); } /** - * Removes trackback record for current article from trackbacks table - * @deprecated since 1.18 - */ - public function deletetrackback() { - return Action::factory( 'deletetrackback', $this )->show(); - } - - /** - * Handle action=render - */ - - public function render() { - global $wgOut; - - $wgOut->setArticleBodyOnly( true ); - $this->view(); - } - - /** - * Handle action=purge - */ - public function purge() { - return Action::factory( 'purge', $this )->show(); - } - - /** - * Mark this particular edit/page as patrolled - * @deprecated since 1.18 - */ - public function markpatrolled() { - Action::factory( 'markpatrolled', $this )->show(); - } - - /** - * User-interface handler for the "watch" action. - * Requires Request to pass a token as of 1.18. - * @deprecated since 1.18 - */ - public function watch() { - Action::factory( 'watch', $this )->show(); - } - - /** - * Add this page to $wgUser's watchlist - * - * This is safe to be called multiple times - * - * @return bool true on successful watch operation - * @deprecated since 1.18 - */ - public function doWatch() { - global $wgUser; - return WatchAction::doWatch( $this->getTitle(), $wgUser ); - } - - /** - * User interface handler for the "unwatch" action. - * Requires Request to pass a token as of 1.18. - * @deprecated since 1.18 - */ - public function unwatch() { - Action::factory( 'unwatch', $this )->show(); - } - - /** - * Stop watching a page - * @return bool true on successful unwatch - * @deprecated since 1.18 - */ - public function doUnwatch() { - global $wgUser; - return WatchAction::doUnwatch( $this->getTitle(), $wgUser ); - } - - /** - * action=protect handler + * action=protect handler */ public function protect() { $form = new ProtectionForm( $this ); @@ -1243,53 +1276,6 @@ class Article extends Page { $this->protect(); } - /** - * Info about this page - * Called for ?action=info when $wgAllowPageInfo is on. - */ - public function info() { - Action::factory( 'info', $this )->show(); - } - - /** - * Overriden by ImagePage class, only present here to avoid a fatal error - * Called for ?action=revert - */ - public function revert() { - Action::factory( 'revert', $this )->show(); - } - - /** - * User interface for rollback operations - */ - public function rollback() { - Action::factory( 'rollback', $this )->show(); - } - - /** - * Output a redirect back to the article. - * This is typically used after an edit. - * - * @deprecated in 1.18; call $wgOut->redirect() directly - * @param $noRedir Boolean: add redirect=no - * @param $sectionAnchor String: section to redirect to, including "#" - * @param $extraQuery String: extra query params - */ - public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) { - wfDeprecated( __METHOD__ ); - global $wgOut; - - if ( $noRedir ) { - $query = 'redirect=no'; - if ( $extraQuery ) - $query .= "&$extraQuery"; - } else { - $query = $extraQuery; - } - - $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor ); - } - /** * UI entry point for page deletion */ @@ -1331,18 +1317,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( "
\n$1\n
\n", - array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) ); - - return; - } - $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' ); $deleteReason = $wgRequest->getText( 'wpReason' ); @@ -1380,7 +1354,7 @@ class Article extends Page { // 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( '' . wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) . @@ -1391,7 +1365,7 @@ class Article extends Page { '' ); - if ( $bigHistory ) { + if ( $this->mTitle->isBigDeletion() ) { global $wgDeleteRevisionsLimit; $wgOut->wrapWikiMsg( "
\n$1\n
\n", array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) ); @@ -1486,7 +1460,7 @@ class Article extends Page { " . 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' ) ) { @@ -1515,10 +1489,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' ) ); @@ -1547,142 +1519,6 @@ class Article extends Page { } } - /** - * Generate the navigation links when browsing through an article revisions - * It shows the information as: - * Revision as of \; view current revision - * \<- Previous version | Next Version -\> - * - * @param $oldid String: revision ID of this article revision - */ - public function setOldSubtitle( $oldid = 0 ) { - global $wgLang, $wgOut, $wgUser, $wgRequest; - - if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) { - return; - } - - $unhide = $wgRequest->getInt( 'unhide' ) == 1; - - # Cascade unhide param in links for easy deletion browsing - $extraParams = array(); - if ( $wgRequest->getVal( 'unhide' ) ) { - $extraParams['unhide'] = 1; - } - - $revision = Revision::newFromId( $oldid ); - $timestamp = $revision->getTimestamp(); - - $current = ( $oldid == $this->mPage->getLatest() ); - $td = $wgLang->timeanddate( $timestamp, true ); - $tddate = $wgLang->date( $timestamp, true ); - $tdtime = $wgLang->time( $timestamp, true ); - - # Show user links if allowed to see them. If hidden, then show them only if requested... - $userlinks = Linker::revUserTools( $revision, !$unhide ); - - $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled() - ? 'revision-info-current' - : 'revision-info'; - - $wgOut->addSubtitle( "
" . wfMessage( $infomsg, - $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate, - $tdtime, $revision->getUser() )->parse() . "
" ); - - $lnk = $current - ? wfMsgHtml( 'currentrevisionlink' ) - : Linker::link( - $this->getTitle(), - wfMsgHtml( 'currentrevisionlink' ), - array(), - $extraParams, - array( 'known', 'noclasses' ) - ); - $curdiff = $current - ? wfMsgHtml( 'diff' ) - : Linker::link( - $this->getTitle(), - wfMsgHtml( 'diff' ), - array(), - array( - 'diff' => 'cur', - 'oldid' => $oldid - ) + $extraParams, - array( 'known', 'noclasses' ) - ); - $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ; - $prevlink = $prev - ? Linker::link( - $this->getTitle(), - wfMsgHtml( 'previousrevision' ), - array(), - array( - 'direction' => 'prev', - 'oldid' => $oldid - ) + $extraParams, - array( 'known', 'noclasses' ) - ) - : wfMsgHtml( 'previousrevision' ); - $prevdiff = $prev - ? Linker::link( - $this->getTitle(), - wfMsgHtml( 'diff' ), - array(), - array( - 'diff' => 'prev', - 'oldid' => $oldid - ) + $extraParams, - array( 'known', 'noclasses' ) - ) - : wfMsgHtml( 'diff' ); - $nextlink = $current - ? wfMsgHtml( 'nextrevision' ) - : Linker::link( - $this->getTitle(), - wfMsgHtml( 'nextrevision' ), - array(), - array( - 'direction' => 'next', - 'oldid' => $oldid - ) + $extraParams, - array( 'known', 'noclasses' ) - ); - $nextdiff = $current - ? wfMsgHtml( 'diff' ) - : Linker::link( - $this->getTitle(), - wfMsgHtml( 'diff' ), - array(), - array( - 'diff' => 'next', - 'oldid' => $oldid - ) + $extraParams, - 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 .= ' '; - } - - $wgOut->addSubtitle( "
" . $cdel . - wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ), - $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "
" ); - } - /* Caching functions */ /** @@ -1739,25 +1575,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 @@ -1770,98 +1587,17 @@ 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 ); } /** * Get parser options suitable for rendering the primary article wikitext - * @return ParserOptions|false + * @return ParserOptions */ public function getParserOptions() { global $wgUser; @@ -1897,6 +1633,119 @@ class Article extends Page { } } + /** + * Info about this page + * @deprecated since 1.19 + */ + public function info() { + wfDeprecated( __METHOD__, '1.19' ); + Action::factory( 'info', $this )->show(); + } + + /** + * Mark this particular edit/page as patrolled + * @deprecated since 1.18 + */ + public function markpatrolled() { + wfDeprecated( __METHOD__, '1.18' ); + Action::factory( 'markpatrolled', $this )->show(); + } + + /** + * Handle action=purge + * @deprecated since 1.19 + */ + public function purge() { + return Action::factory( 'purge', $this )->show(); + } + + /** + * Handle action=revert + * @deprecated since 1.19 + */ + public function revert() { + wfDeprecated( __METHOD__, '1.19' ); + Action::factory( 'revert', $this )->show(); + } + + /** + * Handle action=rollback + * @deprecated since 1.19 + */ + public function rollback() { + wfDeprecated( __METHOD__, '1.19' ); + Action::factory( 'rollback', $this )->show(); + } + + /** + * User-interface handler for the "watch" action. + * Requires Request to pass a token as of 1.18. + * @deprecated since 1.18 + */ + public function watch() { + wfDeprecated( __METHOD__, '1.18' ); + Action::factory( 'watch', $this )->show(); + } + + /** + * Add this page to $wgUser's watchlist + * + * This is safe to be called multiple times + * + * @return bool true on successful watch operation + * @deprecated since 1.18 + */ + public function doWatch() { + global $wgUser; + wfDeprecated( __METHOD__, '1.18' ); + return WatchAction::doWatch( $this->getTitle(), $wgUser ); + } + + /** + * User interface handler for the "unwatch" action. + * Requires Request to pass a token as of 1.18. + * @deprecated since 1.18 + */ + public function unwatch() { + wfDeprecated( __METHOD__, '1.18' ); + Action::factory( 'unwatch', $this )->show(); + } + + /** + * Stop watching a page + * @return bool true on successful unwatch + * @deprecated since 1.18 + */ + public function doUnwatch() { + global $wgUser; + wfDeprecated( __METHOD__, '1.18' ); + return WatchAction::doUnwatch( $this->getTitle(), $wgUser ); + } + + /** + * Output a redirect back to the article. + * This is typically used after an edit. + * + * @deprecated in 1.18; call $wgOut->redirect() directly + * @param $noRedir Boolean: add redirect=no + * @param $sectionAnchor String: section to redirect to, including "#" + * @param $extraQuery String: extra query params + */ + public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) { + wfDeprecated( __METHOD__, '1.18' ); + global $wgOut; + + if ( $noRedir ) { + $query = 'redirect=no'; + if ( $extraQuery ) + $query .= "&$extraQuery"; + } else { + $query = $extraQuery; + } + + $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor ); + } + /** * Use PHP's magic __get handler to handle accessing of * raw WikiPage fields for backwards compatibility. @@ -1936,6 +1785,7 @@ class Article extends Page { * * @param $fname String Name of called method * @param $args Array Arguments to the method + * @return mixed */ public function __call( $fname, $args ) { if ( is_callable( array( $this->mPage, $fname ) ) ) { @@ -1947,6 +1797,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 @@ -2048,68 +1910,3 @@ class Article extends Page { } // ****** } - -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( '
' . $errortext . '
' ); - - return false; - } -}