mOldId = $oldId;
$this->mPage = $this->newPage( $title );
}
/**
* @param $title Title
* @return WikiPage
*/
protected function newPage( Title $title ) {
return new WikiPage( $title );
}
/**
* Constructor from a page id
* @param $id Int article ID to load
* @return Article|null
*/
public static function newFromID( $id ) {
$t = Title::newFromID( $id );
# @todo FIXME: Doesn't inherit right
return $t == null ? null : new self( $t );
# return $t == null ? null : new static( $t ); // PHP 5.3
}
/**
* Create an Article object of the appropriate class for the given page.
*
* @param $title Title
* @param $context IContextSource
* @return Article object
*/
public static function newFromTitle( $title, IContextSource $context ) {
if ( NS_MEDIA == $title->getNamespace() ) {
// FIXME: where should this go?
$title = Title::makeTitle( NS_FILE, $title->getDBkey() );
}
$page = null;
wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
if ( !$page ) {
switch( $title->getNamespace() ) {
case NS_FILE:
$page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler
break;
case NS_CATEGORY:
$page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler
break;
default:
$handler = ContentHandler::getForTitle( $title );
$page = $handler->createArticle( $title );
}
}
$page->setContext( $context );
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.
* @param $from Title object.
*/
public function setRedirectedFrom( Title $from ) {
$this->mRedirectedFrom = $from;
}
/**
* 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
*/
public function clear() {
$this->mContentLoaded = false;
$this->mRedirectedFrom = null; # Title object if set
$this->mRevIdFetched = 0;
$this->mRedirectUrl = false;
$this->mPage->clear();
}
/**
* 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.
*
* @deprecated in 1.20; use getContentObject() instead
*
* @return string The text of this revision
*/
public function getContent() {
wfDeprecated( __METHOD__, '1.20' );
$content = $this->getContentObject();
return ContentHandler::getContentText( $content );
}
/**
* Returns a Content object representing the pages effective display content,
* not necessarily the revision's 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 Content
*/
protected function getContentObject() {
global $wgUser;
wfProfileIn( __METHOD__ );
if ( $this->mPage->getID() === 0 ) {
# If this is a MediaWiki:x message, then load the messages
# and return the message value for x.
if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
$text = $this->getTitle()->getDefaultMessageText();
if ( $text === false ) {
$text = '';
}
$content = ContentHandler::makeContent( $text, $this->getTitle() );
} else {
$content = new MessageContent( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', null, 'parsemag' );
}
wfProfileOut( __METHOD__ );
return $content;
} else {
$this->fetchContentObject();
wfProfileOut( __METHOD__ );
return $this->mContentObject;
}
}
/**
* @return int The oldid of the article that is to be shown, 0 for the
* current revision
*/
public function getOldID() {
if ( is_null( $this->mOldId ) ) {
$this->mOldId = $this->getOldIDFromRequest();
}
return $this->mOldId;
}
/**
* Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
*
* @return int The old id for the request
*/
public function getOldIDFromRequest() {
global $wgRequest;
$this->mRedirectUrl = false;
$oldid = $wgRequest->getIntOrNull( 'oldid' );
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 ( $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;
}
/**
* Load the revision (including text) into this object
*
* @deprecated in 1.19; use fetchContent()
*/
function loadContent() {
wfDeprecated( __METHOD__, '1.19' );
$this->fetchContent();
}
/**
* Get text of an article from database
* Does *NOT* follow redirects.
*
* @return mixed string containing article contents, or false if null
* @deprecated in 1.20, use getContentObject() instead
*/
protected function fetchContent() { #BC cruft!
wfDeprecated( __METHOD__, '1.20' );
if ( $this->mContentLoaded && $this->mContent ) {
return $this->mContent;
}
wfProfileIn( __METHOD__ );
$content = $this->fetchContentObject();
$this->mContent = ContentHandler::getContentText( $content ); #FIXME: get rid of mContent everywhere!
wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ); #BC cruft!
wfProfileOut( __METHOD__ );
return $this->mContent;
}
/**
* Get text content object
* Does *NOT* follow redirects.
* TODO: when is this null?
*
* @return Content|null
*/
protected function fetchContentObject() {
if ( $this->mContentLoaded ) {
return $this->mContentObject;
}
wfProfileIn( __METHOD__ );
$this->mContentLoaded = true;
$this->mContent = null;
$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__, '1.18' );
}
/**
* Returns true if the currently-referenced revision is the current edit
* to this page (and it exists).
* @return bool
*/
public function isCurrent() {
# If no oldid, this is the current version.
if ( $this->getOldID() == 0 ) {
return true;
}
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
*
* @return int revision ID of last article revision
*/
public function getRevIdFetched() {
if ( $this->mRevIdFetched ) {
return $this->mRevIdFetched;
} else {
return $this->mPage->getLatest();
}
}
/**
* This is the default action of the index.php entry point: just view the
* page of the given title.
*/
public function view() {
global $wgUser, $wgOut, $wgRequest, $wgParser;
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();
# 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" );
wfProfileOut( __METHOD__ );
return;
}
# 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" );
$this->showDiffPage();
wfProfileOut( __METHOD__ );
return;
}
# Set page title (may be overridden by DISPLAYTITLE)
$wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
$wgOut->setArticleFlag( true );
# Allow frames by default
$wgOut->allowClickjacking();
$parserCache = ParserCache::singleton();
$parserOptions = $this->getParserOptions();
# Render printable version, use printable version cache
if ( $wgOut->isPrintable() ) {
$parserOptions->setIsPrintable( true );
$parserOptions->setEditSection( false );
} elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit' ) ) {
$parserOptions->setEditSection( false );
}
# Try client and file cache
if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
if ( $wgUseETag ) {
$wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
}
# Is it client cached?
if ( $wgOut->checkLastModified( $this->mPage->getTouched() ) ) {
wfDebug( __METHOD__ . ": done 304\n" );
wfProfileOut( __METHOD__ );
return;
# Try file cache
} elseif ( $wgUseFileCache && $this->tryFileCache() ) {
wfDebug( __METHOD__ . ": done file cache\n" );
# tell wgOut that output is taken care of
$wgOut->disable();
$this->mPage->doViewUpdates( $wgUser );
wfProfileOut( __METHOD__ );
return;
}
}
# Should the parser cache be used?
$useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
if ( $wgUser->getStubThreshold() ) {
wfIncrStats( 'pcache_miss_stub' );
}
$this->showRedirectedFromHeader();
$this->showNamespaceHeader();
# Iterate through the possible ways of constructing the output text.
# Keep going until $outputDone is set, or we run out of things to do.
$pass = 0;
$outputDone = false;
$this->mParserOutput = false;
while ( !$outputDone && ++$pass ) {
switch( $pass ) {
case 1:
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 ) {
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() );
# Preload timestamp to avoid a DB hit
$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->fetchContentObject();
# Are we looking at an old revision
if ( $oldid && $this->mRevision ) {
$this->setOldSubtitle( $oldid );
if ( !$this->showDeletedRevisionHeader() ) {
wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
wfProfileOut( __METHOD__ );
return;
}
}
# 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() ) {
wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
$this->showCssOrJsPage();
$outputDone = true;
} 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 {
$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 = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
$wgOut->addParserOutputNoText( $this->mParserOutput );
$outputDone = true;
}
}
break;
case 4:
# Run the parse, protected by a pool counter
wfDebug( __METHOD__ . ": doing uncached parse\n" );
$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( '
' . $errortext . '
' );
}
# Connection or timeout error
wfProfileOut( __METHOD__ );
return;
}
$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:
break 2;
}
}
# Get the ParserOutput actually *displayed* here.
# Note that $this->mParserOutput is the *current* version output.
$pOutput = ( $outputDone instanceof ParserOutput )
? $outputDone // object fetched by hook
: $this->mParserOutput;
# Adjust title for main page & pages with displaytitle
if ( $pOutput ) {
$this->adjustDisplayTitle( $pOutput );
}
# For the main page, overwrite the element with the con-
# tents of 'pagetitle-view-mainpage' instead of the default (if
# that's not empty).
# This message always exists because it is in the i18n files
if ( $this->getTitle()->isMainPage() ) {
$msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
if ( !$msg->isDisabled() ) {
$wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
}
}
# Check for any __NOINDEX__ tags on the page using $pOutput
$policy = $this->getRobotPolicy( 'view', $pOutput );
$wgOut->setIndexPolicy( $policy['index'] );
$wgOut->setFollowPolicy( $policy['follow'] );
$this->showViewFooter();
$this->mPage->doViewUpdates( $wgUser );
wfProfileOut( __METHOD__ );
}
/**
* Adjust title for pages with displaytitle, -{T|}- or language conversion
* @param $pOutput ParserOutput
*/
public function adjustDisplayTitle( ParserOutput $pOutput ) {
global $wgOut;
# Adjust the title if it was set by displaytitle, -{T|}- or language conversion
$titleText = $pOutput->getTitleText();
if ( strval( $titleText ) !== '' ) {
$wgOut->setPageTitle( $titleText );
}
}
/**
* Show a diff page according to current request variables. For use within
* Article::view() only, other callers should use the DifferenceEngine class.
*/
public function showDiffPage() {
global $wgRequest, $wgUser;
$diff = $wgRequest->getVal( 'diff' );
$rcid = $wgRequest->getVal( 'rcid' );
$diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
$purge = $wgRequest->getVal( 'action' ) == 'purge';
$unhide = $wgRequest->getInt( 'unhide' ) == 1;
$oldid = $this->getOldID();
$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->doViewUpdates( $wgUser );
}
}
/**
* Show a page view for a page formatted as CSS or JavaScript. To be called by
* Article::view() only.
*
* This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
* page views.
*/
protected function showCssOrJsPage( $showCacheHint = true ) {
global $wgOut;
if ( $showCacheHint ) {
$dir = $this->getContext()->getLanguage()->getDir();
$lang = $this->getContext()->getLanguage()->getCode();
$wgOut->wrapWikiMsg( "
\n$1\n
",
'clearyourcache' );
}
// Give hooks a chance to customise the output
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() );
}
}
/**
* Get the robot policy to be used for the current view
* @param $action String the action= GET parameter
* @param $pOutput ParserOutput
* @return Array the policy that should be set
* TODO: actions other than 'view'
*/
public function getRobotPolicy( $action, $pOutput ) {
global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
global $wgDefaultRobotPolicy, $wgRequest;
$ns = $this->getTitle()->getNamespace();
if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
# Don't index user and user talk pages for blocked users (bug 11443)
if ( !$this->getTitle()->isSubpage() ) {
if ( Block::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block ) {
return array(
'index' => 'noindex',
'follow' => 'nofollow'
);
}
}
}
if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
# Non-articles (special pages etc), and old revisions
return array(
'index' => 'noindex',
'follow' => 'nofollow'
);
} elseif ( $wgOut->isPrintable() ) {
# Discourage indexing of printable versions, but encourage following
return array(
'index' => 'noindex',
'follow' => 'follow'
);
} elseif ( $wgRequest->getInt( 'curid' ) ) {
# For ?curid=x urls, disallow indexing
return array(
'index' => 'noindex',
'follow' => 'follow'
);
}
# Otherwise, construct the policy based on the various config variables.
$policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
# Honour customised robot policies for this namespace
$policy = array_merge(
$policy,
self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
);
}
if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
# __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
# a final sanity check that we have really got the parser output.
$policy = array_merge(
$policy,
array( 'index' => $pOutput->getIndexPolicy() )
);
}
if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
# (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
$policy = array_merge(
$policy,
self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
);
}
return $policy;
}
/**
* Converts a String robot policy into an associative array, to allow
* merging of several policies using array_merge().
* @param $policy Mixed, returns empty array on null/false/'', transparent
* to already-converted arrays, converts String.
* @return Array: 'index' => , 'follow' =>
*/
public static function formatRobotPolicy( $policy ) {
if ( is_array( $policy ) ) {
return $policy;
} elseif ( !$policy ) {
return array();
}
$policy = explode( ',', $policy );
$policy = array_map( 'trim', $policy );
$arr = array();
foreach ( $policy as $var ) {
if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
$arr['index'] = $var;
} elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
$arr['follow'] = $var;
}
}
return $arr;
}
/**
* If this request is a redirect view, send "redirected from" subtitle to
* $wgOut. Returns true if the header was needed, false if this is not a
* redirect view. Handles both local and remote redirects.
*
* @return boolean
*/
public function showRedirectedFromHeader() {
global $wgOut, $wgRequest, $wgRedirectSources;
$rdfrom = $wgRequest->getVal( 'rdfrom' );
if ( isset( $this->mRedirectedFrom ) ) {
// This is an internally redirected page view.
// We'll need a backlink to the source page for navigation.
if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
$redir = Linker::linkKnown(
$this->mRedirectedFrom,
null,
array(),
array( 'redirect' => 'no' )
);
$wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
// Set the fragment if one was specified in the redirect
if ( strval( $this->getTitle()->getFragment() ) != '' ) {
$fragment = Xml::escapeJsString( $this->getTitle()->getFragmentForURL() );
$wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
}
// Add a tag
$wgOut->addLink( array( 'rel' => 'canonical',
'href' => $this->getTitle()->getLocalURL() )
);
// Tell $wgOut the user arrived at this article through a redirect
$wgOut->setRedirectedFrom( $this->mRedirectedFrom );
return true;
}
} elseif ( $rdfrom ) {
// This is an externally redirected view, from some other wiki.
// If it was reported from a trusted site, supply a backlink.
if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
$redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
$wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
return true;
}
}
return false;
}
/**
* Show a header specific to the namespace currently being viewed, like
* [[MediaWiki:Talkpagetext]]. For Article::view().
*/
public function showNamespaceHeader() {
global $wgOut;
if ( $this->getTitle()->isTalkPage() ) {
if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
$wgOut->wrapWikiMsg( "
\n$1\n
", array( 'talkpageheader' ) );
}
}
}
/**
* Show the footer section of an ordinary page view
*/
public function showViewFooter() {
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() ) ) {
$wgOut->addWikiMsg( 'anontalkpagetext' );
}
# If we have been passed an &rcid= parameter, we want to give the user a
# chance to mark this new article as patrolled.
$this->showPatrolFooter();
wfRunHooks( 'ArticleViewFooter', array( $this ) );
}
/**
* If patrol is possible, output a patrol UI box. This is called from the
* footer section of ordinary page views. If patrol is not possible or not
* desired, does nothing.
*/
public function showPatrolFooter() {
global $wgOut, $wgRequest, $wgUser;
$rcid = $wgRequest->getVal( 'rcid' );
if ( !$rcid || !$this->getTitle()->quickUserCan( 'patrol' ) ) {
return;
}
$token = $wgUser->getEditToken( $rcid );
$wgOut->preventClickjacking();
$wgOut->addHTML(
"
'
);
}
/**
* Show the error text for a missing article. For articles in the MediaWiki
* namespace, show the default message text. To be called from Article::view().
*/
public function showMissingArticle() {
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 ) {
$parts = explode( '/', $this->getTitle()->getText() );
$rootPart = $parts[0];
$user = User::newFromName( $rootPart, false /* allow IP users*/ );
$ip = User::isIP( $rootPart );
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
LogEventsList::showLogExtract(
$wgOut,
'block',
$user->getUserPage()->getPrefixedText(),
'',
array(
'lim' => 1,
'showIfEmpty' => false,
'msgKey' => array(
'blocked-notice-logextract',
$user->getName() # Support GENDER in notice
)
)
);
}
}
wfRunHooks( 'ShowMissingArticle', array( $this ) );
# Show delete and move logs
LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
array( 'lim' => 10,
'conds' => array( "log_action != 'revision'" ),
'showIfEmpty' => false,
'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 ) {
$text = wfMsgNoTrans( 'missing-article',
$this->getTitle()->getPrefixedText(),
wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
} elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI ) {
// Use the default message text
$text = $this->getTitle()->getDefaultMessageText();
} else {
$createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
$editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
$errors = array_merge( $createErrors, $editErrors );
if ( !count( $errors ) ) {
$text = wfMsgNoTrans( 'noarticletext' );
} else {
$text = wfMsgNoTrans( 'noarticletext-nopermission' );
}
}
$text = "
\n$text\n
";
$wgOut->addWikiText( $text );
}
/**
* If the revision requested for view is deleted, check permissions.
* Send either an error message or a warning header to $wgOut.
*
* @return boolean true if the view is allowed, false if not.
*/
public function showDeletedRevisionHeader() {
global $wgOut, $wgRequest;
if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
// Not deleted
return true;
}
// If the user is not allowed to see it...
if ( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
$wgOut->wrapWikiMsg( "
\n$1\n
\n",
'rev-deleted-text-permission' );
return false;
// If the user needs to confirm that they want to see it...
} elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
# Give explanation and add a link to view the revision...
$oldid = intval( $this->getOldID() );
$link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
$msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
$wgOut->wrapWikiMsg( "
\n$1\n
\n",
array( $msg, $link ) );
return false;
// We are allowed to see...
} else {
$msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
'rev-suppressed-text-view' : 'rev-deleted-text-view';
$wgOut->wrapWikiMsg( "
\n$1\n
\n", $msg );
return true;
}
}
/**
* 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 ( $unhide ) {
$extraParams['unhide'] = 1;
}
if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
$revision = $this->mRevision;
} else {
$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( "