3 * User interface for page actions.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Class for viewing MediaWiki article and history.
26 * This maintains WikiPage functions for backwards compatibility.
28 * @todo Move and rewrite code to an Action class
30 * See design.txt for an overview.
31 * Note: edit user interface and cache support functions have been
32 * moved to separate EditPage and HTMLFileCache classes.
34 * @internal documentation reviewed 15 Mar 2010
36 class Article
implements Page
{
37 /** @var IContextSource The context this Article is executed in */
40 /** @var WikiPage The WikiPage object of this instance */
43 /** @var ParserOptions ParserOptions object for $wgUser articles */
44 public $mParserOptions;
47 * @var string Text of the revision we are working on
53 * @var Content Content of the revision we are working on
56 protected $mContentObject;
58 /** @var bool Is the content ($mContent) already loaded? */
59 protected $mContentLoaded = false;
61 /** @var int|null The oldid of the article that is to be shown, 0 for the current revision */
64 /** @var Title Title from which we were redirected here */
65 protected $mRedirectedFrom = null;
67 /** @var string|bool URL to redirect to or false if none */
68 protected $mRedirectUrl = false;
70 /** @var int Revision ID of revision we are working on */
71 protected $mRevIdFetched = 0;
73 /** @var Revision Revision we are working on */
74 protected $mRevision = null;
76 /** @var ParserOutput */
77 public $mParserOutput;
80 * Constructor and clear the article
81 * @param Title $title Reference to a Title object.
82 * @param int $oldId Revision ID, null to fetch from request, zero for current
84 public function __construct( Title
$title, $oldId = null ) {
85 $this->mOldId
= $oldId;
86 $this->mPage
= $this->newPage( $title );
93 protected function newPage( Title
$title ) {
94 return new WikiPage( $title );
98 * Constructor from a page id
99 * @param int $id Article ID to load
100 * @return Article|null
102 public static function newFromID( $id ) {
103 $t = Title
::newFromID( $id );
104 # @todo FIXME: Doesn't inherit right
105 return $t == null ?
null : new self( $t );
106 # return $t == null ? null : new static( $t ); // PHP 5.3
110 * Create an Article object of the appropriate class for the given page.
112 * @param Title $title
113 * @param IContextSource $context
116 public static function newFromTitle( $title, IContextSource
$context ) {
117 if ( NS_MEDIA
== $title->getNamespace() ) {
118 // FIXME: where should this go?
119 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
123 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page, $context ) );
125 switch ( $title->getNamespace() ) {
127 $page = new ImagePage( $title );
130 $page = new CategoryPage( $title );
133 $page = new Article( $title );
136 $page->setContext( $context );
142 * Create an Article object of the appropriate class for the given page.
144 * @param WikiPage $page
145 * @param IContextSource $context
148 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
149 $article = self
::newFromTitle( $page->getTitle(), $context );
150 $article->mPage
= $page; // override to keep process cached vars
155 * Tell the page view functions that this view was redirected
156 * from another page on the wiki.
159 public function setRedirectedFrom( Title
$from ) {
160 $this->mRedirectedFrom
= $from;
164 * Get the title object of the article
166 * @return Title Title object of this page
168 public function getTitle() {
169 return $this->mPage
->getTitle();
173 * Get the WikiPage object of this instance
178 public function getPage() {
185 public function clear() {
186 $this->mContentLoaded
= false;
188 $this->mRedirectedFrom
= null; # Title object if set
189 $this->mRevIdFetched
= 0;
190 $this->mRedirectUrl
= false;
192 $this->mPage
->clear();
196 * Note that getContent/loadContent do not follow redirects anymore.
197 * If you need to fetch redirectable content easily, try
198 * the shortcut in WikiPage::getRedirectTarget()
200 * This function has side effects! Do not use this function if you
201 * only want the real revision text if any.
203 * @deprecated since 1.21; use WikiPage::getContent() instead
205 * @return string Return the text of this revision
207 public function getContent() {
208 ContentHandler
::deprecated( __METHOD__
, '1.21' );
209 $content = $this->getContentObject();
210 return ContentHandler
::getContentText( $content );
214 * Returns a Content object representing the pages effective display content,
215 * not necessarily the revision's content!
217 * Note that getContent/loadContent do not follow redirects anymore.
218 * If you need to fetch redirectable content easily, try
219 * the shortcut in WikiPage::getRedirectTarget()
221 * This function has side effects! Do not use this function if you
222 * only want the real revision text if any.
224 * @return Content Return the content of this revision
228 protected function getContentObject() {
229 wfProfileIn( __METHOD__
);
231 if ( $this->mPage
->getID() === 0 ) {
232 # If this is a MediaWiki:x message, then load the messages
233 # and return the message value for x.
234 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
235 $text = $this->getTitle()->getDefaultMessageText();
236 if ( $text === false ) {
240 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
242 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
243 $content = new MessageContent( $message, null, 'parsemag' );
246 $this->fetchContentObject();
247 $content = $this->mContentObject
;
250 wfProfileOut( __METHOD__
);
255 * @return int The oldid of the article that is to be shown, 0 for the current revision
257 public function getOldID() {
258 if ( is_null( $this->mOldId
) ) {
259 $this->mOldId
= $this->getOldIDFromRequest();
262 return $this->mOldId
;
266 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
268 * @return int The old id for the request
270 public function getOldIDFromRequest() {
271 $this->mRedirectUrl
= false;
273 $request = $this->getContext()->getRequest();
274 $oldid = $request->getIntOrNull( 'oldid' );
276 if ( $oldid === null ) {
280 if ( $oldid !== 0 ) {
281 # Load the given revision and check whether the page is another one.
282 # In that case, update this instance to reflect the change.
283 if ( $oldid === $this->mPage
->getLatest() ) {
284 $this->mRevision
= $this->mPage
->getRevision();
286 $this->mRevision
= Revision
::newFromId( $oldid );
287 if ( $this->mRevision
!== null ) {
288 // Revision title doesn't match the page title given?
289 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
290 $function = array( get_class( $this->mPage
), 'newFromID' );
291 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
297 if ( $request->getVal( 'direction' ) == 'next' ) {
298 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
301 $this->mRevision
= null;
303 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
305 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
306 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
309 $this->mRevision
= null;
317 * Load the revision (including text) into this object
319 * @deprecated since 1.19; use fetchContent()
321 function loadContent() {
322 wfDeprecated( __METHOD__
, '1.19' );
323 $this->fetchContent();
327 * Get text of an article from database
328 * Does *NOT* follow redirects.
331 * @note This is really internal functionality that should really NOT be
332 * used by other functions. For accessing article content, use the WikiPage
333 * class, especially WikiBase::getContent(). However, a lot of legacy code
334 * uses this method to retrieve page text from the database, so the function
335 * has to remain public for now.
337 * @return string|bool String containing article contents, or false if null
338 * @deprecated since 1.21, use WikiPage::getContent() instead
340 function fetchContent() { #BC cruft!
341 ContentHandler
::deprecated( __METHOD__
, '1.21' );
343 if ( $this->mContentLoaded
&& $this->mContent
) {
344 return $this->mContent
;
347 wfProfileIn( __METHOD__
);
349 $content = $this->fetchContentObject();
352 wfProfileOut( __METHOD__
);
356 // @todo Get rid of mContent everywhere!
357 $this->mContent
= ContentHandler
::getContentText( $content );
358 ContentHandler
::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
360 wfProfileOut( __METHOD__
);
362 return $this->mContent
;
366 * Get text content object
367 * Does *NOT* follow redirects.
368 * @todo When is this null?
370 * @note Code that wants to retrieve page content from the database should
371 * use WikiPage::getContent().
373 * @return Content|null|bool
377 protected function fetchContentObject() {
378 if ( $this->mContentLoaded
) {
379 return $this->mContentObject
;
382 wfProfileIn( __METHOD__
);
384 $this->mContentLoaded
= true;
385 $this->mContent
= null;
387 $oldid = $this->getOldID();
389 # Pre-fill content with error message so that if something
390 # fails we'll have something telling us what we intended.
391 //XXX: this isn't page content but a UI message. horrible.
392 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ), array() );
395 # $this->mRevision might already be fetched by getOldIDFromRequest()
396 if ( !$this->mRevision
) {
397 $this->mRevision
= Revision
::newFromId( $oldid );
398 if ( !$this->mRevision
) {
399 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
400 wfProfileOut( __METHOD__
);
405 if ( !$this->mPage
->getLatest() ) {
406 wfDebug( __METHOD__
. " failed to find page data for title " .
407 $this->getTitle()->getPrefixedText() . "\n" );
408 wfProfileOut( __METHOD__
);
412 $this->mRevision
= $this->mPage
->getRevision();
414 if ( !$this->mRevision
) {
415 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " .
416 $this->mPage
->getLatest() . "\n" );
417 wfProfileOut( __METHOD__
);
422 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
423 // We should instead work with the Revision object when we need it...
424 // Loads if user is allowed
425 $this->mContentObject
= $this->mRevision
->getContent(
426 Revision
::FOR_THIS_USER
,
427 $this->getContext()->getUser()
429 $this->mRevIdFetched
= $this->mRevision
->getId();
431 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
433 wfProfileOut( __METHOD__
);
435 return $this->mContentObject
;
439 * Returns true if the currently-referenced revision is the current edit
440 * to this page (and it exists).
443 public function isCurrent() {
444 # If no oldid, this is the current version.
445 if ( $this->getOldID() == 0 ) {
449 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
453 * Get the fetched Revision object depending on request parameters or null
457 * @return Revision|null
459 public function getRevisionFetched() {
460 $this->fetchContentObject();
462 return $this->mRevision
;
466 * Use this to fetch the rev ID used on page views
468 * @return int Revision ID of last article revision
470 public function getRevIdFetched() {
471 if ( $this->mRevIdFetched
) {
472 return $this->mRevIdFetched
;
474 return $this->mPage
->getLatest();
479 * This is the default action of the index.php entry point: just view the
480 * page of the given title.
482 public function view() {
483 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar, $wgMaxRedirects;
485 wfProfileIn( __METHOD__
);
487 # Get variables from query string
488 # As side effect this will load the revision and update the title
489 # in a revision ID is passed in the request, so this should remain
490 # the first call of this method even if $oldid is used way below.
491 $oldid = $this->getOldID();
493 $user = $this->getContext()->getUser();
494 # Another whitelist check in case getOldID() is altering the title
495 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
496 if ( count( $permErrors ) ) {
497 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
498 wfProfileOut( __METHOD__
);
499 throw new PermissionsError( 'read', $permErrors );
502 $outputPage = $this->getContext()->getOutput();
503 # getOldID() may as well want us to redirect somewhere else
504 if ( $this->mRedirectUrl
) {
505 $outputPage->redirect( $this->mRedirectUrl
);
506 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
507 wfProfileOut( __METHOD__
);
512 # If we got diff in the query, we want to see a diff page instead of the article.
513 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
514 wfDebug( __METHOD__
. ": showing diff page\n" );
515 $this->showDiffPage();
516 wfProfileOut( __METHOD__
);
521 # Set page title (may be overridden by DISPLAYTITLE)
522 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
524 $outputPage->setArticleFlag( true );
525 # Allow frames by default
526 $outputPage->allowClickjacking();
528 $parserCache = ParserCache
::singleton();
530 $parserOptions = $this->getParserOptions();
531 # Render printable version, use printable version cache
532 if ( $outputPage->isPrintable() ) {
533 $parserOptions->setIsPrintable( true );
534 $parserOptions->setEditSection( false );
535 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
536 $parserOptions->setEditSection( false );
539 # Try client and file cache
540 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
542 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
545 # Use the greatest of the page's timestamp or the timestamp of any
546 # redirect in the chain (bug 67849)
547 $timestamp = $this->mPage
->getTouched();
548 if ( isset( $this->mRedirectedFrom
) ) {
549 $timestamp = max( $timestamp, $this->mRedirectedFrom
->getTouched() );
551 # If there can be more than one redirect in the chain, we have
552 # to go through the whole chain too in case an intermediate
553 # redirect was changed.
554 if ( $wgMaxRedirects > 1 ) {
555 $titles = Revision
::newFromTitle( $this->mRedirectedFrom
)
556 ->getContent( Revision
::FOR_THIS_USER
, $user )
557 ->getRedirectChain();
558 $thisTitle = $this->getTitle();
559 foreach ( $titles as $title ) {
560 if ( Title
::compare( $title, $thisTitle ) === 0 ) {
563 $timestamp = max( $timestamp, $title->getTouched() );
568 # Is it client cached?
569 if ( $outputPage->checkLastModified( $timestamp ) ) {
570 wfDebug( __METHOD__
. ": done 304\n" );
571 wfProfileOut( __METHOD__
);
575 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
576 wfDebug( __METHOD__
. ": done file cache\n" );
577 # tell wgOut that output is taken care of
578 $outputPage->disable();
579 $this->mPage
->doViewUpdates( $user, $oldid );
580 wfProfileOut( __METHOD__
);
586 # Should the parser cache be used?
587 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
588 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
589 if ( $user->getStubThreshold() ) {
590 wfIncrStats( 'pcache_miss_stub' );
593 $this->showRedirectedFromHeader();
594 $this->showNamespaceHeader();
596 # Iterate through the possible ways of constructing the output text.
597 # Keep going until $outputDone is set, or we run out of things to do.
600 $this->mParserOutput
= false;
602 while ( !$outputDone && ++
$pass ) {
605 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
608 # Early abort if the page doesn't exist
609 if ( !$this->mPage
->exists() ) {
610 wfDebug( __METHOD__
. ": showing missing article\n" );
611 $this->showMissingArticle();
612 $this->mPage
->doViewUpdates( $user );
613 wfProfileOut( __METHOD__
);
617 # Try the parser cache
618 if ( $useParserCache ) {
619 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
621 if ( $this->mParserOutput
!== false ) {
623 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
624 $this->setOldSubtitle( $oldid );
626 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
628 $outputPage->addParserOutput( $this->mParserOutput
);
629 # Ensure that UI elements requiring revision ID have
630 # the correct version information.
631 $outputPage->setRevisionId( $this->mPage
->getLatest() );
632 # Preload timestamp to avoid a DB hit
633 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
634 if ( $cachedTimestamp !== null ) {
635 $outputPage->setRevisionTimestamp( $cachedTimestamp );
636 $this->mPage
->setTimestamp( $cachedTimestamp );
643 # This will set $this->mRevision if needed
644 $this->fetchContentObject();
646 # Are we looking at an old revision
647 if ( $oldid && $this->mRevision
) {
648 $this->setOldSubtitle( $oldid );
650 if ( !$this->showDeletedRevisionHeader() ) {
651 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
652 wfProfileOut( __METHOD__
);
657 # Ensure that UI elements requiring revision ID have
658 # the correct version information.
659 $outputPage->setRevisionId( $this->getRevIdFetched() );
660 # Preload timestamp to avoid a DB hit
661 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
663 # Pages containing custom CSS or JavaScript get special treatment
664 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
665 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
666 $this->showCssOrJsPage();
668 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
669 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
671 # Allow extensions do their own custom view for certain pages
673 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
674 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
676 # Allow extensions do their own custom view for certain pages
681 # Run the parse, protected by a pool counter
682 wfDebug( __METHOD__
. ": doing uncached parse\n" );
684 $content = $this->getContentObject();
685 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
686 $this->getRevIdFetched(), $useParserCache, $content );
688 if ( !$poolArticleView->execute() ) {
689 $error = $poolArticleView->getError();
691 $outputPage->clearHTML(); // for release() errors
692 $outputPage->enableClientCache( false );
693 $outputPage->setRobotPolicy( 'noindex,nofollow' );
695 $errortext = $error->getWikiText( false, 'view-pool-error' );
696 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
698 # Connection or timeout error
699 wfProfileOut( __METHOD__
);
703 $this->mParserOutput
= $poolArticleView->getParserOutput();
704 $outputPage->addParserOutput( $this->mParserOutput
);
705 if ( $content->getRedirectTarget() ) {
706 $outputPage->addSubtitle(
707 "<span id=\"redirectsub\">" . wfMessage( 'redirectpagesub' )->parse() . "</span>"
711 # Don't cache a dirty ParserOutput object
712 if ( $poolArticleView->getIsDirty() ) {
713 $outputPage->setSquidMaxage( 0 );
714 $outputPage->addHTML( "<!-- parser cache is expired, " .
715 "sending anyway due to pool overload-->\n" );
720 # Should be unreachable, but just in case...
726 # Get the ParserOutput actually *displayed* here.
727 # Note that $this->mParserOutput is the *current* version output.
728 $pOutput = ( $outputDone instanceof ParserOutput
)
729 ?
$outputDone // object fetched by hook
730 : $this->mParserOutput
;
732 # Adjust title for main page & pages with displaytitle
734 $this->adjustDisplayTitle( $pOutput );
737 # For the main page, overwrite the <title> element with the con-
738 # tents of 'pagetitle-view-mainpage' instead of the default (if
740 # This message always exists because it is in the i18n files
741 if ( $this->getTitle()->isMainPage() ) {
742 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
743 if ( !$msg->isDisabled() ) {
744 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
748 # Check for any __NOINDEX__ tags on the page using $pOutput
749 $policy = $this->getRobotPolicy( 'view', $pOutput );
750 $outputPage->setIndexPolicy( $policy['index'] );
751 $outputPage->setFollowPolicy( $policy['follow'] );
753 $this->showViewFooter();
754 $this->mPage
->doViewUpdates( $user, $oldid );
756 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
758 wfProfileOut( __METHOD__
);
762 * Adjust title for pages with displaytitle, -{T|}- or language conversion
763 * @param ParserOutput $pOutput
765 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
766 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
767 $titleText = $pOutput->getTitleText();
768 if ( strval( $titleText ) !== '' ) {
769 $this->getContext()->getOutput()->setPageTitle( $titleText );
774 * Show a diff page according to current request variables. For use within
775 * Article::view() only, other callers should use the DifferenceEngine class.
777 * @todo Make protected
779 public function showDiffPage() {
780 $request = $this->getContext()->getRequest();
781 $user = $this->getContext()->getUser();
782 $diff = $request->getVal( 'diff' );
783 $rcid = $request->getVal( 'rcid' );
784 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
785 $purge = $request->getVal( 'action' ) == 'purge';
786 $unhide = $request->getInt( 'unhide' ) == 1;
787 $oldid = $this->getOldID();
789 $rev = $this->getRevisionFetched();
792 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
793 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
797 $contentHandler = $rev->getContentHandler();
798 $de = $contentHandler->createDifferenceEngine(
807 // DifferenceEngine directly fetched the revision:
808 $this->mRevIdFetched
= $de->mNewid
;
809 $de->showDiffPage( $diffOnly );
811 // Run view updates for the newer revision being diffed (and shown
812 // below the diff if not $diffOnly).
813 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
814 // New can be false, convert it to 0 - this conveniently means the latest revision
815 $this->mPage
->doViewUpdates( $user, (int)$new );
819 * Show a page view for a page formatted as CSS or JavaScript. To be called by
820 * Article::view() only.
822 * This exists mostly to serve the deprecated ShowRawCssJs hook (used to customize these views).
823 * It has been replaced by the ContentGetParserOutput hook, which lets you do the same but with
826 * @param bool $showCacheHint Whether to show a message telling the user
827 * to clear the browser cache (default: true).
829 protected function showCssOrJsPage( $showCacheHint = true ) {
830 $outputPage = $this->getContext()->getOutput();
832 if ( $showCacheHint ) {
833 $dir = $this->getContext()->getLanguage()->getDir();
834 $lang = $this->getContext()->getLanguage()->getCode();
836 $outputPage->wrapWikiMsg(
837 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
842 $this->fetchContentObject();
844 if ( $this->mContentObject
) {
845 // Give hooks a chance to customise the output
846 if ( ContentHandler
::runLegacyHooks(
848 array( $this->mContentObject
, $this->getTitle(), $outputPage ) )
850 // If no legacy hooks ran, display the content of the parser output, including RL modules,
851 // but excluding metadata like categories and language links
852 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
853 $outputPage->addParserOutputContent( $po );
859 * Get the robot policy to be used for the current view
860 * @param string $action The action= GET parameter
861 * @param ParserOutput|null $pOutput
862 * @return array The policy that should be set
863 * @todo actions other than 'view'
865 public function getRobotPolicy( $action, $pOutput = null ) {
866 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
868 $ns = $this->getTitle()->getNamespace();
870 # Don't index user and user talk pages for blocked users (bug 11443)
871 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
872 $specificTarget = null;
874 $titleText = $this->getTitle()->getText();
875 if ( IP
::isValid( $titleText ) ) {
876 $vagueTarget = $titleText;
878 $specificTarget = $titleText;
880 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
882 'index' => 'noindex',
883 'follow' => 'nofollow'
888 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
889 # Non-articles (special pages etc), and old revisions
891 'index' => 'noindex',
892 'follow' => 'nofollow'
894 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
895 # Discourage indexing of printable versions, but encourage following
897 'index' => 'noindex',
900 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
901 # For ?curid=x urls, disallow indexing
903 'index' => 'noindex',
908 # Otherwise, construct the policy based on the various config variables.
909 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
911 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
912 # Honour customised robot policies for this namespace
913 $policy = array_merge(
915 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
918 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
919 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
920 # a final sanity check that we have really got the parser output.
921 $policy = array_merge(
923 array( 'index' => $pOutput->getIndexPolicy() )
927 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
928 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
929 $policy = array_merge(
931 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
939 * Converts a String robot policy into an associative array, to allow
940 * merging of several policies using array_merge().
941 * @param array|string $policy Returns empty array on null/false/'', transparent
942 * to already-converted arrays, converts string.
943 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
945 public static function formatRobotPolicy( $policy ) {
946 if ( is_array( $policy ) ) {
948 } elseif ( !$policy ) {
952 $policy = explode( ',', $policy );
953 $policy = array_map( 'trim', $policy );
956 foreach ( $policy as $var ) {
957 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
958 $arr['index'] = $var;
959 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
960 $arr['follow'] = $var;
968 * If this request is a redirect view, send "redirected from" subtitle to
969 * the output. Returns true if the header was needed, false if this is not
970 * a redirect view. Handles both local and remote redirects.
974 public function showRedirectedFromHeader() {
975 global $wgRedirectSources;
976 $outputPage = $this->getContext()->getOutput();
978 $request = $this->getContext()->getRequest();
979 $rdfrom = $request->getVal( 'rdfrom' );
981 // Construct a URL for the current page view, but with the target title
982 $query = $request->getValues();
983 unset( $query['rdfrom'] );
984 unset( $query['title'] );
985 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
987 if ( isset( $this->mRedirectedFrom
) ) {
988 // This is an internally redirected page view.
989 // We'll need a backlink to the source page for navigation.
990 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
991 $redir = Linker
::linkKnown(
992 $this->mRedirectedFrom
,
995 array( 'redirect' => 'no' )
998 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1000 // Add the script to update the displayed URL and
1001 // set the fragment if one was specified in the redirect
1002 $outputPage->addJsConfigVars( array(
1003 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1005 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1007 // Add a <link rel="canonical"> tag
1008 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
1010 // Tell the output object that the user arrived at this article through a redirect
1011 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1015 } elseif ( $rdfrom ) {
1016 // This is an externally redirected view, from some other wiki.
1017 // If it was reported from a trusted site, supply a backlink.
1018 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1019 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1020 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1022 // Add the script to update the displayed URL
1023 $outputPage->addJsConfigVars( array(
1024 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1026 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1036 * Show a header specific to the namespace currently being viewed, like
1037 * [[MediaWiki:Talkpagetext]]. For Article::view().
1039 public function showNamespaceHeader() {
1040 if ( $this->getTitle()->isTalkPage() ) {
1041 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1042 $this->getContext()->getOutput()->wrapWikiMsg(
1043 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1044 array( 'talkpageheader' )
1051 * Show the footer section of an ordinary page view
1053 public function showViewFooter() {
1054 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1055 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1056 && IP
::isValid( $this->getTitle()->getText() )
1058 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1061 // Show a footer allowing the user to patrol the shown revision or page if possible
1062 $patrolFooterShown = $this->showPatrolFooter();
1064 wfRunHooks( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1068 * If patrol is possible, output a patrol UI box. This is called from the
1069 * footer section of ordinary page views. If patrol is not possible or not
1070 * desired, does nothing.
1071 * Side effect: When the patrol link is build, this method will call
1072 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1076 public function showPatrolFooter() {
1077 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1079 $outputPage = $this->getContext()->getOutput();
1080 $user = $this->getContext()->getUser();
1081 $cache = wfGetMainCache();
1084 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1085 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1087 // Patrolling is disabled or the user isn't allowed to
1091 wfProfileIn( __METHOD__
);
1093 // New page patrol: Get the timestamp of the oldest revison which
1094 // the revision table holds for the given page. Then we look
1095 // whether it's within the RC lifespan and if it is, we try
1096 // to get the recentchanges row belonging to that entry
1097 // (with rc_new = 1).
1099 // Check for cached results
1100 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1101 wfProfileOut( __METHOD__
);
1105 if ( $this->mRevision
1106 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1108 // The current revision is already older than what could be in the RC table
1109 // 6h tolerance because the RC might not be cleaned out regularly
1110 wfProfileOut( __METHOD__
);
1114 $dbr = wfGetDB( DB_SLAVE
);
1115 $oldestRevisionTimestamp = $dbr->selectField(
1117 'MIN( rev_timestamp )',
1118 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1122 if ( $oldestRevisionTimestamp
1123 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1125 // 6h tolerance because the RC might not be cleaned out regularly
1126 $rc = RecentChange
::newFromConds(
1129 'rc_timestamp' => $oldestRevisionTimestamp,
1130 'rc_namespace' => $this->getTitle()->getNamespace(),
1131 'rc_cur_id' => $this->getTitle()->getArticleID(),
1135 array( 'USE INDEX' => 'new_name_timestamp' )
1140 // No RC entry around
1142 // Cache the information we gathered above in case we can't patrol
1143 // Don't cache in case we can patrol as this could change
1144 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1146 wfProfileOut( __METHOD__
);
1150 if ( $rc->getPerformer()->getName() == $user->getName() ) {
1151 // Don't show a patrol link for own creations. If the user could
1152 // patrol them, they already would be patrolled
1153 wfProfileOut( __METHOD__
);
1157 $rcid = $rc->getAttribute( 'rc_id' );
1159 $token = $user->getEditToken( $rcid );
1161 $outputPage->preventClickjacking();
1162 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1163 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1166 $link = Linker
::linkKnown(
1168 wfMessage( 'markaspatrolledtext' )->escaped(),
1171 'action' => 'markpatrolled',
1177 $outputPage->addHTML(
1178 "<div class='patrollink'>" .
1179 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1183 wfProfileOut( __METHOD__
);
1188 * Show the error text for a missing article. For articles in the MediaWiki
1189 * namespace, show the default message text. To be called from Article::view().
1191 public function showMissingArticle() {
1192 global $wgSend404Code;
1193 $outputPage = $this->getContext()->getOutput();
1194 // Whether the page is a root user page of an existing user (but not a subpage)
1195 $validUserPage = false;
1197 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1198 if ( $this->getTitle()->getNamespace() == NS_USER
1199 ||
$this->getTitle()->getNamespace() == NS_USER_TALK
1201 $parts = explode( '/', $this->getTitle()->getText() );
1202 $rootPart = $parts[0];
1203 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1204 $ip = User
::isIP( $rootPart );
1205 $block = Block
::newFromTarget( $user, $user );
1207 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1208 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1209 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1210 } elseif ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) { # Show log extract if the user is currently blocked
1211 LogEventsList
::showLogExtract(
1214 MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget(),
1218 'showIfEmpty' => false,
1220 'blocked-notice-logextract',
1221 $user->getName() # Support GENDER in notice
1225 $validUserPage = !$this->getTitle()->isSubpage();
1227 $validUserPage = !$this->getTitle()->isSubpage();
1231 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1233 // Give extensions a chance to hide their (unrelated) log entries
1234 $logTypes = array( 'delete', 'move' );
1235 $conds = array( "log_action != 'revision'" );
1236 wfRunHooks( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1238 # Show delete and move logs
1239 LogEventsList
::showLogExtract( $outputPage, $logTypes, $this->getTitle(), '',
1242 'showIfEmpty' => false,
1243 'msgKey' => array( 'moveddeleted-notice' ) )
1246 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1247 // If there's no backing content, send a 404 Not Found
1248 // for better machine handling of broken links.
1249 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1252 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1253 $policy = $this->getRobotPolicy( 'view' );
1254 $outputPage->setIndexPolicy( $policy['index'] );
1255 $outputPage->setFollowPolicy( $policy['follow'] );
1257 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1259 if ( !$hookResult ) {
1263 # Show error message
1264 $oldid = $this->getOldID();
1266 $text = wfMessage( 'missing-revision', $oldid )->plain();
1267 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1268 // Use the default message text
1269 $text = $this->getTitle()->getDefaultMessageText();
1270 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1271 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1273 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1274 $text = wfMessage( $message )->plain();
1276 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1278 $text = "<div class='noarticletext'>\n$text\n</div>";
1280 $outputPage->addWikiText( $text );
1284 * If the revision requested for view is deleted, check permissions.
1285 * Send either an error message or a warning header to the output.
1287 * @return bool True if the view is allowed, false if not.
1289 public function showDeletedRevisionHeader() {
1290 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1295 $outputPage = $this->getContext()->getOutput();
1296 $user = $this->getContext()->getUser();
1297 // If the user is not allowed to see it...
1298 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1299 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1300 'rev-deleted-text-permission' );
1303 // If the user needs to confirm that they want to see it...
1304 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1305 # Give explanation and add a link to view the revision...
1306 $oldid = intval( $this->getOldID() );
1307 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1308 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1309 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1310 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1311 array( $msg, $link ) );
1314 // We are allowed to see...
1316 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1317 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1318 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1325 * Generate the navigation links when browsing through an article revisions
1326 * It shows the information as:
1327 * Revision as of \<date\>; view current revision
1328 * \<- Previous version | Next Version -\>
1330 * @param int $oldid Revision ID of this article revision
1332 public function setOldSubtitle( $oldid = 0 ) {
1333 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1337 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1339 # Cascade unhide param in links for easy deletion browsing
1340 $extraParams = array();
1342 $extraParams['unhide'] = 1;
1345 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1346 $revision = $this->mRevision
;
1348 $revision = Revision
::newFromId( $oldid );
1351 $timestamp = $revision->getTimestamp();
1353 $current = ( $oldid == $this->mPage
->getLatest() );
1354 $language = $this->getContext()->getLanguage();
1355 $user = $this->getContext()->getUser();
1357 $td = $language->userTimeAndDate( $timestamp, $user );
1358 $tddate = $language->userDate( $timestamp, $user );
1359 $tdtime = $language->userTime( $timestamp, $user );
1361 # Show user links if allowed to see them. If hidden, then show them only if requested...
1362 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1364 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1365 ?
'revision-info-current'
1368 $outputPage = $this->getContext()->getOutput();
1369 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1370 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1371 $tdtime, $revision->getUserText() )->rawParams( Linker
::revComment( $revision, true, true ) )->parse() . "</div>" );
1374 ?
wfMessage( 'currentrevisionlink' )->escaped()
1375 : Linker
::linkKnown(
1377 wfMessage( 'currentrevisionlink' )->escaped(),
1382 ?
wfMessage( 'diff' )->escaped()
1383 : Linker
::linkKnown(
1385 wfMessage( 'diff' )->escaped(),
1392 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1394 ? Linker
::linkKnown(
1396 wfMessage( 'previousrevision' )->escaped(),
1399 'direction' => 'prev',
1403 : wfMessage( 'previousrevision' )->escaped();
1405 ? Linker
::linkKnown(
1407 wfMessage( 'diff' )->escaped(),
1414 : wfMessage( 'diff' )->escaped();
1415 $nextlink = $current
1416 ?
wfMessage( 'nextrevision' )->escaped()
1417 : Linker
::linkKnown(
1419 wfMessage( 'nextrevision' )->escaped(),
1422 'direction' => 'next',
1426 $nextdiff = $current
1427 ?
wfMessage( 'diff' )->escaped()
1428 : Linker
::linkKnown(
1430 wfMessage( 'diff' )->escaped(),
1438 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1439 if ( $cdel !== '' ) {
1443 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1444 wfMessage( 'revision-nav' )->rawParams(
1445 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1446 )->escaped() . "</div>" );
1450 * Return the HTML for the top of a redirect page
1452 * Chances are you should just be using the ParserOutput from
1453 * WikitextContent::getParserOutput instead of calling this for redirects.
1455 * @param Title|array $target Destination(s) to redirect
1456 * @param bool $appendSubtitle [optional]
1457 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1458 * @return string Containing HMTL with redirect link
1460 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1461 $lang = $this->getTitle()->getPageLanguage();
1462 if ( $appendSubtitle ) {
1463 $out = $this->getContext()->getOutput();
1464 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1466 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1470 * Return the HTML for the top of a redirect page
1472 * Chances are you should just be using the ParserOutput from
1473 * WikitextContent::getParserOutput instead of calling this for redirects.
1476 * @param Language $lang
1477 * @param Title|array $target Destination(s) to redirect
1478 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1479 * @return string Containing HMTL with redirect link
1481 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1482 global $wgStylePath;
1484 if ( !is_array( $target ) ) {
1485 $target = array( $target );
1488 $imageDir = $lang->getDir();
1490 // the loop prepends the arrow image before the link, so the first case needs to be outside
1492 /** @var $title Title */
1493 $title = array_shift( $target );
1495 if ( $forceKnown ) {
1496 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1498 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1501 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1502 $alt = $lang->isRTL() ?
'←' : '→';
1504 // Automatically append redirect=no to each link, since most of them are
1505 // redirect pages themselves.
1506 /** @var Title $rt */
1507 foreach ( $target as $rt ) {
1508 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1509 if ( $forceKnown ) {
1510 $link .= Linker
::linkKnown(
1512 htmlspecialchars( $rt->getFullText(),
1514 array( 'redirect' => 'no' )
1518 $link .= Linker
::link(
1520 htmlspecialchars( $rt->getFullText() ),
1522 array( 'redirect' => 'no' )
1527 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1528 return '<div class="redirectMsg">' .
1529 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1530 '<span class="redirectText">' . $link . '</span></div>';
1534 * Handle action=render
1536 public function render() {
1537 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1538 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1539 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1544 * action=protect handler
1546 public function protect() {
1547 $form = new ProtectionForm( $this );
1552 * action=unprotect handler (alias)
1554 public function unprotect() {
1559 * UI entry point for page deletion
1561 public function delete() {
1562 # This code desperately needs to be totally rewritten
1564 $title = $this->getTitle();
1565 $user = $this->getContext()->getUser();
1568 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1569 if ( count( $permissionErrors ) ) {
1570 throw new PermissionsError( 'delete', $permissionErrors );
1573 # Read-only check...
1574 if ( wfReadOnly() ) {
1575 throw new ReadOnlyError
;
1578 # Better double-check that it hasn't been deleted yet!
1579 $this->mPage
->loadPageData( 'fromdbmaster' );
1580 if ( !$this->mPage
->exists() ) {
1581 $deleteLogPage = new LogPage( 'delete' );
1582 $outputPage = $this->getContext()->getOutput();
1583 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1584 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1585 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1587 $outputPage->addHTML(
1588 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1590 LogEventsList
::showLogExtract(
1599 $request = $this->getContext()->getRequest();
1600 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1601 $deleteReason = $request->getText( 'wpReason' );
1603 if ( $deleteReasonList == 'other' ) {
1604 $reason = $deleteReason;
1605 } elseif ( $deleteReason != '' ) {
1606 // Entry from drop down menu + additional comment
1607 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1608 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1610 $reason = $deleteReasonList;
1613 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1614 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1616 # Flag to hide all contents of the archived revisions
1617 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1619 $this->doDelete( $reason, $suppress );
1621 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1626 // Generate deletion reason
1627 $hasHistory = false;
1630 $reason = $this->generateReason( $hasHistory );
1631 } catch ( MWException
$e ) {
1632 # if a page is horribly broken, we still want to be able to
1633 # delete it. So be lenient about errors here.
1634 wfDebug( "Error while building auto delete summary: $e" );
1639 // If the page has a history, insert a warning
1640 if ( $hasHistory ) {
1641 $title = $this->getTitle();
1643 // The following can use the real revision count as this is only being shown for users that can delete
1645 // This, as a side-effect, also makes sure that the following query isn't being run for pages with a
1646 // larger history, unless the user has the 'bigdelete' right (and is about to delete this page).
1647 $dbr = wfGetDB( DB_SLAVE
);
1648 $revisions = $edits = (int)$dbr->selectField(
1651 array( 'rev_page' => $title->getArticleID() ),
1655 // @todo FIXME: i18n issue/patchwork message
1656 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1657 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1658 wfMessage( 'word-separator' )->plain() . Linker
::linkKnown( $title,
1659 wfMessage( 'history' )->escaped(),
1660 array( 'rel' => 'archives' ),
1661 array( 'action' => 'history' ) ) .
1665 if ( $title->isBigDeletion() ) {
1666 global $wgDeleteRevisionsLimit;
1667 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1669 'delete-warning-toobig',
1670 $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1676 $this->confirmDelete( $reason );
1680 * Output deletion confirmation dialog
1681 * @todo FIXME: Move to another file?
1682 * @param string $reason Prefilled reason
1684 public function confirmDelete( $reason ) {
1685 wfDebug( "Article::confirmDelete\n" );
1687 $title = $this->getTitle();
1688 $outputPage = $this->getContext()->getOutput();
1689 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1690 $outputPage->addBacklinkSubtitle( $title );
1691 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1692 $backlinkCache = $title->getBacklinkCache();
1693 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1694 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1695 'deleting-backlinks-warning' );
1697 $outputPage->addWikiMsg( 'confirmdeletetext' );
1699 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1701 $user = $this->getContext()->getUser();
1703 if ( $user->isAllowed( 'suppressrevision' ) ) {
1704 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1706 <td class='mw-input'><strong>" .
1707 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1708 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1714 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1716 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1717 'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1718 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1719 Xml
::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1720 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1721 "<tr id=\"wpDeleteReasonListRow\">
1722 <td class='mw-label'>" .
1723 Xml
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1725 <td class='mw-input'>" .
1727 'wpDeleteReasonList',
1728 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1729 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1736 <tr id=\"wpDeleteReasonRow\">
1737 <td class='mw-label'>" .
1738 Xml
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1740 <td class='mw-input'>" .
1741 Html
::input( 'wpReason', $reason, 'text', array(
1743 'maxlength' => '255',
1751 # Disallow watching if user is not logged in
1752 if ( $user->isLoggedIn() ) {
1756 <td class='mw-input'>" .
1757 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1758 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1767 <td class='mw-submit'>" .
1768 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1769 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1772 Xml
::closeElement( 'table' ) .
1773 Xml
::closeElement( 'fieldset' ) .
1776 $user->getEditToken( array( 'delete', $title->getPrefixedText() ) )
1778 Xml
::closeElement( 'form' );
1780 if ( $user->isAllowed( 'editinterface' ) ) {
1781 $dropdownTitle = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1782 $link = Linker
::link(
1784 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1786 array( 'action' => 'edit' )
1788 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1791 $outputPage->addHTML( $form );
1793 $deleteLogPage = new LogPage( 'delete' );
1794 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1795 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
1799 * Perform a deletion and output success or failure messages
1800 * @param string $reason
1801 * @param bool $suppress
1803 public function doDelete( $reason, $suppress = false ) {
1805 $outputPage = $this->getContext()->getOutput();
1806 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1808 if ( $status->isGood() ) {
1809 $deleted = $this->getTitle()->getPrefixedText();
1811 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1812 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1814 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1816 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1817 $outputPage->returnToMain( false );
1819 $outputPage->setPageTitle(
1820 wfMessage( 'cannotdelete-title',
1821 $this->getTitle()->getPrefixedText() )
1824 if ( $error == '' ) {
1825 $outputPage->addWikiText(
1826 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1828 $deleteLogPage = new LogPage( 'delete' );
1829 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1831 LogEventsList
::showLogExtract(
1837 $outputPage->addHTML( $error );
1842 /* Caching functions */
1845 * checkLastModified returns true if it has taken care of all
1846 * output to the client that is necessary for this request.
1847 * (that is, it has sent a cached version of the page)
1849 * @return bool True if cached version send, false otherwise
1851 protected function tryFileCache() {
1852 static $called = false;
1855 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1860 if ( $this->isFileCacheable() ) {
1861 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1862 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1863 wfDebug( "Article::tryFileCache(): about to load file\n" );
1864 $cache->loadFromFileCache( $this->getContext() );
1867 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1868 ob_start( array( &$cache, 'saveToFileCache' ) );
1871 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1878 * Check if the page can be cached
1881 public function isFileCacheable() {
1884 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1885 $cacheable = $this->mPage
->getID()
1886 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1887 // Extension may have reason to disable file caching on some pages.
1889 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1899 * Lightweight method to get the parser output for a page, checking the parser cache
1900 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1901 * consider, so it's not appropriate to use there.
1903 * @since 1.16 (r52326) for LiquidThreads
1905 * @param int|null $oldid Revision ID or null
1906 * @param User $user The relevant user
1907 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1909 public function getParserOutput( $oldid = null, User
$user = null ) {
1910 //XXX: bypasses mParserOptions and thus setParserOptions()
1912 if ( $user === null ) {
1913 $parserOptions = $this->getParserOptions();
1915 $parserOptions = $this->mPage
->makeParserOptions( $user );
1918 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1922 * Override the ParserOptions used to render the primary article wikitext.
1924 * @param ParserOptions $options
1925 * @throws MWException If the parser options where already initialized.
1927 public function setParserOptions( ParserOptions
$options ) {
1928 if ( $this->mParserOptions
) {
1929 throw new MWException( "can't change parser options after they have already been set" );
1932 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1933 $this->mParserOptions
= clone $options;
1937 * Get parser options suitable for rendering the primary article wikitext
1938 * @return ParserOptions
1940 public function getParserOptions() {
1941 if ( !$this->mParserOptions
) {
1942 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1944 // Clone to allow modifications of the return value without affecting cache
1945 return clone $this->mParserOptions
;
1949 * Sets the context this Article is executed in
1951 * @param IContextSource $context
1954 public function setContext( $context ) {
1955 $this->mContext
= $context;
1959 * Gets the context this Article is executed in
1961 * @return IContextSource
1964 public function getContext() {
1965 if ( $this->mContext
instanceof IContextSource
) {
1966 return $this->mContext
;
1968 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1969 "Return RequestContext::getMain(); for sanity\n" );
1970 return RequestContext
::getMain();
1975 * Use PHP's magic __get handler to handle accessing of
1976 * raw WikiPage fields for backwards compatibility.
1978 * @param string $fname Field name
1981 public function __get( $fname ) {
1982 if ( property_exists( $this->mPage
, $fname ) ) {
1983 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1984 return $this->mPage
->$fname;
1986 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1990 * Use PHP's magic __set handler to handle setting of
1991 * raw WikiPage fields for backwards compatibility.
1993 * @param string $fname Field name
1994 * @param mixed $fvalue New value
1996 public function __set( $fname, $fvalue ) {
1997 if ( property_exists( $this->mPage
, $fname ) ) {
1998 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1999 $this->mPage
->$fname = $fvalue;
2000 // Note: extensions may want to toss on new fields
2001 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2002 $this->mPage
->$fname = $fvalue;
2004 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2009 * Use PHP's magic __call handler to transform instance calls to
2010 * WikiPage functions for backwards compatibility.
2012 * @param string $fname Name of called method
2013 * @param array $args Arguments to the method
2016 public function __call( $fname, $args ) {
2017 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2018 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2019 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2021 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2024 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2027 * @param array $limit
2028 * @param array $expiry
2029 * @param bool $cascade
2030 * @param string $reason
2034 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2037 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2041 * @param array $limit
2042 * @param string $reason
2043 * @param int $cascade
2044 * @param array $expiry
2047 public function updateRestrictions( $limit = array(), $reason = '',
2048 &$cascade = 0, $expiry = array()
2050 return $this->mPage
->doUpdateRestrictions(
2055 $this->getContext()->getUser()
2060 * @param string $reason
2061 * @param bool $suppress
2063 * @param bool $commit
2064 * @param string $error
2067 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2068 $commit = true, &$error = ''
2070 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2074 * @param string $fromP
2075 * @param string $summary
2076 * @param string $token
2078 * @param array $resultDetails
2079 * @param User|null $user
2082 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2083 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2084 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2088 * @param string $fromP
2089 * @param string $summary
2091 * @param array $resultDetails
2092 * @param User|null $guser
2095 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2096 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2097 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2101 * @param bool $hasHistory
2104 public function generateReason( &$hasHistory ) {
2105 $title = $this->mPage
->getTitle();
2106 $handler = ContentHandler
::getForTitle( $title );
2107 return $handler->getAutoDeleteReason( $title, $hasHistory );
2110 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2115 * @deprecated since 1.24, use WikiPage::selectFields() instead
2117 public static function selectFields() {
2118 wfDeprecated( __METHOD__
, '1.24' );
2119 return WikiPage
::selectFields();
2123 * @param Title $title
2125 * @deprecated since 1.24, use WikiPage::onArticleCreate() instead
2127 public static function onArticleCreate( $title ) {
2128 wfDeprecated( __METHOD__
, '1.24' );
2129 WikiPage
::onArticleCreate( $title );
2133 * @param Title $title
2135 * @deprecated since 1.24, use WikiPage::onArticleDelete() instead
2137 public static function onArticleDelete( $title ) {
2138 wfDeprecated( __METHOD__
, '1.24' );
2139 WikiPage
::onArticleDelete( $title );
2143 * @param Title $title
2145 * @deprecated since 1.24, use WikiPage::onArticleEdit() instead
2147 public static function onArticleEdit( $title ) {
2148 wfDeprecated( __METHOD__
, '1.24' );
2149 WikiPage
::onArticleEdit( $title );
2153 * @param string $oldtext
2154 * @param string $newtext
2157 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2159 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2160 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );