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*/oldid 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;
962 $context = $this->getContext();
963 $outputPage = $context->getOutput();
964 $request = $context->getRequest();
965 $rdfrom = $request->getVal( 'rdfrom' );
967 // Construct a URL for the current page view, but with the target title
968 $query = $request->getValues();
969 unset( $query['rdfrom'] );
970 unset( $query['title'] );
971 if ( $this->getTitle()->isRedirect() ) {
972 // Prevent double redirects
973 $query['redirect'] = 'no';
975 $redirectTargetUrl = $this->getTitle()->getLinkURL( $query );
977 if ( isset( $this->mRedirectedFrom
) ) {
978 // This is an internally redirected page view.
979 // We'll need a backlink to the source page for navigation.
980 if ( Hooks
::run( 'ArticleViewRedirect', array( &$this ) ) ) {
981 $redir = Linker
::linkKnown(
982 $this->mRedirectedFrom
,
985 array( 'redirect' => 'no' )
988 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
989 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
992 // Add the script to update the displayed URL and
993 // set the fragment if one was specified in the redirect
994 $outputPage->addJsConfigVars( array(
995 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
997 $outputPage->addModules( 'mediawiki.action.view.redirect' );
999 // Add a <link rel="canonical"> tag
1000 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
1002 // Tell the output object that the user arrived at this article through a redirect
1003 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1007 } elseif ( $rdfrom ) {
1008 // This is an externally redirected view, from some other wiki.
1009 // If it was reported from a trusted site, supply a backlink.
1010 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1011 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1012 $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" .
1013 $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse()
1016 // Add the script to update the displayed URL
1017 $outputPage->addJsConfigVars( array(
1018 'wgInternalRedirectTargetUrl' => $redirectTargetUrl,
1020 $outputPage->addModules( 'mediawiki.action.view.redirect' );
1030 * Show a header specific to the namespace currently being viewed, like
1031 * [[MediaWiki:Talkpagetext]]. For Article::view().
1033 public function showNamespaceHeader() {
1034 if ( $this->getTitle()->isTalkPage() ) {
1035 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1036 $this->getContext()->getOutput()->wrapWikiMsg(
1037 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1038 array( 'talkpageheader' )
1045 * Show the footer section of an ordinary page view
1047 public function showViewFooter() {
1048 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1049 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1050 && IP
::isValid( $this->getTitle()->getText() )
1052 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1055 // Show a footer allowing the user to patrol the shown revision or page if possible
1056 $patrolFooterShown = $this->showPatrolFooter();
1058 Hooks
::run( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1062 * If patrol is possible, output a patrol UI box. This is called from the
1063 * footer section of ordinary page views. If patrol is not possible or not
1064 * desired, does nothing.
1065 * Side effect: When the patrol link is build, this method will call
1066 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1070 public function showPatrolFooter() {
1071 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1073 $outputPage = $this->getContext()->getOutput();
1074 $user = $this->getContext()->getUser();
1075 $cache = wfGetMainCache();
1078 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1079 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1081 // Patrolling is disabled or the user isn't allowed to
1085 // New page patrol: Get the timestamp of the oldest revison which
1086 // the revision table holds for the given page. Then we look
1087 // whether it's within the RC lifespan and if it is, we try
1088 // to get the recentchanges row belonging to that entry
1089 // (with rc_new = 1).
1091 // Check for cached results
1092 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1096 if ( $this->mRevision
1097 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1099 // The current revision is already older than what could be in the RC table
1100 // 6h tolerance because the RC might not be cleaned out regularly
1104 $dbr = wfGetDB( DB_SLAVE
);
1105 $oldestRevisionTimestamp = $dbr->selectField(
1107 'MIN( rev_timestamp )',
1108 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1112 if ( $oldestRevisionTimestamp
1113 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1115 // 6h tolerance because the RC might not be cleaned out regularly
1116 $rc = RecentChange
::newFromConds(
1119 'rc_timestamp' => $oldestRevisionTimestamp,
1120 'rc_namespace' => $this->getTitle()->getNamespace(),
1121 'rc_cur_id' => $this->getTitle()->getArticleID(),
1125 array( 'USE INDEX' => 'new_name_timestamp' )
1130 // No RC entry around
1132 // Cache the information we gathered above in case we can't patrol
1133 // Don't cache in case we can patrol as this could change
1134 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1139 if ( $rc->getPerformer()->equals( $user ) ) {
1140 // Don't show a patrol link for own creations. If the user could
1141 // patrol them, they already would be patrolled
1145 $rcid = $rc->getAttribute( 'rc_id' );
1147 $token = $user->getEditToken( $rcid );
1149 $outputPage->preventClickjacking();
1150 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1151 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1154 $link = Linker
::linkKnown(
1156 wfMessage( 'markaspatrolledtext' )->escaped(),
1159 'action' => 'markpatrolled',
1165 $outputPage->addHTML(
1166 "<div class='patrollink'>" .
1167 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1175 * Show the error text for a missing article. For articles in the MediaWiki
1176 * namespace, show the default message text. To be called from Article::view().
1178 public function showMissingArticle() {
1179 global $wgSend404Code;
1181 $outputPage = $this->getContext()->getOutput();
1182 // Whether the page is a root user page of an existing user (but not a subpage)
1183 $validUserPage = false;
1185 $title = $this->getTitle();
1187 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1188 if ( $title->getNamespace() == NS_USER
1189 ||
$title->getNamespace() == NS_USER_TALK
1191 $parts = explode( '/', $title->getText() );
1192 $rootPart = $parts[0];
1193 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1194 $ip = User
::isIP( $rootPart );
1195 $block = Block
::newFromTarget( $user, $user );
1197 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1198 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1199 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1200 } elseif ( !is_null( $block ) && $block->getType() != Block
::TYPE_AUTO
) {
1201 # Show log extract if the user is currently blocked
1202 LogEventsList
::showLogExtract(
1205 MWNamespace
::getCanonicalName( NS_USER
) . ':' . $block->getTarget(),
1209 'showIfEmpty' => false,
1211 'blocked-notice-logextract',
1212 $user->getName() # Support GENDER in notice
1216 $validUserPage = !$title->isSubpage();
1218 $validUserPage = !$title->isSubpage();
1222 Hooks
::run( 'ShowMissingArticle', array( $this ) );
1224 // Give extensions a chance to hide their (unrelated) log entries
1225 $logTypes = array( 'delete', 'move' );
1226 $conds = array( "log_action != 'revision'" );
1227 Hooks
::run( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1229 # Show delete and move logs
1230 LogEventsList
::showLogExtract( $outputPage, $logTypes, $title, '',
1233 'showIfEmpty' => false,
1234 'msgKey' => array( 'moveddeleted-notice' ) )
1237 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1238 // If there's no backing content, send a 404 Not Found
1239 // for better machine handling of broken links.
1240 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1243 // Also apply the robot policy for nonexisting pages (even if a 404 was used for sanity)
1244 $policy = $this->getRobotPolicy( 'view' );
1245 $outputPage->setIndexPolicy( $policy['index'] );
1246 $outputPage->setFollowPolicy( $policy['follow'] );
1248 $hookResult = Hooks
::run( 'BeforeDisplayNoArticleText', array( $this ) );
1250 if ( !$hookResult ) {
1254 # Show error message
1255 $oldid = $this->getOldID();
1257 $text = wfMessage( 'missing-revision', $oldid )->plain();
1258 } elseif ( $title->getNamespace() === NS_MEDIAWIKI
) {
1259 // Use the default message text
1260 $text = $title->getDefaultMessageText();
1261 } elseif ( $title->quickUserCan( 'create', $this->getContext()->getUser() )
1262 && $title->quickUserCan( 'edit', $this->getContext()->getUser() )
1264 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1265 $text = wfMessage( $message )->plain();
1267 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1269 $text = "<div class='noarticletext'>\n$text\n</div>";
1271 $outputPage->addWikiText( $text );
1275 * If the revision requested for view is deleted, check permissions.
1276 * Send either an error message or a warning header to the output.
1278 * @return bool True if the view is allowed, false if not.
1280 public function showDeletedRevisionHeader() {
1281 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1286 $outputPage = $this->getContext()->getOutput();
1287 $user = $this->getContext()->getUser();
1288 // If the user is not allowed to see it...
1289 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1290 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1291 'rev-deleted-text-permission' );
1294 // If the user needs to confirm that they want to see it...
1295 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1296 # Give explanation and add a link to view the revision...
1297 $oldid = intval( $this->getOldID() );
1298 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1299 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1300 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1301 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1302 array( $msg, $link ) );
1305 // We are allowed to see...
1307 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1308 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1309 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1316 * Generate the navigation links when browsing through an article revisions
1317 * It shows the information as:
1318 * Revision as of \<date\>; view current revision
1319 * \<- Previous version | Next Version -\>
1321 * @param int $oldid Revision ID of this article revision
1323 public function setOldSubtitle( $oldid = 0 ) {
1324 if ( !Hooks
::run( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1328 $context = $this->getContext();
1329 $unhide = $context->getRequest()->getInt( 'unhide' ) == 1;
1331 # Cascade unhide param in links for easy deletion browsing
1332 $extraParams = array();
1334 $extraParams['unhide'] = 1;
1337 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1338 $revision = $this->mRevision
;
1340 $revision = Revision
::newFromId( $oldid );
1343 $timestamp = $revision->getTimestamp();
1345 $current = ( $oldid == $this->mPage
->getLatest() );
1346 $language = $context->getLanguage();
1347 $user = $context->getUser();
1349 $td = $language->userTimeAndDate( $timestamp, $user );
1350 $tddate = $language->userDate( $timestamp, $user );
1351 $tdtime = $language->userTime( $timestamp, $user );
1353 # Show user links if allowed to see them. If hidden, then show them only if requested...
1354 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1356 $infomsg = $current && !$context->msg( 'revision-info-current' )->isDisabled()
1357 ?
'revision-info-current'
1360 $outputPage = $context->getOutput();
1361 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" .
1362 $context->msg( $infomsg, $td )
1363 ->rawParams( $userlinks )
1364 ->params( $revision->getID(), $tddate, $tdtime, $revision->getUserText() )
1365 ->rawParams( Linker
::revComment( $revision, true, true ) )
1371 ?
$context->msg( 'currentrevisionlink' )->escaped()
1372 : Linker
::linkKnown(
1374 $context->msg( 'currentrevisionlink' )->escaped(),
1379 ?
$context->msg( 'diff' )->escaped()
1380 : Linker
::linkKnown(
1382 $context->msg( 'diff' )->escaped(),
1389 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1391 ? Linker
::linkKnown(
1393 $context->msg( 'previousrevision' )->escaped(),
1396 'direction' => 'prev',
1400 : $context->msg( 'previousrevision' )->escaped();
1402 ? Linker
::linkKnown(
1404 $context->msg( 'diff' )->escaped(),
1411 : $context->msg( 'diff' )->escaped();
1412 $nextlink = $current
1413 ?
$context->msg( 'nextrevision' )->escaped()
1414 : Linker
::linkKnown(
1416 $context->msg( 'nextrevision' )->escaped(),
1419 'direction' => 'next',
1423 $nextdiff = $current
1424 ?
$context->msg( 'diff' )->escaped()
1425 : Linker
::linkKnown(
1427 $context->msg( 'diff' )->escaped(),
1435 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1436 if ( $cdel !== '' ) {
1440 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1441 $context->msg( 'revision-nav' )->rawParams(
1442 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1443 )->escaped() . "</div>" );
1447 * Return the HTML for the top of a redirect page
1449 * Chances are you should just be using the ParserOutput from
1450 * WikitextContent::getParserOutput instead of calling this for redirects.
1452 * @param Title|array $target Destination(s) to redirect
1453 * @param bool $appendSubtitle [optional]
1454 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1455 * @return string Containing HTML with redirect link
1457 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1458 $lang = $this->getTitle()->getPageLanguage();
1459 $out = $this->getContext()->getOutput();
1460 if ( $appendSubtitle ) {
1461 $out->addSubtitle( wfMessage( 'redirectpagesub' ) );
1463 $out->addModuleStyles( 'mediawiki.action.view.redirectPage' );
1464 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1468 * Return the HTML for the top of a redirect page
1470 * Chances are you should just be using the ParserOutput from
1471 * WikitextContent::getParserOutput instead of calling this for redirects.
1474 * @param Language $lang
1475 * @param Title|array $target Destination(s) to redirect
1476 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1477 * @return string Containing HTML with redirect link
1479 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1480 if ( !is_array( $target ) ) {
1481 $target = array( $target );
1484 $html = '<ul class="redirectText">';
1485 /** @var Title $title */
1486 foreach ( $target as $title ) {
1487 $html .= '<li>' . Linker
::link(
1489 htmlspecialchars( $title->getFullText() ),
1491 // Automatically append redirect=no to each link, since most of them are
1492 // redirect pages themselves.
1493 array( 'redirect' => 'no' ),
1494 ( $forceKnown ?
array( 'known', 'noclasses' ) : array() )
1499 $redirectToText = wfMessage( 'redirectto' )->inLanguage( $lang )->escaped();
1501 return '<div class="redirectMsg">' .
1502 '<p>' . $redirectToText . '</p>' .
1508 * Handle action=render
1510 public function render() {
1511 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1512 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1513 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1518 * action=protect handler
1520 public function protect() {
1521 $form = new ProtectionForm( $this );
1526 * action=unprotect handler (alias)
1528 public function unprotect() {
1533 * UI entry point for page deletion
1535 public function delete() {
1536 # This code desperately needs to be totally rewritten
1538 $title = $this->getTitle();
1539 $context = $this->getContext();
1540 $user = $context->getUser();
1543 $permissionErrors = $title->getUserPermissionsErrors( 'delete', $user );
1544 if ( count( $permissionErrors ) ) {
1545 throw new PermissionsError( 'delete', $permissionErrors );
1548 # Read-only check...
1549 if ( wfReadOnly() ) {
1550 throw new ReadOnlyError
;
1553 # Better double-check that it hasn't been deleted yet!
1554 $this->mPage
->loadPageData( 'fromdbmaster' );
1555 if ( !$this->mPage
->exists() ) {
1556 $deleteLogPage = new LogPage( 'delete' );
1557 $outputPage = $context->getOutput();
1558 $outputPage->setPageTitle( $context->msg( 'cannotdelete-title', $title->getPrefixedText() ) );
1559 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1560 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1562 $outputPage->addHTML(
1563 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1565 LogEventsList
::showLogExtract(
1574 $request = $context->getRequest();
1575 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1576 $deleteReason = $request->getText( 'wpReason' );
1578 if ( $deleteReasonList == 'other' ) {
1579 $reason = $deleteReason;
1580 } elseif ( $deleteReason != '' ) {
1581 // Entry from drop down menu + additional comment
1582 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1583 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1585 $reason = $deleteReasonList;
1588 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1589 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1591 # Flag to hide all contents of the archived revisions
1592 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1594 $this->doDelete( $reason, $suppress );
1596 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1601 // Generate deletion reason
1602 $hasHistory = false;
1605 $reason = $this->generateReason( $hasHistory );
1606 } catch ( Exception
$e ) {
1607 # if a page is horribly broken, we still want to be able to
1608 # delete it. So be lenient about errors here.
1609 wfDebug( "Error while building auto delete summary: $e" );
1614 // If the page has a history, insert a warning
1615 if ( $hasHistory ) {
1616 $title = $this->getTitle();
1618 // The following can use the real revision count as this is only being shown for users
1619 // that can delete this page.
1620 // This, as a side-effect, also makes sure that the following query isn't being run for
1621 // pages with a larger history, unless the user has the 'bigdelete' right
1622 // (and is about to delete this page).
1623 $dbr = wfGetDB( DB_SLAVE
);
1624 $revisions = $edits = (int)$dbr->selectField(
1627 array( 'rev_page' => $title->getArticleID() ),
1631 // @todo FIXME: i18n issue/patchwork message
1632 $context->getOutput()->addHTML(
1633 '<strong class="mw-delete-warning-revisions">' .
1634 $context->msg( 'historywarning' )->numParams( $revisions )->parse() .
1635 $context->msg( 'word-separator' )->escaped() . Linker
::linkKnown( $title,
1636 $context->msg( 'history' )->escaped(),
1637 array( 'rel' => 'archives' ),
1638 array( 'action' => 'history' ) ) .
1642 if ( $title->isBigDeletion() ) {
1643 global $wgDeleteRevisionsLimit;
1644 $context->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1646 'delete-warning-toobig',
1647 $context->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1653 $this->confirmDelete( $reason );
1657 * Output deletion confirmation dialog
1658 * @todo FIXME: Move to another file?
1659 * @param string $reason Prefilled reason
1661 public function confirmDelete( $reason ) {
1662 wfDebug( "Article::confirmDelete\n" );
1664 $title = $this->getTitle();
1665 $ctx = $this->getContext();
1666 $outputPage = $ctx->getOutput();
1667 $useMediaWikiUIEverywhere = $ctx->getConfig()->get( 'UseMediaWikiUIEverywhere' );
1668 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $title->getPrefixedText() ) );
1669 $outputPage->addBacklinkSubtitle( $title );
1670 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1671 $backlinkCache = $title->getBacklinkCache();
1672 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1673 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1674 'deleting-backlinks-warning' );
1676 $outputPage->addWikiMsg( 'confirmdeletetext' );
1678 Hooks
::run( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1680 $user = $this->getContext()->getUser();
1682 if ( $user->isAllowed( 'suppressrevision' ) ) {
1683 $suppress = Html
::openElement( 'div', array( 'id' => 'wpDeleteSuppressRow' ) ) .
1685 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1686 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1688 Html
::closeElement( 'div' );
1692 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $title );
1694 $form = Html
::openElement( 'form', array( 'method' => 'post',
1695 'action' => $title->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1696 Html
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1697 Html
::element( 'legend', null, wfMessage( 'delete-legend' )->text() ) .
1698 Html
::openElement( 'div', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1699 Html
::openElement( 'div', array( 'id' => 'wpDeleteReasonListRow' ) ) .
1700 Html
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1703 'wpDeleteReasonList',
1704 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1705 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1710 Html
::closeElement( 'div' ) .
1711 Html
::openElement( 'div', array( 'id' => 'wpDeleteReasonRow' ) ) .
1712 Html
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1714 Html
::input( 'wpReason', $reason, 'text', array(
1716 'maxlength' => '255',
1719 'class' => 'mw-ui-input-inline',
1722 Html
::closeElement( 'div' );
1724 # Disallow watching if user is not logged in
1725 if ( $user->isLoggedIn() ) {
1727 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1728 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) );
1732 Html
::openElement( 'div' ) .
1734 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1736 'name' => 'wpConfirmB',
1737 'id' => 'wpConfirmB',
1739 'class' => $useMediaWikiUIEverywhere ?
'mw-ui-button mw-ui-destructive' : '',
1742 Html
::closeElement( 'div' ) .
1743 Html
::closeElement( 'div' ) .
1744 Xml
::closeElement( 'fieldset' ) .
1747 $user->getEditToken( array( 'delete', $title->getPrefixedText() ) )
1749 Xml
::closeElement( 'form' );
1751 if ( $user->isAllowed( 'editinterface' ) ) {
1752 $dropdownTitle = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1753 $link = Linker
::link(
1755 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1757 array( 'action' => 'edit' )
1759 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1762 $outputPage->addHTML( $form );
1764 $deleteLogPage = new LogPage( 'delete' );
1765 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1766 LogEventsList
::showLogExtract( $outputPage, 'delete', $title );
1770 * Perform a deletion and output success or failure messages
1771 * @param string $reason
1772 * @param bool $suppress
1774 public function doDelete( $reason, $suppress = false ) {
1776 $outputPage = $this->getContext()->getOutput();
1777 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1779 if ( $status->isGood() ) {
1780 $deleted = $this->getTitle()->getPrefixedText();
1782 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1783 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1785 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1787 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1789 Hooks
::run( 'ArticleDeleteAfterSuccess', array( $this->getTitle(), $outputPage ) );
1791 $outputPage->returnToMain( false );
1793 $outputPage->setPageTitle(
1794 wfMessage( 'cannotdelete-title',
1795 $this->getTitle()->getPrefixedText() )
1798 if ( $error == '' ) {
1799 $outputPage->addWikiText(
1800 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1802 $deleteLogPage = new LogPage( 'delete' );
1803 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1805 LogEventsList
::showLogExtract(
1811 $outputPage->addHTML( $error );
1816 /* Caching functions */
1819 * checkLastModified returns true if it has taken care of all
1820 * output to the client that is necessary for this request.
1821 * (that is, it has sent a cached version of the page)
1823 * @return bool True if cached version send, false otherwise
1825 protected function tryFileCache() {
1826 static $called = false;
1829 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1834 if ( $this->isFileCacheable() ) {
1835 $cache = new HTMLFileCache( $this->getTitle(), 'view' );
1836 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1837 wfDebug( "Article::tryFileCache(): about to load file\n" );
1838 $cache->loadFromFileCache( $this->getContext() );
1841 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1842 ob_start( array( &$cache, 'saveToFileCache' ) );
1845 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1852 * Check if the page can be cached
1855 public function isFileCacheable() {
1858 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1859 $cacheable = $this->mPage
->getID()
1860 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1861 // Extension may have reason to disable file caching on some pages.
1863 $cacheable = Hooks
::run( 'IsFileCacheable', array( &$this ) );
1873 * Lightweight method to get the parser output for a page, checking the parser cache
1874 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1875 * consider, so it's not appropriate to use there.
1877 * @since 1.16 (r52326) for LiquidThreads
1879 * @param int|null $oldid Revision ID or null
1880 * @param User $user The relevant user
1881 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1883 public function getParserOutput( $oldid = null, User
$user = null ) {
1884 //XXX: bypasses mParserOptions and thus setParserOptions()
1886 if ( $user === null ) {
1887 $parserOptions = $this->getParserOptions();
1889 $parserOptions = $this->mPage
->makeParserOptions( $user );
1892 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1896 * Override the ParserOptions used to render the primary article wikitext.
1898 * @param ParserOptions $options
1899 * @throws MWException If the parser options where already initialized.
1901 public function setParserOptions( ParserOptions
$options ) {
1902 if ( $this->mParserOptions
) {
1903 throw new MWException( "can't change parser options after they have already been set" );
1906 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1907 $this->mParserOptions
= clone $options;
1911 * Get parser options suitable for rendering the primary article wikitext
1912 * @return ParserOptions
1914 public function getParserOptions() {
1915 if ( !$this->mParserOptions
) {
1916 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1918 // Clone to allow modifications of the return value without affecting cache
1919 return clone $this->mParserOptions
;
1923 * Sets the context this Article is executed in
1925 * @param IContextSource $context
1928 public function setContext( $context ) {
1929 $this->mContext
= $context;
1933 * Gets the context this Article is executed in
1935 * @return IContextSource
1938 public function getContext() {
1939 if ( $this->mContext
instanceof IContextSource
) {
1940 return $this->mContext
;
1942 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1943 "Return RequestContext::getMain(); for sanity\n" );
1944 return RequestContext
::getMain();
1949 * Use PHP's magic __get handler to handle accessing of
1950 * raw WikiPage fields for backwards compatibility.
1952 * @param string $fname Field name
1955 public function __get( $fname ) {
1956 if ( property_exists( $this->mPage
, $fname ) ) {
1957 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1958 return $this->mPage
->$fname;
1960 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1964 * Use PHP's magic __set handler to handle setting of
1965 * raw WikiPage fields for backwards compatibility.
1967 * @param string $fname Field name
1968 * @param mixed $fvalue New value
1970 public function __set( $fname, $fvalue ) {
1971 if ( property_exists( $this->mPage
, $fname ) ) {
1972 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1973 $this->mPage
->$fname = $fvalue;
1974 // Note: extensions may want to toss on new fields
1975 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1976 $this->mPage
->$fname = $fvalue;
1978 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1983 * Use PHP's magic __call handler to transform instance calls to
1984 * WikiPage functions for backwards compatibility.
1986 * @param string $fname Name of called method
1987 * @param array $args Arguments to the method
1990 public function __call( $fname, $args ) {
1991 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1992 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1993 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1995 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1998 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2001 * @param array $limit
2002 * @param array $expiry
2003 * @param bool $cascade
2004 * @param string $reason
2008 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2011 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2015 * @param array $limit
2016 * @param string $reason
2017 * @param int $cascade
2018 * @param array $expiry
2021 public function updateRestrictions( $limit = array(), $reason = '',
2022 &$cascade = 0, $expiry = array()
2024 return $this->mPage
->doUpdateRestrictions(
2029 $this->getContext()->getUser()
2034 * @param string $reason
2035 * @param bool $suppress
2037 * @param bool $commit
2038 * @param string $error
2041 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2042 $commit = true, &$error = ''
2044 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2048 * @param string $fromP
2049 * @param string $summary
2050 * @param string $token
2052 * @param array $resultDetails
2053 * @param User|null $user
2056 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2057 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2058 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2062 * @param string $fromP
2063 * @param string $summary
2065 * @param array $resultDetails
2066 * @param User|null $guser
2069 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2070 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2071 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2075 * @param bool $hasHistory
2078 public function generateReason( &$hasHistory ) {
2079 $title = $this->mPage
->getTitle();
2080 $handler = ContentHandler
::getForTitle( $title );
2081 return $handler->getAutoDeleteReason( $title, $hasHistory );
2084 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2089 * @deprecated since 1.24, use WikiPage::selectFields() instead
2091 public static function selectFields() {
2092 wfDeprecated( __METHOD__
, '1.24' );
2093 return WikiPage
::selectFields();
2097 * @param Title $title
2099 * @deprecated since 1.24, use WikiPage::onArticleCreate() instead
2101 public static function onArticleCreate( $title ) {
2102 wfDeprecated( __METHOD__
, '1.24' );
2103 WikiPage
::onArticleCreate( $title );
2107 * @param Title $title
2109 * @deprecated since 1.24, use WikiPage::onArticleDelete() instead
2111 public static function onArticleDelete( $title ) {
2112 wfDeprecated( __METHOD__
, '1.24' );
2113 WikiPage
::onArticleDelete( $title );
2117 * @param Title $title
2119 * @deprecated since 1.24, use WikiPage::onArticleEdit() instead
2121 public static function onArticleEdit( $title ) {
2122 wfDeprecated( __METHOD__
, '1.24' );
2123 WikiPage
::onArticleEdit( $title );
2127 * @param string $oldtext
2128 * @param string $newtext
2131 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2133 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2134 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );