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 public $mContentObject;
58 /** @var bool Is the content ($mContent) already loaded? */
59 public $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 public $mRedirectedFrom = null;
67 /** @var string|bool URL to redirect to or false if none */
68 public $mRedirectUrl = false;
70 /** @var int Revision ID of revision we are working on */
71 public $mRevIdFetched = 0;
73 /** @var Revision Revision we are working on */
74 public $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 Hooks
::run( '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() {
230 if ( $this->mPage
->getID() === 0 ) {
231 # If this is a MediaWiki:x message, then load the messages
232 # and return the message value for x.
233 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
234 $text = $this->getTitle()->getDefaultMessageText();
235 if ( $text === false ) {
239 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
241 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
242 $content = new MessageContent( $message, null, 'parsemag' );
245 $this->fetchContentObject();
246 $content = $this->mContentObject
;
253 * @return int The oldid of the article that is to be shown, 0 for the current revision
255 public function getOldID() {
256 if ( is_null( $this->mOldId
) ) {
257 $this->mOldId
= $this->getOldIDFromRequest();
260 return $this->mOldId
;
264 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
266 * @return int The old id for the request
268 public function getOldIDFromRequest() {
269 $this->mRedirectUrl
= false;
271 $request = $this->getContext()->getRequest();
272 $oldid = $request->getIntOrNull( 'oldid' );
274 if ( $oldid === null ) {
278 if ( $oldid !== 0 ) {
279 # Load the given revision and check whether the page is another one.
280 # In that case, update this instance to reflect the change.
281 if ( $oldid === $this->mPage
->getLatest() ) {
282 $this->mRevision
= $this->mPage
->getRevision();
284 $this->mRevision
= Revision
::newFromId( $oldid );
285 if ( $this->mRevision
!== null ) {
286 // Revision title doesn't match the page title given?
287 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
288 $function = array( get_class( $this->mPage
), 'newFromID' );
289 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
295 if ( $request->getVal( 'direction' ) == 'next' ) {
296 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
299 $this->mRevision
= null;
301 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
303 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
304 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
307 $this->mRevision
= null;
315 * Load the revision (including text) into this object
317 * @deprecated since 1.19; use fetchContent()
319 function loadContent() {
320 wfDeprecated( __METHOD__
, '1.19' );
321 $this->fetchContent();
325 * Get text of an article from database
326 * Does *NOT* follow redirects.
329 * @note This is really internal functionality that should really NOT be
330 * used by other functions. For accessing article content, use the WikiPage
331 * class, especially WikiBase::getContent(). However, a lot of legacy code
332 * uses this method to retrieve page text from the database, so the function
333 * has to remain public for now.
335 * @return string|bool String containing article contents, or false if null
336 * @deprecated since 1.21, use WikiPage::getContent() instead
338 function fetchContent() { #BC cruft!
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 ), array() );
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 if ( !$this->mPage
->getLatest() ) {
396 wfDebug( __METHOD__
. " failed to find page data for title " .
397 $this->getTitle()->getPrefixedText() . "\n" );
401 $this->mRevision
= $this->mPage
->getRevision();
403 if ( !$this->mRevision
) {
404 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " .
405 $this->mPage
->getLatest() . "\n" );
410 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
411 // We should instead work with the Revision object when we need it...
412 // Loads if user is allowed
413 $content = $this->mRevision
->getContent(
414 Revision
::FOR_THIS_USER
,
415 $this->getContext()->getUser()
419 wfDebug( __METHOD__
. " failed to retrieve content of revision " .
420 $this->mRevision
->getId() . "\n" );
424 $this->mContentObject
= $content;
425 $this->mRevIdFetched
= $this->mRevision
->getId();
427 Hooks
::run( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
429 return $this->mContentObject
;
433 * Returns true if the currently-referenced revision is the current edit
434 * to this page (and it exists).
437 public function isCurrent() {
438 # If no oldid, this is the current version.
439 if ( $this->getOldID() == 0 ) {
443 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
447 * Get the fetched Revision object depending on request parameters or null
451 * @return Revision|null
453 public function getRevisionFetched() {
454 $this->fetchContentObject();
456 return $this->mRevision
;
460 * Use this to fetch the rev ID used on page views
462 * @return int Revision ID of last article revision
464 public function getRevIdFetched() {
465 if ( $this->mRevIdFetched
) {
466 return $this->mRevIdFetched
;
468 return $this->mPage
->getLatest();
473 * This is the default action of the index.php entry point: just view the
474 * page of the given title.
476 public function view() {
477 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar, $wgMaxRedirects;
479 # Get variables from query string
480 # As side effect this will load the revision and update the title
481 # in a revision ID is passed in the request, so this should remain
482 # the first call of this method even if $oldid is used way below.
483 $oldid = $this->getOldID();
485 $user = $this->getContext()->getUser();
486 # Another whitelist check in case getOldID() is altering the title
487 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
488 if ( count( $permErrors ) ) {
489 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
490 throw new PermissionsError( 'read', $permErrors );
493 $outputPage = $this->getContext()->getOutput();
494 # getOldID() may as well want us to redirect somewhere else
495 if ( $this->mRedirectUrl
) {
496 $outputPage->redirect( $this->mRedirectUrl
);
497 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
502 # If we got diff in the query, we want to see a diff page instead of the article.
503 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
504 wfDebug( __METHOD__
. ": showing diff page\n" );
505 $this->showDiffPage();
510 # Set page title (may be overridden by DISPLAYTITLE)
511 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
513 $outputPage->setArticleFlag( true );
514 # Allow frames by default
515 $outputPage->allowClickjacking();
517 $parserCache = ParserCache
::singleton();
519 $parserOptions = $this->getParserOptions();
520 # Render printable version, use printable version cache
521 if ( $outputPage->isPrintable() ) {
522 $parserOptions->setIsPrintable( true );
523 $parserOptions->setEditSection( false );
524 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
525 $parserOptions->setEditSection( false );
528 # Try client and file cache
529 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
531 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
534 # Use the greatest of the page's timestamp or the timestamp of any
535 # redirect in the chain (bug 67849)
536 $timestamp = $this->mPage
->getTouched();
537 if ( isset( $this->mRedirectedFrom
) ) {
538 $timestamp = max( $timestamp, $this->mRedirectedFrom
->getTouched() );
540 # If there can be more than one redirect in the chain, we have
541 # to go through the whole chain too in case an intermediate
542 # redirect was changed.
543 if ( $wgMaxRedirects > 1 ) {
544 $titles = Revision
::newFromTitle( $this->mRedirectedFrom
)
545 ->getContent( Revision
::FOR_THIS_USER
, $user )
546 ->getRedirectChain();
547 $thisTitle = $this->getTitle();
548 foreach ( $titles as $title ) {
549 if ( Title
::compare( $title, $thisTitle ) === 0 ) {
552 $timestamp = max( $timestamp, $title->getTouched() );
557 # Is it client cached?
558 if ( $outputPage->checkLastModified( $timestamp ) ) {
559 wfDebug( __METHOD__
. ": done 304\n" );
563 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
564 wfDebug( __METHOD__
. ": done file cache\n" );
565 # tell wgOut that output is taken care of
566 $outputPage->disable();
567 $this->mPage
->doViewUpdates( $user, $oldid );
573 # Should the parser cache be used?
574 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
575 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
576 if ( $user->getStubThreshold() ) {
577 wfIncrStats( 'pcache_miss_stub' );
580 $this->showRedirectedFromHeader();
581 $this->showNamespaceHeader();
583 # Iterate through the possible ways of constructing the output text.
584 # Keep going until $outputDone is set, or we run out of things to do.
587 $this->mParserOutput
= false;
589 while ( !$outputDone && ++
$pass ) {
592 Hooks
::run( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
595 # Early abort if the page doesn't exist
596 if ( !$this->mPage
->exists() ) {
597 wfDebug( __METHOD__
. ": showing missing article\n" );
598 $this->showMissingArticle();
599 $this->mPage
->doViewUpdates( $user );
603 # Try the parser cache
604 if ( $useParserCache ) {
605 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
607 if ( $this->mParserOutput
!== false ) {
609 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
610 $this->setOldSubtitle( $oldid );
612 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
614 $outputPage->addParserOutput( $this->mParserOutput
);
615 # Ensure that UI elements requiring revision ID have
616 # the correct version information.
617 $outputPage->setRevisionId( $this->mPage
->getLatest() );
618 # Preload timestamp to avoid a DB hit
619 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
620 if ( $cachedTimestamp !== null ) {
621 $outputPage->setRevisionTimestamp( $cachedTimestamp );
622 $this->mPage
->setTimestamp( $cachedTimestamp );
629 # This will set $this->mRevision if needed
630 $this->fetchContentObject();
632 # Are we looking at an old revision
633 if ( $oldid && $this->mRevision
) {
634 $this->setOldSubtitle( $oldid );
636 if ( !$this->showDeletedRevisionHeader() ) {
637 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
642 # Ensure that UI elements requiring revision ID have
643 # the correct version information.
644 $outputPage->setRevisionId( $this->getRevIdFetched() );
645 # Preload timestamp to avoid a DB hit
646 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
648 # Pages containing custom CSS or JavaScript get special treatment
649 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
650 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
651 $this->showCssOrJsPage();
653 } elseif ( !Hooks
::run( 'ArticleContentViewCustom',
654 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
656 # Allow extensions do their own custom view for certain pages
658 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
659 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
661 # Allow extensions do their own custom view for certain pages
666 # Run the parse, protected by a pool counter
667 wfDebug( __METHOD__
. ": doing uncached parse\n" );
669 $content = $this->getContentObject();
670 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
671 $this->getRevIdFetched(), $useParserCache, $content );
673 if ( !$poolArticleView->execute() ) {
674 $error = $poolArticleView->getError();
676 $outputPage->clearHTML(); // for release() errors
677 $outputPage->enableClientCache( false );
678 $outputPage->setRobotPolicy( 'noindex,nofollow' );
680 $errortext = $error->getWikiText( false, 'view-pool-error' );
681 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
683 # Connection or timeout error
687 $this->mParserOutput
= $poolArticleView->getParserOutput();
688 $outputPage->addParserOutput( $this->mParserOutput
);
689 if ( $content->getRedirectTarget() ) {
690 $outputPage->addSubtitle( "<span id=\"redirectsub\">" .
691 $this->getContext()->msg( 'redirectpagesub' )->parse() . "</span>" );
694 # Don't cache a dirty ParserOutput object
695 if ( $poolArticleView->getIsDirty() ) {
696 $outputPage->setSquidMaxage( 0 );
697 $outputPage->addHTML( "<!-- parser cache is expired, " .
698 "sending anyway due to pool overload-->\n" );
703 # Should be unreachable, but just in case...
709 # Get the ParserOutput actually *displayed* here.
710 # Note that $this->mParserOutput is the *current* version output.
711 $pOutput = ( $outputDone instanceof ParserOutput
)
712 ?
$outputDone // object fetched by hook
713 : $this->mParserOutput
;
715 # Adjust title for main page & pages with displaytitle
717 $this->adjustDisplayTitle( $pOutput );
720 # For the main page, overwrite the <title> element with the con-
721 # tents of 'pagetitle-view-mainpage' instead of the default (if
723 # This message always exists because it is in the i18n files
724 if ( $this->getTitle()->isMainPage() ) {
725 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
726 if ( !$msg->isDisabled() ) {
727 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
731 # Check for any __NOINDEX__ tags on the page using $pOutput
732 $policy = $this->getRobotPolicy( 'view', $pOutput );
733 $outputPage->setIndexPolicy( $policy['index'] );
734 $outputPage->setFollowPolicy( $policy['follow'] );
736 $this->showViewFooter();
737 $this->mPage
->doViewUpdates( $user, $oldid );
739 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
744 * Adjust title for pages with displaytitle, -{T|}- or language conversion
745 * @param ParserOutput $pOutput
747 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
748 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
749 $titleText = $pOutput->getTitleText();
750 if ( strval( $titleText ) !== '' ) {
751 $this->getContext()->getOutput()->setPageTitle( $titleText );
756 * Show a diff page according to current request variables. For use within
757 * Article::view() only, other callers should use the DifferenceEngine class.
760 protected function showDiffPage() {
761 $request = $this->getContext()->getRequest();
762 $user = $this->getContext()->getUser();
763 $diff = $request->getVal( 'diff' );
764 $rcid = $request->getVal( 'rcid' );
765 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
766 $purge = $request->getVal( 'action' ) == 'purge';
767 $unhide = $request->getInt( 'unhide' ) == 1;
768 $oldid = $this->getOldID();
770 $rev = $this->getRevisionFetched();
773 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
774 $msg = $this->getContext()->msg( 'difference-missing-revision' )
778 $this->getContext()->getOutput()->addHtml( $msg );
782 $contentHandler = $rev->getContentHandler();
783 $de = $contentHandler->createDifferenceEngine(
792 // DifferenceEngine directly fetched the revision:
793 $this->mRevIdFetched
= $de->mNewid
;
794 $de->showDiffPage( $diffOnly );
796 // Run view updates for the newer revision being diffed (and shown
797 // below the diff if not $diffOnly).
798 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
799 // New can be false, convert it to 0 - this conveniently means the latest revision
800 $this->mPage
->doViewUpdates( $user, (int)$new );
804 * Show a page view for a page formatted as CSS or JavaScript. To be called by
805 * Article::view() only.
807 * This exists mostly to serve the deprecated ShowRawCssJs hook (used to customize these views).
808 * It has been replaced by the ContentGetParserOutput hook, which lets you do the same but with
811 * @param bool $showCacheHint Whether to show a message telling the user
812 * to clear the browser cache (default: true).
814 protected function showCssOrJsPage( $showCacheHint = true ) {
815 $outputPage = $this->getContext()->getOutput();
817 if ( $showCacheHint ) {
818 $dir = $this->getContext()->getLanguage()->getDir();
819 $lang = $this->getContext()->getLanguage()->getHtmlCode();
821 $outputPage->wrapWikiMsg(
822 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
827 $this->fetchContentObject();
829 if ( $this->mContentObject
) {
830 // Give hooks a chance to customise the output
831 if ( ContentHandler
::runLegacyHooks(
833 array( $this->mContentObject
, $this->getTitle(), $outputPage ) )
835 // If no legacy hooks ran, display the content of the parser output, including RL modules,
836 // but excluding metadata like categories and language links
837 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
838 $outputPage->addParserOutputContent( $po );
844 * Get the robot policy to be used for the current view
845 * @param string $action The action= GET parameter
846 * @param ParserOutput|null $pOutput
847 * @return array The policy that should be set
848 * @todo actions other than 'view'
850 public function getRobotPolicy( $action, $pOutput = null ) {
851 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
853 $ns = $this->getTitle()->getNamespace();
855 # Don't index user and user talk pages for blocked users (bug 11443)
856 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
857 $specificTarget = null;
859 $titleText = $this->getTitle()->getText();
860 if ( IP
::isValid( $titleText ) ) {
861 $vagueTarget = $titleText;
863 $specificTarget = $titleText;
865 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
867 'index' => 'noindex',
868 'follow' => 'nofollow'
873 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
874 # Non-articles (special pages etc), and old revisions
876 'index' => 'noindex',
877 'follow' => 'nofollow'
879 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
880 # Discourage indexing of printable versions, but encourage following
882 'index' => 'noindex',
885 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
886 # For ?curid=x urls, disallow indexing
888 'index' => 'noindex',
893 # Otherwise, construct the policy based on the various config variables.
894 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
896 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
897 # Honour customised robot policies for this namespace
898 $policy = array_merge(
900 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
903 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
904 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
905 # a final sanity check that we have really got the parser output.
906 $policy = array_merge(
908 array( 'index' => $pOutput->getIndexPolicy() )
912 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
913 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
914 $policy = array_merge(
916 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
924 * Converts a String robot policy into an associative array, to allow
925 * merging of several policies using array_merge().
926 * @param array|string $policy Returns empty array on null/false/'', transparent
927 * to already-converted arrays, converts string.
928 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
930 public static function formatRobotPolicy( $policy ) {
931 if ( is_array( $policy ) ) {
933 } elseif ( !$policy ) {
937 $policy = explode( ',', $policy );
938 $policy = array_map( 'trim', $policy );
941 foreach ( $policy as $var ) {
942 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
943 $arr['index'] = $var;
944 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
945 $arr['follow'] = $var;
953 * If this request is a redirect view, send "redirected from" subtitle to
954 * the output. Returns true if the header was needed, false if this is not
955 * a redirect view. Handles both local and remote redirects.
959 public function showRedirectedFromHeader() {
960 global $wgRedirectSources;
961 $outputPage = $this->getContext()->getOutput();
963 $request = $this->getContext()->getRequest();
964 $rdfrom = $request->getVal( 'rdfrom' );
966 // Construct a URL for the current page view, but with the target title
967 $query = $request->getValues();
968 unset( $query['rdfrom'] );
969 unset( $query['title'] );
970 if ( $this->getTitle()->isRedirect() ) {
971 // Prevent double redirects
972 $query['redirect'] = 'no';
974 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
976 if ( isset( $this->mRedirectedFrom
) ) {
977 // This is an internally redirected page view.
978 // We'll need a backlink to the source page for navigation.
979 if ( Hooks
::run( 'ArticleViewRedirect', array( &$this ) ) ) {
980 $redir = Linker
::linkKnown(
981 $this->mRedirectedFrom
,
984 array( 'redirect' => 'no' )
987 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
988 wfMessage( 'redirectedfrom' )->rawParams( $redir )->parse()
991 // Add the script to update the displayed URL and
992 // set the fragment if one was specified in the redirect
993 $outputPage->addJsConfigVars( array(
994 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
996 $outputPage->addModules( 'mediawiki.action.view.redirect' );
998 // Add a <link rel="canonical"> tag
999 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
1001 // Tell the output object that the user arrived at this article through a redirect
1002 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1006 } elseif ( $rdfrom ) {
1007 // This is an externally redirected view, from some other wiki.
1008 // If it was reported from a trusted site, supply a backlink.
1009 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1010 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1011 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1012 wfMessage( 'redirectedfrom' )->rawParams( $redir )->parse()
1015 // Add the script to update the displayed URL
1016 $outputPage->addJsConfigVars( array(
1017 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1019 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1029 * Show a header specific to the namespace currently being viewed, like
1030 * [[MediaWiki:Talkpagetext]]. For Article::view().
1032 public function showNamespaceHeader() {
1033 if ( $this->getTitle()->isTalkPage() ) {
1034 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1035 $this->getContext()->getOutput()->wrapWikiMsg(
1036 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1037 array( 'talkpageheader' )
1044 * Show the footer section of an ordinary page view
1046 public function showViewFooter() {
1047 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1048 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1049 && IP
::isValid( $this->getTitle()->getText() )
1051 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1054 // Show a footer allowing the user to patrol the shown revision or page if possible
1055 $patrolFooterShown = $this->showPatrolFooter();
1057 Hooks
::run( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1061 * If patrol is possible, output a patrol UI box. This is called from the
1062 * footer section of ordinary page views. If patrol is not possible or not
1063 * desired, does nothing.
1064 * Side effect: When the patrol link is build, this method will call
1065 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1069 public function showPatrolFooter() {
1070 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1072 $outputPage = $this->getContext()->getOutput();
1073 $user = $this->getContext()->getUser();
1074 $cache = wfGetMainCache();
1077 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1078 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1080 // Patrolling is disabled or the user isn't allowed to
1084 // New page patrol: Get the timestamp of the oldest revison which
1085 // the revision table holds for the given page. Then we look
1086 // whether it's within the RC lifespan and if it is, we try
1087 // to get the recentchanges row belonging to that entry
1088 // (with rc_new = 1).
1090 // Check for cached results
1091 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1095 if ( $this->mRevision
1096 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1098 // The current revision is already older than what could be in the RC table
1099 // 6h tolerance because the RC might not be cleaned out regularly
1103 $dbr = wfGetDB( DB_SLAVE
);
1104 $oldestRevisionTimestamp = $dbr->selectField(
1106 'MIN( rev_timestamp )',
1107 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1111 if ( $oldestRevisionTimestamp
1112 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1114 // 6h tolerance because the RC might not be cleaned out regularly
1115 $rc = RecentChange
::newFromConds(
1118 'rc_timestamp' => $oldestRevisionTimestamp,
1119 'rc_namespace' => $this->getTitle()->getNamespace(),
1120 'rc_cur_id' => $this->getTitle()->getArticleID(),
1124 array( 'USE INDEX' => 'new_name_timestamp' )
1129 // No RC entry around
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( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1138 if ( $rc->getPerformer()->equals( $user ) ) {
1139 // Don't show a patrol link for own creations. If the user could
1140 // patrol them, they already would be patrolled
1144 $rcid = $rc->getAttribute( 'rc_id' );
1146 $token = $user->getEditToken( $rcid );
1148 $outputPage->preventClickjacking();
1149 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1150 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1153 $link = Linker
::linkKnown(
1155 wfMessage( 'markaspatrolledtext' )->escaped(),
1158 'action' => 'markpatrolled',
1164 $outputPage->addHTML(
1165 "<div class='patrollink'>" .
1166 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1174 * Show the error text for a missing article. For articles in the MediaWiki
1175 * namespace, show the default message text. To be called from Article::view().
1177 public function showMissingArticle() {
1178 global $wgSend404Code;
1180 $outputPage = $this->getContext()->getOutput();
1181 // Whether the page is a root user page of an existing user (but not a subpage)
1182 $validUserPage = false;
1184 $title = $this->getTitle();
1186 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1187 if ( $title->getNamespace() == NS_USER
1188 ||
$title->getNamespace() == NS_USER_TALK
1190 $parts = explode( '/', $title->getText() );
1191 $rootPart = $parts[0];
1192 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1193 $ip = User
::isIP( $rootPart );
1194 $block = Block
::newFromTarget( $user, $user );
1196 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1197 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1198 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1199 } elseif ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
1200 # Show log extract if the user is currently blocked
1201 LogEventsList
::showLogExtract(
1204 MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget(),
1208 'showIfEmpty' => false,
1210 'blocked-notice-logextract',
1211 $user->getName() # Support GENDER in notice
1215 $validUserPage = !$title->isSubpage();
1217 $validUserPage = !$title->isSubpage();
1221 Hooks
::run( 'ShowMissingArticle', array( $this ) );
1223 // Give extensions a chance to hide their (unrelated) log entries
1224 $logTypes = array( 'delete', 'move' );
1225 $conds = array( "log_action != 'revision'" );
1226 Hooks
::run( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1228 # Show delete and move logs
1229 LogEventsList
::showLogExtract( $outputPage, $logTypes, $title, '',
1232 'showIfEmpty' => false,
1233 'msgKey' => array( 'moveddeleted-notice' ) )
1236 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1237 // If there's no backing content, send a 404 Not Found
1238 // for better machine handling of broken links.
1239 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1242 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1243 $policy = $this->getRobotPolicy( 'view' );
1244 $outputPage->setIndexPolicy( $policy['index'] );
1245 $outputPage->setFollowPolicy( $policy['follow'] );
1247 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', array( $this ) );
1249 if ( !$hookResult ) {
1253 # Show error message
1254 $oldid = $this->getOldID();
1256 $text = wfMessage( 'missing-revision', $oldid )->plain();
1257 } elseif ( $title->getNamespace() === NS_MEDIAWIKI
) {
1258 // Use the default message text
1259 $text = $title->getDefaultMessageText();
1260 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1261 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1263 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1264 $text = wfMessage( $message )->plain();
1266 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1268 $text = "<div class='noarticletext'>\n$text\n</div>";
1270 $outputPage->addWikiText( $text );
1274 * If the revision requested for view is deleted, check permissions.
1275 * Send either an error message or a warning header to the output.
1277 * @return bool True if the view is allowed, false if not.
1279 public function showDeletedRevisionHeader() {
1280 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1285 $outputPage = $this->getContext()->getOutput();
1286 $user = $this->getContext()->getUser();
1287 // If the user is not allowed to see it...
1288 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1289 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1290 'rev-deleted-text-permission' );
1293 // If the user needs to confirm that they want to see it...
1294 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1295 # Give explanation and add a link to view the revision...
1296 $oldid = intval( $this->getOldID() );
1297 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1298 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1299 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1300 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1301 array( $msg, $link ) );
1304 // We are allowed to see...
1306 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1307 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1308 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1315 * Generate the navigation links when browsing through an article revisions
1316 * It shows the information as:
1317 * Revision as of \<date\>; view current revision
1318 * \<- Previous version | Next Version -\>
1320 * @param int $oldid Revision ID of this article revision
1322 public function setOldSubtitle( $oldid = 0 ) {
1323 if ( !Hooks
::run( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1327 $context = $this->getContext();
1328 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1330 # Cascade unhide param in links for easy deletion browsing
1331 $extraParams = array();
1333 $extraParams['unhide'] = 1;
1336 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1337 $revision = $this->mRevision
;
1339 $revision = Revision
::newFromId( $oldid );
1342 $timestamp = $revision->getTimestamp();
1344 $current = ( $oldid == $this->mPage
->getLatest() );
1345 $language = $context->getLanguage();
1346 $user = $context->getUser();
1348 $td = $language->userTimeAndDate( $timestamp, $user );
1349 $tddate = $language->userDate( $timestamp, $user );
1350 $tdtime = $language->userTime( $timestamp, $user );
1352 # Show user links if allowed to see them. If hidden, then show them only if requested...
1353 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1355 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1356 ?
'revision-info-current'
1359 $outputPage = $context->getOutput();
1360 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" .
1361 $context->msg( $infomsg, $td )
1362 ->rawParams( $userlinks )
1363 ->params( $revision->getID(), $tddate, $tdtime, $revision->getUserText() )
1364 ->rawParams( Linker
::revComment( $revision, true, true ) )
1370 ?
$context->msg( 'currentrevisionlink' )->escaped()
1371 : Linker
::linkKnown(
1373 $context->msg( 'currentrevisionlink' )->escaped(),
1378 ?
$context->msg( 'diff' )->escaped()
1379 : Linker
::linkKnown(
1381 $context->msg( 'diff' )->escaped(),
1388 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1390 ? Linker
::linkKnown(
1392 $context->msg( 'previousrevision' )->escaped(),
1395 'direction' => 'prev',
1399 : $context->msg( 'previousrevision' )->escaped();
1401 ? Linker
::linkKnown(
1403 $context->msg( 'diff' )->escaped(),
1410 : $context->msg( 'diff' )->escaped();
1411 $nextlink = $current
1412 ?
$context->msg( 'nextrevision' )->escaped()
1413 : Linker
::linkKnown(
1415 $context->msg( 'nextrevision' )->escaped(),
1418 'direction' => 'next',
1422 $nextdiff = $current
1423 ?
$context->msg( 'diff' )->escaped()
1424 : Linker
::linkKnown(
1426 $context->msg( 'diff' )->escaped(),
1434 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1435 if ( $cdel !== '' ) {
1439 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1440 $context->msg( 'revision-nav' )->rawParams(
1441 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1442 )->escaped() . "</div>" );
1446 * Return the HTML for the top of a redirect page
1448 * Chances are you should just be using the ParserOutput from
1449 * WikitextContent::getParserOutput instead of calling this for redirects.
1451 * @param Title|array $target Destination(s) to redirect
1452 * @param bool $appendSubtitle [optional]
1453 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1454 * @return string Containing HTML with redirect link
1456 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1457 $lang = $this->getTitle()->getPageLanguage();
1458 $out = $this->getContext()->getOutput();
1459 if ( $appendSubtitle ) {
1460 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1462 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1463 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
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.
1473 * @param Language $lang
1474 * @param Title|array $target Destination(s) to redirect
1475 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1476 * @return string Containing HTML with redirect link
1478 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1479 if ( !is_array( $target ) ) {
1480 $target = array( $target );
1483 $html = '<ul class="redirectText">';
1484 /** @var Title $title */
1485 foreach ( $target as $title ) {
1486 $html .= '<li>' . Linker
::link(
1488 htmlspecialchars( $title->getFullText() ),
1490 // Automatically append redirect=no to each link, since most of them are
1491 // redirect pages themselves.
1492 array( 'redirect' => 'no' ),
1493 ( $forceKnown ?
array( 'known', 'noclasses' ) : array() )
1498 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->text();
1500 return '<div class="redirectMsg">' .
1501 '<p>' . $redirectToText . '</p>' .
1507 * Handle action=render
1509 public function render() {
1510 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1511 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1512 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1517 * action=protect handler
1519 public function protect() {
1520 $form = new ProtectionForm( $this );
1525 * action=unprotect handler (alias)
1527 public function unprotect() {
1532 * UI entry point for page deletion
1534 public function delete() {
1535 # This code desperately needs to be totally rewritten
1537 $title = $this->getTitle();
1538 $context = $this->getContext();
1539 $user = $context->getUser();
1542 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1543 if ( count( $permissionErrors ) ) {
1544 throw new PermissionsError( 'delete', $permissionErrors );
1547 # Read-only check...
1548 if ( wfReadOnly() ) {
1549 throw new ReadOnlyError
;
1552 # Better double-check that it hasn't been deleted yet!
1553 $this->mPage
->loadPageData( 'fromdbmaster' );
1554 if ( !$this->mPage
->exists() ) {
1555 $deleteLogPage = new LogPage( 'delete' );
1556 $outputPage = $context->getOutput();
1557 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1558 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1559 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1561 $outputPage->addHTML(
1562 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1564 LogEventsList
::showLogExtract(
1573 $request = $context->getRequest();
1574 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1575 $deleteReason = $request->getText( 'wpReason' );
1577 if ( $deleteReasonList == 'other' ) {
1578 $reason = $deleteReason;
1579 } elseif ( $deleteReason != '' ) {
1580 // Entry from drop down menu + additional comment
1581 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1582 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1584 $reason = $deleteReasonList;
1587 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1588 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1590 # Flag to hide all contents of the archived revisions
1591 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1593 $this->doDelete( $reason, $suppress );
1595 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1600 // Generate deletion reason
1601 $hasHistory = false;
1604 $reason = $this->generateReason( $hasHistory );
1605 } catch ( Exception
$e ) {
1606 # if a page is horribly broken, we still want to be able to
1607 # delete it. So be lenient about errors here.
1608 wfDebug( "Error while building auto delete summary: $e" );
1613 // If the page has a history, insert a warning
1614 if ( $hasHistory ) {
1615 $title = $this->getTitle();
1617 // The following can use the real revision count as this is only being shown for users
1618 // that can delete this page.
1619 // This, as a side-effect, also makes sure that the following query isn't being run for
1620 // pages with a larger history, unless the user has the 'bigdelete' right
1621 // (and is about to delete this page).
1622 $dbr = wfGetDB( DB_SLAVE
);
1623 $revisions = $edits = (int)$dbr->selectField(
1626 array( 'rev_page' => $title->getArticleID() ),
1630 // @todo FIXME: i18n issue/patchwork message
1631 $context->getOutput()->addHTML(
1632 '<strong class="mw-delete-warning-revisions">' .
1633 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1634 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1635 $context->msg( 'history' )->escaped(),
1636 array( 'rel' => 'archives' ),
1637 array( 'action' => 'history' ) ) .
1641 if ( $title->isBigDeletion() ) {
1642 global $wgDeleteRevisionsLimit;
1643 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1645 'delete-warning-toobig',
1646 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1652 $this->confirmDelete( $reason );
1656 * Output deletion confirmation dialog
1657 * @todo FIXME: Move to another file?
1658 * @param string $reason Prefilled reason
1660 public function confirmDelete( $reason ) {
1661 wfDebug( "Article::confirmDelete\n" );
1663 $title = $this->getTitle();
1664 $ctx = $this->getContext();
1665 $outputPage = $ctx->getOutput();
1666 $useMediaWikiUIEverywhere = $ctx->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1667 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1668 $outputPage->addBacklinkSubtitle( $title );
1669 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1670 $backlinkCache = $title->getBacklinkCache();
1671 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1672 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1673 'deleting-backlinks-warning' );
1675 $outputPage->addWikiMsg( 'confirmdeletetext' );
1677 Hooks
::run( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1679 $user = $this->getContext()->getUser();
1681 if ( $user->isAllowed( 'suppressrevision' ) ) {
1682 $suppress = Html
::openElement( 'div', array( 'id' => 'wpDeleteSuppressRow' ) ) .
1684 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1685 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1687 Html
::closeElement( 'div' );
1691 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1693 $form = Html
::openElement( 'form', array( 'method' => 'post',
1694 'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1695 Html
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1696 Html
::element( 'legend', null, wfMessage( 'delete-legend' )->text() ) .
1697 Html
::openElement( 'div', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1698 Html
::openElement( 'div', array( 'id' => 'wpDeleteReasonListRow' ) ) .
1699 Html
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1702 'wpDeleteReasonList',
1703 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1704 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1709 Html
::closeElement( 'div' ) .
1710 Html
::openElement( 'div', array( 'id' => 'wpDeleteReasonRow' ) ) .
1711 Html
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1713 Html
::input( 'wpReason', $reason, 'text', array(
1715 'maxlength' => '255',
1718 'class' => 'mw-ui-input-inline',
1721 Html
::closeElement( 'div' );
1723 # Disallow watching if user is not logged in
1724 if ( $user->isLoggedIn() ) {
1726 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1727 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) );
1731 Html
::openElement( 'div' ) .
1733 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1735 'name' => 'wpConfirmB',
1736 'id' => 'wpConfirmB',
1738 'class' => $useMediaWikiUIEverywhere ?
'mw-ui-button mw-ui-destructive' : '',
1741 Html
::closeElement( 'div' ) .
1742 Html
::closeElement( 'div' ) .
1743 Xml
::closeElement( 'fieldset' ) .
1746 $user->getEditToken( array( 'delete', $title->getPrefixedText() ) )
1748 Xml
::closeElement( 'form' );
1750 if ( $user->isAllowed( 'editinterface' ) ) {
1751 $dropdownTitle = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1752 $link = Linker
::link(
1754 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1756 array( 'action' => 'edit' )
1758 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1761 $outputPage->addHTML( $form );
1763 $deleteLogPage = new LogPage( 'delete' );
1764 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1765 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
1769 * Perform a deletion and output success or failure messages
1770 * @param string $reason
1771 * @param bool $suppress
1773 public function doDelete( $reason, $suppress = false ) {
1775 $outputPage = $this->getContext()->getOutput();
1776 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1778 if ( $status->isGood() ) {
1779 $deleted = $this->getTitle()->getPrefixedText();
1781 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1782 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1784 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1786 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1788 Hooks
::run( 'ArticleDeleteAfterSuccess', array( $this->getTitle(), $outputPage ) );
1790 $outputPage->returnToMain( false );
1792 $outputPage->setPageTitle(
1793 wfMessage( 'cannotdelete-title',
1794 $this->getTitle()->getPrefixedText() )
1797 if ( $error == '' ) {
1798 $outputPage->addWikiText(
1799 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1801 $deleteLogPage = new LogPage( 'delete' );
1802 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1804 LogEventsList
::showLogExtract(
1810 $outputPage->addHTML( $error );
1815 /* Caching functions */
1818 * checkLastModified returns true if it has taken care of all
1819 * output to the client that is necessary for this request.
1820 * (that is, it has sent a cached version of the page)
1822 * @return bool True if cached version send, false otherwise
1824 protected function tryFileCache() {
1825 static $called = false;
1828 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1833 if ( $this->isFileCacheable() ) {
1834 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
1835 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1836 wfDebug( "Article::tryFileCache(): about to load file\n" );
1837 $cache->loadFromFileCache( $this->getContext() );
1840 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1841 ob_start( array( &$cache, 'saveToFileCache' ) );
1844 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1851 * Check if the page can be cached
1854 public function isFileCacheable() {
1857 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1858 $cacheable = $this->mPage
->getID()
1859 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1860 // Extension may have reason to disable file caching on some pages.
1862 $cacheable = Hooks
::run( 'IsFileCacheable', array( &$this ) );
1872 * Lightweight method to get the parser output for a page, checking the parser cache
1873 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1874 * consider, so it's not appropriate to use there.
1876 * @since 1.16 (r52326) for LiquidThreads
1878 * @param int|null $oldid Revision ID or null
1879 * @param User $user The relevant user
1880 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1882 public function getParserOutput( $oldid = null, User
$user = null ) {
1883 //XXX: bypasses mParserOptions and thus setParserOptions()
1885 if ( $user === null ) {
1886 $parserOptions = $this->getParserOptions();
1888 $parserOptions = $this->mPage
->makeParserOptions( $user );
1891 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1895 * Override the ParserOptions used to render the primary article wikitext.
1897 * @param ParserOptions $options
1898 * @throws MWException If the parser options where already initialized.
1900 public function setParserOptions( ParserOptions
$options ) {
1901 if ( $this->mParserOptions
) {
1902 throw new MWException( "can't change parser options after they have already been set" );
1905 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1906 $this->mParserOptions
= clone $options;
1910 * Get parser options suitable for rendering the primary article wikitext
1911 * @return ParserOptions
1913 public function getParserOptions() {
1914 if ( !$this->mParserOptions
) {
1915 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1917 // Clone to allow modifications of the return value without affecting cache
1918 return clone $this->mParserOptions
;
1922 * Sets the context this Article is executed in
1924 * @param IContextSource $context
1927 public function setContext( $context ) {
1928 $this->mContext
= $context;
1932 * Gets the context this Article is executed in
1934 * @return IContextSource
1937 public function getContext() {
1938 if ( $this->mContext
instanceof IContextSource
) {
1939 return $this->mContext
;
1941 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1942 "Return RequestContext::getMain(); for sanity\n" );
1943 return RequestContext
::getMain();
1948 * Use PHP's magic __get handler to handle accessing of
1949 * raw WikiPage fields for backwards compatibility.
1951 * @param string $fname Field name
1954 public function __get( $fname ) {
1955 if ( property_exists( $this->mPage
, $fname ) ) {
1956 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1957 return $this->mPage
->$fname;
1959 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1963 * Use PHP's magic __set handler to handle setting of
1964 * raw WikiPage fields for backwards compatibility.
1966 * @param string $fname Field name
1967 * @param mixed $fvalue New value
1969 public function __set( $fname, $fvalue ) {
1970 if ( property_exists( $this->mPage
, $fname ) ) {
1971 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1972 $this->mPage
->$fname = $fvalue;
1973 // Note: extensions may want to toss on new fields
1974 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1975 $this->mPage
->$fname = $fvalue;
1977 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1982 * Use PHP's magic __call handler to transform instance calls to
1983 * WikiPage functions for backwards compatibility.
1985 * @param string $fname Name of called method
1986 * @param array $args Arguments to the method
1989 public function __call( $fname, $args ) {
1990 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1991 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1992 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1994 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1997 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2000 * @param array $limit
2001 * @param array $expiry
2002 * @param bool $cascade
2003 * @param string $reason
2007 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2010 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2014 * @param array $limit
2015 * @param string $reason
2016 * @param int $cascade
2017 * @param array $expiry
2020 public function updateRestrictions( $limit = array(), $reason = '',
2021 &$cascade = 0, $expiry = array()
2023 return $this->mPage
->doUpdateRestrictions(
2028 $this->getContext()->getUser()
2033 * @param string $reason
2034 * @param bool $suppress
2036 * @param bool $commit
2037 * @param string $error
2040 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2041 $commit = true, &$error = ''
2043 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2047 * @param string $fromP
2048 * @param string $summary
2049 * @param string $token
2051 * @param array $resultDetails
2052 * @param User|null $user
2055 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2056 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2057 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2061 * @param string $fromP
2062 * @param string $summary
2064 * @param array $resultDetails
2065 * @param User|null $guser
2068 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2069 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2070 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2074 * @param bool $hasHistory
2077 public function generateReason( &$hasHistory ) {
2078 $title = $this->mPage
->getTitle();
2079 $handler = ContentHandler
::getForTitle( $title );
2080 return $handler->getAutoDeleteReason( $title, $hasHistory );
2083 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2088 * @deprecated since 1.24, use WikiPage::selectFields() instead
2090 public static function selectFields() {
2091 wfDeprecated( __METHOD__
, '1.24' );
2092 return WikiPage
::selectFields();
2096 * @param Title $title
2098 * @deprecated since 1.24, use WikiPage::onArticleCreate() instead
2100 public static function onArticleCreate( $title ) {
2101 wfDeprecated( __METHOD__
, '1.24' );
2102 WikiPage
::onArticleCreate( $title );
2106 * @param Title $title
2108 * @deprecated since 1.24, use WikiPage::onArticleDelete() instead
2110 public static function onArticleDelete( $title ) {
2111 wfDeprecated( __METHOD__
, '1.24' );
2112 WikiPage
::onArticleDelete( $title );
2116 * @param Title $title
2118 * @deprecated since 1.24, use WikiPage::onArticleEdit() instead
2120 public static function onArticleEdit( $title ) {
2121 wfDeprecated( __METHOD__
, '1.24' );
2122 WikiPage
::onArticleEdit( $title );
2126 * @param string $oldtext
2127 * @param string $newtext
2130 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2132 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2133 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );