8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article
extends Page
{
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
41 var $mContentLoaded = false; // !<
47 var $mRedirectedFrom = null;
50 * @var mixed: boolean false or URL string
52 var $mRedirectUrl = false; // !<
53 var $mRevIdFetched = 0; // !<
58 var $mRevision = null;
68 * Constructor and clear the article
69 * @param $title Title Reference to a Title object.
70 * @param $oldId Integer revision ID, null to fetch from request, zero for current
72 public function __construct( Title
$title, $oldId = null ) {
73 $this->mOldId
= $oldId;
74 $this->mPage
= $this->newPage( $title );
81 protected function newPage( Title
$title ) {
82 return new WikiPage( $title );
86 * Constructor from a page id
87 * @param $id Int article ID to load
88 * @return Article|null
90 public static function newFromID( $id ) {
91 $t = Title
::newFromID( $id );
92 # @todo FIXME: Doesn't inherit right
93 return $t == null ?
null : new self( $t );
94 # return $t == null ? null : new static( $t ); // PHP 5.3
98 * Create an Article object of the appropriate class for the given page.
100 * @param $title Title
101 * @param $context IContextSource
102 * @return Article object
104 public static function newFromTitle( $title, IContextSource
$context ) {
105 if ( NS_MEDIA
== $title->getNamespace() ) {
106 // FIXME: where should this go?
107 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
113 switch( $title->getNamespace() ) {
115 $page = new ImagePage( $title );
118 $page = new CategoryPage( $title );
121 $page = new Article( $title );
124 $page->setContext( $context );
130 * Create an Article object of the appropriate class for the given page.
132 * @param $page WikiPage
133 * @param $context IContextSource
134 * @return Article object
136 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
137 $article = self
::newFromTitle( $page->getTitle(), $context );
138 $article->mPage
= $page; // override to keep process cached vars
143 * Tell the page view functions that this view was redirected
144 * from another page on the wiki.
145 * @param $from Title object.
147 public function setRedirectedFrom( Title
$from ) {
148 $this->mRedirectedFrom
= $from;
152 * Get the title object of the article
153 * @return Title object of this page
155 public function getTitle() {
156 return $this->mPage
->getTitle();
162 public function clear() {
163 $this->mContentLoaded
= false;
165 $this->mRedirectedFrom
= null; # Title object if set
166 $this->mRevIdFetched
= 0;
167 $this->mRedirectUrl
= false;
169 $this->mPage
->clear();
173 * Note that getContent/loadContent do not follow redirects anymore.
174 * If you need to fetch redirectable content easily, try
175 * the shortcut in Article::followRedirect()
177 * This function has side effects! Do not use this function if you
178 * only want the real revision text if any.
180 * @return Return the text of this revision
182 public function getContent() {
185 wfProfileIn( __METHOD__
);
187 if ( $this->mPage
->getID() === 0 ) {
188 # If this is a MediaWiki:x message, then load the messages
189 # and return the message value for x.
190 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
191 $text = $this->getTitle()->getDefaultMessageText();
192 if ( $text === false ) {
196 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
198 wfProfileOut( __METHOD__
);
202 $this->fetchContent();
203 wfProfileOut( __METHOD__
);
205 return $this->mContent
;
210 * @return int The oldid of the article that is to be shown, 0 for the
213 public function getOldID() {
214 if ( is_null( $this->mOldId
) ) {
215 $this->mOldId
= $this->getOldIDFromRequest();
218 return $this->mOldId
;
222 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
224 * @return int The old id for the request
226 public function getOldIDFromRequest() {
229 $this->mRedirectUrl
= false;
231 $oldid = $wgRequest->getIntOrNull( 'oldid' );
233 if ( $oldid === null ) {
237 if ( $oldid !== 0 ) {
238 # Load the given revision and check whether the page is another one.
239 # In that case, update this instance to reflect the change.
240 $this->mRevision
= Revision
::newFromId( $oldid );
241 if ( $this->mRevision
!== null ) {
242 // Revision title doesn't match the page title given?
243 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
244 $function = array( get_class( $this->mPage
), 'newFromID' );
245 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
250 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
251 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
255 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
257 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
258 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
268 * Load the revision (including text) into this object
270 * @deprecated in 1.19; use fetchContent()
272 function loadContent() {
273 wfDeprecated( __METHOD__
, '1.19' );
274 $this->fetchContent();
278 * Get text of an article from database
279 * Does *NOT* follow redirects.
281 * @return mixed string containing article contents, or false if null
283 function fetchContent() {
284 if ( $this->mContentLoaded
) {
285 return $this->mContent
;
288 wfProfileIn( __METHOD__
);
290 $this->mContentLoaded
= true;
292 $oldid = $this->getOldID();
294 # Pre-fill content with error message so that if something
295 # fails we'll have something telling us what we intended.
296 $t = $this->getTitle()->getPrefixedText();
297 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
298 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
301 # $this->mRevision might already be fetched by getOldIDFromRequest()
302 if ( !$this->mRevision
) {
303 $this->mRevision
= Revision
::newFromId( $oldid );
304 if ( !$this->mRevision
) {
305 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
306 wfProfileOut( __METHOD__
);
311 if ( !$this->mPage
->getLatest() ) {
312 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
313 wfProfileOut( __METHOD__
);
317 $this->mRevision
= $this->mPage
->getRevision();
318 if ( !$this->mRevision
) {
319 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
320 wfProfileOut( __METHOD__
);
325 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
326 // We should instead work with the Revision object when we need it...
327 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
328 $this->mRevIdFetched
= $this->mRevision
->getId();
330 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
332 wfProfileOut( __METHOD__
);
334 return $this->mContent
;
339 * @deprecated since 1.18
341 public function forUpdate() {
342 wfDeprecated( __METHOD__
, '1.18' );
346 * Returns true if the currently-referenced revision is the current edit
347 * to this page (and it exists).
350 public function isCurrent() {
351 # If no oldid, this is the current version.
352 if ( $this->getOldID() == 0 ) {
356 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
360 * Use this to fetch the rev ID used on page views
362 * @return int revision ID of last article revision
364 public function getRevIdFetched() {
365 if ( $this->mRevIdFetched
) {
366 return $this->mRevIdFetched
;
368 return $this->mPage
->getLatest();
373 * This is the default action of the index.php entry point: just view the
374 * page of the given title.
376 public function view() {
377 global $wgUser, $wgOut, $wgRequest, $wgParser;
378 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
380 wfProfileIn( __METHOD__
);
382 # Get variables from query string
383 # As side effect this will load the revision and update the title
384 # in a revision ID is passed in the request, so this should remain
385 # the first call of this method even if $oldid is used way below.
386 $oldid = $this->getOldID();
388 # Another whitelist check in case getOldID() is altering the title
389 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
390 if ( count( $permErrors ) ) {
391 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
392 wfProfileOut( __METHOD__
);
393 throw new PermissionsError( 'read', $permErrors );
396 # getOldID() may as well want us to redirect somewhere else
397 if ( $this->mRedirectUrl
) {
398 $wgOut->redirect( $this->mRedirectUrl
);
399 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
400 wfProfileOut( __METHOD__
);
405 # If we got diff in the query, we want to see a diff page instead of the article.
406 if ( $wgRequest->getCheck( 'diff' ) ) {
407 wfDebug( __METHOD__
. ": showing diff page\n" );
408 $this->showDiffPage();
409 wfProfileOut( __METHOD__
);
414 # Set page title (may be overridden by DISPLAYTITLE)
415 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
417 $wgOut->setArticleFlag( true );
418 # Allow frames by default
419 $wgOut->allowClickjacking();
421 $parserCache = ParserCache
::singleton();
423 $parserOptions = $this->getParserOptions();
424 # Render printable version, use printable version cache
425 if ( $wgOut->isPrintable() ) {
426 $parserOptions->setIsPrintable( true );
427 $parserOptions->setEditSection( false );
428 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
429 $parserOptions->setEditSection( false );
432 # Try client and file cache
433 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
435 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
438 # Is it client cached?
439 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
440 wfDebug( __METHOD__
. ": done 304\n" );
441 wfProfileOut( __METHOD__
);
445 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
446 wfDebug( __METHOD__
. ": done file cache\n" );
447 # tell wgOut that output is taken care of
449 $this->mPage
->viewUpdates();
450 wfProfileOut( __METHOD__
);
456 # Should the parser cache be used?
457 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
458 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
459 if ( $wgUser->getStubThreshold() ) {
460 wfIncrStats( 'pcache_miss_stub' );
463 $this->showRedirectedFromHeader();
464 $this->showNamespaceHeader();
466 # Iterate through the possible ways of constructing the output text.
467 # Keep going until $outputDone is set, or we run out of things to do.
470 $this->mParserOutput
= false;
472 while ( !$outputDone && ++
$pass ) {
475 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
478 # Early abort if the page doesn't exist
479 if ( !$this->mPage
->exists() ) {
480 wfDebug( __METHOD__
. ": showing missing article\n" );
481 $this->showMissingArticle();
482 wfProfileOut( __METHOD__
);
486 # Try the parser cache
487 if ( $useParserCache ) {
488 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
490 if ( $this->mParserOutput
!== false ) {
492 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
493 $this->setOldSubtitle( $oldid );
495 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
497 $wgOut->addParserOutput( $this->mParserOutput
);
498 # Ensure that UI elements requiring revision ID have
499 # the correct version information.
500 $wgOut->setRevisionId( $this->mPage
->getLatest() );
501 # Preload timestamp to avoid a DB hit
502 $wgOut->setRevisionTimestamp( $this->mParserOutput
->getTimestamp() );
503 $this->mPage
->setTimestamp( $this->mParserOutput
->getTimestamp() );
509 # This will set $this->mRevision if needed
510 $this->fetchContent();
512 # Are we looking at an old revision
513 if ( $oldid && $this->mRevision
) {
514 $this->setOldSubtitle( $oldid );
516 if ( !$this->showDeletedRevisionHeader() ) {
517 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
518 wfProfileOut( __METHOD__
);
523 # Ensure that UI elements requiring revision ID have
524 # the correct version information.
525 $wgOut->setRevisionId( $this->getRevIdFetched() );
526 # Preload timestamp to avoid a DB hit
527 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
529 # Pages containing custom CSS or JavaScript get special treatment
530 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
531 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
532 $this->showCssOrJsPage();
534 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
535 # Allow extensions do their own custom view for certain pages
538 $text = $this->getContent();
539 $rt = Title
::newFromRedirectArray( $text );
541 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
542 # Viewing a redirect page (e.g. with parameter redirect=no)
543 $wgOut->addHTML( $this->viewRedirect( $rt ) );
544 # Parse just to get categories, displaytitle, etc.
545 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
546 $wgOut->addParserOutputNoText( $this->mParserOutput
);
552 # Run the parse, protected by a pool counter
553 wfDebug( __METHOD__
. ": doing uncached parse\n" );
555 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
556 $this->getRevIdFetched(), $useParserCache, $this->getContent() );
558 if ( !$poolArticleView->execute() ) {
559 $error = $poolArticleView->getError();
561 $wgOut->clearHTML(); // for release() errors
562 $wgOut->enableClientCache( false );
563 $wgOut->setRobotPolicy( 'noindex,nofollow' );
565 $errortext = $error->getWikiText( false, 'view-pool-error' );
566 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
568 # Connection or timeout error
569 wfProfileOut( __METHOD__
);
573 $this->mParserOutput
= $poolArticleView->getParserOutput();
574 $wgOut->addParserOutput( $this->mParserOutput
);
576 # Don't cache a dirty ParserOutput object
577 if ( $poolArticleView->getIsDirty() ) {
578 $wgOut->setSquidMaxage( 0 );
579 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
584 # Should be unreachable, but just in case...
590 # Get the ParserOutput actually *displayed* here.
591 # Note that $this->mParserOutput is the *current* version output.
592 $pOutput = ( $outputDone instanceof ParserOutput
)
593 ?
$outputDone // object fetched by hook
594 : $this->mParserOutput
;
596 # Adjust title for main page & pages with displaytitle
598 $this->adjustDisplayTitle( $pOutput );
601 # For the main page, overwrite the <title> element with the con-
602 # tents of 'pagetitle-view-mainpage' instead of the default (if
604 # This message always exists because it is in the i18n files
605 if ( $this->getTitle()->isMainPage() ) {
606 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
607 if ( !$msg->isDisabled() ) {
608 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
612 # Check for any __NOINDEX__ tags on the page using $pOutput
613 $policy = $this->getRobotPolicy( 'view', $pOutput );
614 $wgOut->setIndexPolicy( $policy['index'] );
615 $wgOut->setFollowPolicy( $policy['follow'] );
617 $this->showViewFooter();
618 $this->mPage
->doViewUpdates( $this->getContext()->getUser() );
620 wfProfileOut( __METHOD__
);
624 * Adjust title for pages with displaytitle, -{T|}- or language conversion
625 * @param $pOutput ParserOutput
627 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
629 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
630 $titleText = $pOutput->getTitleText();
631 if ( strval( $titleText ) !== '' ) {
632 $wgOut->setPageTitle( $titleText );
637 * Show a diff page according to current request variables. For use within
638 * Article::view() only, other callers should use the DifferenceEngine class.
640 public function showDiffPage() {
641 global $wgRequest, $wgUser;
643 $diff = $wgRequest->getVal( 'diff' );
644 $rcid = $wgRequest->getVal( 'rcid' );
645 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
646 $purge = $wgRequest->getVal( 'action' ) == 'purge';
647 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
648 $oldid = $this->getOldID();
650 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
651 // DifferenceEngine directly fetched the revision:
652 $this->mRevIdFetched
= $de->mNewid
;
653 $de->showDiffPage( $diffOnly );
655 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
656 # Run view updates for current revision only
657 $this->mPage
->doViewUpdates( $this->getContext()->getUser() );
662 * Show a page view for a page formatted as CSS or JavaScript. To be called by
663 * Article::view() only.
665 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
668 protected function showCssOrJsPage() {
671 $dir = $this->getContext()->getLanguage()->getDir();
672 $lang = $this->getContext()->getLanguage()->getCode();
674 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
677 // Give hooks a chance to customise the output
678 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
679 // Wrap the whole lot in a <pre> and don't parse
681 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
682 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
683 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
684 $wgOut->addHTML( "\n</pre>\n" );
689 * Get the robot policy to be used for the current view
690 * @param $action String the action= GET parameter
691 * @param $pOutput ParserOutput
692 * @return Array the policy that should be set
693 * TODO: actions other than 'view'
695 public function getRobotPolicy( $action, $pOutput ) {
696 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
697 global $wgDefaultRobotPolicy, $wgRequest;
699 $ns = $this->getTitle()->getNamespace();
701 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
702 # Don't index user and user talk pages for blocked users (bug 11443)
703 if ( !$this->getTitle()->isSubpage() ) {
704 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
706 'index' => 'noindex',
707 'follow' => 'nofollow'
713 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
714 # Non-articles (special pages etc), and old revisions
716 'index' => 'noindex',
717 'follow' => 'nofollow'
719 } elseif ( $wgOut->isPrintable() ) {
720 # Discourage indexing of printable versions, but encourage following
722 'index' => 'noindex',
725 } elseif ( $wgRequest->getInt( 'curid' ) ) {
726 # For ?curid=x urls, disallow indexing
728 'index' => 'noindex',
733 # Otherwise, construct the policy based on the various config variables.
734 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
736 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
737 # Honour customised robot policies for this namespace
738 $policy = array_merge(
740 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
743 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
744 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
745 # a final sanity check that we have really got the parser output.
746 $policy = array_merge(
748 array( 'index' => $pOutput->getIndexPolicy() )
752 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
753 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
754 $policy = array_merge(
756 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
764 * Converts a String robot policy into an associative array, to allow
765 * merging of several policies using array_merge().
766 * @param $policy Mixed, returns empty array on null/false/'', transparent
767 * to already-converted arrays, converts String.
768 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
770 public static function formatRobotPolicy( $policy ) {
771 if ( is_array( $policy ) ) {
773 } elseif ( !$policy ) {
777 $policy = explode( ',', $policy );
778 $policy = array_map( 'trim', $policy );
781 foreach ( $policy as $var ) {
782 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
783 $arr['index'] = $var;
784 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
785 $arr['follow'] = $var;
793 * If this request is a redirect view, send "redirected from" subtitle to
794 * $wgOut. Returns true if the header was needed, false if this is not a
795 * redirect view. Handles both local and remote redirects.
799 public function showRedirectedFromHeader() {
800 global $wgOut, $wgRequest, $wgRedirectSources;
802 $rdfrom = $wgRequest->getVal( 'rdfrom' );
804 if ( isset( $this->mRedirectedFrom
) ) {
805 // This is an internally redirected page view.
806 // We'll need a backlink to the source page for navigation.
807 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
808 $redir = Linker
::linkKnown(
809 $this->mRedirectedFrom
,
812 array( 'redirect' => 'no' )
815 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
817 // Set the fragment if one was specified in the redirect
818 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
819 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
820 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
823 // Add a <link rel="canonical"> tag
824 $wgOut->addLink( array( 'rel' => 'canonical',
825 'href' => $this->getTitle()->getLocalURL() )
828 // Tell $wgOut the user arrived at this article through a redirect
829 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
833 } elseif ( $rdfrom ) {
834 // This is an externally redirected view, from some other wiki.
835 // If it was reported from a trusted site, supply a backlink.
836 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
837 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
838 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
848 * Show a header specific to the namespace currently being viewed, like
849 * [[MediaWiki:Talkpagetext]]. For Article::view().
851 public function showNamespaceHeader() {
854 if ( $this->getTitle()->isTalkPage() ) {
855 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
856 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
862 * Show the footer section of an ordinary page view
864 public function showViewFooter() {
867 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
868 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
869 $wgOut->addWikiMsg( 'anontalkpagetext' );
872 # If we have been passed an &rcid= parameter, we want to give the user a
873 # chance to mark this new article as patrolled.
874 $this->showPatrolFooter();
876 wfRunHooks( 'ArticleViewFooter', array( $this ) );
881 * If patrol is possible, output a patrol UI box. This is called from the
882 * footer section of ordinary page views. If patrol is not possible or not
883 * desired, does nothing.
885 public function showPatrolFooter() {
886 global $wgOut, $wgRequest, $wgUser;
888 $rcid = $wgRequest->getVal( 'rcid' );
890 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
894 $token = $wgUser->getEditToken( $rcid );
895 $wgOut->preventClickjacking();
898 "<div class='patrollink'>" .
900 'markaspatrolledlink',
903 wfMsgHtml( 'markaspatrolledtext' ),
906 'action' => 'markpatrolled',
910 array( 'known', 'noclasses' )
918 * Show the error text for a missing article. For articles in the MediaWiki
919 * namespace, show the default message text. To be called from Article::view().
921 public function showMissingArticle() {
922 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
924 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
925 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
926 $parts = explode( '/', $this->getTitle()->getText() );
927 $rootPart = $parts[0];
928 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
929 $ip = User
::isIP( $rootPart );
931 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
932 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
933 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
934 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
935 LogEventsList
::showLogExtract(
938 $user->getUserPage()->getPrefixedText(),
942 'showIfEmpty' => false,
944 'blocked-notice-logextract',
945 $user->getName() # Support GENDER in notice
952 wfRunHooks( 'ShowMissingArticle', array( $this ) );
954 # Show delete and move logs
955 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
957 'conds' => array( "log_action != 'revision'" ),
958 'showIfEmpty' => false,
959 'msgKey' => array( 'moveddeleted-notice' ) )
963 $oldid = $this->getOldID();
965 $text = wfMsgNoTrans( 'missing-article',
966 $this->getTitle()->getPrefixedText(),
967 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
968 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
969 // Use the default message text
970 $text = $this->getTitle()->getDefaultMessageText();
972 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
973 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
974 $errors = array_merge( $createErrors, $editErrors );
976 if ( !count( $errors ) ) {
977 $text = wfMsgNoTrans( 'noarticletext' );
979 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
982 $text = "<div class='noarticletext'>\n$text\n</div>";
984 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
985 // If there's no backing content, send a 404 Not Found
986 // for better machine handling of broken links.
987 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
990 $wgOut->addWikiText( $text );
994 * If the revision requested for view is deleted, check permissions.
995 * Send either an error message or a warning header to $wgOut.
997 * @return boolean true if the view is allowed, false if not.
999 public function showDeletedRevisionHeader() {
1000 global $wgOut, $wgRequest;
1002 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1007 // If the user is not allowed to see it...
1008 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1009 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1010 'rev-deleted-text-permission' );
1013 // If the user needs to confirm that they want to see it...
1014 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1015 # Give explanation and add a link to view the revision...
1016 $oldid = intval( $this->getOldID() );
1017 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1018 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1019 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1020 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1021 array( $msg, $link ) );
1024 // We are allowed to see...
1026 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1027 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1028 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1035 * Generate the navigation links when browsing through an article revisions
1036 * It shows the information as:
1037 * Revision as of \<date\>; view current revision
1038 * \<- Previous version | Next Version -\>
1040 * @param $oldid String: revision ID of this article revision
1042 public function setOldSubtitle( $oldid = 0 ) {
1043 global $wgLang, $wgOut, $wgUser, $wgRequest;
1045 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1049 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1051 # Cascade unhide param in links for easy deletion browsing
1052 $extraParams = array();
1053 if ( $wgRequest->getVal( 'unhide' ) ) {
1054 $extraParams['unhide'] = 1;
1057 $revision = Revision
::newFromId( $oldid );
1058 $timestamp = $revision->getTimestamp();
1060 $current = ( $oldid == $this->mPage
->getLatest() );
1061 $td = $wgLang->timeanddate( $timestamp, true );
1062 $tddate = $wgLang->date( $timestamp, true );
1063 $tdtime = $wgLang->time( $timestamp, true );
1065 # Show user links if allowed to see them. If hidden, then show them only if requested...
1066 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1068 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1069 ?
'revision-info-current'
1072 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1073 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1074 $tdtime, $revision->getUser() )->parse() . "</div>" );
1077 ?
wfMsgHtml( 'currentrevisionlink' )
1080 wfMsgHtml( 'currentrevisionlink' ),
1083 array( 'known', 'noclasses' )
1086 ?
wfMsgHtml( 'diff' )
1089 wfMsgHtml( 'diff' ),
1095 array( 'known', 'noclasses' )
1097 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1101 wfMsgHtml( 'previousrevision' ),
1104 'direction' => 'prev',
1107 array( 'known', 'noclasses' )
1109 : wfMsgHtml( 'previousrevision' );
1113 wfMsgHtml( 'diff' ),
1119 array( 'known', 'noclasses' )
1121 : wfMsgHtml( 'diff' );
1122 $nextlink = $current
1123 ?
wfMsgHtml( 'nextrevision' )
1126 wfMsgHtml( 'nextrevision' ),
1129 'direction' => 'next',
1132 array( 'known', 'noclasses' )
1134 $nextdiff = $current
1135 ?
wfMsgHtml( 'diff' )
1138 wfMsgHtml( 'diff' ),
1144 array( 'known', 'noclasses' )
1149 // User can delete revisions or view deleted revisions...
1150 $canHide = $wgUser->isAllowed( 'deleterevision' );
1151 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1152 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1153 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1156 'type' => 'revision',
1157 'target' => $this->getTitle()->getPrefixedDbkey(),
1160 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1165 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1166 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1167 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1173 * @param $target Title|Array of destination(s) to redirect
1174 * @param $appendSubtitle Boolean [optional]
1175 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1176 * @return string containing HMTL with redirect link
1178 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1179 global $wgOut, $wgStylePath;
1181 if ( !is_array( $target ) ) {
1182 $target = array( $target );
1185 $lang = $this->getTitle()->getPageLanguage();
1186 $imageDir = $lang->getDir();
1188 if ( $appendSubtitle ) {
1189 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1192 // the loop prepends the arrow image before the link, so the first case needs to be outside
1197 $title = array_shift( $target );
1199 if ( $forceKnown ) {
1200 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1202 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1205 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1206 $alt = $lang->isRTL() ?
'←' : '→';
1207 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1208 foreach ( $target as $rt ) {
1209 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1210 if ( $forceKnown ) {
1211 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1213 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1217 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1218 return '<div class="redirectMsg">' .
1219 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1220 '<span class="redirectText">' . $link . '</span></div>';
1224 * Handle action=render
1226 public function render() {
1229 $wgOut->setArticleBodyOnly( true );
1234 * action=protect handler
1236 public function protect() {
1237 $form = new ProtectionForm( $this );
1242 * action=unprotect handler (alias)
1244 public function unprotect() {
1249 * UI entry point for page deletion
1251 public function delete() {
1252 global $wgOut, $wgRequest, $wgLang;
1254 # This code desperately needs to be totally rewritten
1256 $title = $this->getTitle();
1257 $user = $this->getContext()->getUser();
1260 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1261 if ( count( $permission_errors ) ) {
1262 throw new PermissionsError( 'delete', $permission_errors );
1265 # Read-only check...
1266 if ( wfReadOnly() ) {
1267 throw new ReadOnlyError
;
1270 # Better double-check that it hasn't been deleted yet!
1271 $dbw = wfGetDB( DB_MASTER
);
1272 $conds = $title->pageCond();
1273 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1274 if ( $latest === false ) {
1275 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1276 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1277 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1279 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1280 LogEventsList
::showLogExtract(
1283 $title->getPrefixedText()
1289 # Hack for big sites
1290 $bigHistory = $this->mPage
->isBigDeletion();
1291 if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
1292 global $wgDeleteRevisionsLimit;
1294 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1295 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1296 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1301 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1302 $deleteReason = $wgRequest->getText( 'wpReason' );
1304 if ( $deleteReasonList == 'other' ) {
1305 $reason = $deleteReason;
1306 } elseif ( $deleteReason != '' ) {
1307 // Entry from drop down menu + additional comment
1308 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1310 $reason = $deleteReasonList;
1313 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1314 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1316 # Flag to hide all contents of the archived revisions
1317 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1319 $this->doDelete( $reason, $suppress );
1321 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1323 } elseif ( $title->userIsWatching() ) {
1330 // Generate deletion reason
1331 $hasHistory = false;
1333 $reason = $this->generateReason( $hasHistory );
1336 // If the page has a history, insert a warning
1337 if ( $hasHistory ) {
1338 $revisions = $this->mPage
->estimateRevisionCount();
1339 // @todo FIXME: i18n issue/patchwork message
1340 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1341 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1342 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1343 wfMsgHtml( 'history' ),
1344 array( 'rel' => 'archives' ),
1345 array( 'action' => 'history' ) ) .
1349 if ( $bigHistory ) {
1350 global $wgDeleteRevisionsLimit;
1351 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1352 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1356 return $this->confirmDelete( $reason );
1360 * Output deletion confirmation dialog
1361 * @todo FIXME: Move to another file?
1362 * @param $reason String: prefilled reason
1364 public function confirmDelete( $reason ) {
1367 wfDebug( "Article::confirmDelete\n" );
1369 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1370 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1371 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1372 $wgOut->addWikiMsg( 'confirmdeletetext' );
1374 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1376 $user = $this->getContext()->getUser();
1378 if ( $user->isAllowed( 'suppressrevision' ) ) {
1379 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1381 <td class='mw-input'><strong>" .
1382 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1383 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1389 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1391 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1392 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1393 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1394 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1395 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1396 "<tr id=\"wpDeleteReasonListRow\">
1397 <td class='mw-label'>" .
1398 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1400 <td class='mw-input'>" .
1401 Xml
::listDropDown( 'wpDeleteReasonList',
1402 wfMsgForContent( 'deletereason-dropdown' ),
1403 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1406 <tr id=\"wpDeleteReasonRow\">
1407 <td class='mw-label'>" .
1408 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1410 <td class='mw-input'>" .
1411 Html
::input( 'wpReason', $reason, 'text', array(
1413 'maxlength' => '255',
1421 # Disallow watching if user is not logged in
1422 if ( $user->isLoggedIn() ) {
1426 <td class='mw-input'>" .
1427 Xml
::checkLabel( wfMsg( 'watchthis' ),
1428 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1437 <td class='mw-submit'>" .
1438 Xml
::submitButton( wfMsg( 'deletepage' ),
1439 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1442 Xml
::closeElement( 'table' ) .
1443 Xml
::closeElement( 'fieldset' ) .
1444 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1445 Xml
::closeElement( 'form' );
1447 if ( $user->isAllowed( 'editinterface' ) ) {
1448 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1449 $link = Linker
::link(
1451 wfMsgHtml( 'delete-edit-reasonlist' ),
1453 array( 'action' => 'edit' )
1455 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1458 $wgOut->addHTML( $form );
1459 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1460 LogEventsList
::showLogExtract( $wgOut, 'delete',
1461 $this->getTitle()->getPrefixedText()
1466 * Perform a deletion and output success or failure messages
1468 * @param $suppress bool
1470 public function doDelete( $reason, $suppress = false ) {
1473 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1476 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
1477 $deleted = $this->getTitle()->getPrefixedText();
1479 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1480 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1482 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1484 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1485 $wgOut->returnToMain( false );
1487 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1488 if ( $error == '' ) {
1489 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1490 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1492 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1494 LogEventsList
::showLogExtract(
1497 $this->getTitle()->getPrefixedText()
1500 $wgOut->addHTML( $error );
1505 /* Caching functions */
1508 * checkLastModified returns true if it has taken care of all
1509 * output to the client that is necessary for this request.
1510 * (that is, it has sent a cached version of the page)
1512 * @return boolean true if cached version send, false otherwise
1514 protected function tryFileCache() {
1515 static $called = false;
1518 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1523 if ( $this->isFileCacheable() ) {
1524 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1525 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1526 wfDebug( "Article::tryFileCache(): about to load file\n" );
1527 $cache->loadFromFileCache( $this->getContext() );
1530 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1531 ob_start( array( &$cache, 'saveToFileCache' ) );
1534 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1541 * Check if the page can be cached
1544 public function isFileCacheable() {
1547 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1548 $cacheable = $this->mPage
->getID()
1549 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1550 // Extension may have reason to disable file caching on some pages.
1552 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1562 * Lightweight method to get the parser output for a page, checking the parser cache
1563 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1564 * consider, so it's not appropriate to use there.
1566 * @since 1.16 (r52326) for LiquidThreads
1568 * @param $oldid mixed integer Revision ID or null
1569 * @param $user User The relevant user
1570 * @return ParserOutput or false if the given revsion ID is not found
1572 public function getParserOutput( $oldid = null, User
$user = null ) {
1575 $user = is_null( $user ) ?
$wgUser : $user;
1576 $parserOptions = $this->mPage
->makeParserOptions( $user );
1578 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1582 * Get parser options suitable for rendering the primary article wikitext
1583 * @return ParserOptions|false
1585 public function getParserOptions() {
1587 if ( !$this->mParserOptions
) {
1588 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1590 // Clone to allow modifications of the return value without affecting cache
1591 return clone $this->mParserOptions
;
1595 * Sets the context this Article is executed in
1597 * @param $context IContextSource
1600 public function setContext( $context ) {
1601 $this->mContext
= $context;
1605 * Gets the context this Article is executed in
1607 * @return IContextSource
1610 public function getContext() {
1611 if ( $this->mContext
instanceof IContextSource
) {
1612 return $this->mContext
;
1614 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1615 return RequestContext
::getMain();
1620 * Info about this page
1621 * @deprecated since 1.19
1623 public function info() {
1624 wfDeprecated( __METHOD__
, '1.19' );
1625 Action
::factory( 'info', $this )->show();
1629 * Mark this particular edit/page as patrolled
1630 * @deprecated since 1.18
1632 public function markpatrolled() {
1633 wfDeprecated( __METHOD__
, '1.18' );
1634 Action
::factory( 'markpatrolled', $this )->show();
1638 * Handle action=purge
1639 * @deprecated since 1.19
1641 public function purge() {
1642 return Action
::factory( 'purge', $this )->show();
1646 * Handle action=revert
1647 * @deprecated since 1.19
1649 public function revert() {
1650 wfDeprecated( __METHOD__
, '1.19' );
1651 Action
::factory( 'revert', $this )->show();
1655 * Handle action=rollback
1656 * @deprecated since 1.19
1658 public function rollback() {
1659 wfDeprecated( __METHOD__
, '1.19' );
1660 Action
::factory( 'rollback', $this )->show();
1664 * User-interface handler for the "watch" action.
1665 * Requires Request to pass a token as of 1.18.
1666 * @deprecated since 1.18
1668 public function watch() {
1669 wfDeprecated( __METHOD__
, '1.18' );
1670 Action
::factory( 'watch', $this )->show();
1674 * Add this page to $wgUser's watchlist
1676 * This is safe to be called multiple times
1678 * @return bool true on successful watch operation
1679 * @deprecated since 1.18
1681 public function doWatch() {
1683 wfDeprecated( __METHOD__
, '1.18' );
1684 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1688 * User interface handler for the "unwatch" action.
1689 * Requires Request to pass a token as of 1.18.
1690 * @deprecated since 1.18
1692 public function unwatch() {
1693 wfDeprecated( __METHOD__
, '1.18' );
1694 Action
::factory( 'unwatch', $this )->show();
1698 * Stop watching a page
1699 * @return bool true on successful unwatch
1700 * @deprecated since 1.18
1702 public function doUnwatch() {
1704 wfDeprecated( __METHOD__
, '1.18' );
1705 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1709 * Output a redirect back to the article.
1710 * This is typically used after an edit.
1712 * @deprecated in 1.18; call $wgOut->redirect() directly
1713 * @param $noRedir Boolean: add redirect=no
1714 * @param $sectionAnchor String: section to redirect to, including "#"
1715 * @param $extraQuery String: extra query params
1717 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1718 wfDeprecated( __METHOD__
, '1.18' );
1722 $query = 'redirect=no';
1724 $query .= "&$extraQuery";
1726 $query = $extraQuery;
1729 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1733 * Use PHP's magic __get handler to handle accessing of
1734 * raw WikiPage fields for backwards compatibility.
1736 * @param $fname String Field name
1738 public function __get( $fname ) {
1739 if ( property_exists( $this->mPage
, $fname ) ) {
1740 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1741 return $this->mPage
->$fname;
1743 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1747 * Use PHP's magic __set handler to handle setting of
1748 * raw WikiPage fields for backwards compatibility.
1750 * @param $fname String Field name
1751 * @param $fvalue mixed New value
1753 public function __set( $fname, $fvalue ) {
1754 if ( property_exists( $this->mPage
, $fname ) ) {
1755 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1756 $this->mPage
->$fname = $fvalue;
1757 // Note: extensions may want to toss on new fields
1758 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1759 $this->mPage
->$fname = $fvalue;
1761 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1766 * Use PHP's magic __call handler to transform instance calls to
1767 * WikiPage functions for backwards compatibility.
1769 * @param $fname String Name of called method
1770 * @param $args Array Arguments to the method
1772 public function __call( $fname, $args ) {
1773 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1774 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1775 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1777 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1780 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1783 * @param $limit array
1784 * @param $reason string
1785 * @param $cascade int
1786 * @param $expiry array
1789 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1790 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1794 * @param $reason string
1795 * @param $suppress bool
1797 * @param $commit bool
1798 * @param $error string
1801 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1802 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1810 * @param $resultDetails
1814 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1816 $user = is_null( $user ) ?
$wgUser : $user;
1817 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1824 * @param $resultDetails
1825 * @param $guser User
1828 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1830 $guser = is_null( $guser ) ?
$wgUser : $guser;
1831 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1835 * @param $hasHistory bool
1838 public function generateReason( &$hasHistory ) {
1839 return $this->mPage
->getAutoDeleteReason( $hasHistory );
1842 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1847 public static function selectFields() {
1848 return WikiPage
::selectFields();
1852 * @param $title Title
1854 public static function onArticleCreate( $title ) {
1855 WikiPage
::onArticleCreate( $title );
1859 * @param $title Title
1861 public static function onArticleDelete( $title ) {
1862 WikiPage
::onArticleDelete( $title );
1866 * @param $title Title
1868 public static function onArticleEdit( $title ) {
1869 WikiPage
::onArticleEdit( $title );
1878 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1879 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );