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;
40 var $mContent; // !< #BC cruft
41 var $mContentObject; // !<
42 var $mContentLoaded = false; // !<
48 var $mRedirectedFrom = null;
51 * @var mixed: boolean false or URL string
53 var $mRedirectUrl = false; // !<
54 var $mRevIdFetched = 0; // !<
59 var $mRevision = null;
69 * Constructor and clear the article
70 * @param $title Title Reference to a Title object.
71 * @param $oldId Integer revision ID, null to fetch from request, zero for current
73 public function __construct( Title
$title, $oldId = null ) {
74 $this->mOldId
= $oldId;
75 $this->mPage
= $this->newPage( $title );
82 protected function newPage( Title
$title ) {
83 return new WikiPage( $title );
87 * Constructor from a page id
88 * @param $id Int article ID to load
89 * @return Article|null
91 public static function newFromID( $id ) {
92 $t = Title
::newFromID( $id );
93 # @todo FIXME: Doesn't inherit right
94 return $t == null ?
null : new self( $t );
95 # return $t == null ? null : new static( $t ); // PHP 5.3
99 * Create an Article object of the appropriate class for the given page.
101 * @param $title Title
102 * @param $context IContextSource
103 * @return Article object
105 public static function newFromTitle( $title, IContextSource
$context ) {
106 if ( NS_MEDIA
== $title->getNamespace() ) {
107 // FIXME: where should this go?
108 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
112 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
114 switch( $title->getNamespace() ) {
116 $page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler
119 $page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler
122 $handler = ContentHandler
::getForTitle( $title );
123 $page = $handler->createArticle( $title );
126 $page->setContext( $context );
132 * Create an Article object of the appropriate class for the given page.
134 * @param $page WikiPage
135 * @param $context IContextSource
136 * @return Article object
138 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
139 $article = self
::newFromTitle( $page->getTitle(), $context );
140 $article->mPage
= $page; // override to keep process cached vars
145 * Tell the page view functions that this view was redirected
146 * from another page on the wiki.
147 * @param $from Title object.
149 public function setRedirectedFrom( Title
$from ) {
150 $this->mRedirectedFrom
= $from;
154 * Get the title object of the article
156 * @return Title object of this page
158 public function getTitle() {
159 return $this->mPage
->getTitle();
163 * Get the WikiPage object of this instance
168 public function getPage() {
175 public function clear() {
176 $this->mContentLoaded
= false;
178 $this->mRedirectedFrom
= null; # Title object if set
179 $this->mRevIdFetched
= 0;
180 $this->mRedirectUrl
= false;
182 $this->mPage
->clear();
186 * Note that getContent/loadContent do not follow redirects anymore.
187 * If you need to fetch redirectable content easily, try
188 * the shortcut in WikiPage::getRedirectTarget()
190 * This function has side effects! Do not use this function if you
191 * only want the real revision text if any.
193 * @return Return the text of this revision
194 * @deprecated in 1.20; use getContentObject() instead
196 public function getContent() {
197 wfDeprecated( __METHOD__
, '1.20' );
198 $content = $this->getContentObject();
199 return ContentHandler
::getContentText( $content );
203 * Note that getContent/loadContent do not follow redirects anymore.
204 * If you need to fetch redirectable content easily, try
205 * the shortcut in WikiPage::getRedirectTarget()
207 * This function has side effects! Do not use this function if you
208 * only want the real revision text if any.
210 * @return Return the content of this revision
212 public function getContentObject() {
215 wfProfileIn( __METHOD__
);
217 if ( $this->mPage
->getID() === 0 ) {
218 # If this is a MediaWiki:x message, then load the messages
219 # and return the message value for x.
220 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
221 $text = $this->getTitle()->getDefaultMessageText();
222 if ( $text === false ) {
226 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
228 $content = new MessageContent( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', null, 'parsemag' );
230 wfProfileOut( __METHOD__
);
234 $this->fetchContentObject();
235 wfProfileOut( __METHOD__
);
237 return $this->mContentObject
;
242 * @return int The oldid of the article that is to be shown, 0 for the
245 public function getOldID() {
246 if ( is_null( $this->mOldId
) ) {
247 $this->mOldId
= $this->getOldIDFromRequest();
250 return $this->mOldId
;
254 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
256 * @return int The old id for the request
258 public function getOldIDFromRequest() {
261 $this->mRedirectUrl
= false;
263 $oldid = $wgRequest->getIntOrNull( 'oldid' );
265 if ( $oldid === null ) {
269 if ( $oldid !== 0 ) {
270 # Load the given revision and check whether the page is another one.
271 # In that case, update this instance to reflect the change.
272 $this->mRevision
= Revision
::newFromId( $oldid );
273 if ( $this->mRevision
!== null ) {
274 // Revision title doesn't match the page title given?
275 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
276 $function = array( get_class( $this->mPage
), 'newFromID' );
277 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
282 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
283 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
286 $this->mRevision
= null;
288 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
290 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
291 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
294 $this->mRevision
= null;
302 * Load the revision (including text) into this object
304 * @deprecated in 1.19; use fetchContent()
306 function loadContent() {
307 wfDeprecated( __METHOD__
, '1.19' );
308 $this->fetchContent();
312 * Get text of an article from database
313 * Does *NOT* follow redirects.
315 * @return mixed string containing article contents, or false if null
316 * @deprecated in 1.20, use getContentObject() instead
318 protected function fetchContent() { #BC cruft!
319 wfDeprecated( __METHOD__
, '1.20' );
321 if ( $this->mContentLoaded
&& $this->mContent
) {
322 return $this->mContent
;
325 wfProfileIn( __METHOD__
);
327 $content = $this->fetchContentObject();
329 $this->mContent
= ContentHandler
::getContentText( $content ); #FIXME: get rid of mContent everywhere!
330 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft!
332 wfProfileOut( __METHOD__
);
334 return $this->mContent
;
339 * Get text content object
340 * Does *NOT* follow redirects.
342 * @return Content object containing article contents, or null
344 protected function fetchContentObject() {
345 if ( $this->mContentLoaded
) {
346 return $this->mContentObject
;
349 wfProfileIn( __METHOD__
);
351 $this->mContentLoaded
= true;
352 $this->mContent
= null;
354 $oldid = $this->getOldID();
356 # Pre-fill content with error message so that if something
357 # fails we'll have something telling us what we intended.
358 $t = $this->getTitle()->getPrefixedText();
359 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
360 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ;
363 # $this->mRevision might already be fetched by getOldIDFromRequest()
364 if ( !$this->mRevision
) {
365 $this->mRevision
= Revision
::newFromId( $oldid );
366 if ( !$this->mRevision
) {
367 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
368 wfProfileOut( __METHOD__
);
373 if ( !$this->mPage
->getLatest() ) {
374 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
375 wfProfileOut( __METHOD__
);
379 $this->mRevision
= $this->mPage
->getRevision();
381 if ( !$this->mRevision
) {
382 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
383 wfProfileOut( __METHOD__
);
388 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
389 // We should instead work with the Revision object when we need it...
390 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
391 $this->mRevIdFetched
= $this->mRevision
->getId();
393 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) ); #FIXME: register new hook
395 wfProfileOut( __METHOD__
);
397 return $this->mContentObject
;
402 * @deprecated since 1.18
404 public function forUpdate() {
405 wfDeprecated( __METHOD__
, '1.18' );
409 * Returns true if the currently-referenced revision is the current edit
410 * to this page (and it exists).
413 public function isCurrent() {
414 # If no oldid, this is the current version.
415 if ( $this->getOldID() == 0 ) {
419 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
423 * Get the fetched Revision object depending on request parameters or null
427 * @return Revision|null
429 public function getRevisionFetched() {
430 $this->fetchContentObject();
432 return $this->mRevision
;
436 * Use this to fetch the rev ID used on page views
438 * @return int revision ID of last article revision
440 public function getRevIdFetched() {
441 if ( $this->mRevIdFetched
) {
442 return $this->mRevIdFetched
;
444 return $this->mPage
->getLatest();
449 * This is the default action of the index.php entry point: just view the
450 * page of the given title.
452 public function view() {
453 global $wgUser, $wgOut, $wgRequest, $wgParser;
454 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
456 wfProfileIn( __METHOD__
);
458 # Get variables from query string
459 # As side effect this will load the revision and update the title
460 # in a revision ID is passed in the request, so this should remain
461 # the first call of this method even if $oldid is used way below.
462 $oldid = $this->getOldID();
464 # Another whitelist check in case getOldID() is altering the title
465 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
466 if ( count( $permErrors ) ) {
467 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
468 wfProfileOut( __METHOD__
);
469 throw new PermissionsError( 'read', $permErrors );
472 # getOldID() may as well want us to redirect somewhere else
473 if ( $this->mRedirectUrl
) {
474 $wgOut->redirect( $this->mRedirectUrl
);
475 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
476 wfProfileOut( __METHOD__
);
481 # If we got diff in the query, we want to see a diff page instead of the article.
482 if ( $wgRequest->getCheck( 'diff' ) ) {
483 wfDebug( __METHOD__
. ": showing diff page\n" );
484 $this->showDiffPage();
485 wfProfileOut( __METHOD__
);
490 # Set page title (may be overridden by DISPLAYTITLE)
491 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
493 $wgOut->setArticleFlag( true );
494 # Allow frames by default
495 $wgOut->allowClickjacking();
497 $parserCache = ParserCache
::singleton();
499 $parserOptions = $this->getParserOptions();
500 # Render printable version, use printable version cache
501 if ( $wgOut->isPrintable() ) {
502 $parserOptions->setIsPrintable( true );
503 $parserOptions->setEditSection( false );
504 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
505 $parserOptions->setEditSection( false );
508 # Try client and file cache
509 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
511 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
514 # Is it client cached?
515 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
516 wfDebug( __METHOD__
. ": done 304\n" );
517 wfProfileOut( __METHOD__
);
521 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
522 wfDebug( __METHOD__
. ": done file cache\n" );
523 # tell wgOut that output is taken care of
525 $this->mPage
->doViewUpdates( $wgUser );
526 wfProfileOut( __METHOD__
);
532 # Should the parser cache be used?
533 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
534 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
535 if ( $wgUser->getStubThreshold() ) {
536 wfIncrStats( 'pcache_miss_stub' );
539 $this->showRedirectedFromHeader();
540 $this->showNamespaceHeader();
542 # Iterate through the possible ways of constructing the output text.
543 # Keep going until $outputDone is set, or we run out of things to do.
546 $this->mParserOutput
= false;
548 while ( !$outputDone && ++
$pass ) {
551 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
554 # Early abort if the page doesn't exist
555 if ( !$this->mPage
->exists() ) {
556 wfDebug( __METHOD__
. ": showing missing article\n" );
557 $this->showMissingArticle();
558 wfProfileOut( __METHOD__
);
562 # Try the parser cache
563 if ( $useParserCache ) {
564 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
566 if ( $this->mParserOutput
!== false ) {
568 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
569 $this->setOldSubtitle( $oldid );
571 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
573 $wgOut->addParserOutput( $this->mParserOutput
);
574 # Ensure that UI elements requiring revision ID have
575 # the correct version information.
576 $wgOut->setRevisionId( $this->mPage
->getLatest() );
577 # Preload timestamp to avoid a DB hit
578 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
579 if ( $cachedTimestamp !== null ) {
580 $wgOut->setRevisionTimestamp( $cachedTimestamp );
581 $this->mPage
->setTimestamp( $cachedTimestamp );
588 # This will set $this->mRevision if needed
589 $this->fetchContentObject();
591 # Are we looking at an old revision
592 if ( $oldid && $this->mRevision
) {
593 $this->setOldSubtitle( $oldid );
595 if ( !$this->showDeletedRevisionHeader() ) {
596 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
597 wfProfileOut( __METHOD__
);
602 # Ensure that UI elements requiring revision ID have
603 # the correct version information.
604 $wgOut->setRevisionId( $this->getRevIdFetched() );
605 # Preload timestamp to avoid a DB hit
606 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
608 # Pages containing custom CSS or JavaScript get special treatment
609 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
610 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
611 $this->showCssOrJsPage();
613 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) { #FIXME: document new hook!
614 # Allow extensions do their own custom view for certain pages
616 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated! #FIXME: deprecate hook!
617 # Allow extensions do their own custom view for certain pages
620 $content = $this->getContentObject();
621 $rt = $content->getRedirectChain();
623 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
624 # Viewing a redirect page (e.g. with parameter redirect=no)
625 $wgOut->addHTML( $this->viewRedirect( $rt ) );
626 # Parse just to get categories, displaytitle, etc.
627 $this->mParserOutput
= $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions );
628 $wgOut->addParserOutputNoText( $this->mParserOutput
);
634 # Run the parse, protected by a pool counter
635 wfDebug( __METHOD__
. ": doing uncached parse\n" );
637 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
638 $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
640 if ( !$poolArticleView->execute() ) {
641 $error = $poolArticleView->getError();
643 $wgOut->clearHTML(); // for release() errors
644 $wgOut->enableClientCache( false );
645 $wgOut->setRobotPolicy( 'noindex,nofollow' );
647 $errortext = $error->getWikiText( false, 'view-pool-error' );
648 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
650 # Connection or timeout error
651 wfProfileOut( __METHOD__
);
655 $this->mParserOutput
= $poolArticleView->getParserOutput();
656 $wgOut->addParserOutput( $this->mParserOutput
);
658 # Don't cache a dirty ParserOutput object
659 if ( $poolArticleView->getIsDirty() ) {
660 $wgOut->setSquidMaxage( 0 );
661 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
666 # Should be unreachable, but just in case...
672 # Get the ParserOutput actually *displayed* here.
673 # Note that $this->mParserOutput is the *current* version output.
674 $pOutput = ( $outputDone instanceof ParserOutput
)
675 ?
$outputDone // object fetched by hook
676 : $this->mParserOutput
;
678 # Adjust title for main page & pages with displaytitle
680 $this->adjustDisplayTitle( $pOutput );
683 # For the main page, overwrite the <title> element with the con-
684 # tents of 'pagetitle-view-mainpage' instead of the default (if
686 # This message always exists because it is in the i18n files
687 if ( $this->getTitle()->isMainPage() ) {
688 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
689 if ( !$msg->isDisabled() ) {
690 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
694 # Check for any __NOINDEX__ tags on the page using $pOutput
695 $policy = $this->getRobotPolicy( 'view', $pOutput );
696 $wgOut->setIndexPolicy( $policy['index'] );
697 $wgOut->setFollowPolicy( $policy['follow'] );
699 $this->showViewFooter();
700 $this->mPage
->doViewUpdates( $wgUser );
702 wfProfileOut( __METHOD__
);
706 * Adjust title for pages with displaytitle, -{T|}- or language conversion
707 * @param $pOutput ParserOutput
709 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
711 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
712 $titleText = $pOutput->getTitleText();
713 if ( strval( $titleText ) !== '' ) {
714 $wgOut->setPageTitle( $titleText );
719 * Show a diff page according to current request variables. For use within
720 * Article::view() only, other callers should use the DifferenceEngine class.
722 public function showDiffPage() {
723 global $wgRequest, $wgUser;
725 $diff = $wgRequest->getVal( 'diff' );
726 $rcid = $wgRequest->getVal( 'rcid' );
727 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
728 $purge = $wgRequest->getVal( 'action' ) == 'purge';
729 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
730 $oldid = $this->getOldID();
732 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
733 $de = $contentHandler->getDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
735 // DifferenceEngine directly fetched the revision:
736 $this->mRevIdFetched
= $de->mNewid
;
737 $de->showDiffPage( $diffOnly );
739 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
740 # Run view updates for current revision only
741 $this->mPage
->doViewUpdates( $wgUser );
746 * Show a page view for a page formatted as CSS or JavaScript. To be called by
747 * Article::view() only.
749 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
752 protected function showCssOrJsPage( $showCacheHint = true ) {
755 if ( $showCacheHint ) {
756 $dir = $this->getContext()->getLanguage()->getDir();
757 $lang = $this->getContext()->getLanguage()->getCode();
759 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
763 // Give hooks a chance to customise the output
764 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated
765 $po = $this->mContentObject
->getParserOutput();
766 $wgOut->addHTML( $po->getText() );
771 * Get the robot policy to be used for the current view
772 * @param $action String the action= GET parameter
773 * @param $pOutput ParserOutput
774 * @return Array the policy that should be set
775 * TODO: actions other than 'view'
777 public function getRobotPolicy( $action, $pOutput ) {
778 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
779 global $wgDefaultRobotPolicy, $wgRequest;
781 $ns = $this->getTitle()->getNamespace();
783 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
784 # Don't index user and user talk pages for blocked users (bug 11443)
785 if ( !$this->getTitle()->isSubpage() ) {
786 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
788 'index' => 'noindex',
789 'follow' => 'nofollow'
795 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
796 # Non-articles (special pages etc), and old revisions
798 'index' => 'noindex',
799 'follow' => 'nofollow'
801 } elseif ( $wgOut->isPrintable() ) {
802 # Discourage indexing of printable versions, but encourage following
804 'index' => 'noindex',
807 } elseif ( $wgRequest->getInt( 'curid' ) ) {
808 # For ?curid=x urls, disallow indexing
810 'index' => 'noindex',
815 # Otherwise, construct the policy based on the various config variables.
816 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
818 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
819 # Honour customised robot policies for this namespace
820 $policy = array_merge(
822 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
825 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
826 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
827 # a final sanity check that we have really got the parser output.
828 $policy = array_merge(
830 array( 'index' => $pOutput->getIndexPolicy() )
834 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
835 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
836 $policy = array_merge(
838 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
846 * Converts a String robot policy into an associative array, to allow
847 * merging of several policies using array_merge().
848 * @param $policy Mixed, returns empty array on null/false/'', transparent
849 * to already-converted arrays, converts String.
850 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
852 public static function formatRobotPolicy( $policy ) {
853 if ( is_array( $policy ) ) {
855 } elseif ( !$policy ) {
859 $policy = explode( ',', $policy );
860 $policy = array_map( 'trim', $policy );
863 foreach ( $policy as $var ) {
864 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
865 $arr['index'] = $var;
866 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
867 $arr['follow'] = $var;
875 * If this request is a redirect view, send "redirected from" subtitle to
876 * $wgOut. Returns true if the header was needed, false if this is not a
877 * redirect view. Handles both local and remote redirects.
881 public function showRedirectedFromHeader() {
882 global $wgOut, $wgRequest, $wgRedirectSources;
884 $rdfrom = $wgRequest->getVal( 'rdfrom' );
886 if ( isset( $this->mRedirectedFrom
) ) {
887 // This is an internally redirected page view.
888 // We'll need a backlink to the source page for navigation.
889 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
890 $redir = Linker
::linkKnown(
891 $this->mRedirectedFrom
,
894 array( 'redirect' => 'no' )
897 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
899 // Set the fragment if one was specified in the redirect
900 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
901 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
902 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
905 // Add a <link rel="canonical"> tag
906 $wgOut->addLink( array( 'rel' => 'canonical',
907 'href' => $this->getTitle()->getLocalURL() )
910 // Tell $wgOut the user arrived at this article through a redirect
911 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
915 } elseif ( $rdfrom ) {
916 // This is an externally redirected view, from some other wiki.
917 // If it was reported from a trusted site, supply a backlink.
918 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
919 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
920 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
930 * Show a header specific to the namespace currently being viewed, like
931 * [[MediaWiki:Talkpagetext]]. For Article::view().
933 public function showNamespaceHeader() {
936 if ( $this->getTitle()->isTalkPage() ) {
937 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
938 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
944 * Show the footer section of an ordinary page view
946 public function showViewFooter() {
949 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
950 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
951 $wgOut->addWikiMsg( 'anontalkpagetext' );
954 # If we have been passed an &rcid= parameter, we want to give the user a
955 # chance to mark this new article as patrolled.
956 $this->showPatrolFooter();
958 wfRunHooks( 'ArticleViewFooter', array( $this ) );
963 * If patrol is possible, output a patrol UI box. This is called from the
964 * footer section of ordinary page views. If patrol is not possible or not
965 * desired, does nothing.
967 public function showPatrolFooter() {
968 global $wgOut, $wgRequest, $wgUser;
970 $rcid = $wgRequest->getVal( 'rcid' );
972 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
976 $token = $wgUser->getEditToken( $rcid );
977 $wgOut->preventClickjacking();
980 "<div class='patrollink'>" .
982 'markaspatrolledlink',
985 wfMsgHtml( 'markaspatrolledtext' ),
988 'action' => 'markpatrolled',
992 array( 'known', 'noclasses' )
1000 * Show the error text for a missing article. For articles in the MediaWiki
1001 * namespace, show the default message text. To be called from Article::view().
1003 public function showMissingArticle() {
1004 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
1006 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1007 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1008 $parts = explode( '/', $this->getTitle()->getText() );
1009 $rootPart = $parts[0];
1010 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1011 $ip = User
::isIP( $rootPart );
1013 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1014 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1015 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1016 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1017 LogEventsList
::showLogExtract(
1020 $user->getUserPage()->getPrefixedText(),
1024 'showIfEmpty' => false,
1026 'blocked-notice-logextract',
1027 $user->getName() # Support GENDER in notice
1034 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1036 # Show delete and move logs
1037 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1039 'conds' => array( "log_action != 'revision'" ),
1040 'showIfEmpty' => false,
1041 'msgKey' => array( 'moveddeleted-notice' ) )
1044 # Show error message
1045 $oldid = $this->getOldID();
1047 $text = wfMsgNoTrans( 'missing-article',
1048 $this->getTitle()->getPrefixedText(),
1049 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1050 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1051 // Use the default message text
1052 $text = $this->getTitle()->getDefaultMessageText();
1054 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1055 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1056 $errors = array_merge( $createErrors, $editErrors );
1058 if ( !count( $errors ) ) {
1059 $text = wfMsgNoTrans( 'noarticletext' );
1061 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1064 $text = "<div class='noarticletext'>\n$text\n</div>";
1066 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1067 // If there's no backing content, send a 404 Not Found
1068 // for better machine handling of broken links.
1069 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1072 $wgOut->addWikiText( $text );
1076 * If the revision requested for view is deleted, check permissions.
1077 * Send either an error message or a warning header to $wgOut.
1079 * @return boolean true if the view is allowed, false if not.
1081 public function showDeletedRevisionHeader() {
1082 global $wgOut, $wgRequest;
1084 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1089 // If the user is not allowed to see it...
1090 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1091 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1092 'rev-deleted-text-permission' );
1095 // If the user needs to confirm that they want to see it...
1096 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1097 # Give explanation and add a link to view the revision...
1098 $oldid = intval( $this->getOldID() );
1099 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1100 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1101 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1102 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1103 array( $msg, $link ) );
1106 // We are allowed to see...
1108 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1109 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1110 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1117 * Generate the navigation links when browsing through an article revisions
1118 * It shows the information as:
1119 * Revision as of \<date\>; view current revision
1120 * \<- Previous version | Next Version -\>
1122 * @param $oldid String: revision ID of this article revision
1124 public function setOldSubtitle( $oldid = 0 ) {
1125 global $wgLang, $wgOut, $wgUser, $wgRequest;
1127 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1131 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1133 # Cascade unhide param in links for easy deletion browsing
1134 $extraParams = array();
1135 if ( $wgRequest->getVal( 'unhide' ) ) {
1136 $extraParams['unhide'] = 1;
1139 $revision = Revision
::newFromId( $oldid );
1140 $timestamp = $revision->getTimestamp();
1142 $current = ( $oldid == $this->mPage
->getLatest() );
1143 $td = $wgLang->timeanddate( $timestamp, true );
1144 $tddate = $wgLang->date( $timestamp, true );
1145 $tdtime = $wgLang->time( $timestamp, true );
1147 # Show user links if allowed to see them. If hidden, then show them only if requested...
1148 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1150 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1151 ?
'revision-info-current'
1154 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1155 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1156 $tdtime, $revision->getUser() )->parse() . "</div>" );
1159 ?
wfMsgHtml( 'currentrevisionlink' )
1162 wfMsgHtml( 'currentrevisionlink' ),
1165 array( 'known', 'noclasses' )
1168 ?
wfMsgHtml( 'diff' )
1171 wfMsgHtml( 'diff' ),
1177 array( 'known', 'noclasses' )
1179 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1183 wfMsgHtml( 'previousrevision' ),
1186 'direction' => 'prev',
1189 array( 'known', 'noclasses' )
1191 : wfMsgHtml( 'previousrevision' );
1195 wfMsgHtml( 'diff' ),
1201 array( 'known', 'noclasses' )
1203 : wfMsgHtml( 'diff' );
1204 $nextlink = $current
1205 ?
wfMsgHtml( 'nextrevision' )
1208 wfMsgHtml( 'nextrevision' ),
1211 'direction' => 'next',
1214 array( 'known', 'noclasses' )
1216 $nextdiff = $current
1217 ?
wfMsgHtml( 'diff' )
1220 wfMsgHtml( 'diff' ),
1226 array( 'known', 'noclasses' )
1229 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1230 if ( $cdel !== '' ) {
1234 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1235 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1236 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1242 * @param $target Title|Array of destination(s) to redirect
1243 * @param $appendSubtitle Boolean [optional]
1244 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1245 * @return string containing HMTL with redirect link
1247 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1248 global $wgOut, $wgStylePath;
1250 if ( !is_array( $target ) ) {
1251 $target = array( $target );
1254 $lang = $this->getTitle()->getPageLanguage();
1255 $imageDir = $lang->getDir();
1257 if ( $appendSubtitle ) {
1258 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1261 // the loop prepends the arrow image before the link, so the first case needs to be outside
1266 $title = array_shift( $target );
1268 if ( $forceKnown ) {
1269 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1271 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1274 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1275 $alt = $lang->isRTL() ?
'←' : '→';
1276 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1277 foreach ( $target as $rt ) {
1278 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1279 if ( $forceKnown ) {
1280 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1282 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1286 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1287 return '<div class="redirectMsg">' .
1288 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1289 '<span class="redirectText">' . $link . '</span></div>';
1293 * Handle action=render
1295 public function render() {
1298 $wgOut->setArticleBodyOnly( true );
1303 * action=protect handler
1305 public function protect() {
1306 $form = new ProtectionForm( $this );
1311 * action=unprotect handler (alias)
1313 public function unprotect() {
1318 * UI entry point for page deletion
1320 public function delete() {
1321 global $wgOut, $wgRequest, $wgLang;
1323 # This code desperately needs to be totally rewritten
1325 $title = $this->getTitle();
1326 $user = $this->getContext()->getUser();
1329 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1330 if ( count( $permission_errors ) ) {
1331 throw new PermissionsError( 'delete', $permission_errors );
1334 # Read-only check...
1335 if ( wfReadOnly() ) {
1336 throw new ReadOnlyError
;
1339 # Better double-check that it hasn't been deleted yet!
1340 $dbw = wfGetDB( DB_MASTER
);
1341 $conds = $title->pageCond();
1342 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1343 if ( $latest === false ) {
1344 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1345 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1346 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1348 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1349 LogEventsList
::showLogExtract(
1352 $title->getPrefixedText()
1358 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1359 $deleteReason = $wgRequest->getText( 'wpReason' );
1361 if ( $deleteReasonList == 'other' ) {
1362 $reason = $deleteReason;
1363 } elseif ( $deleteReason != '' ) {
1364 // Entry from drop down menu + additional comment
1365 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1367 $reason = $deleteReasonList;
1370 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1371 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1373 # Flag to hide all contents of the archived revisions
1374 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1376 $this->doDelete( $reason, $suppress );
1378 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1380 } elseif ( $title->userIsWatching() ) {
1387 // Generate deletion reason
1388 $hasHistory = false;
1391 $reason = $this->generateReason( $hasHistory );
1392 } catch (MWException
$e) {
1393 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1394 wfDebug("Error while building auto delete summary: $e");
1399 // If the page has a history, insert a warning
1400 if ( $hasHistory ) {
1401 $revisions = $this->mTitle
->estimateRevisionCount();
1402 // @todo FIXME: i18n issue/patchwork message
1403 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1404 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1405 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1406 wfMsgHtml( 'history' ),
1407 array( 'rel' => 'archives' ),
1408 array( 'action' => 'history' ) ) .
1412 if ( $this->mTitle
->isBigDeletion() ) {
1413 global $wgDeleteRevisionsLimit;
1414 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1415 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1419 return $this->confirmDelete( $reason );
1423 * Output deletion confirmation dialog
1424 * @todo FIXME: Move to another file?
1425 * @param $reason String: prefilled reason
1427 public function confirmDelete( $reason ) {
1430 wfDebug( "Article::confirmDelete\n" );
1432 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1433 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1434 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1435 $wgOut->addWikiMsg( 'confirmdeletetext' );
1437 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1439 $user = $this->getContext()->getUser();
1441 if ( $user->isAllowed( 'suppressrevision' ) ) {
1442 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1444 <td class='mw-input'><strong>" .
1445 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1446 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1452 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1454 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1455 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1456 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1457 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1458 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1459 "<tr id=\"wpDeleteReasonListRow\">
1460 <td class='mw-label'>" .
1461 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1463 <td class='mw-input'>" .
1464 Xml
::listDropDown( 'wpDeleteReasonList',
1465 wfMsgForContent( 'deletereason-dropdown' ),
1466 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1469 <tr id=\"wpDeleteReasonRow\">
1470 <td class='mw-label'>" .
1471 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1473 <td class='mw-input'>" .
1474 Html
::input( 'wpReason', $reason, 'text', array(
1476 'maxlength' => '255',
1484 # Disallow watching if user is not logged in
1485 if ( $user->isLoggedIn() ) {
1489 <td class='mw-input'>" .
1490 Xml
::checkLabel( wfMsg( 'watchthis' ),
1491 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1500 <td class='mw-submit'>" .
1501 Xml
::submitButton( wfMsg( 'deletepage' ),
1502 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1505 Xml
::closeElement( 'table' ) .
1506 Xml
::closeElement( 'fieldset' ) .
1507 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1508 Xml
::closeElement( 'form' );
1510 if ( $user->isAllowed( 'editinterface' ) ) {
1511 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1512 $link = Linker
::link(
1514 wfMsgHtml( 'delete-edit-reasonlist' ),
1516 array( 'action' => 'edit' )
1518 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1521 $wgOut->addHTML( $form );
1522 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1523 LogEventsList
::showLogExtract( $wgOut, 'delete',
1524 $this->getTitle()->getPrefixedText()
1529 * Perform a deletion and output success or failure messages
1531 * @param $suppress bool
1533 public function doDelete( $reason, $suppress = false ) {
1537 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1538 $deleted = $this->getTitle()->getPrefixedText();
1540 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1541 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1543 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1545 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1546 $wgOut->returnToMain( false );
1548 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1549 if ( $error == '' ) {
1550 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1551 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1553 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1555 LogEventsList
::showLogExtract(
1558 $this->getTitle()->getPrefixedText()
1561 $wgOut->addHTML( $error );
1566 /* Caching functions */
1569 * checkLastModified returns true if it has taken care of all
1570 * output to the client that is necessary for this request.
1571 * (that is, it has sent a cached version of the page)
1573 * @return boolean true if cached version send, false otherwise
1575 protected function tryFileCache() {
1576 static $called = false;
1579 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1584 if ( $this->isFileCacheable() ) {
1585 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1586 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1587 wfDebug( "Article::tryFileCache(): about to load file\n" );
1588 $cache->loadFromFileCache( $this->getContext() );
1591 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1592 ob_start( array( &$cache, 'saveToFileCache' ) );
1595 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1602 * Check if the page can be cached
1605 public function isFileCacheable() {
1608 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1609 $cacheable = $this->mPage
->getID()
1610 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1611 // Extension may have reason to disable file caching on some pages.
1613 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1623 * Lightweight method to get the parser output for a page, checking the parser cache
1624 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1625 * consider, so it's not appropriate to use there.
1627 * @since 1.16 (r52326) for LiquidThreads
1629 * @param $oldid mixed integer Revision ID or null
1630 * @param $user User The relevant user
1631 * @return ParserOutput or false if the given revsion ID is not found
1633 public function getParserOutput( $oldid = null, User
$user = null ) {
1636 $user = is_null( $user ) ?
$wgUser : $user;
1637 $parserOptions = $this->mPage
->makeParserOptions( $user );
1639 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1643 * Get parser options suitable for rendering the primary article wikitext
1644 * @return ParserOptions|false
1646 public function getParserOptions() {
1648 if ( !$this->mParserOptions
) {
1649 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1651 // Clone to allow modifications of the return value without affecting cache
1652 return clone $this->mParserOptions
;
1656 * Sets the context this Article is executed in
1658 * @param $context IContextSource
1661 public function setContext( $context ) {
1662 $this->mContext
= $context;
1666 * Gets the context this Article is executed in
1668 * @return IContextSource
1671 public function getContext() {
1672 if ( $this->mContext
instanceof IContextSource
) {
1673 return $this->mContext
;
1675 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1676 return RequestContext
::getMain();
1681 * Info about this page
1682 * @deprecated since 1.19
1684 public function info() {
1685 wfDeprecated( __METHOD__
, '1.19' );
1686 Action
::factory( 'info', $this )->show();
1690 * Mark this particular edit/page as patrolled
1691 * @deprecated since 1.18
1693 public function markpatrolled() {
1694 wfDeprecated( __METHOD__
, '1.18' );
1695 Action
::factory( 'markpatrolled', $this )->show();
1699 * Handle action=purge
1700 * @deprecated since 1.19
1702 public function purge() {
1703 return Action
::factory( 'purge', $this )->show();
1707 * Handle action=revert
1708 * @deprecated since 1.19
1710 public function revert() {
1711 wfDeprecated( __METHOD__
, '1.19' );
1712 Action
::factory( 'revert', $this )->show();
1716 * Handle action=rollback
1717 * @deprecated since 1.19
1719 public function rollback() {
1720 wfDeprecated( __METHOD__
, '1.19' );
1721 Action
::factory( 'rollback', $this )->show();
1725 * User-interface handler for the "watch" action.
1726 * Requires Request to pass a token as of 1.18.
1727 * @deprecated since 1.18
1729 public function watch() {
1730 wfDeprecated( __METHOD__
, '1.18' );
1731 Action
::factory( 'watch', $this )->show();
1735 * Add this page to $wgUser's watchlist
1737 * This is safe to be called multiple times
1739 * @return bool true on successful watch operation
1740 * @deprecated since 1.18
1742 public function doWatch() {
1744 wfDeprecated( __METHOD__
, '1.18' );
1745 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1749 * User interface handler for the "unwatch" action.
1750 * Requires Request to pass a token as of 1.18.
1751 * @deprecated since 1.18
1753 public function unwatch() {
1754 wfDeprecated( __METHOD__
, '1.18' );
1755 Action
::factory( 'unwatch', $this )->show();
1759 * Stop watching a page
1760 * @return bool true on successful unwatch
1761 * @deprecated since 1.18
1763 public function doUnwatch() {
1765 wfDeprecated( __METHOD__
, '1.18' );
1766 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1770 * Output a redirect back to the article.
1771 * This is typically used after an edit.
1773 * @deprecated in 1.18; call $wgOut->redirect() directly
1774 * @param $noRedir Boolean: add redirect=no
1775 * @param $sectionAnchor String: section to redirect to, including "#"
1776 * @param $extraQuery String: extra query params
1778 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1779 wfDeprecated( __METHOD__
, '1.18' );
1783 $query = 'redirect=no';
1785 $query .= "&$extraQuery";
1787 $query = $extraQuery;
1790 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1794 * Use PHP's magic __get handler to handle accessing of
1795 * raw WikiPage fields for backwards compatibility.
1797 * @param $fname String Field name
1799 public function __get( $fname ) {
1800 if ( property_exists( $this->mPage
, $fname ) ) {
1801 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1802 return $this->mPage
->$fname;
1804 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1808 * Use PHP's magic __set handler to handle setting of
1809 * raw WikiPage fields for backwards compatibility.
1811 * @param $fname String Field name
1812 * @param $fvalue mixed New value
1814 public function __set( $fname, $fvalue ) {
1815 if ( property_exists( $this->mPage
, $fname ) ) {
1816 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1817 $this->mPage
->$fname = $fvalue;
1818 // Note: extensions may want to toss on new fields
1819 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1820 $this->mPage
->$fname = $fvalue;
1822 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1827 * Use PHP's magic __call handler to transform instance calls to
1828 * WikiPage functions for backwards compatibility.
1830 * @param $fname String Name of called method
1831 * @param $args Array Arguments to the method
1833 public function __call( $fname, $args ) {
1834 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1835 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1836 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1838 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1841 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1844 * @param $limit array
1845 * @param $expiry array
1846 * @param $cascade bool
1847 * @param $reason string
1851 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1852 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1856 * @param $limit array
1857 * @param $reason string
1858 * @param $cascade int
1859 * @param $expiry array
1862 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1863 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1867 * @param $reason string
1868 * @param $suppress bool
1870 * @param $commit bool
1871 * @param $error string
1874 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1875 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1883 * @param $resultDetails
1887 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1889 $user = is_null( $user ) ?
$wgUser : $user;
1890 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1897 * @param $resultDetails
1898 * @param $guser User
1901 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1903 $guser = is_null( $guser ) ?
$wgUser : $guser;
1904 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1908 * @param $hasHistory bool
1911 public function generateReason( &$hasHistory ) {
1912 $title = $this->mPage
->getTitle();
1913 $handler = ContentHandler
::getForTitle( $title );
1914 return $handler->getAutoDeleteReason( $title, $hasHistory );
1917 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1922 public static function selectFields() {
1923 return WikiPage
::selectFields();
1927 * @param $title Title
1929 public static function onArticleCreate( $title ) {
1930 WikiPage
::onArticleCreate( $title );
1934 * @param $title Title
1936 public static function onArticleDelete( $title ) {
1937 WikiPage
::onArticleDelete( $title );
1941 * @param $title Title
1943 public static function onArticleEdit( $title ) {
1944 WikiPage
::onArticleEdit( $title );
1952 * @deprecated since 1.20, use ContentHandler::getAutosummary() instead
1954 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1955 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );