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
48 var $mContentLoaded = false; // !<
54 var $mRedirectedFrom = null;
57 * @var mixed: boolean false or URL string
59 var $mRedirectUrl = false; // !<
60 var $mRevIdFetched = 0; // !<
65 var $mRevision = null;
75 * Constructor and clear the article
76 * @param $title Title Reference to a Title object.
77 * @param $oldId Integer revision ID, null to fetch from request, zero for current
79 public function __construct( Title
$title, $oldId = null ) {
80 $this->mOldId
= $oldId;
81 $this->mPage
= $this->newPage( $title );
88 protected function newPage( Title
$title ) {
89 return new WikiPage( $title );
93 * Constructor from a page id
94 * @param $id Int article ID to load
95 * @return Article|null
97 public static function newFromID( $id ) {
98 $t = Title
::newFromID( $id );
99 # @todo FIXME: Doesn't inherit right
100 return $t == null ?
null : new self( $t );
101 # return $t == null ? null : new static( $t ); // PHP 5.3
105 * Create an Article object of the appropriate class for the given page.
107 * @param $title Title
108 * @param $context IContextSource
109 * @return Article object
111 public static function newFromTitle( $title, IContextSource
$context ) {
112 if ( NS_MEDIA
== $title->getNamespace() ) {
113 // FIXME: where should this go?
114 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
118 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
120 switch( $title->getNamespace() ) {
122 $page = new ImagePage( $title ); #FIXME: teach ImagePage to use ContentHandler
125 $page = new CategoryPage( $title ); #FIXME: teach ImagePage to use ContentHandler
128 $handler = ContentHandler
::getForTitle( $title );
129 $page = $handler->createArticle( $title );
132 $page->setContext( $context );
138 * Create an Article object of the appropriate class for the given page.
140 * @param $page WikiPage
141 * @param $context IContextSource
142 * @return Article object
144 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
145 $article = self
::newFromTitle( $page->getTitle(), $context );
146 $article->mPage
= $page; // override to keep process cached vars
151 * Tell the page view functions that this view was redirected
152 * from another page on the wiki.
153 * @param $from Title object.
155 public function setRedirectedFrom( Title
$from ) {
156 $this->mRedirectedFrom
= $from;
160 * Get the title object of the article
162 * @return Title object of this page
164 public function getTitle() {
165 return $this->mPage
->getTitle();
169 * Get the WikiPage object of this instance
174 public function getPage() {
181 public function clear() {
182 $this->mContentLoaded
= false;
184 $this->mRedirectedFrom
= null; # Title object if set
185 $this->mRevIdFetched
= 0;
186 $this->mRedirectUrl
= false;
188 $this->mPage
->clear();
192 * Note that getContent/loadContent do not follow redirects anymore.
193 * If you need to fetch redirectable content easily, try
194 * the shortcut in WikiPage::getRedirectTarget()
196 * This function has side effects! Do not use this function if you
197 * only want the real revision text if any.
199 * @deprecated in 1.WD; use getContentObject() instead
201 * @return string Return the text of this revision
203 public function getContent() {
204 wfDeprecated( __METHOD__
, '1.WD' );
205 $content = $this->getContentObject();
206 return ContentHandler
::getContentText( $content );
210 * Returns a Content object representing the pages effective display content,
211 * not necessarily the revision's content!
213 * Note that getContent/loadContent do not follow redirects anymore.
214 * If you need to fetch redirectable content easily, try
215 * the shortcut in WikiPage::getRedirectTarget()
217 * This function has side effects! Do not use this function if you
218 * only want the real revision text if any.
220 * @return Content Return the content of this revision
224 protected function getContentObject() {
226 wfProfileIn( __METHOD__
);
228 if ( $this->mPage
->getID() === 0 ) {
229 # If this is a MediaWiki:x message, then load the messages
230 # and return the message value for x.
231 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
232 $text = $this->getTitle()->getDefaultMessageText();
233 if ( $text === false ) {
237 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
239 $content = new MessageContent( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', null, 'parsemag' );
241 wfProfileOut( __METHOD__
);
245 $this->fetchContentObject();
246 wfProfileOut( __METHOD__
);
248 return $this->mContentObject
;
253 * @return int The oldid of the article that is to be shown, 0 for the
256 public function getOldID() {
257 if ( is_null( $this->mOldId
) ) {
258 $this->mOldId
= $this->getOldIDFromRequest();
261 return $this->mOldId
;
265 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
267 * @return int The old id for the request
269 public function getOldIDFromRequest() {
270 $this->mRedirectUrl
= false;
272 $request = $this->getContext()->getRequest();
273 $oldid = $request->getIntOrNull( 'oldid' );
275 if ( $oldid === null ) {
279 if ( $oldid !== 0 ) {
280 # Load the given revision and check whether the page is another one.
281 # In that case, update this instance to reflect the change.
282 if ( $oldid === $this->mPage
->getLatest() ) {
283 $this->mRevision
= $this->mPage
->getRevision();
285 $this->mRevision
= Revision
::newFromId( $oldid );
286 if ( $this->mRevision
!== null ) {
287 // Revision title doesn't match the page title given?
288 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
289 $function = array( get_class( $this->mPage
), 'newFromID' );
290 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
296 if ( $request->getVal( 'direction' ) == 'next' ) {
297 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
300 $this->mRevision
= null;
302 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
304 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
305 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
308 $this->mRevision
= null;
316 * Load the revision (including text) into this object
318 * @deprecated in 1.19; use fetchContent()
320 function loadContent() {
321 wfDeprecated( __METHOD__
, '1.19' );
322 $this->fetchContent();
326 * Get text of an article from database
327 * Does *NOT* follow redirects.
329 * @return mixed string containing article contents, or false if null
330 * @deprecated in 1.WD, use getContentObject() instead
332 protected function fetchContent() { #BC cruft!
333 wfDeprecated( __METHOD__
, '1.WD' );
335 if ( $this->mContentLoaded
&& $this->mContent
) {
336 return $this->mContent
;
339 wfProfileIn( __METHOD__
);
341 $content = $this->fetchContentObject();
343 $this->mContent
= ContentHandler
::getContentText( $content ); #@todo: get rid of mContent everywhere!
344 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) ); #BC cruft! #XXX: can we deprecate that hook?
346 wfProfileOut( __METHOD__
);
348 return $this->mContent
;
353 * Get text content object
354 * Does *NOT* follow redirects.
355 * TODO: when is this null?
357 * @return Content|null
361 protected function fetchContentObject() {
362 if ( $this->mContentLoaded
) {
363 return $this->mContentObject
;
366 wfProfileIn( __METHOD__
);
368 $this->mContentLoaded
= true;
369 $this->mContent
= null;
371 $oldid = $this->getOldID();
373 # Pre-fill content with error message so that if something
374 # fails we'll have something telling us what we intended.
375 $t = $this->getTitle()->getPrefixedText();
376 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
377 $this->mContentObject
= new MessageContent( 'missing-article', array($t, $d), array() ) ; // @todo: this isn't page content but a UI message. horrible.
380 # $this->mRevision might already be fetched by getOldIDFromRequest()
381 if ( !$this->mRevision
) {
382 $this->mRevision
= Revision
::newFromId( $oldid );
383 if ( !$this->mRevision
) {
384 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
385 wfProfileOut( __METHOD__
);
390 if ( !$this->mPage
->getLatest() ) {
391 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
392 wfProfileOut( __METHOD__
);
396 $this->mRevision
= $this->mPage
->getRevision();
398 if ( !$this->mRevision
) {
399 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
400 wfProfileOut( __METHOD__
);
405 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
406 // We should instead work with the Revision object when we need it...
407 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
); // Loads if user is allowed
408 $this->mRevIdFetched
= $this->mRevision
->getId();
410 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
412 wfProfileOut( __METHOD__
);
414 return $this->mContentObject
;
419 * @deprecated since 1.18
421 public function forUpdate() {
422 wfDeprecated( __METHOD__
, '1.18' );
426 * Returns true if the currently-referenced revision is the current edit
427 * to this page (and it exists).
430 public function isCurrent() {
431 # If no oldid, this is the current version.
432 if ( $this->getOldID() == 0 ) {
436 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
440 * Get the fetched Revision object depending on request parameters or null
444 * @return Revision|null
446 public function getRevisionFetched() {
447 $this->fetchContentObject();
449 return $this->mRevision
;
453 * Use this to fetch the rev ID used on page views
455 * @return int revision ID of last article revision
457 public function getRevIdFetched() {
458 if ( $this->mRevIdFetched
) {
459 return $this->mRevIdFetched
;
461 return $this->mPage
->getLatest();
466 * This is the default action of the index.php entry point: just view the
467 * page of the given title.
469 public function view() {
470 global $wgParser, $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
472 wfProfileIn( __METHOD__
);
474 # Get variables from query string
475 # As side effect this will load the revision and update the title
476 # in a revision ID is passed in the request, so this should remain
477 # the first call of this method even if $oldid is used way below.
478 $oldid = $this->getOldID();
480 $user = $this->getContext()->getUser();
481 # Another whitelist check in case getOldID() is altering the title
482 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
483 if ( count( $permErrors ) ) {
484 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
485 wfProfileOut( __METHOD__
);
486 throw new PermissionsError( 'read', $permErrors );
489 $outputPage = $this->getContext()->getOutput();
490 # getOldID() may as well want us to redirect somewhere else
491 if ( $this->mRedirectUrl
) {
492 $outputPage->redirect( $this->mRedirectUrl
);
493 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
494 wfProfileOut( __METHOD__
);
499 # If we got diff in the query, we want to see a diff page instead of the article.
500 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
501 wfDebug( __METHOD__
. ": showing diff page\n" );
502 $this->showDiffPage();
503 wfProfileOut( __METHOD__
);
508 # Set page title (may be overridden by DISPLAYTITLE)
509 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
511 $outputPage->setArticleFlag( true );
512 # Allow frames by default
513 $outputPage->allowClickjacking();
515 $parserCache = ParserCache
::singleton();
517 $parserOptions = $this->getParserOptions();
518 # Render printable version, use printable version cache
519 if ( $outputPage->isPrintable() ) {
520 $parserOptions->setIsPrintable( true );
521 $parserOptions->setEditSection( false );
522 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
523 $parserOptions->setEditSection( false );
526 # Try client and file cache
527 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
529 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
532 # Is it client cached?
533 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
534 wfDebug( __METHOD__
. ": done 304\n" );
535 wfProfileOut( __METHOD__
);
539 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
540 wfDebug( __METHOD__
. ": done file cache\n" );
541 # tell wgOut that output is taken care of
542 $outputPage->disable();
543 $this->mPage
->doViewUpdates( $user );
544 wfProfileOut( __METHOD__
);
550 # Should the parser cache be used?
551 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
552 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
553 if ( $user->getStubThreshold() ) {
554 wfIncrStats( 'pcache_miss_stub' );
557 $this->showRedirectedFromHeader();
558 $this->showNamespaceHeader();
560 # Iterate through the possible ways of constructing the output text.
561 # Keep going until $outputDone is set, or we run out of things to do.
564 $this->mParserOutput
= false;
566 while ( !$outputDone && ++
$pass ) {
569 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
572 # Early abort if the page doesn't exist
573 if ( !$this->mPage
->exists() ) {
574 wfDebug( __METHOD__
. ": showing missing article\n" );
575 $this->showMissingArticle();
576 wfProfileOut( __METHOD__
);
580 # Try the parser cache
581 if ( $useParserCache ) {
582 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
584 if ( $this->mParserOutput
!== false ) {
586 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
587 $this->setOldSubtitle( $oldid );
589 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
591 $outputPage->addParserOutput( $this->mParserOutput
);
592 # Ensure that UI elements requiring revision ID have
593 # the correct version information.
594 $outputPage->setRevisionId( $this->mPage
->getLatest() );
595 # Preload timestamp to avoid a DB hit
596 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
597 if ( $cachedTimestamp !== null ) {
598 $outputPage->setRevisionTimestamp( $cachedTimestamp );
599 $this->mPage
->setTimestamp( $cachedTimestamp );
606 # This will set $this->mRevision if needed
607 $this->fetchContentObject();
609 # Are we looking at an old revision
610 if ( $oldid && $this->mRevision
) {
611 $this->setOldSubtitle( $oldid );
613 if ( !$this->showDeletedRevisionHeader() ) {
614 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
615 wfProfileOut( __METHOD__
);
620 # Ensure that UI elements requiring revision ID have
621 # the correct version information.
622 $outputPage->setRevisionId( $this->getRevIdFetched() );
623 # Preload timestamp to avoid a DB hit
624 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
626 # Pages containing custom CSS or JavaScript get special treatment
627 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
628 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
629 $this->showCssOrJsPage();
631 } elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->fetchContentObject(), $this->getTitle(), $wgOut ) ) ) {
632 # Allow extensions do their own custom view for certain pages
634 } elseif( Hooks
::isRegistered( 'ArticleViewCustom' ) && !wfRunHooks( 'ArticleViewCustom', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated!
635 # Allow extensions do their own custom view for certain pages
638 $content = $this->getContentObject();
639 $rt = $content->getRedirectChain();
641 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
642 # Viewing a redirect page (e.g. with parameter redirect=no)
643 $outputPage->addHTML( $this->viewRedirect( $rt ) );
644 # Parse just to get categories, displaytitle, etc.
645 $this->mParserOutput
= $content->getParserOutput( $this->getContext(), $oldid, $parserOptions, false );
646 $wgOut->addParserOutputNoText( $this->mParserOutput
);
652 # Run the parse, protected by a pool counter
653 wfDebug( __METHOD__
. ": doing uncached parse\n" );
655 // @todo: shouldn't we be passing $this->getPage() to PoolWorkArticleView instead of plain $this?
656 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
657 $this->getRevIdFetched(), $useParserCache, $this->getContentObject(), $this->getContext() );
659 if ( !$poolArticleView->execute() ) {
660 $error = $poolArticleView->getError();
662 $outputPage->clearHTML(); // for release() errors
663 $outputPage->enableClientCache( false );
664 $outputPage->setRobotPolicy( 'noindex,nofollow' );
666 $errortext = $error->getWikiText( false, 'view-pool-error' );
667 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
669 # Connection or timeout error
670 wfProfileOut( __METHOD__
);
674 $this->mParserOutput
= $poolArticleView->getParserOutput();
675 $outputPage->addParserOutput( $this->mParserOutput
);
677 # Don't cache a dirty ParserOutput object
678 if ( $poolArticleView->getIsDirty() ) {
679 $outputPage->setSquidMaxage( 0 );
680 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
685 # Should be unreachable, but just in case...
691 # Get the ParserOutput actually *displayed* here.
692 # Note that $this->mParserOutput is the *current* version output.
693 $pOutput = ( $outputDone instanceof ParserOutput
)
694 ?
$outputDone // object fetched by hook
695 : $this->mParserOutput
;
697 # Adjust title for main page & pages with displaytitle
699 $this->adjustDisplayTitle( $pOutput );
702 # For the main page, overwrite the <title> element with the con-
703 # tents of 'pagetitle-view-mainpage' instead of the default (if
705 # This message always exists because it is in the i18n files
706 if ( $this->getTitle()->isMainPage() ) {
707 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
708 if ( !$msg->isDisabled() ) {
709 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
713 # Check for any __NOINDEX__ tags on the page using $pOutput
714 $policy = $this->getRobotPolicy( 'view', $pOutput );
715 $outputPage->setIndexPolicy( $policy['index'] );
716 $outputPage->setFollowPolicy( $policy['follow'] );
718 $this->showViewFooter();
719 $this->mPage
->doViewUpdates( $user );
721 wfProfileOut( __METHOD__
);
725 * Adjust title for pages with displaytitle, -{T|}- or language conversion
726 * @param $pOutput ParserOutput
728 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
729 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
730 $titleText = $pOutput->getTitleText();
731 if ( strval( $titleText ) !== '' ) {
732 $this->getContext()->getOutput()->setPageTitle( $titleText );
737 * Show a diff page according to current request variables. For use within
738 * Article::view() only, other callers should use the DifferenceEngine class.
740 public function showDiffPage() {
741 $request = $this->getContext()->getRequest();
742 $user = $this->getContext()->getUser();
743 $diff = $request->getVal( 'diff' );
744 $rcid = $request->getVal( 'rcid' );
745 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
746 $purge = $request->getVal( 'action' ) == 'purge';
747 $unhide = $request->getInt( 'unhide' ) == 1;
748 $oldid = $this->getOldID();
750 $contentHandler = ContentHandler
::getForTitle( $this->getTitle() );
751 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
753 // DifferenceEngine directly fetched the revision:
754 $this->mRevIdFetched
= $de->mNewid
;
755 $de->showDiffPage( $diffOnly );
757 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
758 # Run view updates for current revision only
759 $this->mPage
->doViewUpdates( $user );
764 * Show a page view for a page formatted as CSS or JavaScript. To be called by
765 * Article::view() only.
767 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
770 protected function showCssOrJsPage( $showCacheHint = true ) {
773 if ( $showCacheHint ) {
774 $dir = $this->getContext()->getLanguage()->getDir();
775 $lang = $this->getContext()->getLanguage()->getCode();
777 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
781 // Give hooks a chance to customise the output
782 if ( !Hooks
::isRegistered('ShowRawCssJs') ||
wfRunHooks( 'ShowRawCssJs', array( $this->fetchContent(), $this->getTitle(), $wgOut ) ) ) { #FIXME: fetchContent() is deprecated
783 $po = $this->mContentObject
->getParserOutput( $this->getContext() );
784 $wgOut->addHTML( $po->getText() );
789 * Get the robot policy to be used for the current view
790 * @param $action String the action= GET parameter
791 * @param $pOutput ParserOutput
792 * @return Array the policy that should be set
793 * TODO: actions other than 'view'
795 public function getRobotPolicy( $action, $pOutput ) {
796 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
798 $ns = $this->getTitle()->getNamespace();
800 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
801 # Don't index user and user talk pages for blocked users (bug 11443)
802 if ( !$this->getTitle()->isSubpage() ) {
803 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
805 'index' => 'noindex',
806 'follow' => 'nofollow'
812 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
813 # Non-articles (special pages etc), and old revisions
815 'index' => 'noindex',
816 'follow' => 'nofollow'
818 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
819 # Discourage indexing of printable versions, but encourage following
821 'index' => 'noindex',
824 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
825 # For ?curid=x urls, disallow indexing
827 'index' => 'noindex',
832 # Otherwise, construct the policy based on the various config variables.
833 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
835 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
836 # Honour customised robot policies for this namespace
837 $policy = array_merge(
839 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
842 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
843 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
844 # a final sanity check that we have really got the parser output.
845 $policy = array_merge(
847 array( 'index' => $pOutput->getIndexPolicy() )
851 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
852 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
853 $policy = array_merge(
855 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
863 * Converts a String robot policy into an associative array, to allow
864 * merging of several policies using array_merge().
865 * @param $policy Mixed, returns empty array on null/false/'', transparent
866 * to already-converted arrays, converts String.
867 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
869 public static function formatRobotPolicy( $policy ) {
870 if ( is_array( $policy ) ) {
872 } elseif ( !$policy ) {
876 $policy = explode( ',', $policy );
877 $policy = array_map( 'trim', $policy );
880 foreach ( $policy as $var ) {
881 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
882 $arr['index'] = $var;
883 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
884 $arr['follow'] = $var;
892 * If this request is a redirect view, send "redirected from" subtitle to
893 * the output. Returns true if the header was needed, false if this is not
894 * a redirect view. Handles both local and remote redirects.
898 public function showRedirectedFromHeader() {
899 global $wgRedirectSources;
900 $outputPage = $this->getContext()->getOutput();
902 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
904 if ( isset( $this->mRedirectedFrom
) ) {
905 // This is an internally redirected page view.
906 // We'll need a backlink to the source page for navigation.
907 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
908 $redir = Linker
::linkKnown(
909 $this->mRedirectedFrom
,
912 array( 'redirect' => 'no' )
915 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
917 // Set the fragment if one was specified in the redirect
918 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
919 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
920 $outputPage->addInlineScript( "redirectToFragment(\"$fragment\");" );
923 // Add a <link rel="canonical"> tag
924 $outputPage->addLink( array( 'rel' => 'canonical',
925 'href' => $this->getTitle()->getLocalURL() )
928 // Tell the output object that the user arrived at this article through a redirect
929 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
933 } elseif ( $rdfrom ) {
934 // This is an externally redirected view, from some other wiki.
935 // If it was reported from a trusted site, supply a backlink.
936 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
937 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
938 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
948 * Show a header specific to the namespace currently being viewed, like
949 * [[MediaWiki:Talkpagetext]]. For Article::view().
951 public function showNamespaceHeader() {
952 if ( $this->getTitle()->isTalkPage() ) {
953 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
954 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
960 * Show the footer section of an ordinary page view
962 public function showViewFooter() {
963 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
964 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
965 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
968 # If we have been passed an &rcid= parameter, we want to give the user a
969 # chance to mark this new article as patrolled.
970 $this->showPatrolFooter();
972 wfRunHooks( 'ArticleViewFooter', array( $this ) );
977 * If patrol is possible, output a patrol UI box. This is called from the
978 * footer section of ordinary page views. If patrol is not possible or not
979 * desired, does nothing.
981 public function showPatrolFooter() {
982 $request = $this->getContext()->getRequest();
983 $outputPage = $this->getContext()->getOutput();
984 $user = $this->getContext()->getUser();
985 $rcid = $request->getVal( 'rcid' );
987 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
991 $token = $user->getEditToken( $rcid );
992 $outputPage->preventClickjacking();
994 $outputPage->addHTML(
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 $wgSend404Code;
1020 $outputPage = $this->getContext()->getOutput();
1022 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1023 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1024 $parts = explode( '/', $this->getTitle()->getText() );
1025 $rootPart = $parts[0];
1026 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1027 $ip = User
::isIP( $rootPart );
1029 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
1030 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1031 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1032 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1033 LogEventsList
::showLogExtract(
1036 $user->getUserPage()->getPrefixedText(),
1040 'showIfEmpty' => false,
1042 'blocked-notice-logextract',
1043 $user->getName() # Support GENDER in notice
1050 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1052 # Show delete and move logs
1053 LogEventsList
::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
1055 'conds' => array( "log_action != 'revision'" ),
1056 'showIfEmpty' => false,
1057 'msgKey' => array( 'moveddeleted-notice' ) )
1060 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code ) {
1061 // If there's no backing content, send a 404 Not Found
1062 // for better machine handling of broken links.
1063 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1066 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1068 if ( ! $hookResult ) {
1072 # Show error message
1073 $oldid = $this->getOldID();
1075 $text = wfMsgNoTrans( 'missing-article',
1076 $this->getTitle()->getPrefixedText(),
1077 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1078 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1079 // Use the default message text
1080 $text = $this->getTitle()->getDefaultMessageText();
1082 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $this->getContext()->getUser() );
1083 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getContext()->getUser() );
1084 $errors = array_merge( $createErrors, $editErrors );
1086 if ( !count( $errors ) ) {
1087 $text = wfMsgNoTrans( 'noarticletext' );
1089 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1092 $text = "<div class='noarticletext'>\n$text\n</div>";
1094 $outputPage->addWikiText( $text );
1098 * If the revision requested for view is deleted, check permissions.
1099 * Send either an error message or a warning header to the output.
1101 * @return boolean true if the view is allowed, false if not.
1103 public function showDeletedRevisionHeader() {
1104 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1109 $outputPage = $this->getContext()->getOutput();
1110 // If the user is not allowed to see it...
1111 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1112 $outputPage->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 ( $this->getContext()->getRequest()->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 $outputPage->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 $outputPage->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 int: revision ID of this article revision
1145 public function setOldSubtitle( $oldid = 0 ) {
1146 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1150 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1152 # Cascade unhide param in links for easy deletion browsing
1153 $extraParams = array();
1155 $extraParams['unhide'] = 1;
1158 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1159 $revision = $this->mRevision
;
1161 $revision = Revision
::newFromId( $oldid );
1164 $timestamp = $revision->getTimestamp();
1166 $current = ( $oldid == $this->mPage
->getLatest() );
1167 $language = $this->getContext()->getLanguage();
1168 $td = $language->timeanddate( $timestamp, true );
1169 $tddate = $language->date( $timestamp, true );
1170 $tdtime = $language->time( $timestamp, true );
1172 # Show user links if allowed to see them. If hidden, then show them only if requested...
1173 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1175 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1176 ?
'revision-info-current'
1179 $outputPage = $this->getContext()->getOutput();
1180 $outputPage->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( $this->getContext()->getUser(), $revision, $this->getTitle() );
1256 if ( $cdel !== '' ) {
1260 $outputPage->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 $wgStylePath;
1276 if ( !is_array( $target ) ) {
1277 $target = array( $target );
1280 $lang = $this->getTitle()->getPageLanguage();
1281 $imageDir = $lang->getDir();
1283 if ( $appendSubtitle ) {
1284 $this->getContext()->getOutput()->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() {
1322 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1327 * action=protect handler
1329 public function protect() {
1330 $form = new ProtectionForm( $this );
1335 * action=unprotect handler (alias)
1337 public function unprotect() {
1342 * UI entry point for page deletion
1344 public function delete() {
1345 # This code desperately needs to be totally rewritten
1347 $title = $this->getTitle();
1348 $user = $this->getContext()->getUser();
1351 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1352 if ( count( $permission_errors ) ) {
1353 throw new PermissionsError( 'delete', $permission_errors );
1356 # Read-only check...
1357 if ( wfReadOnly() ) {
1358 throw new ReadOnlyError
;
1361 # Better double-check that it hasn't been deleted yet!
1362 $dbw = wfGetDB( DB_MASTER
);
1363 $conds = $title->pageCond();
1364 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1365 if ( $latest === false ) {
1366 $outputPage = $this->getContext()->getOutput();
1367 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1368 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1369 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1371 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1372 LogEventsList
::showLogExtract(
1375 $title->getPrefixedText()
1381 $request = $this->getContext()->getRequest();
1382 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1383 $deleteReason = $request->getText( 'wpReason' );
1385 if ( $deleteReasonList == 'other' ) {
1386 $reason = $deleteReason;
1387 } elseif ( $deleteReason != '' ) {
1388 // Entry from drop down menu + additional comment
1389 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1391 $reason = $deleteReasonList;
1394 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1395 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1397 # Flag to hide all contents of the archived revisions
1398 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1400 $this->doDelete( $reason, $suppress );
1402 if ( $request->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1404 } elseif ( $title->userIsWatching() ) {
1411 // Generate deletion reason
1412 $hasHistory = false;
1415 $reason = $this->generateReason( $hasHistory );
1416 } catch (MWException
$e) {
1417 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1418 wfDebug("Error while building auto delete summary: $e");
1423 // If the page has a history, insert a warning
1424 if ( $hasHistory ) {
1425 $revisions = $this->mTitle
->estimateRevisionCount();
1426 // @todo FIXME: i18n issue/patchwork message
1427 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1428 wfMsgExt( 'historywarning', array( 'parseinline' ), $this->getContext()->getLanguage()->formatNum( $revisions ) ) .
1429 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1430 wfMsgHtml( 'history' ),
1431 array( 'rel' => 'archives' ),
1432 array( 'action' => 'history' ) ) .
1436 if ( $this->mTitle
->isBigDeletion() ) {
1437 global $wgDeleteRevisionsLimit;
1438 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1439 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1443 return $this->confirmDelete( $reason );
1447 * Output deletion confirmation dialog
1448 * @todo FIXME: Move to another file?
1449 * @param $reason String: prefilled reason
1451 public function confirmDelete( $reason ) {
1452 wfDebug( "Article::confirmDelete\n" );
1454 $outputPage = $this->getContext()->getOutput();
1455 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1456 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1457 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1458 $outputPage->addWikiMsg( 'confirmdeletetext' );
1460 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1462 $user = $this->getContext()->getUser();
1464 if ( $user->isAllowed( 'suppressrevision' ) ) {
1465 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1467 <td class='mw-input'><strong>" .
1468 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1469 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1475 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1477 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1478 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1479 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1480 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1481 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1482 "<tr id=\"wpDeleteReasonListRow\">
1483 <td class='mw-label'>" .
1484 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1486 <td class='mw-input'>" .
1487 Xml
::listDropDown( 'wpDeleteReasonList',
1488 wfMsgForContent( 'deletereason-dropdown' ),
1489 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1492 <tr id=\"wpDeleteReasonRow\">
1493 <td class='mw-label'>" .
1494 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1496 <td class='mw-input'>" .
1497 Html
::input( 'wpReason', $reason, 'text', array(
1499 'maxlength' => '255',
1507 # Disallow watching if user is not logged in
1508 if ( $user->isLoggedIn() ) {
1512 <td class='mw-input'>" .
1513 Xml
::checkLabel( wfMsg( 'watchthis' ),
1514 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1523 <td class='mw-submit'>" .
1524 Xml
::submitButton( wfMsg( 'deletepage' ),
1525 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1528 Xml
::closeElement( 'table' ) .
1529 Xml
::closeElement( 'fieldset' ) .
1530 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1531 Xml
::closeElement( 'form' );
1533 if ( $user->isAllowed( 'editinterface' ) ) {
1534 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1535 $link = Linker
::link(
1537 wfMsgHtml( 'delete-edit-reasonlist' ),
1539 array( 'action' => 'edit' )
1541 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1544 $outputPage->addHTML( $form );
1545 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1546 LogEventsList
::showLogExtract( $outputPage, 'delete',
1547 $this->getTitle()->getPrefixedText()
1552 * Perform a deletion and output success or failure messages
1554 * @param $suppress bool
1556 public function doDelete( $reason, $suppress = false ) {
1558 $outputPage = $this->getContext()->getOutput();
1559 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1560 $deleted = $this->getTitle()->getPrefixedText();
1562 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1563 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1565 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1567 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1568 $outputPage->returnToMain( false );
1570 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1571 if ( $error == '' ) {
1572 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1573 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1575 $outputPage->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1577 LogEventsList
::showLogExtract(
1580 $this->getTitle()->getPrefixedText()
1583 $outputPage->addHTML( $error );
1588 /* Caching functions */
1591 * checkLastModified returns true if it has taken care of all
1592 * output to the client that is necessary for this request.
1593 * (that is, it has sent a cached version of the page)
1595 * @return boolean true if cached version send, false otherwise
1597 protected function tryFileCache() {
1598 static $called = false;
1601 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1606 if ( $this->isFileCacheable() ) {
1607 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1608 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1609 wfDebug( "Article::tryFileCache(): about to load file\n" );
1610 $cache->loadFromFileCache( $this->getContext() );
1613 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1614 ob_start( array( &$cache, 'saveToFileCache' ) );
1617 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1624 * Check if the page can be cached
1627 public function isFileCacheable() {
1630 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1631 $cacheable = $this->mPage
->getID()
1632 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1633 // Extension may have reason to disable file caching on some pages.
1635 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1645 * Lightweight method to get the parser output for a page, checking the parser cache
1646 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1647 * consider, so it's not appropriate to use there.
1649 * @since 1.16 (r52326) for LiquidThreads
1651 * @param $oldid mixed integer Revision ID or null
1652 * @param $user User The relevant user
1653 * @return ParserOutput or false if the given revsion ID is not found
1655 public function getParserOutput( $oldid = null, User
$user = null ) {
1656 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1657 $parserOptions = $this->mPage
->makeParserOptions( $user );
1659 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1663 * Get parser options suitable for rendering the primary article wikitext
1664 * @return ParserOptions
1666 public function getParserOptions() {
1667 if ( !$this->mParserOptions
) {
1668 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext()->getUser() );
1670 // Clone to allow modifications of the return value without affecting cache
1671 return clone $this->mParserOptions
;
1675 * Sets the context this Article is executed in
1677 * @param $context IContextSource
1680 public function setContext( $context ) {
1681 $this->mContext
= $context;
1685 * Gets the context this Article is executed in
1687 * @return IContextSource
1690 public function getContext() {
1691 if ( $this->mContext
instanceof IContextSource
) {
1692 return $this->mContext
;
1694 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1695 return RequestContext
::getMain();
1700 * Info about this page
1701 * @deprecated since 1.19
1703 public function info() {
1704 wfDeprecated( __METHOD__
, '1.19' );
1705 Action
::factory( 'info', $this )->show();
1709 * Mark this particular edit/page as patrolled
1710 * @deprecated since 1.18
1712 public function markpatrolled() {
1713 wfDeprecated( __METHOD__
, '1.18' );
1714 Action
::factory( 'markpatrolled', $this )->show();
1718 * Handle action=purge
1719 * @deprecated since 1.19
1721 public function purge() {
1722 return Action
::factory( 'purge', $this )->show();
1726 * Handle action=revert
1727 * @deprecated since 1.19
1729 public function revert() {
1730 wfDeprecated( __METHOD__
, '1.19' );
1731 Action
::factory( 'revert', $this )->show();
1735 * Handle action=rollback
1736 * @deprecated since 1.19
1738 public function rollback() {
1739 wfDeprecated( __METHOD__
, '1.19' );
1740 Action
::factory( 'rollback', $this )->show();
1744 * User-interface handler for the "watch" action.
1745 * Requires Request to pass a token as of 1.18.
1746 * @deprecated since 1.18
1748 public function watch() {
1749 wfDeprecated( __METHOD__
, '1.18' );
1750 Action
::factory( 'watch', $this )->show();
1754 * Add this page to the current user's watchlist
1756 * This is safe to be called multiple times
1758 * @return bool true on successful watch operation
1759 * @deprecated since 1.18
1761 public function doWatch() {
1762 wfDeprecated( __METHOD__
, '1.18' );
1763 return WatchAction
::doWatch( $this->getTitle(), $this->getContext()->getUser() );
1767 * User interface handler for the "unwatch" action.
1768 * Requires Request to pass a token as of 1.18.
1769 * @deprecated since 1.18
1771 public function unwatch() {
1772 wfDeprecated( __METHOD__
, '1.18' );
1773 Action
::factory( 'unwatch', $this )->show();
1777 * Stop watching a page
1778 * @return bool true on successful unwatch
1779 * @deprecated since 1.18
1781 public function doUnwatch() {
1782 wfDeprecated( __METHOD__
, '1.18' );
1783 return WatchAction
::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
1787 * Output a redirect back to the article.
1788 * This is typically used after an edit.
1790 * @deprecated in 1.18; call OutputPage::redirect() directly
1791 * @param $noRedir Boolean: add redirect=no
1792 * @param $sectionAnchor String: section to redirect to, including "#"
1793 * @param $extraQuery String: extra query params
1795 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1796 wfDeprecated( __METHOD__
, '1.18' );
1798 $query = 'redirect=no';
1800 $query .= "&$extraQuery";
1802 $query = $extraQuery;
1805 $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1809 * Use PHP's magic __get handler to handle accessing of
1810 * raw WikiPage fields for backwards compatibility.
1812 * @param $fname String Field name
1814 public function __get( $fname ) {
1815 if ( property_exists( $this->mPage
, $fname ) ) {
1816 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1817 return $this->mPage
->$fname;
1819 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1823 * Use PHP's magic __set handler to handle setting of
1824 * raw WikiPage fields for backwards compatibility.
1826 * @param $fname String Field name
1827 * @param $fvalue mixed New value
1829 public function __set( $fname, $fvalue ) {
1830 if ( property_exists( $this->mPage
, $fname ) ) {
1831 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1832 $this->mPage
->$fname = $fvalue;
1833 // Note: extensions may want to toss on new fields
1834 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1835 $this->mPage
->$fname = $fvalue;
1837 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1842 * Use PHP's magic __call handler to transform instance calls to
1843 * WikiPage functions for backwards compatibility.
1845 * @param $fname String Name of called method
1846 * @param $args Array Arguments to the method
1849 public function __call( $fname, $args ) {
1850 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1851 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1852 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1854 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1857 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1860 * @param $limit array
1861 * @param $expiry array
1862 * @param $cascade bool
1863 * @param $reason string
1867 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1868 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1872 * @param $limit array
1873 * @param $reason string
1874 * @param $cascade int
1875 * @param $expiry array
1878 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1879 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1883 * @param $reason string
1884 * @param $suppress bool
1886 * @param $commit bool
1887 * @param $error string
1890 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1891 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1899 * @param $resultDetails
1903 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1904 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
1905 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1912 * @param $resultDetails
1913 * @param $guser User
1916 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1917 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
1918 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1922 * @param $hasHistory bool
1925 public function generateReason( &$hasHistory ) {
1926 $title = $this->mPage
->getTitle();
1927 $handler = ContentHandler
::getForTitle( $title );
1928 return $handler->getAutoDeleteReason( $title, $hasHistory );
1931 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1936 public static function selectFields() {
1937 return WikiPage
::selectFields();
1941 * @param $title Title
1943 public static function onArticleCreate( $title ) {
1944 WikiPage
::onArticleCreate( $title );
1948 * @param $title Title
1950 public static function onArticleDelete( $title ) {
1951 WikiPage
::onArticleDelete( $title );
1955 * @param $title Title
1957 public static function onArticleEdit( $title ) {
1958 WikiPage
::onArticleEdit( $title );
1966 * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
1968 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1969 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );