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
47 var $mContentLoaded = false; // !<
53 var $mRedirectedFrom = null;
56 * @var mixed: boolean false or URL string
58 var $mRedirectUrl = false; // !<
59 var $mRevIdFetched = 0; // !<
64 var $mRevision = null;
74 * Constructor and clear the article
75 * @param $title Title Reference to a Title object.
76 * @param $oldId Integer revision ID, null to fetch from request, zero for current
78 public function __construct( Title
$title, $oldId = null ) {
79 $this->mOldId
= $oldId;
80 $this->mPage
= $this->newPage( $title );
87 protected function newPage( Title
$title ) {
88 return new WikiPage( $title );
92 * Constructor from a page id
93 * @param $id Int article ID to load
94 * @return Article|null
96 public static function newFromID( $id ) {
97 $t = Title
::newFromID( $id );
98 # @todo FIXME: Doesn't inherit right
99 return $t == null ?
null : new self( $t );
100 # return $t == null ? null : new static( $t ); // PHP 5.3
104 * Create an Article object of the appropriate class for the given page.
106 * @param $title Title
107 * @param $context IContextSource
108 * @return Article object
110 public static function newFromTitle( $title, IContextSource
$context ) {
111 if ( NS_MEDIA
== $title->getNamespace() ) {
112 // FIXME: where should this go?
113 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
117 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
119 switch( $title->getNamespace() ) {
121 $page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler
124 $page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler
127 $handler = ContentHandler
::getForTitle( $title );
128 $page = $handler->createArticle( $title );
131 $page->setContext( $context );
137 * Create an Article object of the appropriate class for the given page.
139 * @param $page WikiPage
140 * @param $context IContextSource
141 * @return Article object
143 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
144 $article = self
::newFromTitle( $page->getTitle(), $context );
145 $article->mPage
= $page; // override to keep process cached vars
150 * Tell the page view functions that this view was redirected
151 * from another page on the wiki.
152 * @param $from Title object.
154 public function setRedirectedFrom( Title
$from ) {
155 $this->mRedirectedFrom
= $from;
159 * Get the title object of the article
161 * @return Title object of this page
163 public function getTitle() {
164 return $this->mPage
->getTitle();
168 * Get the WikiPage object of this instance
173 public function getPage() {
180 public function clear() {
181 $this->mContentLoaded
= false;
183 $this->mRedirectedFrom
= null; # Title object if set
184 $this->mRevIdFetched
= 0;
185 $this->mRedirectUrl
= false;
187 $this->mPage
->clear();
191 * Note that getContent/loadContent do not follow redirects anymore.
192 * If you need to fetch redirectable content easily, try
193 * the shortcut in WikiPage::getRedirectTarget()
195 * This function has side effects! Do not use this function if you
196 * only want the real revision text if any.
198 * @deprecated in 1.20; use getContentObject() instead
200 * @return string The text of this revision
202 public function getContent() {
203 wfDeprecated( __METHOD__
, '1.20' );
204 $content = $this->getContentObject();
205 return ContentHandler
::getContentText( $content );
209 * Returns a Content object representing the pages effective display content,
210 * not necessarily the revision's content!
212 * Note that getContent/loadContent do not follow redirects anymore.
213 * If you need to fetch redirectable content easily, try
214 * the shortcut in WikiPage::getRedirectTarget()
216 * This function has side effects! Do not use this function if you
217 * only want the real revision text if any.
221 protected function getContentObject() {
224 wfProfileIn( __METHOD__
);
226 if ( $this->mPage
->getID() === 0 ) {
227 # If this is a MediaWiki:x message, then load the messages
228 # and return the message value for x.
229 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
230 $text = $this->getTitle()->getDefaultMessageText();
231 if ( $text === false ) {
235 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
237 $content = new MessageContent( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', null, 'parsemag' );
239 wfProfileOut( __METHOD__
);
243 $this->fetchContentObject();
244 wfProfileOut( __METHOD__
);
246 return $this->mContentObject
;
251 * @return int The oldid of the article that is to be shown, 0 for the
254 public function getOldID() {
255 if ( is_null( $this->mOldId
) ) {
256 $this->mOldId
= $this->getOldIDFromRequest();
259 return $this->mOldId
;
263 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
265 * @return int The old id for the request
267 public function getOldIDFromRequest() {
270 $this->mRedirectUrl
= false;
272 $oldid = $wgRequest->getIntOrNull( 'oldid' );
274 if ( $oldid === null ) {
278 if ( $oldid !== 0 ) {
279 # Load the given revision and check whether the page is another one.
280 # In that case, update this instance to reflect the change.
281 if ( $oldid === $this->mPage
->getLatest() ) {
282 $this->mRevision
= $this->mPage
->getRevision();
284 $this->mRevision
= Revision
::newFromId( $oldid );
285 if ( $this->mRevision
!== null ) {
286 // Revision title doesn't match the page title given?
287 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
288 $function = array( get_class( $this->mPage
), 'newFromID' );
289 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
295 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
296 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
299 $this->mRevision
= null;
301 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
303 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
304 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
307 $this->mRevision
= null;
315 * Load the revision (including text) into this object
317 * @deprecated in 1.19; use fetchContent()
319 function loadContent() {
320 wfDeprecated( __METHOD__
, '1.19' );
321 $this->fetchContent();
325 * Get text of an article from database
326 * Does *NOT* follow redirects.
328 * @return mixed string containing article contents, or false if null
329 * @deprecated in 1.20, use getContentObject() instead
331 protected function fetchContent() { #BC cruft!
332 wfDeprecated( __METHOD__
, '1.20' );
334 if ( $this->mContentLoaded
&& $this->mContent
) {
335 return $this->mContent
;
338 wfProfileIn( __METHOD__
);
340 $content = $this->fetchContentObject();
342 $this->mContent
= ContentHandler
::getContentText( $content ); #FIXME: get rid of mContent everywhere!
343 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft!
345 wfProfileOut( __METHOD__
);
347 return $this->mContent
;
352 * Get text content object
353 * Does *NOT* follow redirects.
354 * TODO: when is this null?
356 * @return Content|null
358 protected function fetchContentObject() {
359 if ( $this->mContentLoaded
) {
360 return $this->mContentObject
;
363 wfProfileIn( __METHOD__
);
365 $this->mContentLoaded
= true;
366 $this->mContent
= null;
368 $oldid = $this->getOldID();
370 # Pre-fill content with error message so that if something
371 # fails we'll have something telling us what we intended.
372 $t = $this->getTitle()->getPrefixedText();
373 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
374 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ; // @todo: this isn't page content but a UI message. horrible.
377 # $this->mRevision might already be fetched by getOldIDFromRequest()
378 if ( !$this->mRevision
) {
379 $this->mRevision
= Revision
::newFromId( $oldid );
380 if ( !$this->mRevision
) {
381 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
382 wfProfileOut( __METHOD__
);
387 if ( !$this->mPage
->getLatest() ) {
388 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
389 wfProfileOut( __METHOD__
);
393 $this->mRevision
= $this->mPage
->getRevision();
395 if ( !$this->mRevision
) {
396 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
397 wfProfileOut( __METHOD__
);
402 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
403 // We should instead work with the Revision object when we need it...
404 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
405 $this->mRevIdFetched
= $this->mRevision
->getId();
407 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) ); #FIXME: register new hook
409 wfProfileOut( __METHOD__
);
411 return $this->mContentObject
;
416 * @deprecated since 1.18
418 public function forUpdate() {
419 wfDeprecated( __METHOD__
, '1.18' );
423 * Returns true if the currently-referenced revision is the current edit
424 * to this page (and it exists).
427 public function isCurrent() {
428 # If no oldid, this is the current version.
429 if ( $this->getOldID() == 0 ) {
433 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
437 * Get the fetched Revision object depending on request parameters or null
441 * @return Revision|null
443 public function getRevisionFetched() {
444 $this->fetchContentObject();
446 return $this->mRevision
;
450 * Use this to fetch the rev ID used on page views
452 * @return int revision ID of last article revision
454 public function getRevIdFetched() {
455 if ( $this->mRevIdFetched
) {
456 return $this->mRevIdFetched
;
458 return $this->mPage
->getLatest();
463 * This is the default action of the index.php entry point: just view the
464 * page of the given title.
466 public function view() {
467 global $wgUser, $wgOut, $wgRequest, $wgParser;
468 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
470 wfProfileIn( __METHOD__
);
472 # Get variables from query string
473 # As side effect this will load the revision and update the title
474 # in a revision ID is passed in the request, so this should remain
475 # the first call of this method even if $oldid is used way below.
476 $oldid = $this->getOldID();
478 # Another whitelist check in case getOldID() is altering the title
479 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
480 if ( count( $permErrors ) ) {
481 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
482 wfProfileOut( __METHOD__
);
483 throw new PermissionsError( 'read', $permErrors );
486 # getOldID() may as well want us to redirect somewhere else
487 if ( $this->mRedirectUrl
) {
488 $wgOut->redirect( $this->mRedirectUrl
);
489 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
490 wfProfileOut( __METHOD__
);
495 # If we got diff in the query, we want to see a diff page instead of the article.
496 if ( $wgRequest->getCheck( 'diff' ) ) {
497 wfDebug( __METHOD__
. ": showing diff page\n" );
498 $this->showDiffPage();
499 wfProfileOut( __METHOD__
);
504 # Set page title (may be overridden by DISPLAYTITLE)
505 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
507 $wgOut->setArticleFlag( true );
508 # Allow frames by default
509 $wgOut->allowClickjacking();
511 $parserCache = ParserCache
::singleton();
513 $parserOptions = $this->getParserOptions();
514 # Render printable version, use printable version cache
515 if ( $wgOut->isPrintable() ) {
516 $parserOptions->setIsPrintable( true );
517 $parserOptions->setEditSection( false );
518 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
519 $parserOptions->setEditSection( false );
522 # Try client and file cache
523 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
525 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
528 # Is it client cached?
529 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
530 wfDebug( __METHOD__
. ": done 304\n" );
531 wfProfileOut( __METHOD__
);
535 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
536 wfDebug( __METHOD__
. ": done file cache\n" );
537 # tell wgOut that output is taken care of
539 $this->mPage
->doViewUpdates( $wgUser );
540 wfProfileOut( __METHOD__
);
546 # Should the parser cache be used?
547 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
548 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
549 if ( $wgUser->getStubThreshold() ) {
550 wfIncrStats( 'pcache_miss_stub' );
553 $this->showRedirectedFromHeader();
554 $this->showNamespaceHeader();
556 # Iterate through the possible ways of constructing the output text.
557 # Keep going until $outputDone is set, or we run out of things to do.
560 $this->mParserOutput
= false;
562 while ( !$outputDone && ++
$pass ) {
565 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
568 # Early abort if the page doesn't exist
569 if ( !$this->mPage
->exists() ) {
570 wfDebug( __METHOD__
. ": showing missing article\n" );
571 $this->showMissingArticle();
572 wfProfileOut( __METHOD__
);
576 # Try the parser cache
577 if ( $useParserCache ) {
578 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
580 if ( $this->mParserOutput
!== false ) {
582 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
583 $this->setOldSubtitle( $oldid );
585 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
587 $wgOut->addParserOutput( $this->mParserOutput
);
588 # Ensure that UI elements requiring revision ID have
589 # the correct version information.
590 $wgOut->setRevisionId( $this->mPage
->getLatest() );
591 # Preload timestamp to avoid a DB hit
592 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
593 if ( $cachedTimestamp !== null ) {
594 $wgOut->setRevisionTimestamp( $cachedTimestamp );
595 $this->mPage
->setTimestamp( $cachedTimestamp );
602 # This will set $this->mRevision if needed
603 $this->fetchContentObject();
605 # Are we looking at an old revision
606 if ( $oldid && $this->mRevision
) {
607 $this->setOldSubtitle( $oldid );
609 if ( !$this->showDeletedRevisionHeader() ) {
610 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
611 wfProfileOut( __METHOD__
);
616 # Ensure that UI elements requiring revision ID have
617 # the correct version information.
618 $wgOut->setRevisionId( $this->getRevIdFetched() );
619 # Preload timestamp to avoid a DB hit
620 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
622 # Pages containing custom CSS or JavaScript get special treatment
623 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
624 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
625 $this->showCssOrJsPage();
627 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) { #FIXME: document new hook!
628 # Allow extensions do their own custom view for certain pages
630 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated! #FIXME: deprecate hook!
631 # Allow extensions do their own custom view for certain pages
634 $content = $this->getContentObject();
635 $rt = $content->getRedirectChain();
637 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
638 # Viewing a redirect page (e.g. with parameter redirect=no)
639 $wgOut->addHTML( $this->viewRedirect( $rt ) );
640 # Parse just to get categories, displaytitle, etc.
641 $this->mParserOutput
= $content->getParserOutput( $this->getContext(), $oldid, $parserOptions, false );
642 $wgOut->addParserOutputNoText( $this->mParserOutput
);
648 # Run the parse, protected by a pool counter
649 wfDebug( __METHOD__
. ": doing uncached parse\n" );
651 // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
652 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
653 $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
655 if ( !$poolArticleView->execute() ) {
656 $error = $poolArticleView->getError();
658 $wgOut->clearHTML(); // for release() errors
659 $wgOut->enableClientCache( false );
660 $wgOut->setRobotPolicy( 'noindex,nofollow' );
662 $errortext = $error->getWikiText( false, 'view-pool-error' );
663 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
665 # Connection or timeout error
666 wfProfileOut( __METHOD__
);
670 $this->mParserOutput
= $poolArticleView->getParserOutput();
671 $wgOut->addParserOutput( $this->mParserOutput
);
673 # Don't cache a dirty ParserOutput object
674 if ( $poolArticleView->getIsDirty() ) {
675 $wgOut->setSquidMaxage( 0 );
676 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
681 # Should be unreachable, but just in case...
687 # Get the ParserOutput actually *displayed* here.
688 # Note that $this->mParserOutput is the *current* version output.
689 $pOutput = ( $outputDone instanceof ParserOutput
)
690 ?
$outputDone // object fetched by hook
691 : $this->mParserOutput
;
693 # Adjust title for main page & pages with displaytitle
695 $this->adjustDisplayTitle( $pOutput );
698 # For the main page, overwrite the <title> element with the con-
699 # tents of 'pagetitle-view-mainpage' instead of the default (if
701 # This message always exists because it is in the i18n files
702 if ( $this->getTitle()->isMainPage() ) {
703 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
704 if ( !$msg->isDisabled() ) {
705 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
709 # Check for any __NOINDEX__ tags on the page using $pOutput
710 $policy = $this->getRobotPolicy( 'view', $pOutput );
711 $wgOut->setIndexPolicy( $policy['index'] );
712 $wgOut->setFollowPolicy( $policy['follow'] );
714 $this->showViewFooter();
715 $this->mPage
->doViewUpdates( $wgUser );
717 wfProfileOut( __METHOD__
);
721 * Adjust title for pages with displaytitle, -{T|}- or language conversion
722 * @param $pOutput ParserOutput
724 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
726 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
727 $titleText = $pOutput->getTitleText();
728 if ( strval( $titleText ) !== '' ) {
729 $wgOut->setPageTitle( $titleText );
734 * Show a diff page according to current request variables. For use within
735 * Article::view() only, other callers should use the DifferenceEngine class.
737 public function showDiffPage() {
738 global $wgRequest, $wgUser;
740 $diff = $wgRequest->getVal( 'diff' );
741 $rcid = $wgRequest->getVal( 'rcid' );
742 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
743 $purge = $wgRequest->getVal( 'action' ) == 'purge';
744 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
745 $oldid = $this->getOldID();
747 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
748 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
750 // DifferenceEngine directly fetched the revision:
751 $this->mRevIdFetched
= $de->mNewid
;
752 $de->showDiffPage( $diffOnly );
754 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
755 # Run view updates for current revision only
756 $this->mPage
->doViewUpdates( $wgUser );
761 * Show a page view for a page formatted as CSS or JavaScript. To be called by
762 * Article::view() only.
764 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
767 protected function showCssOrJsPage( $showCacheHint = true ) {
770 if ( $showCacheHint ) {
771 $dir = $this->getContext()->getLanguage()->getDir();
772 $lang = $this->getContext()->getLanguage()->getCode();
774 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
778 // Give hooks a chance to customise the output
779 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated #FIXME: hook is deprecated
780 $po = $this->mContentObject
->getParserOutput( $this->getContext() );
781 $wgOut->addHTML( $po->getText() );
786 * Get the robot policy to be used for the current view
787 * @param $action String the action= GET parameter
788 * @param $pOutput ParserOutput
789 * @return Array the policy that should be set
790 * TODO: actions other than 'view'
792 public function getRobotPolicy( $action, $pOutput ) {
793 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
794 global $wgDefaultRobotPolicy, $wgRequest;
796 $ns = $this->getTitle()->getNamespace();
798 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
799 # Don't index user and user talk pages for blocked users (bug 11443)
800 if ( !$this->getTitle()->isSubpage() ) {
801 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
803 'index' => 'noindex',
804 'follow' => 'nofollow'
810 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
811 # Non-articles (special pages etc), and old revisions
813 'index' => 'noindex',
814 'follow' => 'nofollow'
816 } elseif ( $wgOut->isPrintable() ) {
817 # Discourage indexing of printable versions, but encourage following
819 'index' => 'noindex',
822 } elseif ( $wgRequest->getInt( 'curid' ) ) {
823 # For ?curid=x urls, disallow indexing
825 'index' => 'noindex',
830 # Otherwise, construct the policy based on the various config variables.
831 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
833 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
834 # Honour customised robot policies for this namespace
835 $policy = array_merge(
837 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
840 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
841 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
842 # a final sanity check that we have really got the parser output.
843 $policy = array_merge(
845 array( 'index' => $pOutput->getIndexPolicy() )
849 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
850 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
851 $policy = array_merge(
853 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
861 * Converts a String robot policy into an associative array, to allow
862 * merging of several policies using array_merge().
863 * @param $policy Mixed, returns empty array on null/false/'', transparent
864 * to already-converted arrays, converts String.
865 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
867 public static function formatRobotPolicy( $policy ) {
868 if ( is_array( $policy ) ) {
870 } elseif ( !$policy ) {
874 $policy = explode( ',', $policy );
875 $policy = array_map( 'trim', $policy );
878 foreach ( $policy as $var ) {
879 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
880 $arr['index'] = $var;
881 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
882 $arr['follow'] = $var;
890 * If this request is a redirect view, send "redirected from" subtitle to
891 * $wgOut. Returns true if the header was needed, false if this is not a
892 * redirect view. Handles both local and remote redirects.
896 public function showRedirectedFromHeader() {
897 global $wgOut, $wgRequest, $wgRedirectSources;
899 $rdfrom = $wgRequest->getVal( 'rdfrom' );
901 if ( isset( $this->mRedirectedFrom
) ) {
902 // This is an internally redirected page view.
903 // We'll need a backlink to the source page for navigation.
904 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
905 $redir = Linker
::linkKnown(
906 $this->mRedirectedFrom
,
909 array( 'redirect' => 'no' )
912 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
914 // Set the fragment if one was specified in the redirect
915 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
916 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
917 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
920 // Add a <link rel="canonical"> tag
921 $wgOut->addLink( array( 'rel' => 'canonical',
922 'href' => $this->getTitle()->getLocalURL() )
925 // Tell $wgOut the user arrived at this article through a redirect
926 $wgOut->setRedirectedFrom( $this->mRedirectedFrom
);
930 } elseif ( $rdfrom ) {
931 // This is an externally redirected view, from some other wiki.
932 // If it was reported from a trusted site, supply a backlink.
933 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
934 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
935 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
945 * Show a header specific to the namespace currently being viewed, like
946 * [[MediaWiki:Talkpagetext]]. For Article::view().
948 public function showNamespaceHeader() {
951 if ( $this->getTitle()->isTalkPage() ) {
952 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
953 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
959 * Show the footer section of an ordinary page view
961 public function showViewFooter() {
964 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
965 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
966 $wgOut->addWikiMsg( 'anontalkpagetext' );
969 # If we have been passed an &rcid= parameter, we want to give the user a
970 # chance to mark this new article as patrolled.
971 $this->showPatrolFooter();
973 wfRunHooks( 'ArticleViewFooter', array( $this ) );
978 * If patrol is possible, output a patrol UI box. This is called from the
979 * footer section of ordinary page views. If patrol is not possible or not
980 * desired, does nothing.
982 public function showPatrolFooter() {
983 global $wgOut, $wgRequest, $wgUser;
985 $rcid = $wgRequest->getVal( 'rcid' );
987 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
991 $token = $wgUser->getEditToken( $rcid );
992 $wgOut->preventClickjacking();
995 "<div class='patrollink'>" .
997 'markaspatrolledlink',
1000 wfMsgHtml( 'markaspatrolledtext' ),
1003 'action' => 'markpatrolled',
1007 array( 'known', 'noclasses' )
1015 * Show the error text for a missing article. For articles in the MediaWiki
1016 * namespace, show the default message text. To be called from Article::view().
1018 public function showMissingArticle() {
1019 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
1021 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1022 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1023 $parts = explode( '/', $this->getTitle()->getText() );
1024 $rootPart = $parts[0];
1025 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1026 $ip = User
::isIP( $rootPart );
1028 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1029 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1030 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1031 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1032 LogEventsList
::showLogExtract(
1035 $user->getUserPage()->getPrefixedText(),
1039 'showIfEmpty' => false,
1041 'blocked-notice-logextract',
1042 $user->getName() # Support GENDER in notice
1049 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1051 # Show delete and move logs
1052 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1054 'conds' => array( "log_action != 'revision'" ),
1055 'showIfEmpty' => false,
1056 'msgKey' => array( 'moveddeleted-notice' ) )
1059 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1060 // If there's no backing content, send a 404 Not Found
1061 // for better machine handling of broken links.
1062 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
1065 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1067 if ( ! $hookResult ) {
1071 # Show error message
1072 $oldid = $this->getOldID();
1074 $text = wfMsgNoTrans( 'missing-article',
1075 $this->getTitle()->getPrefixedText(),
1076 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1077 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1078 // Use the default message text
1079 $text = $this->getTitle()->getDefaultMessageText();
1081 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1082 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1083 $errors = array_merge( $createErrors, $editErrors );
1085 if ( !count( $errors ) ) {
1086 $text = wfMsgNoTrans( 'noarticletext' );
1088 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1091 $text = "<div class='noarticletext'>\n$text\n</div>";
1093 $wgOut->addWikiText( $text );
1097 * If the revision requested for view is deleted, check permissions.
1098 * Send either an error message or a warning header to $wgOut.
1100 * @return boolean true if the view is allowed, false if not.
1102 public function showDeletedRevisionHeader() {
1103 global $wgOut, $wgRequest;
1105 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1110 // If the user is not allowed to see it...
1111 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1112 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1113 'rev-deleted-text-permission' );
1116 // If the user needs to confirm that they want to see it...
1117 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1118 # Give explanation and add a link to view the revision...
1119 $oldid = intval( $this->getOldID() );
1120 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1121 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1122 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1123 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1124 array( $msg, $link ) );
1127 // We are allowed to see...
1129 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1130 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1131 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1138 * Generate the navigation links when browsing through an article revisions
1139 * It shows the information as:
1140 * Revision as of \<date\>; view current revision
1141 * \<- Previous version | Next Version -\>
1143 * @param $oldid String: revision ID of this article revision
1145 public function setOldSubtitle( $oldid = 0 ) {
1146 global $wgLang, $wgOut, $wgUser, $wgRequest;
1148 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1152 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1154 # Cascade unhide param in links for easy deletion browsing
1155 $extraParams = array();
1157 $extraParams['unhide'] = 1;
1160 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1161 $revision = $this->mRevision
;
1163 $revision = Revision
::newFromId( $oldid );
1166 $timestamp = $revision->getTimestamp();
1168 $current = ( $oldid == $this->mPage
->getLatest() );
1169 $td = $wgLang->timeanddate( $timestamp, true );
1170 $tddate = $wgLang->date( $timestamp, true );
1171 $tdtime = $wgLang->time( $timestamp, true );
1173 # Show user links if allowed to see them. If hidden, then show them only if requested...
1174 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1176 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1177 ?
'revision-info-current'
1180 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1181 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1182 $tdtime, $revision->getUser() )->parse() . "</div>" );
1185 ?
wfMsgHtml( 'currentrevisionlink' )
1188 wfMsgHtml( 'currentrevisionlink' ),
1191 array( 'known', 'noclasses' )
1194 ?
wfMsgHtml( 'diff' )
1197 wfMsgHtml( 'diff' ),
1203 array( 'known', 'noclasses' )
1205 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1209 wfMsgHtml( 'previousrevision' ),
1212 'direction' => 'prev',
1215 array( 'known', 'noclasses' )
1217 : wfMsgHtml( 'previousrevision' );
1221 wfMsgHtml( 'diff' ),
1227 array( 'known', 'noclasses' )
1229 : wfMsgHtml( 'diff' );
1230 $nextlink = $current
1231 ?
wfMsgHtml( 'nextrevision' )
1234 wfMsgHtml( 'nextrevision' ),
1237 'direction' => 'next',
1240 array( 'known', 'noclasses' )
1242 $nextdiff = $current
1243 ?
wfMsgHtml( 'diff' )
1246 wfMsgHtml( 'diff' ),
1252 array( 'known', 'noclasses' )
1255 $cdel = Linker
::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1256 if ( $cdel !== '' ) {
1260 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1261 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1262 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1268 * @param $target Title|Array of destination(s) to redirect
1269 * @param $appendSubtitle Boolean [optional]
1270 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1271 * @return string containing HMTL with redirect link
1273 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1274 global $wgOut, $wgStylePath;
1276 if ( !is_array( $target ) ) {
1277 $target = array( $target );
1280 $lang = $this->getTitle()->getPageLanguage();
1281 $imageDir = $lang->getDir();
1283 if ( $appendSubtitle ) {
1284 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1287 // the loop prepends the arrow image before the link, so the first case needs to be outside
1292 $title = array_shift( $target );
1294 if ( $forceKnown ) {
1295 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1297 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1300 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1301 $alt = $lang->isRTL() ?
'←' : '→';
1302 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1303 foreach ( $target as $rt ) {
1304 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1305 if ( $forceKnown ) {
1306 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1308 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1312 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1313 return '<div class="redirectMsg">' .
1314 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1315 '<span class="redirectText">' . $link . '</span></div>';
1319 * Handle action=render
1321 public function render() {
1324 $wgOut->setArticleBodyOnly( true );
1329 * action=protect handler
1331 public function protect() {
1332 $form = new ProtectionForm( $this );
1337 * action=unprotect handler (alias)
1339 public function unprotect() {
1344 * UI entry point for page deletion
1346 public function delete() {
1347 global $wgOut, $wgRequest, $wgLang;
1349 # This code desperately needs to be totally rewritten
1351 $title = $this->getTitle();
1352 $user = $this->getContext()->getUser();
1355 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1356 if ( count( $permission_errors ) ) {
1357 throw new PermissionsError( 'delete', $permission_errors );
1360 # Read-only check...
1361 if ( wfReadOnly() ) {
1362 throw new ReadOnlyError
;
1365 # Better double-check that it hasn't been deleted yet!
1366 $dbw = wfGetDB( DB_MASTER
);
1367 $conds = $title->pageCond();
1368 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1369 if ( $latest === false ) {
1370 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1371 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1372 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1374 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1375 LogEventsList
::showLogExtract(
1378 $title->getPrefixedText()
1384 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1385 $deleteReason = $wgRequest->getText( 'wpReason' );
1387 if ( $deleteReasonList == 'other' ) {
1388 $reason = $deleteReason;
1389 } elseif ( $deleteReason != '' ) {
1390 // Entry from drop down menu + additional comment
1391 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1393 $reason = $deleteReasonList;
1396 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1397 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1399 # Flag to hide all contents of the archived revisions
1400 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1402 $this->doDelete( $reason, $suppress );
1404 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1406 } elseif ( $title->userIsWatching() ) {
1413 // Generate deletion reason
1414 $hasHistory = false;
1417 $reason = $this->generateReason( $hasHistory );
1418 } catch (MWException
$e) {
1419 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1420 wfDebug("Error while building auto delete summary: $e");
1425 // If the page has a history, insert a warning
1426 if ( $hasHistory ) {
1427 $revisions = $this->mTitle
->estimateRevisionCount();
1428 // @todo FIXME: i18n issue/patchwork message
1429 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1430 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1431 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1432 wfMsgHtml( 'history' ),
1433 array( 'rel' => 'archives' ),
1434 array( 'action' => 'history' ) ) .
1438 if ( $this->mTitle
->isBigDeletion() ) {
1439 global $wgDeleteRevisionsLimit;
1440 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1441 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1445 return $this->confirmDelete( $reason );
1449 * Output deletion confirmation dialog
1450 * @todo FIXME: Move to another file?
1451 * @param $reason String: prefilled reason
1453 public function confirmDelete( $reason ) {
1456 wfDebug( "Article::confirmDelete\n" );
1458 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1459 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1460 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1461 $wgOut->addWikiMsg( 'confirmdeletetext' );
1463 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1465 $user = $this->getContext()->getUser();
1467 if ( $user->isAllowed( 'suppressrevision' ) ) {
1468 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1470 <td class='mw-input'><strong>" .
1471 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1472 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1478 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1480 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1481 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1482 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1483 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1484 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1485 "<tr id=\"wpDeleteReasonListRow\">
1486 <td class='mw-label'>" .
1487 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1489 <td class='mw-input'>" .
1490 Xml
::listDropDown( 'wpDeleteReasonList',
1491 wfMsgForContent( 'deletereason-dropdown' ),
1492 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1495 <tr id=\"wpDeleteReasonRow\">
1496 <td class='mw-label'>" .
1497 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1499 <td class='mw-input'>" .
1500 Html
::input( 'wpReason', $reason, 'text', array(
1502 'maxlength' => '255',
1510 # Disallow watching if user is not logged in
1511 if ( $user->isLoggedIn() ) {
1515 <td class='mw-input'>" .
1516 Xml
::checkLabel( wfMsg( 'watchthis' ),
1517 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1526 <td class='mw-submit'>" .
1527 Xml
::submitButton( wfMsg( 'deletepage' ),
1528 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1531 Xml
::closeElement( 'table' ) .
1532 Xml
::closeElement( 'fieldset' ) .
1533 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1534 Xml
::closeElement( 'form' );
1536 if ( $user->isAllowed( 'editinterface' ) ) {
1537 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1538 $link = Linker
::link(
1540 wfMsgHtml( 'delete-edit-reasonlist' ),
1542 array( 'action' => 'edit' )
1544 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1547 $wgOut->addHTML( $form );
1548 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1549 LogEventsList
::showLogExtract( $wgOut, 'delete',
1550 $this->getTitle()->getPrefixedText()
1555 * Perform a deletion and output success or failure messages
1557 * @param $suppress bool
1559 public function doDelete( $reason, $suppress = false ) {
1563 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1564 $deleted = $this->getTitle()->getPrefixedText();
1566 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1567 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1569 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1571 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1572 $wgOut->returnToMain( false );
1574 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1575 if ( $error == '' ) {
1576 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1577 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1579 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1581 LogEventsList
::showLogExtract(
1584 $this->getTitle()->getPrefixedText()
1587 $wgOut->addHTML( $error );
1592 /* Caching functions */
1595 * checkLastModified returns true if it has taken care of all
1596 * output to the client that is necessary for this request.
1597 * (that is, it has sent a cached version of the page)
1599 * @return boolean true if cached version send, false otherwise
1601 protected function tryFileCache() {
1602 static $called = false;
1605 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1610 if ( $this->isFileCacheable() ) {
1611 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1612 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1613 wfDebug( "Article::tryFileCache(): about to load file\n" );
1614 $cache->loadFromFileCache( $this->getContext() );
1617 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1618 ob_start( array( &$cache, 'saveToFileCache' ) );
1621 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1628 * Check if the page can be cached
1631 public function isFileCacheable() {
1634 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1635 $cacheable = $this->mPage
->getID()
1636 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1637 // Extension may have reason to disable file caching on some pages.
1639 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1649 * Lightweight method to get the parser output for a page, checking the parser cache
1650 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1651 * consider, so it's not appropriate to use there.
1653 * @since 1.16 (r52326) for LiquidThreads
1655 * @param $oldid mixed integer Revision ID or null
1656 * @param $user User The relevant user
1657 * @return ParserOutput or false if the given revsion ID is not found
1659 public function getParserOutput( $oldid = null, User
$user = null ) {
1662 $user = is_null( $user ) ?
$wgUser : $user;
1663 $parserOptions = $this->mPage
->makeParserOptions( $user );
1665 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1669 * Get parser options suitable for rendering the primary article wikitext
1670 * @return ParserOptions
1672 public function getParserOptions() {
1674 if ( !$this->mParserOptions
) {
1675 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1677 // Clone to allow modifications of the return value without affecting cache
1678 return clone $this->mParserOptions
;
1682 * Sets the context this Article is executed in
1684 * @param $context IContextSource
1687 public function setContext( $context ) {
1688 $this->mContext
= $context;
1692 * Gets the context this Article is executed in
1694 * @return IContextSource
1697 public function getContext() {
1698 if ( $this->mContext
instanceof IContextSource
) {
1699 return $this->mContext
;
1701 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1702 return RequestContext
::getMain();
1707 * Info about this page
1708 * @deprecated since 1.19
1710 public function info() {
1711 wfDeprecated( __METHOD__
, '1.19' );
1712 Action
::factory( 'info', $this )->show();
1716 * Mark this particular edit/page as patrolled
1717 * @deprecated since 1.18
1719 public function markpatrolled() {
1720 wfDeprecated( __METHOD__
, '1.18' );
1721 Action
::factory( 'markpatrolled', $this )->show();
1725 * Handle action=purge
1726 * @deprecated since 1.19
1728 public function purge() {
1729 return Action
::factory( 'purge', $this )->show();
1733 * Handle action=revert
1734 * @deprecated since 1.19
1736 public function revert() {
1737 wfDeprecated( __METHOD__
, '1.19' );
1738 Action
::factory( 'revert', $this )->show();
1742 * Handle action=rollback
1743 * @deprecated since 1.19
1745 public function rollback() {
1746 wfDeprecated( __METHOD__
, '1.19' );
1747 Action
::factory( 'rollback', $this )->show();
1751 * User-interface handler for the "watch" action.
1752 * Requires Request to pass a token as of 1.18.
1753 * @deprecated since 1.18
1755 public function watch() {
1756 wfDeprecated( __METHOD__
, '1.18' );
1757 Action
::factory( 'watch', $this )->show();
1761 * Add this page to $wgUser's watchlist
1763 * This is safe to be called multiple times
1765 * @return bool true on successful watch operation
1766 * @deprecated since 1.18
1768 public function doWatch() {
1770 wfDeprecated( __METHOD__
, '1.18' );
1771 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1775 * User interface handler for the "unwatch" action.
1776 * Requires Request to pass a token as of 1.18.
1777 * @deprecated since 1.18
1779 public function unwatch() {
1780 wfDeprecated( __METHOD__
, '1.18' );
1781 Action
::factory( 'unwatch', $this )->show();
1785 * Stop watching a page
1786 * @return bool true on successful unwatch
1787 * @deprecated since 1.18
1789 public function doUnwatch() {
1791 wfDeprecated( __METHOD__
, '1.18' );
1792 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1796 * Output a redirect back to the article.
1797 * This is typically used after an edit.
1799 * @deprecated in 1.18; call $wgOut->redirect() directly
1800 * @param $noRedir Boolean: add redirect=no
1801 * @param $sectionAnchor String: section to redirect to, including "#"
1802 * @param $extraQuery String: extra query params
1804 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1805 wfDeprecated( __METHOD__
, '1.18' );
1809 $query = 'redirect=no';
1811 $query .= "&$extraQuery";
1813 $query = $extraQuery;
1816 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1820 * Use PHP's magic __get handler to handle accessing of
1821 * raw WikiPage fields for backwards compatibility.
1823 * @param $fname String Field name
1825 public function __get( $fname ) {
1826 if ( property_exists( $this->mPage
, $fname ) ) {
1827 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1828 return $this->mPage
->$fname;
1830 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1834 * Use PHP's magic __set handler to handle setting of
1835 * raw WikiPage fields for backwards compatibility.
1837 * @param $fname String Field name
1838 * @param $fvalue mixed New value
1840 public function __set( $fname, $fvalue ) {
1841 if ( property_exists( $this->mPage
, $fname ) ) {
1842 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1843 $this->mPage
->$fname = $fvalue;
1844 // Note: extensions may want to toss on new fields
1845 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1846 $this->mPage
->$fname = $fvalue;
1848 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1853 * Use PHP's magic __call handler to transform instance calls to
1854 * WikiPage functions for backwards compatibility.
1856 * @param $fname String Name of called method
1857 * @param $args Array Arguments to the method
1860 public function __call( $fname, $args ) {
1861 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1862 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1863 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1865 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1868 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1871 * @param $limit array
1872 * @param $expiry array
1873 * @param $cascade bool
1874 * @param $reason string
1878 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1879 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1883 * @param $limit array
1884 * @param $reason string
1885 * @param $cascade int
1886 * @param $expiry array
1889 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1890 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1894 * @param $reason string
1895 * @param $suppress bool
1897 * @param $commit bool
1898 * @param $error string
1901 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1902 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1910 * @param $resultDetails
1914 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1916 $user = is_null( $user ) ?
$wgUser : $user;
1917 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1924 * @param $resultDetails
1925 * @param $guser User
1928 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1930 $guser = is_null( $guser ) ?
$wgUser : $guser;
1931 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1935 * @param $hasHistory bool
1938 public function generateReason( &$hasHistory ) {
1939 $title = $this->mPage
->getTitle();
1940 $handler = ContentHandler
::getForTitle( $title );
1941 return $handler->getAutoDeleteReason( $title, $hasHistory );
1944 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1949 public static function selectFields() {
1950 return WikiPage
::selectFields();
1954 * @param $title Title
1956 public static function onArticleCreate( $title ) {
1957 WikiPage
::onArticleCreate( $title );
1961 * @param $title Title
1963 public static function onArticleDelete( $title ) {
1964 WikiPage
::onArticleDelete( $title );
1968 * @param $title Title
1970 public static function onArticleEdit( $title ) {
1971 WikiPage
::onArticleEdit( $title );
1979 * @deprecated since 1.20, use ContentHandler::getAutosummary() instead
1981 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1982 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );