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 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
228 wfProfileOut( __METHOD__
);
230 return ContentHandler
::makeContent( $text, $this->getTitle() );
232 $this->fetchContentObject();
233 wfProfileOut( __METHOD__
);
235 return $this->mContentObject
;
240 * @return int The oldid of the article that is to be shown, 0 for the
243 public function getOldID() {
244 if ( is_null( $this->mOldId
) ) {
245 $this->mOldId
= $this->getOldIDFromRequest();
248 return $this->mOldId
;
252 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
254 * @return int The old id for the request
256 public function getOldIDFromRequest() {
259 $this->mRedirectUrl
= false;
261 $oldid = $wgRequest->getIntOrNull( 'oldid' );
263 if ( $oldid === null ) {
267 if ( $oldid !== 0 ) {
268 # Load the given revision and check whether the page is another one.
269 # In that case, update this instance to reflect the change.
270 $this->mRevision
= Revision
::newFromId( $oldid );
271 if ( $this->mRevision
!== null ) {
272 // Revision title doesn't match the page title given?
273 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
274 $function = array( get_class( $this->mPage
), 'newFromID' );
275 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
280 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
281 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
284 $this->mRevision
= null;
286 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
288 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
289 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
292 $this->mRevision
= null;
300 * Load the revision (including text) into this object
302 * @deprecated in 1.19; use fetchContent()
304 function loadContent() {
305 wfDeprecated( __METHOD__
, '1.19' );
306 $this->fetchContent();
310 * Get text of an article from database
311 * Does *NOT* follow redirects.
313 * @return mixed string containing article contents, or false if null
314 * @deprecated in 1.20, use getContentObject() instead
316 protected function fetchContent() { #BC cruft!
317 wfDeprecated( __METHOD__
, '1.20' );
319 if ( $this->mContentLoaded
&& $this->mContent
) {
320 return $this->mContent
;
323 wfProfileIn( __METHOD__
);
325 $content = $this->fetchContentObject();
327 $this->mContent
= ContentHandler
::getContentText( $content ); #FIXME: get rid of mContent everywhere!
328 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft!
330 wfProfileOut( __METHOD__
);
332 return $this->mContent
;
337 * Get text content object
338 * Does *NOT* follow redirects.
340 * @return Content object containing article contents, or null
342 protected function fetchContentObject() {
343 if ( $this->mContentLoaded
) {
344 return $this->mContentObject
;
347 wfProfileIn( __METHOD__
);
349 $this->mContentLoaded
= true;
350 $this->mContent
= null;
352 $oldid = $this->getOldID();
354 # Pre-fill content with error message so that if something
355 # fails we'll have something telling us what we intended.
356 $t = $this->getTitle()->getPrefixedText();
357 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
358 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ;
361 # $this->mRevision might already be fetched by getOldIDFromRequest()
362 if ( !$this->mRevision
) {
363 $this->mRevision
= Revision
::newFromId( $oldid );
364 if ( !$this->mRevision
) {
365 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
366 wfProfileOut( __METHOD__
);
371 if ( !$this->mPage
->getLatest() ) {
372 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
373 wfProfileOut( __METHOD__
);
377 $this->mRevision
= $this->mPage
->getRevision();
379 if ( !$this->mRevision
) {
380 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
381 wfProfileOut( __METHOD__
);
386 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
387 // We should instead work with the Revision object when we need it...
388 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
389 $this->mRevIdFetched
= $this->mRevision
->getId();
391 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) ); #FIXME: register new hook
393 wfProfileOut( __METHOD__
);
395 return $this->mContentObject
;
400 * @deprecated since 1.18
402 public function forUpdate() {
403 wfDeprecated( __METHOD__
, '1.18' );
407 * Returns true if the currently-referenced revision is the current edit
408 * to this page (and it exists).
411 public function isCurrent() {
412 # If no oldid, this is the current version.
413 if ( $this->getOldID() == 0 ) {
417 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
421 * Get the fetched Revision object depending on request parameters or null
425 * @return Revision|null
427 public function getRevisionFetched() {
428 $this->fetchContentObject();
430 return $this->mRevision
;
434 * Use this to fetch the rev ID used on page views
436 * @return int revision ID of last article revision
438 public function getRevIdFetched() {
439 if ( $this->mRevIdFetched
) {
440 return $this->mRevIdFetched
;
442 return $this->mPage
->getLatest();
447 * This is the default action of the index.php entry point: just view the
448 * page of the given title.
450 public function view() {
451 global $wgUser, $wgOut, $wgRequest, $wgParser;
452 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
454 wfProfileIn( __METHOD__
);
456 # Get variables from query string
457 # As side effect this will load the revision and update the title
458 # in a revision ID is passed in the request, so this should remain
459 # the first call of this method even if $oldid is used way below.
460 $oldid = $this->getOldID();
462 # Another whitelist check in case getOldID() is altering the title
463 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
464 if ( count( $permErrors ) ) {
465 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
466 wfProfileOut( __METHOD__
);
467 throw new PermissionsError( 'read', $permErrors );
470 # getOldID() may as well want us to redirect somewhere else
471 if ( $this->mRedirectUrl
) {
472 $wgOut->redirect( $this->mRedirectUrl
);
473 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
474 wfProfileOut( __METHOD__
);
479 # If we got diff in the query, we want to see a diff page instead of the article.
480 if ( $wgRequest->getCheck( 'diff' ) ) {
481 wfDebug( __METHOD__
. ": showing diff page\n" );
482 $this->showDiffPage();
483 wfProfileOut( __METHOD__
);
488 # Set page title (may be overridden by DISPLAYTITLE)
489 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
491 $wgOut->setArticleFlag( true );
492 # Allow frames by default
493 $wgOut->allowClickjacking();
495 $parserCache = ParserCache
::singleton();
497 $parserOptions = $this->getParserOptions();
498 # Render printable version, use printable version cache
499 if ( $wgOut->isPrintable() ) {
500 $parserOptions->setIsPrintable( true );
501 $parserOptions->setEditSection( false );
502 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
503 $parserOptions->setEditSection( false );
506 # Try client and file cache
507 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
509 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
512 # Is it client cached?
513 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
514 wfDebug( __METHOD__
. ": done 304\n" );
515 wfProfileOut( __METHOD__
);
519 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
520 wfDebug( __METHOD__
. ": done file cache\n" );
521 # tell wgOut that output is taken care of
523 $this->mPage
->doViewUpdates( $wgUser );
524 wfProfileOut( __METHOD__
);
530 # Should the parser cache be used?
531 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
532 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
533 if ( $wgUser->getStubThreshold() ) {
534 wfIncrStats( 'pcache_miss_stub' );
537 $this->showRedirectedFromHeader();
538 $this->showNamespaceHeader();
540 # Iterate through the possible ways of constructing the output text.
541 # Keep going until $outputDone is set, or we run out of things to do.
544 $this->mParserOutput
= false;
546 while ( !$outputDone && ++
$pass ) {
549 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
552 # Early abort if the page doesn't exist
553 if ( !$this->mPage
->exists() ) {
554 wfDebug( __METHOD__
. ": showing missing article\n" );
555 $this->showMissingArticle();
556 wfProfileOut( __METHOD__
);
560 # Try the parser cache
561 if ( $useParserCache ) {
562 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
564 if ( $this->mParserOutput
!== false ) {
566 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
567 $this->setOldSubtitle( $oldid );
569 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
571 $wgOut->addParserOutput( $this->mParserOutput
);
572 # Ensure that UI elements requiring revision ID have
573 # the correct version information.
574 $wgOut->setRevisionId( $this->mPage
->getLatest() );
575 # Preload timestamp to avoid a DB hit
576 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
577 if ( $cachedTimestamp !== null ) {
578 $wgOut->setRevisionTimestamp( $cachedTimestamp );
579 $this->mPage
->setTimestamp( $cachedTimestamp );
586 # This will set $this->mRevision if needed
587 $this->fetchContentObject();
589 # Are we looking at an old revision
590 if ( $oldid && $this->mRevision
) {
591 $this->setOldSubtitle( $oldid );
593 if ( !$this->showDeletedRevisionHeader() ) {
594 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
595 wfProfileOut( __METHOD__
);
600 # Ensure that UI elements requiring revision ID have
601 # the correct version information.
602 $wgOut->setRevisionId( $this->getRevIdFetched() );
603 # Preload timestamp to avoid a DB hit
604 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
606 # Pages containing custom CSS or JavaScript get special treatment
607 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
608 #FIXME: use ContentHandler for specialized actions insetad.
609 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
610 $this->showCssOrJsPage();
612 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) { #FIXME: document new hook!
613 # Allow extensions do their own custom view for certain pages
615 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated! #FIXME: deprecate hook!
616 # Allow extensions do their own custom view for certain pages
619 $content = $this->getContentObject();
620 $rt = $content->getRedirectChain();
622 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
623 # Viewing a redirect page (e.g. with parameter redirect=no)
624 $wgOut->addHTML( $this->viewRedirect( $rt ) );
625 # Parse just to get categories, displaytitle, etc.
626 $this->mParserOutput
= $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions );
627 $wgOut->addParserOutputNoText( $this->mParserOutput
);
633 # Run the parse, protected by a pool counter
634 wfDebug( __METHOD__
. ": doing uncached parse\n" );
636 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
637 $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
639 if ( !$poolArticleView->execute() ) {
640 $error = $poolArticleView->getError();
642 $wgOut->clearHTML(); // for release() errors
643 $wgOut->enableClientCache( false );
644 $wgOut->setRobotPolicy( 'noindex,nofollow' );
646 $errortext = $error->getWikiText( false, 'view-pool-error' );
647 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
649 # Connection or timeout error
650 wfProfileOut( __METHOD__
);
654 $this->mParserOutput
= $poolArticleView->getParserOutput();
655 $wgOut->addParserOutput( $this->mParserOutput
);
657 # Don't cache a dirty ParserOutput object
658 if ( $poolArticleView->getIsDirty() ) {
659 $wgOut->setSquidMaxage( 0 );
660 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
665 # Should be unreachable, but just in case...
671 # Get the ParserOutput actually *displayed* here.
672 # Note that $this->mParserOutput is the *current* version output.
673 $pOutput = ( $outputDone instanceof ParserOutput
)
674 ?
$outputDone // object fetched by hook
675 : $this->mParserOutput
;
677 # Adjust title for main page & pages with displaytitle
679 $this->adjustDisplayTitle( $pOutput );
682 # For the main page, overwrite the <title> element with the con-
683 # tents of 'pagetitle-view-mainpage' instead of the default (if
685 # This message always exists because it is in the i18n files
686 if ( $this->getTitle()->isMainPage() ) {
687 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
688 if ( !$msg->isDisabled() ) {
689 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
693 # Check for any __NOINDEX__ tags on the page using $pOutput
694 $policy = $this->getRobotPolicy( 'view', $pOutput );
695 $wgOut->setIndexPolicy( $policy['index'] );
696 $wgOut->setFollowPolicy( $policy['follow'] );
698 $this->showViewFooter();
699 $this->mPage
->doViewUpdates( $wgUser );
701 wfProfileOut( __METHOD__
);
705 * Adjust title for pages with displaytitle, -{T|}- or language conversion
706 * @param $pOutput ParserOutput
708 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
710 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
711 $titleText = $pOutput->getTitleText();
712 if ( strval( $titleText ) !== '' ) {
713 $wgOut->setPageTitle( $titleText );
718 * Show a diff page according to current request variables. For use within
719 * Article::view() only, other callers should use the DifferenceEngine class.
721 public function showDiffPage() {
722 global $wgRequest, $wgUser;
724 $diff = $wgRequest->getVal( 'diff' );
725 $rcid = $wgRequest->getVal( 'rcid' );
726 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
727 $purge = $wgRequest->getVal( 'action' ) == 'purge';
728 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
729 $oldid = $this->getOldID();
731 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
732 $de = $contentHandler->getDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
734 // DifferenceEngine directly fetched the revision:
735 $this->mRevIdFetched
= $de->mNewid
;
736 $de->showDiffPage( $diffOnly );
738 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
739 # Run view updates for current revision only
740 $this->mPage
->doViewUpdates( $wgUser );
745 * Show a page view for a page formatted as CSS or JavaScript. To be called by
746 * Article::view() only.
748 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
751 protected function showCssOrJsPage() {
754 $dir = $this->getContext()->getLanguage()->getDir();
755 $lang = $this->getContext()->getLanguage()->getCode();
757 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
760 // Give hooks a chance to customise the output
761 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated
762 $po = $this->mContentObject
->getParserOutput();
763 $wgOut->addHTML( $po->getText() );
768 * Get the robot policy to be used for the current view
769 * @param $action String the action= GET parameter
770 * @param $pOutput ParserOutput
771 * @return Array the policy that should be set
772 * TODO: actions other than 'view'
774 public function getRobotPolicy( $action, $pOutput ) {
775 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
776 global $wgDefaultRobotPolicy, $wgRequest;
778 $ns = $this->getTitle()->getNamespace();
780 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
781 # Don't index user and user talk pages for blocked users (bug 11443)
782 if ( !$this->getTitle()->isSubpage() ) {
783 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
785 'index' => 'noindex',
786 'follow' => 'nofollow'
792 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
793 # Non-articles (special pages etc), and old revisions
795 'index' => 'noindex',
796 'follow' => 'nofollow'
798 } elseif ( $wgOut->isPrintable() ) {
799 # Discourage indexing of printable versions, but encourage following
801 'index' => 'noindex',
804 } elseif ( $wgRequest->getInt( 'curid' ) ) {
805 # For ?curid=x urls, disallow indexing
807 'index' => 'noindex',
812 # Otherwise, construct the policy based on the various config variables.
813 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
815 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
816 # Honour customised robot policies for this namespace
817 $policy = array_merge(
819 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
822 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
823 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
824 # a final sanity check that we have really got the parser output.
825 $policy = array_merge(
827 array( 'index' => $pOutput->getIndexPolicy() )
831 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
832 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
833 $policy = array_merge(
835 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
843 * Converts a String robot policy into an associative array, to allow
844 * merging of several policies using array_merge().
845 * @param $policy Mixed, returns empty array on null/false/'', transparent
846 * to already-converted arrays, converts String.
847 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
849 public static function formatRobotPolicy( $policy ) {
850 if ( is_array( $policy ) ) {
852 } elseif ( !$policy ) {
856 $policy = explode( ',', $policy );
857 $policy = array_map( 'trim', $policy );
860 foreach ( $policy as $var ) {
861 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
862 $arr['index'] = $var;
863 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
864 $arr['follow'] = $var;
872 * If this request is a redirect view, send "redirected from" subtitle to
873 * $wgOut. Returns true if the header was needed, false if this is not a
874 * redirect view. Handles both local and remote redirects.
878 public function showRedirectedFromHeader() {
879 global $wgOut, $wgRequest, $wgRedirectSources;
881 $rdfrom = $wgRequest->getVal( 'rdfrom' );
883 if ( isset( $this->mRedirectedFrom
) ) {
884 // This is an internally redirected page view.
885 // We'll need a backlink to the source page for navigation.
886 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
887 $redir = Linker
::linkKnown(
888 $this->mRedirectedFrom
,
891 array( 'redirect' => 'no' )
894 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
896 // Set the fragment if one was specified in the redirect
897 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
898 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
899 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
902 // Add a <link rel="canonical"> tag
903 $wgOut->addLink( array( 'rel' => 'canonical',
904 'href' => $this->getTitle()->getLocalURL() )
907 // Tell $wgOut the user arrived at this article through a redirect
908 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
912 } elseif ( $rdfrom ) {
913 // This is an externally redirected view, from some other wiki.
914 // If it was reported from a trusted site, supply a backlink.
915 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
916 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
917 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
927 * Show a header specific to the namespace currently being viewed, like
928 * [[MediaWiki:Talkpagetext]]. For Article::view().
930 public function showNamespaceHeader() {
933 if ( $this->getTitle()->isTalkPage() ) {
934 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
935 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
941 * Show the footer section of an ordinary page view
943 public function showViewFooter() {
946 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
947 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
948 $wgOut->addWikiMsg( 'anontalkpagetext' );
951 # If we have been passed an &rcid= parameter, we want to give the user a
952 # chance to mark this new article as patrolled.
953 $this->showPatrolFooter();
955 wfRunHooks( 'ArticleViewFooter', array( $this ) );
960 * If patrol is possible, output a patrol UI box. This is called from the
961 * footer section of ordinary page views. If patrol is not possible or not
962 * desired, does nothing.
964 public function showPatrolFooter() {
965 global $wgOut, $wgRequest, $wgUser;
967 $rcid = $wgRequest->getVal( 'rcid' );
969 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
973 $token = $wgUser->getEditToken( $rcid );
974 $wgOut->preventClickjacking();
977 "<div class='patrollink'>" .
979 'markaspatrolledlink',
982 wfMsgHtml( 'markaspatrolledtext' ),
985 'action' => 'markpatrolled',
989 array( 'known', 'noclasses' )
997 * Show the error text for a missing article. For articles in the MediaWiki
998 * namespace, show the default message text. To be called from Article::view().
1000 public function showMissingArticle() {
1001 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
1003 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1004 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1005 $parts = explode( '/', $this->getTitle()->getText() );
1006 $rootPart = $parts[0];
1007 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1008 $ip = User
::isIP( $rootPart );
1010 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1011 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1012 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1013 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1014 LogEventsList
::showLogExtract(
1017 $user->getUserPage()->getPrefixedText(),
1021 'showIfEmpty' => false,
1023 'blocked-notice-logextract',
1024 $user->getName() # Support GENDER in notice
1031 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1033 # Show delete and move logs
1034 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1036 'conds' => array( "log_action != 'revision'" ),
1037 'showIfEmpty' => false,
1038 'msgKey' => array( 'moveddeleted-notice' ) )
1041 # Show error message
1042 $oldid = $this->getOldID();
1044 $text = wfMsgNoTrans( 'missing-article',
1045 $this->getTitle()->getPrefixedText(),
1046 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1047 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1048 // Use the default message text
1049 $text = $this->getTitle()->getDefaultMessageText();
1051 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1052 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1053 $errors = array_merge( $createErrors, $editErrors );
1055 if ( !count( $errors ) ) {
1056 $text = wfMsgNoTrans( 'noarticletext' );
1058 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1061 $text = "<div class='noarticletext'>\n$text\n</div>";
1063 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1064 // If there's no backing content, send a 404 Not Found
1065 // for better machine handling of broken links.
1066 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1069 $wgOut->addWikiText( $text );
1073 * If the revision requested for view is deleted, check permissions.
1074 * Send either an error message or a warning header to $wgOut.
1076 * @return boolean true if the view is allowed, false if not.
1078 public function showDeletedRevisionHeader() {
1079 global $wgOut, $wgRequest;
1081 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1086 // If the user is not allowed to see it...
1087 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1088 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1089 'rev-deleted-text-permission' );
1092 // If the user needs to confirm that they want to see it...
1093 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1094 # Give explanation and add a link to view the revision...
1095 $oldid = intval( $this->getOldID() );
1096 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1097 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1098 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1099 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1100 array( $msg, $link ) );
1103 // We are allowed to see...
1105 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1106 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1107 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1114 * Generate the navigation links when browsing through an article revisions
1115 * It shows the information as:
1116 * Revision as of \<date\>; view current revision
1117 * \<- Previous version | Next Version -\>
1119 * @param $oldid String: revision ID of this article revision
1121 public function setOldSubtitle( $oldid = 0 ) {
1122 global $wgLang, $wgOut, $wgUser, $wgRequest;
1124 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1128 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1130 # Cascade unhide param in links for easy deletion browsing
1131 $extraParams = array();
1132 if ( $wgRequest->getVal( 'unhide' ) ) {
1133 $extraParams['unhide'] = 1;
1136 $revision = Revision
::newFromId( $oldid );
1137 $timestamp = $revision->getTimestamp();
1139 $current = ( $oldid == $this->mPage
->getLatest() );
1140 $td = $wgLang->timeanddate( $timestamp, true );
1141 $tddate = $wgLang->date( $timestamp, true );
1142 $tdtime = $wgLang->time( $timestamp, true );
1144 # Show user links if allowed to see them. If hidden, then show them only if requested...
1145 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1147 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1148 ?
'revision-info-current'
1151 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1152 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1153 $tdtime, $revision->getUser() )->parse() . "</div>" );
1156 ?
wfMsgHtml( 'currentrevisionlink' )
1159 wfMsgHtml( 'currentrevisionlink' ),
1162 array( 'known', 'noclasses' )
1165 ?
wfMsgHtml( 'diff' )
1168 wfMsgHtml( 'diff' ),
1174 array( 'known', 'noclasses' )
1176 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1180 wfMsgHtml( 'previousrevision' ),
1183 'direction' => 'prev',
1186 array( 'known', 'noclasses' )
1188 : wfMsgHtml( 'previousrevision' );
1192 wfMsgHtml( 'diff' ),
1198 array( 'known', 'noclasses' )
1200 : wfMsgHtml( 'diff' );
1201 $nextlink = $current
1202 ?
wfMsgHtml( 'nextrevision' )
1205 wfMsgHtml( 'nextrevision' ),
1208 'direction' => 'next',
1211 array( 'known', 'noclasses' )
1213 $nextdiff = $current
1214 ?
wfMsgHtml( 'diff' )
1217 wfMsgHtml( 'diff' ),
1223 array( 'known', 'noclasses' )
1226 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1227 if ( $cdel !== '' ) {
1231 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1232 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1233 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1239 * @param $target Title|Array of destination(s) to redirect
1240 * @param $appendSubtitle Boolean [optional]
1241 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1242 * @return string containing HMTL with redirect link
1244 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1245 global $wgOut, $wgStylePath;
1247 if ( !is_array( $target ) ) {
1248 $target = array( $target );
1251 $lang = $this->getTitle()->getPageLanguage();
1252 $imageDir = $lang->getDir();
1254 if ( $appendSubtitle ) {
1255 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1258 // the loop prepends the arrow image before the link, so the first case needs to be outside
1263 $title = array_shift( $target );
1265 if ( $forceKnown ) {
1266 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1268 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1271 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1272 $alt = $lang->isRTL() ?
'←' : '→';
1273 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1274 foreach ( $target as $rt ) {
1275 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1276 if ( $forceKnown ) {
1277 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1279 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1283 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1284 return '<div class="redirectMsg">' .
1285 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1286 '<span class="redirectText">' . $link . '</span></div>';
1290 * Handle action=render
1292 public function render() {
1295 $wgOut->setArticleBodyOnly( true );
1300 * action=protect handler
1302 public function protect() {
1303 $form = new ProtectionForm( $this );
1308 * action=unprotect handler (alias)
1310 public function unprotect() {
1315 * UI entry point for page deletion
1317 public function delete() {
1318 global $wgOut, $wgRequest, $wgLang;
1320 # This code desperately needs to be totally rewritten
1322 $title = $this->getTitle();
1323 $user = $this->getContext()->getUser();
1326 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1327 if ( count( $permission_errors ) ) {
1328 throw new PermissionsError( 'delete', $permission_errors );
1331 # Read-only check...
1332 if ( wfReadOnly() ) {
1333 throw new ReadOnlyError
;
1336 # Better double-check that it hasn't been deleted yet!
1337 $dbw = wfGetDB( DB_MASTER
);
1338 $conds = $title->pageCond();
1339 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1340 if ( $latest === false ) {
1341 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1342 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1343 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1345 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1346 LogEventsList
::showLogExtract(
1349 $title->getPrefixedText()
1355 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1356 $deleteReason = $wgRequest->getText( 'wpReason' );
1358 if ( $deleteReasonList == 'other' ) {
1359 $reason = $deleteReason;
1360 } elseif ( $deleteReason != '' ) {
1361 // Entry from drop down menu + additional comment
1362 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1364 $reason = $deleteReasonList;
1367 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1368 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1370 # Flag to hide all contents of the archived revisions
1371 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1373 $this->doDelete( $reason, $suppress );
1375 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1377 } elseif ( $title->userIsWatching() ) {
1384 // Generate deletion reason
1385 $hasHistory = false;
1388 $reason = $this->generateReason( $hasHistory );
1389 } catch (MWException
$e) {
1390 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1391 wfDebug("Error while building auto delete summary: $e");
1396 // If the page has a history, insert a warning
1397 if ( $hasHistory ) {
1398 $revisions = $this->mTitle
->estimateRevisionCount();
1399 // @todo FIXME: i18n issue/patchwork message
1400 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1401 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1402 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1403 wfMsgHtml( 'history' ),
1404 array( 'rel' => 'archives' ),
1405 array( 'action' => 'history' ) ) .
1409 if ( $this->mTitle
->isBigDeletion() ) {
1410 global $wgDeleteRevisionsLimit;
1411 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1412 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1416 return $this->confirmDelete( $reason );
1420 * Output deletion confirmation dialog
1421 * @todo FIXME: Move to another file?
1422 * @param $reason String: prefilled reason
1424 public function confirmDelete( $reason ) {
1427 wfDebug( "Article::confirmDelete\n" );
1429 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1430 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1431 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1432 $wgOut->addWikiMsg( 'confirmdeletetext' );
1434 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1436 $user = $this->getContext()->getUser();
1438 if ( $user->isAllowed( 'suppressrevision' ) ) {
1439 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1441 <td class='mw-input'><strong>" .
1442 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1443 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1449 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1451 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1452 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1453 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1454 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1455 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1456 "<tr id=\"wpDeleteReasonListRow\">
1457 <td class='mw-label'>" .
1458 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1460 <td class='mw-input'>" .
1461 Xml
::listDropDown( 'wpDeleteReasonList',
1462 wfMsgForContent( 'deletereason-dropdown' ),
1463 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1466 <tr id=\"wpDeleteReasonRow\">
1467 <td class='mw-label'>" .
1468 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1470 <td class='mw-input'>" .
1471 Html
::input( 'wpReason', $reason, 'text', array(
1473 'maxlength' => '255',
1481 # Disallow watching if user is not logged in
1482 if ( $user->isLoggedIn() ) {
1486 <td class='mw-input'>" .
1487 Xml
::checkLabel( wfMsg( 'watchthis' ),
1488 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1497 <td class='mw-submit'>" .
1498 Xml
::submitButton( wfMsg( 'deletepage' ),
1499 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1502 Xml
::closeElement( 'table' ) .
1503 Xml
::closeElement( 'fieldset' ) .
1504 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1505 Xml
::closeElement( 'form' );
1507 if ( $user->isAllowed( 'editinterface' ) ) {
1508 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1509 $link = Linker
::link(
1511 wfMsgHtml( 'delete-edit-reasonlist' ),
1513 array( 'action' => 'edit' )
1515 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1518 $wgOut->addHTML( $form );
1519 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1520 LogEventsList
::showLogExtract( $wgOut, 'delete',
1521 $this->getTitle()->getPrefixedText()
1526 * Perform a deletion and output success or failure messages
1528 * @param $suppress bool
1530 public function doDelete( $reason, $suppress = false ) {
1534 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1535 $deleted = $this->getTitle()->getPrefixedText();
1537 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1538 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1540 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1542 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1543 $wgOut->returnToMain( false );
1545 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1546 if ( $error == '' ) {
1547 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1548 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1550 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1552 LogEventsList
::showLogExtract(
1555 $this->getTitle()->getPrefixedText()
1558 $wgOut->addHTML( $error );
1563 /* Caching functions */
1566 * checkLastModified returns true if it has taken care of all
1567 * output to the client that is necessary for this request.
1568 * (that is, it has sent a cached version of the page)
1570 * @return boolean true if cached version send, false otherwise
1572 protected function tryFileCache() {
1573 static $called = false;
1576 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1581 if ( $this->isFileCacheable() ) {
1582 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1583 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1584 wfDebug( "Article::tryFileCache(): about to load file\n" );
1585 $cache->loadFromFileCache( $this->getContext() );
1588 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1589 ob_start( array( &$cache, 'saveToFileCache' ) );
1592 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1599 * Check if the page can be cached
1602 public function isFileCacheable() {
1605 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1606 $cacheable = $this->mPage
->getID()
1607 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1608 // Extension may have reason to disable file caching on some pages.
1610 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1620 * Lightweight method to get the parser output for a page, checking the parser cache
1621 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1622 * consider, so it's not appropriate to use there.
1624 * @since 1.16 (r52326) for LiquidThreads
1626 * @param $oldid mixed integer Revision ID or null
1627 * @param $user User The relevant user
1628 * @return ParserOutput or false if the given revsion ID is not found
1630 public function getParserOutput( $oldid = null, User
$user = null ) {
1633 $user = is_null( $user ) ?
$wgUser : $user;
1634 $parserOptions = $this->mPage
->makeParserOptions( $user );
1636 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1640 * Get parser options suitable for rendering the primary article wikitext
1641 * @return ParserOptions|false
1643 public function getParserOptions() {
1645 if ( !$this->mParserOptions
) {
1646 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1648 // Clone to allow modifications of the return value without affecting cache
1649 return clone $this->mParserOptions
;
1653 * Sets the context this Article is executed in
1655 * @param $context IContextSource
1658 public function setContext( $context ) {
1659 $this->mContext
= $context;
1663 * Gets the context this Article is executed in
1665 * @return IContextSource
1668 public function getContext() {
1669 if ( $this->mContext
instanceof IContextSource
) {
1670 return $this->mContext
;
1672 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1673 return RequestContext
::getMain();
1678 * Info about this page
1679 * @deprecated since 1.19
1681 public function info() {
1682 wfDeprecated( __METHOD__
, '1.19' );
1683 Action
::factory( 'info', $this )->show();
1687 * Mark this particular edit/page as patrolled
1688 * @deprecated since 1.18
1690 public function markpatrolled() {
1691 wfDeprecated( __METHOD__
, '1.18' );
1692 Action
::factory( 'markpatrolled', $this )->show();
1696 * Handle action=purge
1697 * @deprecated since 1.19
1699 public function purge() {
1700 return Action
::factory( 'purge', $this )->show();
1704 * Handle action=revert
1705 * @deprecated since 1.19
1707 public function revert() {
1708 wfDeprecated( __METHOD__
, '1.19' );
1709 Action
::factory( 'revert', $this )->show();
1713 * Handle action=rollback
1714 * @deprecated since 1.19
1716 public function rollback() {
1717 wfDeprecated( __METHOD__
, '1.19' );
1718 Action
::factory( 'rollback', $this )->show();
1722 * User-interface handler for the "watch" action.
1723 * Requires Request to pass a token as of 1.18.
1724 * @deprecated since 1.18
1726 public function watch() {
1727 wfDeprecated( __METHOD__
, '1.18' );
1728 Action
::factory( 'watch', $this )->show();
1732 * Add this page to $wgUser's watchlist
1734 * This is safe to be called multiple times
1736 * @return bool true on successful watch operation
1737 * @deprecated since 1.18
1739 public function doWatch() {
1741 wfDeprecated( __METHOD__
, '1.18' );
1742 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1746 * User interface handler for the "unwatch" action.
1747 * Requires Request to pass a token as of 1.18.
1748 * @deprecated since 1.18
1750 public function unwatch() {
1751 wfDeprecated( __METHOD__
, '1.18' );
1752 Action
::factory( 'unwatch', $this )->show();
1756 * Stop watching a page
1757 * @return bool true on successful unwatch
1758 * @deprecated since 1.18
1760 public function doUnwatch() {
1762 wfDeprecated( __METHOD__
, '1.18' );
1763 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1767 * Output a redirect back to the article.
1768 * This is typically used after an edit.
1770 * @deprecated in 1.18; call $wgOut->redirect() directly
1771 * @param $noRedir Boolean: add redirect=no
1772 * @param $sectionAnchor String: section to redirect to, including "#"
1773 * @param $extraQuery String: extra query params
1775 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1776 wfDeprecated( __METHOD__
, '1.18' );
1780 $query = 'redirect=no';
1782 $query .= "&$extraQuery";
1784 $query = $extraQuery;
1787 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1791 * Use PHP's magic __get handler to handle accessing of
1792 * raw WikiPage fields for backwards compatibility.
1794 * @param $fname String Field name
1796 public function __get( $fname ) {
1797 if ( property_exists( $this->mPage
, $fname ) ) {
1798 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1799 return $this->mPage
->$fname;
1801 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1805 * Use PHP's magic __set handler to handle setting of
1806 * raw WikiPage fields for backwards compatibility.
1808 * @param $fname String Field name
1809 * @param $fvalue mixed New value
1811 public function __set( $fname, $fvalue ) {
1812 if ( property_exists( $this->mPage
, $fname ) ) {
1813 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1814 $this->mPage
->$fname = $fvalue;
1815 // Note: extensions may want to toss on new fields
1816 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1817 $this->mPage
->$fname = $fvalue;
1819 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1824 * Use PHP's magic __call handler to transform instance calls to
1825 * WikiPage functions for backwards compatibility.
1827 * @param $fname String Name of called method
1828 * @param $args Array Arguments to the method
1830 public function __call( $fname, $args ) {
1831 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1832 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1833 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1835 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1838 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1841 * @param $limit array
1842 * @param $expiry array
1843 * @param $cascade bool
1844 * @param $reason string
1848 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1849 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1853 * @param $limit array
1854 * @param $reason string
1855 * @param $cascade int
1856 * @param $expiry array
1859 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1860 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1864 * @param $reason string
1865 * @param $suppress bool
1867 * @param $commit bool
1868 * @param $error string
1871 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1872 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1880 * @param $resultDetails
1884 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1886 $user = is_null( $user ) ?
$wgUser : $user;
1887 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1894 * @param $resultDetails
1895 * @param $guser User
1898 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1900 $guser = is_null( $guser ) ?
$wgUser : $guser;
1901 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1905 * @param $hasHistory bool
1908 public function generateReason( &$hasHistory ) {
1909 $title = $this->mPage
->getTitle();
1910 $handler = ContentHandler
::getForTitle( $title );
1911 return $handler->getAutoDeleteReason( $title, $hasHistory );
1914 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1919 public static function selectFields() {
1920 return WikiPage
::selectFields();
1924 * @param $title Title
1926 public static function onArticleCreate( $title ) {
1927 WikiPage
::onArticleCreate( $title );
1931 * @param $title Title
1933 public static function onArticleDelete( $title ) {
1934 WikiPage
::onArticleDelete( $title );
1938 * @param $title Title
1940 public static function onArticleEdit( $title ) {
1941 WikiPage
::onArticleEdit( $title );
1949 * @deprecated since 1.20, use ContentHandler::getAutosummary() instead
1951 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1952 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );