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 class Article
implements Page
{
35 /** @var IContextSource The context this Article is executed in */
38 /** @var WikiPage The WikiPage object of this instance */
41 /** @var ParserOptions ParserOptions object for $wgUser articles */
42 public $mParserOptions;
45 * @var string Text of the revision we are working on
51 * @var Content Content of the revision we are working on
54 public $mContentObject;
56 /** @var bool Is the content ($mContent) already loaded? */
57 public $mContentLoaded = false;
59 /** @var int|null The oldid of the article that is to be shown, 0 for the current revision */
62 /** @var Title Title from which we were redirected here */
63 public $mRedirectedFrom = null;
65 /** @var string|bool URL to redirect to or false if none */
66 public $mRedirectUrl = false;
68 /** @var int Revision ID of revision we are working on */
69 public $mRevIdFetched = 0;
71 /** @var Revision Revision we are working on */
72 public $mRevision = null;
74 /** @var ParserOutput */
75 public $mParserOutput;
78 * Constructor and clear the article
79 * @param Title $title Reference to a Title object.
80 * @param int $oldId Revision ID, null to fetch from request, zero for current
82 public function __construct( Title
$title, $oldId = null ) {
83 $this->mOldId
= $oldId;
84 $this->mPage
= $this->newPage( $title );
91 protected function newPage( Title
$title ) {
92 return new WikiPage( $title );
96 * Constructor from a page id
97 * @param int $id Article ID to load
98 * @return Article|null
100 public static function newFromID( $id ) {
101 $t = Title
::newFromID( $id );
102 # @todo FIXME: Doesn't inherit right
103 return $t == null ?
null : new self( $t );
104 # return $t == null ? null : new static( $t ); // PHP 5.3
108 * Create an Article object of the appropriate class for the given page.
110 * @param Title $title
111 * @param IContextSource $context
114 public static function newFromTitle( $title, IContextSource
$context ) {
115 if ( NS_MEDIA
== $title->getNamespace() ) {
116 // FIXME: where should this go?
117 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
121 Hooks
::run( 'ArticleFromTitle', array( &$title, &$page, $context ) );
123 switch ( $title->getNamespace() ) {
125 $page = new ImagePage( $title );
128 $page = new CategoryPage( $title );
131 $page = new Article( $title );
134 $page->setContext( $context );
140 * Create an Article object of the appropriate class for the given page.
142 * @param WikiPage $page
143 * @param IContextSource $context
146 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
147 $article = self
::newFromTitle( $page->getTitle(), $context );
148 $article->mPage
= $page; // override to keep process cached vars
153 * Tell the page view functions that this view was redirected
154 * from another page on the wiki.
157 public function setRedirectedFrom( Title
$from ) {
158 $this->mRedirectedFrom
= $from;
162 * Get the title object of the article
164 * @return Title Title object of this page
166 public function getTitle() {
167 return $this->mPage
->getTitle();
171 * Get the WikiPage object of this instance
176 public function getPage() {
183 public function clear() {
184 $this->mContentLoaded
= false;
186 $this->mRedirectedFrom
= null; # Title object if set
187 $this->mRevIdFetched
= 0;
188 $this->mRedirectUrl
= false;
190 $this->mPage
->clear();
194 * Note that getContent/loadContent do not follow redirects anymore.
195 * If you need to fetch redirectable content easily, try
196 * the shortcut in WikiPage::getRedirectTarget()
198 * This function has side effects! Do not use this function if you
199 * only want the real revision text if any.
201 * @deprecated since 1.21; use WikiPage::getContent() instead
203 * @return string Return the text of this revision
205 public function getContent() {
206 ContentHandler
::deprecated( __METHOD__
, '1.21' );
207 $content = $this->getContentObject();
208 return ContentHandler
::getContentText( $content );
212 * Returns a Content object representing the pages effective display content,
213 * not necessarily the revision's content!
215 * Note that getContent/loadContent do not follow redirects anymore.
216 * If you need to fetch redirectable content easily, try
217 * the shortcut in WikiPage::getRedirectTarget()
219 * This function has side effects! Do not use this function if you
220 * only want the real revision text if any.
222 * @return Content Return the content of this revision
226 protected function getContentObject() {
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 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
240 $content = new MessageContent( $message, null, 'parsemag' );
243 $this->fetchContentObject();
244 $content = $this->mContentObject
;
251 * @return int The oldid of the article that is to be shown, 0 for the current revision
253 public function getOldID() {
254 if ( is_null( $this->mOldId
) ) {
255 $this->mOldId
= $this->getOldIDFromRequest();
258 return $this->mOldId
;
262 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
264 * @return int The old id for the request
266 public function getOldIDFromRequest() {
267 $this->mRedirectUrl
= false;
269 $request = $this->getContext()->getRequest();
270 $oldid = $request->getIntOrNull( 'oldid' );
272 if ( $oldid === null ) {
276 if ( $oldid !== 0 ) {
277 # Load the given revision and check whether the page is another one.
278 # In that case, update this instance to reflect the change.
279 if ( $oldid === $this->mPage
->getLatest() ) {
280 $this->mRevision
= $this->mPage
->getRevision();
282 $this->mRevision
= Revision
::newFromId( $oldid );
283 if ( $this->mRevision
!== null ) {
284 // Revision title doesn't match the page title given?
285 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
286 $function = array( get_class( $this->mPage
), 'newFromID' );
287 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
293 if ( $request->getVal( 'direction' ) == 'next' ) {
294 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
297 $this->mRevision
= null;
299 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
301 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
302 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
305 $this->mRevision
= null;
313 * Load the revision (including text) into this object
315 * @deprecated since 1.19; use fetchContent()
317 function loadContent() {
318 wfDeprecated( __METHOD__
, '1.19' );
319 $this->fetchContent();
323 * Get text of an article from database
324 * Does *NOT* follow redirects.
327 * @note This is really internal functionality that should really NOT be
328 * used by other functions. For accessing article content, use the WikiPage
329 * class, especially WikiBase::getContent(). However, a lot of legacy code
330 * uses this method to retrieve page text from the database, so the function
331 * has to remain public for now.
333 * @return string|bool String containing article contents, or false if null
334 * @deprecated since 1.21, use WikiPage::getContent() instead
336 function fetchContent() {
339 ContentHandler
::deprecated( __METHOD__
, '1.21' );
341 if ( $this->mContentLoaded
&& $this->mContent
) {
342 return $this->mContent
;
345 $content = $this->fetchContentObject();
351 // @todo Get rid of mContent everywhere!
352 $this->mContent
= ContentHandler
::getContentText( $content );
353 ContentHandler
::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
355 return $this->mContent
;
359 * Get text content object
360 * Does *NOT* follow redirects.
361 * @todo When is this null?
363 * @note Code that wants to retrieve page content from the database should
364 * use WikiPage::getContent().
366 * @return Content|null|bool
370 protected function fetchContentObject() {
371 if ( $this->mContentLoaded
) {
372 return $this->mContentObject
;
375 $this->mContentLoaded
= true;
376 $this->mContent
= null;
378 $oldid = $this->getOldID();
380 # Pre-fill content with error message so that if something
381 # fails we'll have something telling us what we intended.
382 //XXX: this isn't page content but a UI message. horrible.
383 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ) );
386 # $this->mRevision might already be fetched by getOldIDFromRequest()
387 if ( !$this->mRevision
) {
388 $this->mRevision
= Revision
::newFromId( $oldid );
389 if ( !$this->mRevision
) {
390 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
395 $oldid = $this->mPage
->getLatest();
397 wfDebug( __METHOD__
. " failed to find page data for title " .
398 $this->getTitle()->getPrefixedText() . "\n" );
402 # Update error message with correct oldid
403 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ) );
405 $this->mRevision
= $this->mPage
->getRevision();
407 if ( !$this->mRevision
) {
408 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id $oldid\n" );
413 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
414 // We should instead work with the Revision object when we need it...
415 // Loads if user is allowed
416 $content = $this->mRevision
->getContent(
417 Revision
::FOR_THIS_USER
,
418 $this->getContext()->getUser()
422 wfDebug( __METHOD__
. " failed to retrieve content of revision " .
423 $this->mRevision
->getId() . "\n" );
427 $this->mContentObject
= $content;
428 $this->mRevIdFetched
= $this->mRevision
->getId();
430 Hooks
::run( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
432 return $this->mContentObject
;
436 * Returns true if the currently-referenced revision is the current edit
437 * to this page (and it exists).
440 public function isCurrent() {
441 # If no oldid, this is the current version.
442 if ( $this->getOldID() == 0 ) {
446 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
450 * Get the fetched Revision object depending on request parameters or null
454 * @return Revision|null
456 public function getRevisionFetched() {
457 $this->fetchContentObject();
459 return $this->mRevision
;
463 * Use this to fetch the rev ID used on page views
465 * @return int Revision ID of last article revision
467 public function getRevIdFetched() {
468 if ( $this->mRevIdFetched
) {
469 return $this->mRevIdFetched
;
471 return $this->mPage
->getLatest();
476 * This is the default action of the index.php entry point: just view the
477 * page of the given title.
479 public function view() {
480 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar, $wgMaxRedirects;
482 # Get variables from query string
483 # As side effect this will load the revision and update the title
484 # in a revision ID is passed in the request, so this should remain
485 # the first call of this method even if $oldid is used way below.
486 $oldid = $this->getOldID();
488 $user = $this->getContext()->getUser();
489 # Another whitelist check in case getOldID() is altering the title
490 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
491 if ( count( $permErrors ) ) {
492 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
493 throw new PermissionsError( 'read', $permErrors );
496 $outputPage = $this->getContext()->getOutput();
497 # getOldID() may as well want us to redirect somewhere else
498 if ( $this->mRedirectUrl
) {
499 $outputPage->redirect( $this->mRedirectUrl
);
500 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
505 # If we got diff in the query, we want to see a diff page instead of the article.
506 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
507 wfDebug( __METHOD__
. ": showing diff page\n" );
508 $this->showDiffPage();
513 # Set page title (may be overridden by DISPLAYTITLE)
514 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
516 $outputPage->setArticleFlag( true );
517 # Allow frames by default
518 $outputPage->allowClickjacking();
520 $parserCache = ParserCache
::singleton();
522 $parserOptions = $this->getParserOptions();
523 # Render printable version, use printable version cache
524 if ( $outputPage->isPrintable() ) {
525 $parserOptions->setIsPrintable( true );
526 $parserOptions->setEditSection( false );
527 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
528 $parserOptions->setEditSection( false );
531 # Try client and file cache
532 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
534 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
537 # Use the greatest of the page's timestamp or the timestamp of any
538 # redirect in the chain (bug 67849)
539 $timestamp = $this->mPage
->getTouched();
540 if ( isset( $this->mRedirectedFrom
) ) {
541 $timestamp = max( $timestamp, $this->mRedirectedFrom
->getTouched() );
543 # If there can be more than one redirect in the chain, we have
544 # to go through the whole chain too in case an intermediate
545 # redirect was changed.
546 if ( $wgMaxRedirects > 1 ) {
547 $titles = Revision
::newFromTitle( $this->mRedirectedFrom
)
548 ->getContent( Revision
::FOR_THIS_USER
, $user )
549 ->getRedirectChain();
550 $thisTitle = $this->getTitle();
551 foreach ( $titles as $title ) {
552 if ( Title
::compare( $title, $thisTitle ) === 0 ) {
555 $timestamp = max( $timestamp, $title->getTouched() );
560 # Is it client cached?
561 if ( $outputPage->checkLastModified( $timestamp ) ) {
562 wfDebug( __METHOD__
. ": done 304\n" );
566 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
567 wfDebug( __METHOD__
. ": done file cache\n" );
568 # tell wgOut that output is taken care of
569 $outputPage->disable();
570 $this->mPage
->doViewUpdates( $user, $oldid );
576 # Should the parser cache be used?
577 $useParserCache = $this->mPage
->shouldCheckParserCache( $parserOptions, $oldid );
578 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
579 if ( $user->getStubThreshold() ) {
580 $this->getContext()->getStats()->increment( 'pcache_miss_stub' );
583 $this->showRedirectedFromHeader();
584 $this->showNamespaceHeader();
586 # Iterate through the possible ways of constructing the output text.
587 # Keep going until $outputDone is set, or we run out of things to do.
590 $this->mParserOutput
= false;
592 while ( !$outputDone && ++
$pass ) {
595 Hooks
::run( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
598 # Early abort if the page doesn't exist
599 if ( !$this->mPage
->exists() ) {
600 wfDebug( __METHOD__
. ": showing missing article\n" );
601 $this->showMissingArticle();
602 $this->mPage
->doViewUpdates( $user );
606 # Try the parser cache
607 if ( $useParserCache ) {
608 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
610 if ( $this->mParserOutput
!== false ) {
612 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
613 $this->setOldSubtitle( $oldid );
615 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
617 $outputPage->addParserOutput( $this->mParserOutput
);
618 # Ensure that UI elements requiring revision ID have
619 # the correct version information.
620 $outputPage->setRevisionId( $this->mPage
->getLatest() );
621 # Preload timestamp to avoid a DB hit
622 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
623 if ( $cachedTimestamp !== null ) {
624 $outputPage->setRevisionTimestamp( $cachedTimestamp );
625 $this->mPage
->setTimestamp( $cachedTimestamp );
632 # This will set $this->mRevision if needed
633 $this->fetchContentObject();
635 # Are we looking at an old revision
636 if ( $oldid && $this->mRevision
) {
637 $this->setOldSubtitle( $oldid );
639 if ( !$this->showDeletedRevisionHeader() ) {
640 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
645 # Ensure that UI elements requiring revision ID have
646 # the correct version information.
647 $outputPage->setRevisionId( $this->getRevIdFetched() );
648 # Preload timestamp to avoid a DB hit
649 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
651 # Pages containing custom CSS or JavaScript get special treatment
652 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
653 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
654 $this->showCssOrJsPage();
656 } elseif ( !Hooks
::run( 'ArticleContentViewCustom',
657 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
659 # Allow extensions do their own custom view for certain pages
661 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
662 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
664 # Allow extensions do their own custom view for certain pages
669 # Run the parse, protected by a pool counter
670 wfDebug( __METHOD__
. ": doing uncached parse\n" );
672 $content = $this->getContentObject();
673 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
674 $this->getRevIdFetched(), $useParserCache, $content );
676 if ( !$poolArticleView->execute() ) {
677 $error = $poolArticleView->getError();
679 $outputPage->clearHTML(); // for release() errors
680 $outputPage->enableClientCache( false );
681 $outputPage->setRobotPolicy( 'noindex,nofollow' );
683 $errortext = $error->getWikiText( false, 'view-pool-error' );
684 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
686 # Connection or timeout error
690 $this->mParserOutput
= $poolArticleView->getParserOutput();
691 $outputPage->addParserOutput( $this->mParserOutput
);
692 if ( $content->getRedirectTarget() ) {
693 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
694 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
697 # Don't cache a dirty ParserOutput object
698 if ( $poolArticleView->getIsDirty() ) {
699 $outputPage->setSquidMaxage( 0 );
700 $outputPage->addHTML( "<!-- parser cache is expired, " .
701 "sending anyway due to pool overload-->\n" );
706 # Should be unreachable, but just in case...
712 # Get the ParserOutput actually *displayed* here.
713 # Note that $this->mParserOutput is the *current*/oldid version output.
714 $pOutput = ( $outputDone instanceof ParserOutput
)
715 ?
$outputDone // object fetched by hook
716 : $this->mParserOutput
;
718 # Adjust title for main page & pages with displaytitle
720 $this->adjustDisplayTitle( $pOutput );
723 # For the main page, overwrite the <title> element with the con-
724 # tents of 'pagetitle-view-mainpage' instead of the default (if
726 # This message always exists because it is in the i18n files
727 if ( $this->getTitle()->isMainPage() ) {
728 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
729 if ( !$msg->isDisabled() ) {
730 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
734 # Check for any __NOINDEX__ tags on the page using $pOutput
735 $policy = $this->getRobotPolicy( 'view', $pOutput );
736 $outputPage->setIndexPolicy( $policy['index'] );
737 $outputPage->setFollowPolicy( $policy['follow'] );
739 $this->showViewFooter();
740 $this->mPage
->doViewUpdates( $user, $oldid );
742 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
747 * Adjust title for pages with displaytitle, -{T|}- or language conversion
748 * @param ParserOutput $pOutput
750 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
751 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
752 $titleText = $pOutput->getTitleText();
753 if ( strval( $titleText ) !== '' ) {
754 $this->getContext()->getOutput()->setPageTitle( $titleText );
759 * Show a diff page according to current request variables. For use within
760 * Article::view() only, other callers should use the DifferenceEngine class.
763 protected function showDiffPage() {
764 $request = $this->getContext()->getRequest();
765 $user = $this->getContext()->getUser();
766 $diff = $request->getVal( 'diff' );
767 $rcid = $request->getVal( 'rcid' );
768 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
769 $purge = $request->getVal( 'action' ) == 'purge';
770 $unhide = $request->getInt( 'unhide' ) == 1;
771 $oldid = $this->getOldID();
773 $rev = $this->getRevisionFetched();
776 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
777 $msg = $this->getContext()->msg( 'difference-missing-revision' )
781 $this->getContext()->getOutput()->addHtml( $msg );
785 $contentHandler = $rev->getContentHandler();
786 $de = $contentHandler->createDifferenceEngine(
795 // DifferenceEngine directly fetched the revision:
796 $this->mRevIdFetched
= $de->mNewid
;
797 $de->showDiffPage( $diffOnly );
799 // Run view updates for the newer revision being diffed (and shown
800 // below the diff if not $diffOnly).
801 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
802 // New can be false, convert it to 0 - this conveniently means the latest revision
803 $this->mPage
->doViewUpdates( $user, (int)$new );
807 * Show a page view for a page formatted as CSS or JavaScript. To be called by
808 * Article::view() only.
810 * This exists mostly to serve the deprecated ShowRawCssJs hook (used to customize these views).
811 * It has been replaced by the ContentGetParserOutput hook, which lets you do the same but with
814 * @param bool $showCacheHint Whether to show a message telling the user
815 * to clear the browser cache (default: true).
817 protected function showCssOrJsPage( $showCacheHint = true ) {
818 $outputPage = $this->getContext()->getOutput();
820 if ( $showCacheHint ) {
821 $dir = $this->getContext()->getLanguage()->getDir();
822 $lang = $this->getContext()->getLanguage()->getHtmlCode();
824 $outputPage->wrapWikiMsg(
825 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
830 $this->fetchContentObject();
832 if ( $this->mContentObject
) {
833 // Give hooks a chance to customise the output
834 if ( ContentHandler
::runLegacyHooks(
836 array( $this->mContentObject
, $this->getTitle(), $outputPage ) )
838 // If no legacy hooks ran, display the content of the parser output, including RL modules,
839 // but excluding metadata like categories and language links
840 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
841 $outputPage->addParserOutputContent( $po );
847 * Get the robot policy to be used for the current view
848 * @param string $action The action= GET parameter
849 * @param ParserOutput|null $pOutput
850 * @return array The policy that should be set
851 * @todo actions other than 'view'
853 public function getRobotPolicy( $action, $pOutput = null ) {
854 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
856 $ns = $this->getTitle()->getNamespace();
858 # Don't index user and user talk pages for blocked users (bug 11443)
859 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
860 $specificTarget = null;
862 $titleText = $this->getTitle()->getText();
863 if ( IP
::isValid( $titleText ) ) {
864 $vagueTarget = $titleText;
866 $specificTarget = $titleText;
868 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
870 'index' => 'noindex',
871 'follow' => 'nofollow'
876 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
877 # Non-articles (special pages etc), and old revisions
879 'index' => 'noindex',
880 'follow' => 'nofollow'
882 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
883 # Discourage indexing of printable versions, but encourage following
885 'index' => 'noindex',
888 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
889 # For ?curid=x urls, disallow indexing
891 'index' => 'noindex',
896 # Otherwise, construct the policy based on the various config variables.
897 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
899 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
900 # Honour customised robot policies for this namespace
901 $policy = array_merge(
903 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
906 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
907 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
908 # a final sanity check that we have really got the parser output.
909 $policy = array_merge(
911 array( 'index' => $pOutput->getIndexPolicy() )
915 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
916 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
917 $policy = array_merge(
919 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
927 * Converts a String robot policy into an associative array, to allow
928 * merging of several policies using array_merge().
929 * @param array|string $policy Returns empty array on null/false/'', transparent
930 * to already-converted arrays, converts string.
931 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
933 public static function formatRobotPolicy( $policy ) {
934 if ( is_array( $policy ) ) {
936 } elseif ( !$policy ) {
940 $policy = explode( ',', $policy );
941 $policy = array_map( 'trim', $policy );
944 foreach ( $policy as $var ) {
945 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
946 $arr['index'] = $var;
947 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
948 $arr['follow'] = $var;
956 * If this request is a redirect view, send "redirected from" subtitle to
957 * the output. Returns true if the header was needed, false if this is not
958 * a redirect view. Handles both local and remote redirects.
962 public function showRedirectedFromHeader() {
963 global $wgRedirectSources;
965 $context = $this->getContext();
966 $outputPage = $context->getOutput();
967 $request = $context->getRequest();
968 $rdfrom = $request->getVal( 'rdfrom' );
970 // Construct a URL for the current page view, but with the target title
971 $query = $request->getValues();
972 unset( $query['rdfrom'] );
973 unset( $query['title'] );
974 if ( $this->getTitle()->isRedirect() ) {
975 // Prevent double redirects
976 $query['redirect'] = 'no';
978 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
980 if ( isset( $this->mRedirectedFrom
) ) {
981 // This is an internally redirected page view.
982 // We'll need a backlink to the source page for navigation.
983 if ( Hooks
::run( 'ArticleViewRedirect', array( &$this ) ) ) {
984 $redir = Linker
::linkKnown(
985 $this->mRedirectedFrom
,
988 array( 'redirect' => 'no' )
991 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
992 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
995 // Add the script to update the displayed URL and
996 // set the fragment if one was specified in the redirect
997 $outputPage->addJsConfigVars( array(
998 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1000 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1002 // Add a <link rel="canonical"> tag
1003 $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() );
1005 // Tell the output object that the user arrived at this article through a redirect
1006 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1010 } elseif ( $rdfrom ) {
1011 // This is an externally redirected view, from some other wiki.
1012 // If it was reported from a trusted site, supply a backlink.
1013 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1014 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1015 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1016 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1019 // Add the script to update the displayed URL
1020 $outputPage->addJsConfigVars( array(
1021 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1023 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1033 * Show a header specific to the namespace currently being viewed, like
1034 * [[MediaWiki:Talkpagetext]]. For Article::view().
1036 public function showNamespaceHeader() {
1037 if ( $this->getTitle()->isTalkPage() ) {
1038 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1039 $this->getContext()->getOutput()->wrapWikiMsg(
1040 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1041 array( 'talkpageheader' )
1048 * Show the footer section of an ordinary page view
1050 public function showViewFooter() {
1051 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1052 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1053 && IP
::isValid( $this->getTitle()->getText() )
1055 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1058 // Show a footer allowing the user to patrol the shown revision or page if possible
1059 $patrolFooterShown = $this->showPatrolFooter();
1061 Hooks
::run( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1065 * If patrol is possible, output a patrol UI box. This is called from the
1066 * footer section of ordinary page views. If patrol is not possible or not
1067 * desired, does nothing.
1068 * Side effect: When the patrol link is build, this method will call
1069 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1073 public function showPatrolFooter() {
1074 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1076 $outputPage = $this->getContext()->getOutput();
1077 $user = $this->getContext()->getUser();
1078 $cache = wfGetMainCache();
1081 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1082 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1084 // Patrolling is disabled or the user isn't allowed to
1088 // New page patrol: Get the timestamp of the oldest revison which
1089 // the revision table holds for the given page. Then we look
1090 // whether it's within the RC lifespan and if it is, we try
1091 // to get the recentchanges row belonging to that entry
1092 // (with rc_new = 1).
1094 if ( $this->mRevision
1095 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1097 // The current revision is already older than what could be in the RC table
1098 // 6h tolerance because the RC might not be cleaned out regularly
1102 // Check for cached results
1103 $key = wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() );
1104 if ( $cache->get( $key ) ) {
1108 $dbr = wfGetDB( DB_SLAVE
);
1109 $oldestRevisionTimestamp = $dbr->selectField(
1111 'MIN( rev_timestamp )',
1112 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1116 if ( $oldestRevisionTimestamp
1117 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1119 // 6h tolerance because the RC might not be cleaned out regularly
1120 $rc = RecentChange
::newFromConds(
1123 'rc_timestamp' => $oldestRevisionTimestamp,
1124 'rc_namespace' => $this->getTitle()->getNamespace(),
1125 'rc_cur_id' => $this->getTitle()->getArticleID()
1128 array( 'USE INDEX' => 'new_name_timestamp' )
1131 // Cache the information we gathered above in case we can't patrol
1132 // Don't cache in case we can patrol as this could change
1133 $cache->set( $key, '1' );
1137 // Don't cache: This can be hit if the page gets accessed very fast after
1138 // its creation or in case we have high slave lag. In case the revision is
1139 // too old, we will already return above.
1143 if ( $rc->getAttribute( 'rc_patrolled' ) ) {
1144 // Patrolled RC entry around
1146 // Cache the information we gathered above in case we can't patrol
1147 // Don't cache in case we can patrol as this could change
1148 $cache->set( $key, '1' );
1153 if ( $rc->getPerformer()->equals( $user ) ) {
1154 // Don't show a patrol link for own creations. If the user could
1155 // patrol them, they already would be patrolled
1159 $rcid = $rc->getAttribute( 'rc_id' );
1161 $token = $user->getEditToken( $rcid );
1163 $outputPage->preventClickjacking();
1164 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1165 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1168 $link = Linker
::linkKnown(
1170 wfMessage( 'markaspatrolledtext' )->escaped(),
1173 'action' => 'markpatrolled',
1179 $outputPage->addHTML(
1180 "<div class='patrollink'>" .
1181 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1189 * Show the error text for a missing article. For articles in the MediaWiki
1190 * namespace, show the default message text. To be called from Article::view().
1192 public function showMissingArticle() {
1193 global $wgSend404Code;
1195 $outputPage = $this->getContext()->getOutput();
1196 // Whether the page is a root user page of an existing user (but not a subpage)
1197 $validUserPage = false;
1199 $title = $this->getTitle();
1201 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1202 if ( $title->getNamespace() == NS_USER
1203 ||
$title->getNamespace() == NS_USER_TALK
1205 $parts = explode( '/', $title->getText() );
1206 $rootPart = $parts[0];
1207 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1208 $ip = User
::isIP( $rootPart );
1209 $block = Block
::newFromTarget( $user, $user );
1211 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1212 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1213 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1214 } elseif ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
1215 # Show log extract if the user is currently blocked
1216 LogEventsList
::showLogExtract(
1219 MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget(),
1223 'showIfEmpty' => false,
1225 'blocked-notice-logextract',
1226 $user->getName() # Support GENDER in notice
1230 $validUserPage = !$title->isSubpage();
1232 $validUserPage = !$title->isSubpage();
1236 Hooks
::run( 'ShowMissingArticle', array( $this ) );
1238 // Give extensions a chance to hide their (unrelated) log entries
1239 $logTypes = array( 'delete', 'move' );
1240 $conds = array( "log_action != 'revision'" );
1241 Hooks
::run( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1243 # Show delete and move logs
1244 LogEventsList
::showLogExtract( $outputPage, $logTypes, $title, '',
1247 'showIfEmpty' => false,
1248 'msgKey' => array( 'moveddeleted-notice' ) )
1251 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1252 // If there's no backing content, send a 404 Not Found
1253 // for better machine handling of broken links.
1254 $this->getContext()->getRequest()->response()->statusHeader( 404 );
1257 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1258 $policy = $this->getRobotPolicy( 'view' );
1259 $outputPage->setIndexPolicy( $policy['index'] );
1260 $outputPage->setFollowPolicy( $policy['follow'] );
1262 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', array( $this ) );
1264 if ( !$hookResult ) {
1268 # Show error message
1269 $oldid = $this->getOldID();
1270 if ( !$oldid && $title->getNamespace() === NS_MEDIAWIKI
&& $title->hasSourceText() ) {
1271 $outputPage->addParserOutput( $this->getContentObject()->getParserOutput( $title ) );
1274 $text = wfMessage( 'missing-revision', $oldid )->plain();
1275 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1276 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1278 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1279 $text = wfMessage( $message )->plain();
1281 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1284 $dir = $this->getContext()->getLanguage()->getDir();
1285 $lang = $this->getContext()->getLanguage()->getCode();
1286 $outputPage->addWikiText( Xml
::openElement( 'div', array(
1287 'class' => "noarticletext mw-content-$dir",
1290 ) ) . "\n$text\n</div>" );
1295 * If the revision requested for view is deleted, check permissions.
1296 * Send either an error message or a warning header to the output.
1298 * @return bool True if the view is allowed, false if not.
1300 public function showDeletedRevisionHeader() {
1301 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1306 $outputPage = $this->getContext()->getOutput();
1307 $user = $this->getContext()->getUser();
1308 // If the user is not allowed to see it...
1309 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1310 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1311 'rev-deleted-text-permission' );
1314 // If the user needs to confirm that they want to see it...
1315 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1316 # Give explanation and add a link to view the revision...
1317 $oldid = intval( $this->getOldID() );
1318 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1319 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1320 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1321 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1322 array( $msg, $link ) );
1325 // We are allowed to see...
1327 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1328 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1329 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1336 * Generate the navigation links when browsing through an article revisions
1337 * It shows the information as:
1338 * Revision as of \<date\>; view current revision
1339 * \<- Previous version | Next Version -\>
1341 * @param int $oldid Revision ID of this article revision
1343 public function setOldSubtitle( $oldid = 0 ) {
1344 if ( !Hooks
::run( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1348 $context = $this->getContext();
1349 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1351 # Cascade unhide param in links for easy deletion browsing
1352 $extraParams = array();
1354 $extraParams['unhide'] = 1;
1357 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1358 $revision = $this->mRevision
;
1360 $revision = Revision
::newFromId( $oldid );
1363 $timestamp = $revision->getTimestamp();
1365 $current = ( $oldid == $this->mPage
->getLatest() );
1366 $language = $context->getLanguage();
1367 $user = $context->getUser();
1369 $td = $language->userTimeAndDate( $timestamp, $user );
1370 $tddate = $language->userDate( $timestamp, $user );
1371 $tdtime = $language->userTime( $timestamp, $user );
1373 # Show user links if allowed to see them. If hidden, then show them only if requested...
1374 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1376 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1377 ?
'revision-info-current'
1380 $outputPage = $context->getOutput();
1381 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" .
1382 $context->msg( $infomsg, $td )
1383 ->rawParams( $userlinks )
1384 ->params( $revision->getID(), $tddate, $tdtime, $revision->getUserText() )
1385 ->rawParams( Linker
::revComment( $revision, true, true ) )
1391 ?
$context->msg( 'currentrevisionlink' )->escaped()
1392 : Linker
::linkKnown(
1394 $context->msg( 'currentrevisionlink' )->escaped(),
1399 ?
$context->msg( 'diff' )->escaped()
1400 : Linker
::linkKnown(
1402 $context->msg( 'diff' )->escaped(),
1409 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1411 ? Linker
::linkKnown(
1413 $context->msg( 'previousrevision' )->escaped(),
1416 'direction' => 'prev',
1420 : $context->msg( 'previousrevision' )->escaped();
1422 ? Linker
::linkKnown(
1424 $context->msg( 'diff' )->escaped(),
1431 : $context->msg( 'diff' )->escaped();
1432 $nextlink = $current
1433 ?
$context->msg( 'nextrevision' )->escaped()
1434 : Linker
::linkKnown(
1436 $context->msg( 'nextrevision' )->escaped(),
1439 'direction' => 'next',
1443 $nextdiff = $current
1444 ?
$context->msg( 'diff' )->escaped()
1445 : Linker
::linkKnown(
1447 $context->msg( 'diff' )->escaped(),
1455 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1456 if ( $cdel !== '' ) {
1460 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1461 $context->msg( 'revision-nav' )->rawParams(
1462 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1463 )->escaped() . "</div>" );
1467 * Return the HTML for the top of a redirect page
1469 * Chances are you should just be using the ParserOutput from
1470 * WikitextContent::getParserOutput instead of calling this for redirects.
1472 * @param Title|array $target Destination(s) to redirect
1473 * @param bool $appendSubtitle [optional]
1474 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1475 * @return string Containing HTML with redirect link
1477 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1478 $lang = $this->getTitle()->getPageLanguage();
1479 $out = $this->getContext()->getOutput();
1480 if ( $appendSubtitle ) {
1481 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1483 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1484 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1488 * Return the HTML for the top of a redirect page
1490 * Chances are you should just be using the ParserOutput from
1491 * WikitextContent::getParserOutput instead of calling this for redirects.
1494 * @param Language $lang
1495 * @param Title|array $target Destination(s) to redirect
1496 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1497 * @return string Containing HTML with redirect link
1499 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1500 if ( !is_array( $target ) ) {
1501 $target = array( $target );
1504 $html = '<ul class="redirectText">';
1505 /** @var Title $title */
1506 foreach ( $target as $title ) {
1507 $html .= '<li>' . Linker
::link(
1509 htmlspecialchars( $title->getFullText() ),
1511 // Automatically append redirect=no to each link, since most of them are
1512 // redirect pages themselves.
1513 array( 'redirect' => 'no' ),
1514 ( $forceKnown ?
array( 'known', 'noclasses' ) : array() )
1519 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1521 return '<div class="redirectMsg">' .
1522 '<p>' . $redirectToText . '</p>' .
1528 * Adds help link with an icon via page indicators.
1529 * Link target can be overridden by a local message containing a wikilink:
1530 * the message key is: 'namespace-' + namespace number + '-helppage'.
1531 * @param string $to Target MediaWiki.org page title or encoded URL.
1532 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
1535 public function addHelpLink( $to, $overrideBaseUrl = false ) {
1537 'namespace-' . $this->getTitle()->getNamespace() . '-helppage'
1540 $out = $this->getContext()->getOutput();
1541 if ( !$msg->isDisabled() ) {
1542 $helpUrl = Skin
::makeUrl( $msg->plain() );
1543 $out->addHelpLink( $helpUrl, true );
1545 $out->addHelpLink( $to, $overrideBaseUrl );
1550 * Handle action=render
1552 public function render() {
1553 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1554 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1555 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1560 * action=protect handler
1562 public function protect() {
1563 $form = new ProtectionForm( $this );
1568 * action=unprotect handler (alias)
1570 public function unprotect() {
1575 * UI entry point for page deletion
1577 public function delete() {
1578 # This code desperately needs to be totally rewritten
1580 $title = $this->getTitle();
1581 $context = $this->getContext();
1582 $user = $context->getUser();
1585 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1586 if ( count( $permissionErrors ) ) {
1587 throw new PermissionsError( 'delete', $permissionErrors );
1590 # Read-only check...
1591 if ( wfReadOnly() ) {
1592 throw new ReadOnlyError
;
1595 # Better double-check that it hasn't been deleted yet!
1596 $this->mPage
->loadPageData( 'fromdbmaster' );
1597 if ( !$this->mPage
->exists() ) {
1598 $deleteLogPage = new LogPage( 'delete' );
1599 $outputPage = $context->getOutput();
1600 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1601 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1602 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1604 $outputPage->addHTML(
1605 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1607 LogEventsList
::showLogExtract(
1616 $request = $context->getRequest();
1617 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1618 $deleteReason = $request->getText( 'wpReason' );
1620 if ( $deleteReasonList == 'other' ) {
1621 $reason = $deleteReason;
1622 } elseif ( $deleteReason != '' ) {
1623 // Entry from drop down menu + additional comment
1624 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1625 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1627 $reason = $deleteReasonList;
1630 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1631 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1633 # Flag to hide all contents of the archived revisions
1634 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1636 $this->doDelete( $reason, $suppress );
1638 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1643 // Generate deletion reason
1644 $hasHistory = false;
1647 $reason = $this->generateReason( $hasHistory );
1648 } catch ( Exception
$e ) {
1649 # if a page is horribly broken, we still want to be able to
1650 # delete it. So be lenient about errors here.
1651 wfDebug( "Error while building auto delete summary: $e" );
1656 // If the page has a history, insert a warning
1657 if ( $hasHistory ) {
1658 $title = $this->getTitle();
1660 // The following can use the real revision count as this is only being shown for users
1661 // that can delete this page.
1662 // This, as a side-effect, also makes sure that the following query isn't being run for
1663 // pages with a larger history, unless the user has the 'bigdelete' right
1664 // (and is about to delete this page).
1665 $dbr = wfGetDB( DB_SLAVE
);
1666 $revisions = $edits = (int)$dbr->selectField(
1669 array( 'rev_page' => $title->getArticleID() ),
1673 // @todo FIXME: i18n issue/patchwork message
1674 $context->getOutput()->addHTML(
1675 '<strong class="mw-delete-warning-revisions">' .
1676 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1677 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1678 $context->msg( 'history' )->escaped(),
1680 array( 'action' => 'history' ) ) .
1684 if ( $title->isBigDeletion() ) {
1685 global $wgDeleteRevisionsLimit;
1686 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1688 'delete-warning-toobig',
1689 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1695 $this->confirmDelete( $reason );
1699 * Output deletion confirmation dialog
1700 * @todo FIXME: Move to another file?
1701 * @param string $reason Prefilled reason
1703 public function confirmDelete( $reason ) {
1704 wfDebug( "Article::confirmDelete\n" );
1706 $title = $this->getTitle();
1707 $ctx = $this->getContext();
1708 $outputPage = $ctx->getOutput();
1709 $useMediaWikiUIEverywhere = $ctx->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1710 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1711 $outputPage->addBacklinkSubtitle( $title );
1712 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1713 $backlinkCache = $title->getBacklinkCache();
1714 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1715 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1716 'deleting-backlinks-warning' );
1718 $outputPage->addWikiMsg( 'confirmdeletetext' );
1720 Hooks
::run( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1722 $user = $this->getContext()->getUser();
1724 if ( $user->isAllowed( 'suppressrevision' ) ) {
1725 $suppress = Html
::openElement( 'div', array( 'id' => 'wpDeleteSuppressRow' ) ) .
1726 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1727 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1728 Html
::closeElement( 'div' );
1732 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1734 $form = Html
::openElement( 'form', array( 'method' => 'post',
1735 'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1736 Html
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1737 Html
::element( 'legend', null, wfMessage( 'delete-legend' )->text() ) .
1738 Html
::openElement( 'div', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1739 Html
::openElement( 'div', array( 'id' => 'wpDeleteReasonListRow' ) ) .
1740 Html
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1743 'wpDeleteReasonList',
1744 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1745 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1750 Html
::closeElement( 'div' ) .
1751 Html
::openElement( 'div', array( 'id' => 'wpDeleteReasonRow' ) ) .
1752 Html
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1754 Html
::input( 'wpReason', $reason, 'text', array(
1756 'maxlength' => '255',
1759 'class' => 'mw-ui-input-inline',
1762 Html
::closeElement( 'div' );
1764 # Disallow watching if user is not logged in
1765 if ( $user->isLoggedIn() ) {
1767 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1768 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) );
1772 Html
::openElement( 'div' ) .
1774 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1776 'name' => 'wpConfirmB',
1777 'id' => 'wpConfirmB',
1779 'class' => $useMediaWikiUIEverywhere ?
'mw-ui-button mw-ui-destructive' : '',
1782 Html
::closeElement( 'div' ) .
1783 Html
::closeElement( 'div' ) .
1784 Xml
::closeElement( 'fieldset' ) .
1787 $user->getEditToken( array( 'delete', $title->getPrefixedText() ) )
1789 Xml
::closeElement( 'form' );
1791 if ( $user->isAllowed( 'editinterface' ) ) {
1792 $link = Linker
::linkKnown(
1793 $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
1794 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1796 array( 'action' => 'edit' )
1798 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1801 $outputPage->addHTML( $form );
1803 $deleteLogPage = new LogPage( 'delete' );
1804 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1805 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
1809 * Perform a deletion and output success or failure messages
1810 * @param string $reason
1811 * @param bool $suppress
1813 public function doDelete( $reason, $suppress = false ) {
1815 $context = $this->getContext();
1816 $outputPage = $context->getOutput();
1817 $user = $context->getUser();
1818 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error, $user );
1820 if ( $status->isGood() ) {
1821 $deleted = $this->getTitle()->getPrefixedText();
1823 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1824 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1826 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1828 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1830 Hooks
::run( 'ArticleDeleteAfterSuccess', array( $this->getTitle(), $outputPage ) );
1832 $outputPage->returnToMain( false );
1834 $outputPage->setPageTitle(
1835 wfMessage( 'cannotdelete-title',
1836 $this->getTitle()->getPrefixedText() )
1839 if ( $error == '' ) {
1840 $outputPage->addWikiText(
1841 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1843 $deleteLogPage = new LogPage( 'delete' );
1844 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1846 LogEventsList
::showLogExtract(
1852 $outputPage->addHTML( $error );
1857 /* Caching functions */
1860 * checkLastModified returns true if it has taken care of all
1861 * output to the client that is necessary for this request.
1862 * (that is, it has sent a cached version of the page)
1864 * @return bool True if cached version send, false otherwise
1866 protected function tryFileCache() {
1867 static $called = false;
1870 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1875 if ( $this->isFileCacheable() ) {
1876 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
1877 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1878 wfDebug( "Article::tryFileCache(): about to load file\n" );
1879 $cache->loadFromFileCache( $this->getContext() );
1882 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1883 ob_start( array( &$cache, 'saveToFileCache' ) );
1886 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1893 * Check if the page can be cached
1896 public function isFileCacheable() {
1899 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1900 $cacheable = $this->mPage
->getID()
1901 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1902 // Extension may have reason to disable file caching on some pages.
1904 $cacheable = Hooks
::run( 'IsFileCacheable', array( &$this ) );
1914 * Lightweight method to get the parser output for a page, checking the parser cache
1915 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1916 * consider, so it's not appropriate to use there.
1918 * @since 1.16 (r52326) for LiquidThreads
1920 * @param int|null $oldid Revision ID or null
1921 * @param User $user The relevant user
1922 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1924 public function getParserOutput( $oldid = null, User
$user = null ) {
1925 //XXX: bypasses mParserOptions and thus setParserOptions()
1927 if ( $user === null ) {
1928 $parserOptions = $this->getParserOptions();
1930 $parserOptions = $this->mPage
->makeParserOptions( $user );
1933 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1937 * Override the ParserOptions used to render the primary article wikitext.
1939 * @param ParserOptions $options
1940 * @throws MWException If the parser options where already initialized.
1942 public function setParserOptions( ParserOptions
$options ) {
1943 if ( $this->mParserOptions
) {
1944 throw new MWException( "can't change parser options after they have already been set" );
1947 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1948 $this->mParserOptions
= clone $options;
1952 * Get parser options suitable for rendering the primary article wikitext
1953 * @return ParserOptions
1955 public function getParserOptions() {
1956 if ( !$this->mParserOptions
) {
1957 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1959 // Clone to allow modifications of the return value without affecting cache
1960 return clone $this->mParserOptions
;
1964 * Sets the context this Article is executed in
1966 * @param IContextSource $context
1969 public function setContext( $context ) {
1970 $this->mContext
= $context;
1974 * Gets the context this Article is executed in
1976 * @return IContextSource
1979 public function getContext() {
1980 if ( $this->mContext
instanceof IContextSource
) {
1981 return $this->mContext
;
1983 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1984 "Return RequestContext::getMain(); for sanity\n" );
1985 return RequestContext
::getMain();
1990 * Use PHP's magic __get handler to handle accessing of
1991 * raw WikiPage fields for backwards compatibility.
1993 * @param string $fname Field name
1996 public function __get( $fname ) {
1997 if ( property_exists( $this->mPage
, $fname ) ) {
1998 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1999 return $this->mPage
->$fname;
2001 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2005 * Use PHP's magic __set handler to handle setting of
2006 * raw WikiPage fields for backwards compatibility.
2008 * @param string $fname Field name
2009 * @param mixed $fvalue New value
2011 public function __set( $fname, $fvalue ) {
2012 if ( property_exists( $this->mPage
, $fname ) ) {
2013 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
2014 $this->mPage
->$fname = $fvalue;
2015 // Note: extensions may want to toss on new fields
2016 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2017 $this->mPage
->$fname = $fvalue;
2019 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2024 * Use PHP's magic __call handler to transform instance calls to
2025 * WikiPage functions for backwards compatibility.
2027 * @param string $fname Name of called method
2028 * @param array $args Arguments to the method
2031 public function __call( $fname, $args ) {
2032 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2033 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2034 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2036 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2039 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2042 * @param array $limit
2043 * @param array $expiry
2044 * @param bool $cascade
2045 * @param string $reason
2049 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2052 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2056 * @param array $limit
2057 * @param string $reason
2058 * @param int $cascade
2059 * @param array $expiry
2062 public function updateRestrictions( $limit = array(), $reason = '',
2063 &$cascade = 0, $expiry = array()
2065 return $this->mPage
->doUpdateRestrictions(
2070 $this->getContext()->getUser()
2075 * @param string $reason
2076 * @param bool $suppress
2078 * @param bool $commit
2079 * @param string $error
2082 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2083 $commit = true, &$error = ''
2085 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2089 * @param string $fromP
2090 * @param string $summary
2091 * @param string $token
2093 * @param array $resultDetails
2094 * @param User|null $user
2097 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2098 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2099 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2103 * @param string $fromP
2104 * @param string $summary
2106 * @param array $resultDetails
2107 * @param User|null $guser
2110 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2111 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2112 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2116 * @param bool $hasHistory
2119 public function generateReason( &$hasHistory ) {
2120 $title = $this->mPage
->getTitle();
2121 $handler = ContentHandler
::getForTitle( $title );
2122 return $handler->getAutoDeleteReason( $title, $hasHistory );
2125 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2130 * @deprecated since 1.24, use WikiPage::selectFields() instead
2132 public static function selectFields() {
2133 wfDeprecated( __METHOD__
, '1.24' );
2134 return WikiPage
::selectFields();
2138 * @param Title $title
2140 * @deprecated since 1.24, use WikiPage::onArticleCreate() instead
2142 public static function onArticleCreate( $title ) {
2143 wfDeprecated( __METHOD__
, '1.24' );
2144 WikiPage
::onArticleCreate( $title );
2148 * @param Title $title
2150 * @deprecated since 1.24, use WikiPage::onArticleDelete() instead
2152 public static function onArticleDelete( $title ) {
2153 wfDeprecated( __METHOD__
, '1.24' );
2154 WikiPage
::onArticleDelete( $title );
2158 * @param Title $title
2160 * @deprecated since 1.24, use WikiPage::onArticleEdit() instead
2162 public static function onArticleEdit( $title ) {
2163 wfDeprecated( __METHOD__
, '1.24' );
2164 WikiPage
::onArticleEdit( $title );
2168 * @param string $oldtext
2169 * @param string $newtext
2172 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2174 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2175 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );