3 * User interface for page actions.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Class for viewing MediaWiki article and history.
26 * This maintains WikiPage functions for backwards compatibility.
28 * @todo Move and rewrite code to an Action class
30 * See design.txt for an overview.
31 * Note: edit user interface and cache support functions have been
32 * moved to separate EditPage and HTMLFileCache classes.
34 * @internal documentation reviewed 15 Mar 2010
36 class Article
implements Page
{
37 /** @var IContextSource The context this Article is executed in */
40 /** @var WikiPage The WikiPage object of this instance */
43 /** @var ParserOptions ParserOptions object for $wgUser articles */
44 public $mParserOptions;
47 * @var string Text of the revision we are working on
53 * @var Content Content of the revision we are working on
56 protected $mContentObject;
58 /** @var bool Is the content ($mContent) already loaded? */
59 protected $mContentLoaded = false;
61 /** @var int|null The oldid of the article that is to be shown, 0 for the current revision */
64 /** @var Title Title from which we were redirected here */
65 protected $mRedirectedFrom = null;
67 /** @var string|bool URL to redirect to or false if none */
68 protected $mRedirectUrl = false;
70 /** @var int Revision ID of revision we are working on */
71 protected $mRevIdFetched = 0;
73 /** @var Revision Revision we are working on */
74 protected $mRevision = null;
76 /** @var ParserOutput */
77 public $mParserOutput;
80 * Constructor and clear the article
81 * @param Title $title Reference to a Title object.
82 * @param int $oldId Revision ID, null to fetch from request, zero for current
84 public function __construct( Title
$title, $oldId = null ) {
85 $this->mOldId
= $oldId;
86 $this->mPage
= $this->newPage( $title );
93 protected function newPage( Title
$title ) {
94 return new WikiPage( $title );
98 * Constructor from a page id
99 * @param int $id Article ID to load
100 * @return Article|null
102 public static function newFromID( $id ) {
103 $t = Title
::newFromID( $id );
104 # @todo FIXME: Doesn't inherit right
105 return $t == null ?
null : new self( $t );
106 # return $t == null ? null : new static( $t ); // PHP 5.3
110 * Create an Article object of the appropriate class for the given page.
112 * @param Title $title
113 * @param IContextSource $context
116 public static function newFromTitle( $title, IContextSource
$context ) {
117 if ( NS_MEDIA
== $title->getNamespace() ) {
118 // FIXME: where should this go?
119 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
123 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page, $context ) );
125 switch ( $title->getNamespace() ) {
127 $page = new ImagePage( $title );
130 $page = new CategoryPage( $title );
133 $page = new Article( $title );
136 $page->setContext( $context );
142 * Create an Article object of the appropriate class for the given page.
144 * @param WikiPage $page
145 * @param IContextSource $context
148 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
149 $article = self
::newFromTitle( $page->getTitle(), $context );
150 $article->mPage
= $page; // override to keep process cached vars
155 * Tell the page view functions that this view was redirected
156 * from another page on the wiki.
159 public function setRedirectedFrom( Title
$from ) {
160 $this->mRedirectedFrom
= $from;
164 * Get the title object of the article
166 * @return Title Title object of this page
168 public function getTitle() {
169 return $this->mPage
->getTitle();
173 * Get the WikiPage object of this instance
178 public function getPage() {
185 public function clear() {
186 $this->mContentLoaded
= false;
188 $this->mRedirectedFrom
= null; # Title object if set
189 $this->mRevIdFetched
= 0;
190 $this->mRedirectUrl
= false;
192 $this->mPage
->clear();
196 * Note that getContent/loadContent do not follow redirects anymore.
197 * If you need to fetch redirectable content easily, try
198 * the shortcut in WikiPage::getRedirectTarget()
200 * This function has side effects! Do not use this function if you
201 * only want the real revision text if any.
203 * @deprecated since 1.21; use WikiPage::getContent() instead
205 * @return string Return the text of this revision
207 public function getContent() {
208 ContentHandler
::deprecated( __METHOD__
, '1.21' );
209 $content = $this->getContentObject();
210 return ContentHandler
::getContentText( $content );
214 * Returns a Content object representing the pages effective display content,
215 * not necessarily the revision's content!
217 * Note that getContent/loadContent do not follow redirects anymore.
218 * If you need to fetch redirectable content easily, try
219 * the shortcut in WikiPage::getRedirectTarget()
221 * This function has side effects! Do not use this function if you
222 * only want the real revision text if any.
224 * @return Content Return the content of this revision
228 protected function getContentObject() {
229 wfProfileIn( __METHOD__
);
231 if ( $this->mPage
->getID() === 0 ) {
232 # If this is a MediaWiki:x message, then load the messages
233 # and return the message value for x.
234 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
235 $text = $this->getTitle()->getDefaultMessageText();
236 if ( $text === false ) {
240 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
242 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
243 $content = new MessageContent( $message, null, 'parsemag' );
246 $this->fetchContentObject();
247 $content = $this->mContentObject
;
250 wfProfileOut( __METHOD__
);
255 * @return int The oldid of the article that is to be shown, 0 for the current revision
257 public function getOldID() {
258 if ( is_null( $this->mOldId
) ) {
259 $this->mOldId
= $this->getOldIDFromRequest();
262 return $this->mOldId
;
266 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
268 * @return int The old id for the request
270 public function getOldIDFromRequest() {
271 $this->mRedirectUrl
= false;
273 $request = $this->getContext()->getRequest();
274 $oldid = $request->getIntOrNull( 'oldid' );
276 if ( $oldid === null ) {
280 if ( $oldid !== 0 ) {
281 # Load the given revision and check whether the page is another one.
282 # In that case, update this instance to reflect the change.
283 if ( $oldid === $this->mPage
->getLatest() ) {
284 $this->mRevision
= $this->mPage
->getRevision();
286 $this->mRevision
= Revision
::newFromId( $oldid );
287 if ( $this->mRevision
!== null ) {
288 // Revision title doesn't match the page title given?
289 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
290 $function = array( get_class( $this->mPage
), 'newFromID' );
291 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
297 if ( $request->getVal( 'direction' ) == 'next' ) {
298 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
301 $this->mRevision
= null;
303 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
305 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
306 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
309 $this->mRevision
= null;
317 * Load the revision (including text) into this object
319 * @deprecated since 1.19; use fetchContent()
321 function loadContent() {
322 wfDeprecated( __METHOD__
, '1.19' );
323 $this->fetchContent();
327 * Get text of an article from database
328 * Does *NOT* follow redirects.
331 * @note This is really internal functionality that should really NOT be
332 * used by other functions. For accessing article content, use the WikiPage
333 * class, especially WikiBase::getContent(). However, a lot of legacy code
334 * uses this method to retrieve page text from the database, so the function
335 * has to remain public for now.
337 * @return string|bool String containing article contents, or false if null
338 * @deprecated since 1.21, use WikiPage::getContent() instead
340 function fetchContent() { #BC cruft!
341 ContentHandler
::deprecated( __METHOD__
, '1.21' );
343 if ( $this->mContentLoaded
&& $this->mContent
) {
344 return $this->mContent
;
347 wfProfileIn( __METHOD__
);
349 $content = $this->fetchContentObject();
352 wfProfileOut( __METHOD__
);
356 // @todo Get rid of mContent everywhere!
357 $this->mContent
= ContentHandler
::getContentText( $content );
358 ContentHandler
::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
360 wfProfileOut( __METHOD__
);
362 return $this->mContent
;
366 * Get text content object
367 * Does *NOT* follow redirects.
368 * @todo When is this null?
370 * @note Code that wants to retrieve page content from the database should
371 * use WikiPage::getContent().
373 * @return Content|null|bool
377 protected function fetchContentObject() {
378 if ( $this->mContentLoaded
) {
379 return $this->mContentObject
;
382 wfProfileIn( __METHOD__
);
384 $this->mContentLoaded
= true;
385 $this->mContent
= null;
387 $oldid = $this->getOldID();
389 # Pre-fill content with error message so that if something
390 # fails we'll have something telling us what we intended.
391 //XXX: this isn't page content but a UI message. horrible.
392 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ), array() );
395 # $this->mRevision might already be fetched by getOldIDFromRequest()
396 if ( !$this->mRevision
) {
397 $this->mRevision
= Revision
::newFromId( $oldid );
398 if ( !$this->mRevision
) {
399 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
400 wfProfileOut( __METHOD__
);
405 if ( !$this->mPage
->getLatest() ) {
406 wfDebug( __METHOD__
. " failed to find page data for title " .
407 $this->getTitle()->getPrefixedText() . "\n" );
408 wfProfileOut( __METHOD__
);
412 $this->mRevision
= $this->mPage
->getRevision();
414 if ( !$this->mRevision
) {
415 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " .
416 $this->mPage
->getLatest() . "\n" );
417 wfProfileOut( __METHOD__
);
422 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
423 // We should instead work with the Revision object when we need it...
424 // Loads if user is allowed
425 $this->mContentObject
= $this->mRevision
->getContent(
426 Revision
::FOR_THIS_USER
,
427 $this->getContext()->getUser()
429 $this->mRevIdFetched
= $this->mRevision
->getId();
431 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
433 wfProfileOut( __METHOD__
);
435 return $this->mContentObject
;
439 * Returns true if the currently-referenced revision is the current edit
440 * to this page (and it exists).
443 public function isCurrent() {
444 # If no oldid, this is the current version.
445 if ( $this->getOldID() == 0 ) {
449 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
453 * Get the fetched Revision object depending on request parameters or null
457 * @return Revision|null
459 public function getRevisionFetched() {
460 $this->fetchContentObject();
462 return $this->mRevision
;
466 * Use this to fetch the rev ID used on page views
468 * @return int Revision ID of last article revision
470 public function getRevIdFetched() {
471 if ( $this->mRevIdFetched
) {
472 return $this->mRevIdFetched
;
474 return $this->mPage
->getLatest();
479 * This is the default action of the index.php entry point: just view the
480 * page of the given title.
482 public function view() {
483 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
485 wfProfileIn( __METHOD__
);
487 # Get variables from query string
488 # As side effect this will load the revision and update the title
489 # in a revision ID is passed in the request, so this should remain
490 # the first call of this method even if $oldid is used way below.
491 $oldid = $this->getOldID();
493 $user = $this->getContext()->getUser();
494 # Another whitelist check in case getOldID() is altering the title
495 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
496 if ( count( $permErrors ) ) {
497 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
498 wfProfileOut( __METHOD__
);
499 throw new PermissionsError( 'read', $permErrors );
502 $outputPage = $this->getContext()->getOutput();
503 # getOldID() may as well want us to redirect somewhere else
504 if ( $this->mRedirectUrl
) {
505 $outputPage->redirect( $this->mRedirectUrl
);
506 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
507 wfProfileOut( __METHOD__
);
512 # If we got diff in the query, we want to see a diff page instead of the article.
513 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
514 wfDebug( __METHOD__
. ": showing diff page\n" );
515 $this->showDiffPage();
516 wfProfileOut( __METHOD__
);
521 # Set page title (may be overridden by DISPLAYTITLE)
522 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
524 $outputPage->setArticleFlag( true );
525 # Allow frames by default
526 $outputPage->allowClickjacking();
528 $parserCache = ParserCache
::singleton();
530 $parserOptions = $this->getParserOptions();
531 # Render printable version, use printable version cache
532 if ( $outputPage->isPrintable() ) {
533 $parserOptions->setIsPrintable( true );
534 $parserOptions->setEditSection( false );
535 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
536 $parserOptions->setEditSection( false );
539 # Try client and file cache
540 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
542 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
545 # Is it client cached?
546 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
547 wfDebug( __METHOD__
. ": done 304\n" );
548 wfProfileOut( __METHOD__
);
552 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
553 wfDebug( __METHOD__
. ": done file cache\n" );
554 # tell wgOut that output is taken care of
555 $outputPage->disable();
556 $this->mPage
->doViewUpdates( $user, $oldid );
557 wfProfileOut( __METHOD__
);
563 # Should the parser cache be used?
564 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
565 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
566 if ( $user->getStubThreshold() ) {
567 wfIncrStats( 'pcache_miss_stub' );
570 $this->showRedirectedFromHeader();
571 $this->showNamespaceHeader();
573 # Iterate through the possible ways of constructing the output text.
574 # Keep going until $outputDone is set, or we run out of things to do.
577 $this->mParserOutput
= false;
579 while ( !$outputDone && ++
$pass ) {
582 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
585 # Early abort if the page doesn't exist
586 if ( !$this->mPage
->exists() ) {
587 wfDebug( __METHOD__
. ": showing missing article\n" );
588 $this->showMissingArticle();
589 $this->mPage
->doViewUpdates( $user );
590 wfProfileOut( __METHOD__
);
594 # Try the parser cache
595 if ( $useParserCache ) {
596 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
598 if ( $this->mParserOutput
!== false ) {
600 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
601 $this->setOldSubtitle( $oldid );
603 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
605 $outputPage->addParserOutput( $this->mParserOutput
);
606 # Ensure that UI elements requiring revision ID have
607 # the correct version information.
608 $outputPage->setRevisionId( $this->mPage
->getLatest() );
609 # Preload timestamp to avoid a DB hit
610 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
611 if ( $cachedTimestamp !== null ) {
612 $outputPage->setRevisionTimestamp( $cachedTimestamp );
613 $this->mPage
->setTimestamp( $cachedTimestamp );
620 # This will set $this->mRevision if needed
621 $this->fetchContentObject();
623 # Are we looking at an old revision
624 if ( $oldid && $this->mRevision
) {
625 $this->setOldSubtitle( $oldid );
627 if ( !$this->showDeletedRevisionHeader() ) {
628 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
629 wfProfileOut( __METHOD__
);
634 # Ensure that UI elements requiring revision ID have
635 # the correct version information.
636 $outputPage->setRevisionId( $this->getRevIdFetched() );
637 # Preload timestamp to avoid a DB hit
638 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
640 # Pages containing custom CSS or JavaScript get special treatment
641 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
642 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
643 $this->showCssOrJsPage();
645 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
646 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
648 # Allow extensions do their own custom view for certain pages
650 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
651 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
653 # Allow extensions do their own custom view for certain pages
658 # Run the parse, protected by a pool counter
659 wfDebug( __METHOD__
. ": doing uncached parse\n" );
661 $content = $this->getContentObject();
662 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
663 $this->getRevIdFetched(), $useParserCache, $content );
665 if ( !$poolArticleView->execute() ) {
666 $error = $poolArticleView->getError();
668 $outputPage->clearHTML(); // for release() errors
669 $outputPage->enableClientCache( false );
670 $outputPage->setRobotPolicy( 'noindex,nofollow' );
672 $errortext = $error->getWikiText( false, 'view-pool-error' );
673 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
675 # Connection or timeout error
676 wfProfileOut( __METHOD__
);
680 $this->mParserOutput
= $poolArticleView->getParserOutput();
681 $outputPage->addParserOutput( $this->mParserOutput
);
682 if ( $content->getRedirectTarget() ) {
683 $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
686 # Don't cache a dirty ParserOutput object
687 if ( $poolArticleView->getIsDirty() ) {
688 $outputPage->setSquidMaxage( 0 );
689 $outputPage->addHTML( "<!-- parser cache is expired, " .
690 "sending anyway due to pool overload-->\n" );
695 # Should be unreachable, but just in case...
701 # Get the ParserOutput actually *displayed* here.
702 # Note that $this->mParserOutput is the *current* version output.
703 $pOutput = ( $outputDone instanceof ParserOutput
)
704 ?
$outputDone // object fetched by hook
705 : $this->mParserOutput
;
707 # Adjust title for main page & pages with displaytitle
709 $this->adjustDisplayTitle( $pOutput );
712 # For the main page, overwrite the <title> element with the con-
713 # tents of 'pagetitle-view-mainpage' instead of the default (if
715 # This message always exists because it is in the i18n files
716 if ( $this->getTitle()->isMainPage() ) {
717 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
718 if ( !$msg->isDisabled() ) {
719 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
723 # Check for any __NOINDEX__ tags on the page using $pOutput
724 $policy = $this->getRobotPolicy( 'view', $pOutput );
725 $outputPage->setIndexPolicy( $policy['index'] );
726 $outputPage->setFollowPolicy( $policy['follow'] );
728 $this->showViewFooter();
729 $this->mPage
->doViewUpdates( $user, $oldid );
731 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
733 wfProfileOut( __METHOD__
);
737 * Adjust title for pages with displaytitle, -{T|}- or language conversion
738 * @param ParserOutput $pOutput
740 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
741 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
742 $titleText = $pOutput->getTitleText();
743 if ( strval( $titleText ) !== '' ) {
744 $this->getContext()->getOutput()->setPageTitle( $titleText );
749 * Show a diff page according to current request variables. For use within
750 * Article::view() only, other callers should use the DifferenceEngine class.
752 * @todo Make protected
754 public function showDiffPage() {
755 $request = $this->getContext()->getRequest();
756 $user = $this->getContext()->getUser();
757 $diff = $request->getVal( 'diff' );
758 $rcid = $request->getVal( 'rcid' );
759 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
760 $purge = $request->getVal( 'action' ) == 'purge';
761 $unhide = $request->getInt( 'unhide' ) == 1;
762 $oldid = $this->getOldID();
764 $rev = $this->getRevisionFetched();
767 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
768 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
772 $contentHandler = $rev->getContentHandler();
773 $de = $contentHandler->createDifferenceEngine(
782 // DifferenceEngine directly fetched the revision:
783 $this->mRevIdFetched
= $de->mNewid
;
784 $de->showDiffPage( $diffOnly );
786 // Run view updates for the newer revision being diffed (and shown
787 // below the diff if not $diffOnly).
788 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
789 // New can be false, convert it to 0 - this conveniently means the latest revision
790 $this->mPage
->doViewUpdates( $user, (int)$new );
794 * Show a page view for a page formatted as CSS or JavaScript. To be called by
795 * Article::view() only.
797 * This exists mostly to serve the deprecated ShowRawCssJs hook (used to customize these views).
798 * It has been replaced by the ContentGetParserOutput hook, which lets you do the same but with
801 * @param bool $showCacheHint Whether to show a message telling the user
802 * to clear the browser cache (default: true).
804 protected function showCssOrJsPage( $showCacheHint = true ) {
805 $outputPage = $this->getContext()->getOutput();
807 if ( $showCacheHint ) {
808 $dir = $this->getContext()->getLanguage()->getDir();
809 $lang = $this->getContext()->getLanguage()->getCode();
811 $outputPage->wrapWikiMsg(
812 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
817 $this->fetchContentObject();
819 if ( $this->mContentObject
) {
820 // Give hooks a chance to customise the output
821 if ( ContentHandler
::runLegacyHooks(
823 array( $this->mContentObject
, $this->getTitle(), $outputPage ) )
825 // If no legacy hooks ran, display the content of the parser output, including RL modules,
826 // but excluding metadata like categories and language links
827 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
828 $outputPage->addParserOutputContent( $po );
834 * Get the robot policy to be used for the current view
835 * @param string $action The action= GET parameter
836 * @param ParserOutput|null $pOutput
837 * @return array The policy that should be set
838 * @todo: actions other than 'view'
840 public function getRobotPolicy( $action, $pOutput = null ) {
841 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
843 $ns = $this->getTitle()->getNamespace();
845 # Don't index user and user talk pages for blocked users (bug 11443)
846 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
847 $specificTarget = null;
849 $titleText = $this->getTitle()->getText();
850 if ( IP
::isValid( $titleText ) ) {
851 $vagueTarget = $titleText;
853 $specificTarget = $titleText;
855 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
857 'index' => 'noindex',
858 'follow' => 'nofollow'
863 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
864 # Non-articles (special pages etc), and old revisions
866 'index' => 'noindex',
867 'follow' => 'nofollow'
869 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
870 # Discourage indexing of printable versions, but encourage following
872 'index' => 'noindex',
875 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
876 # For ?curid=x urls, disallow indexing
878 'index' => 'noindex',
883 # Otherwise, construct the policy based on the various config variables.
884 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
886 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
887 # Honour customised robot policies for this namespace
888 $policy = array_merge(
890 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
893 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
894 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
895 # a final sanity check that we have really got the parser output.
896 $policy = array_merge(
898 array( 'index' => $pOutput->getIndexPolicy() )
902 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
903 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
904 $policy = array_merge(
906 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
914 * Converts a String robot policy into an associative array, to allow
915 * merging of several policies using array_merge().
916 * @param array|string $policy Returns empty array on null/false/'', transparent
917 * to already-converted arrays, converts string.
918 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
920 public static function formatRobotPolicy( $policy ) {
921 if ( is_array( $policy ) ) {
923 } elseif ( !$policy ) {
927 $policy = explode( ',', $policy );
928 $policy = array_map( 'trim', $policy );
931 foreach ( $policy as $var ) {
932 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
933 $arr['index'] = $var;
934 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
935 $arr['follow'] = $var;
943 * If this request is a redirect view, send "redirected from" subtitle to
944 * the output. Returns true if the header was needed, false if this is not
945 * a redirect view. Handles both local and remote redirects.
949 public function showRedirectedFromHeader() {
950 global $wgRedirectSources;
951 $outputPage = $this->getContext()->getOutput();
953 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
955 if ( isset( $this->mRedirectedFrom
) ) {
956 // This is an internally redirected page view.
957 // We'll need a backlink to the source page for navigation.
958 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
959 $redir = Linker
::linkKnown(
960 $this->mRedirectedFrom
,
963 array( 'redirect' => 'no' )
966 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
968 // Set the fragment if one was specified in the redirect
969 if ( $this->getTitle()->hasFragment() ) {
970 $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
971 $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
974 // Add a <link rel="canonical"> tag
975 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
977 // Tell the output object that the user arrived at this article through a redirect
978 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
982 } elseif ( $rdfrom ) {
983 // This is an externally redirected view, from some other wiki.
984 // If it was reported from a trusted site, supply a backlink.
985 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
986 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
987 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
997 * Show a header specific to the namespace currently being viewed, like
998 * [[MediaWiki:Talkpagetext]]. For Article::view().
1000 public function showNamespaceHeader() {
1001 if ( $this->getTitle()->isTalkPage() ) {
1002 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1003 $this->getContext()->getOutput()->wrapWikiMsg(
1004 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1005 array( 'talkpageheader' )
1012 * Show the footer section of an ordinary page view
1014 public function showViewFooter() {
1015 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1016 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1017 && IP
::isValid( $this->getTitle()->getText() )
1019 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1022 // Show a footer allowing the user to patrol the shown revision or page if possible
1023 $patrolFooterShown = $this->showPatrolFooter();
1025 wfRunHooks( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1029 * If patrol is possible, output a patrol UI box. This is called from the
1030 * footer section of ordinary page views. If patrol is not possible or not
1031 * desired, does nothing.
1032 * Side effect: When the patrol link is build, this method will call
1033 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1037 public function showPatrolFooter() {
1038 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1040 $outputPage = $this->getContext()->getOutput();
1041 $user = $this->getContext()->getUser();
1042 $cache = wfGetMainCache();
1045 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1046 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1048 // Patrolling is disabled or the user isn't allowed to
1052 wfProfileIn( __METHOD__
);
1054 // New page patrol: Get the timestamp of the oldest revison which
1055 // the revision table holds for the given page. Then we look
1056 // whether it's within the RC lifespan and if it is, we try
1057 // to get the recentchanges row belonging to that entry
1058 // (with rc_new = 1).
1060 // Check for cached results
1061 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1062 wfProfileOut( __METHOD__
);
1066 if ( $this->mRevision
1067 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1069 // The current revision is already older than what could be in the RC table
1070 // 6h tolerance because the RC might not be cleaned out regularly
1071 wfProfileOut( __METHOD__
);
1075 $dbr = wfGetDB( DB_SLAVE
);
1076 $oldestRevisionTimestamp = $dbr->selectField(
1078 'MIN( rev_timestamp )',
1079 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1083 if ( $oldestRevisionTimestamp
1084 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1086 // 6h tolerance because the RC might not be cleaned out regularly
1087 $rc = RecentChange
::newFromConds(
1090 'rc_timestamp' => $oldestRevisionTimestamp,
1091 'rc_namespace' => $this->getTitle()->getNamespace(),
1092 'rc_cur_id' => $this->getTitle()->getArticleID(),
1096 array( 'USE INDEX' => 'new_name_timestamp' )
1101 // No RC entry around
1103 // Cache the information we gathered above in case we can't patrol
1104 // Don't cache in case we can patrol as this could change
1105 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1107 wfProfileOut( __METHOD__
);
1111 if ( $rc->getPerformer()->getName() == $user->getName() ) {
1112 // Don't show a patrol link for own creations. If the user could
1113 // patrol them, they already would be patrolled
1114 wfProfileOut( __METHOD__
);
1118 $rcid = $rc->getAttribute( 'rc_id' );
1120 $token = $user->getEditToken( $rcid );
1122 $outputPage->preventClickjacking();
1123 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1124 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1127 $link = Linker
::linkKnown(
1129 wfMessage( 'markaspatrolledtext' )->escaped(),
1132 'action' => 'markpatrolled',
1138 $outputPage->addHTML(
1139 "<div class='patrollink'>" .
1140 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1144 wfProfileOut( __METHOD__
);
1149 * Show the error text for a missing article. For articles in the MediaWiki
1150 * namespace, show the default message text. To be called from Article::view().
1152 public function showMissingArticle() {
1153 global $wgSend404Code;
1154 $outputPage = $this->getContext()->getOutput();
1155 // Whether the page is a root user page of an existing user (but not a subpage)
1156 $validUserPage = false;
1158 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1159 if ( $this->getTitle()->getNamespace() == NS_USER
1160 ||
$this->getTitle()->getNamespace() == NS_USER_TALK
1162 $parts = explode( '/', $this->getTitle()->getText() );
1163 $rootPart = $parts[0];
1164 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1165 $ip = User
::isIP( $rootPart );
1167 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1168 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1169 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1170 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1171 LogEventsList
::showLogExtract(
1174 $user->getUserPage(),
1178 'showIfEmpty' => false,
1180 'blocked-notice-logextract',
1181 $user->getName() # Support GENDER in notice
1185 $validUserPage = !$this->getTitle()->isSubpage();
1187 $validUserPage = !$this->getTitle()->isSubpage();
1191 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1193 // Give extensions a chance to hide their (unrelated) log entries
1194 $logTypes = array( 'delete', 'move' );
1195 $conds = array( "log_action != 'revision'" );
1196 wfRunHooks( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1198 # Show delete and move logs
1199 LogEventsList
::showLogExtract( $outputPage, $logTypes, $this->getTitle(), '',
1202 'showIfEmpty' => false,
1203 'msgKey' => array( 'moveddeleted-notice' ) )
1206 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1207 // If there's no backing content, send a 404 Not Found
1208 // for better machine handling of broken links.
1209 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1212 if ( $validUserPage ) {
1213 // Also apply the robot policy for nonexisting user pages (as those aren't served as 404)
1214 $policy = $this->getRobotPolicy( 'view' );
1215 $outputPage->setIndexPolicy( $policy['index'] );
1216 $outputPage->setFollowPolicy( $policy['follow'] );
1219 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1221 if ( ! $hookResult ) {
1225 # Show error message
1226 $oldid = $this->getOldID();
1228 $text = wfMessage( 'missing-revision', $oldid )->plain();
1229 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1230 // Use the default message text
1231 $text = $this->getTitle()->getDefaultMessageText();
1232 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1233 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1235 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1236 $text = wfMessage( $message )->plain();
1238 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1240 $text = "<div class='noarticletext'>\n$text\n</div>";
1242 $outputPage->addWikiText( $text );
1246 * If the revision requested for view is deleted, check permissions.
1247 * Send either an error message or a warning header to the output.
1249 * @return bool true if the view is allowed, false if not.
1251 public function showDeletedRevisionHeader() {
1252 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1257 $outputPage = $this->getContext()->getOutput();
1258 $user = $this->getContext()->getUser();
1259 // If the user is not allowed to see it...
1260 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1261 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1262 'rev-deleted-text-permission' );
1265 // If the user needs to confirm that they want to see it...
1266 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1267 # Give explanation and add a link to view the revision...
1268 $oldid = intval( $this->getOldID() );
1269 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1270 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1271 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1272 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1273 array( $msg, $link ) );
1276 // We are allowed to see...
1278 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1279 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1280 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1287 * Generate the navigation links when browsing through an article revisions
1288 * It shows the information as:
1289 * Revision as of \<date\>; view current revision
1290 * \<- Previous version | Next Version -\>
1292 * @param int $oldid Revision ID of this article revision
1294 public function setOldSubtitle( $oldid = 0 ) {
1295 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1299 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1301 # Cascade unhide param in links for easy deletion browsing
1302 $extraParams = array();
1304 $extraParams['unhide'] = 1;
1307 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1308 $revision = $this->mRevision
;
1310 $revision = Revision
::newFromId( $oldid );
1313 $timestamp = $revision->getTimestamp();
1315 $current = ( $oldid == $this->mPage
->getLatest() );
1316 $language = $this->getContext()->getLanguage();
1317 $user = $this->getContext()->getUser();
1319 $td = $language->userTimeAndDate( $timestamp, $user );
1320 $tddate = $language->userDate( $timestamp, $user );
1321 $tdtime = $language->userTime( $timestamp, $user );
1323 # Show user links if allowed to see them. If hidden, then show them only if requested...
1324 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1326 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1327 ?
'revision-info-current'
1330 $outputPage = $this->getContext()->getOutput();
1331 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1332 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1333 $tdtime, $revision->getUserText() )->rawParams( Linker
::revComment( $revision, true, true ) )->parse() . "</div>" );
1336 ?
wfMessage( 'currentrevisionlink' )->escaped()
1337 : Linker
::linkKnown(
1339 wfMessage( 'currentrevisionlink' )->escaped(),
1344 ?
wfMessage( 'diff' )->escaped()
1345 : Linker
::linkKnown(
1347 wfMessage( 'diff' )->escaped(),
1354 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1356 ? Linker
::linkKnown(
1358 wfMessage( 'previousrevision' )->escaped(),
1361 'direction' => 'prev',
1365 : wfMessage( 'previousrevision' )->escaped();
1367 ? Linker
::linkKnown(
1369 wfMessage( 'diff' )->escaped(),
1376 : wfMessage( 'diff' )->escaped();
1377 $nextlink = $current
1378 ?
wfMessage( 'nextrevision' )->escaped()
1379 : Linker
::linkKnown(
1381 wfMessage( 'nextrevision' )->escaped(),
1384 'direction' => 'next',
1388 $nextdiff = $current
1389 ?
wfMessage( 'diff' )->escaped()
1390 : Linker
::linkKnown(
1392 wfMessage( 'diff' )->escaped(),
1400 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1401 if ( $cdel !== '' ) {
1405 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1406 wfMessage( 'revision-nav' )->rawParams(
1407 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1408 )->escaped() . "</div>" );
1412 * Return the HTML for the top of a redirect page
1414 * Chances are you should just be using the ParserOutput from
1415 * WikitextContent::getParserOutput instead of calling this for redirects.
1417 * @param Title|array $target Destination(s) to redirect
1418 * @param bool $appendSubtitle [optional]
1419 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1420 * @return string Containing HMTL with redirect link
1422 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1423 $lang = $this->getTitle()->getPageLanguage();
1424 if ( $appendSubtitle ) {
1425 $out = $this->getContext()->getOutput();
1426 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1428 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1432 * Return the HTML for the top of a redirect page
1434 * Chances are you should just be using the ParserOutput from
1435 * WikitextContent::getParserOutput instead of calling this for redirects.
1438 * @param Language $lang
1439 * @param Title|array $target Destination(s) to redirect
1440 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1441 * @return string Containing HMTL with redirect link
1443 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1444 global $wgStylePath;
1446 if ( !is_array( $target ) ) {
1447 $target = array( $target );
1450 $imageDir = $lang->getDir();
1452 // the loop prepends the arrow image before the link, so the first case needs to be outside
1454 /** @var $title Title */
1455 $title = array_shift( $target );
1457 if ( $forceKnown ) {
1458 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1460 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1463 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1464 $alt = $lang->isRTL() ?
'←' : '→';
1466 // Automatically append redirect=no to each link, since most of them are
1467 // redirect pages themselves.
1468 /** @var Title $rt */
1469 foreach ( $target as $rt ) {
1470 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1471 if ( $forceKnown ) {
1472 $link .= Linker
::linkKnown(
1474 htmlspecialchars( $rt->getFullText(),
1476 array( 'redirect' => 'no' )
1480 $link .= Linker
::link(
1482 htmlspecialchars( $rt->getFullText() ),
1484 array( 'redirect' => 'no' )
1489 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1490 return '<div class="redirectMsg">' .
1491 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1492 '<span class="redirectText">' . $link . '</span></div>';
1496 * Handle action=render
1498 public function render() {
1499 $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
1500 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1501 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1506 * action=protect handler
1508 public function protect() {
1509 $form = new ProtectionForm( $this );
1514 * action=unprotect handler (alias)
1516 public function unprotect() {
1521 * UI entry point for page deletion
1523 public function delete() {
1524 # This code desperately needs to be totally rewritten
1526 $title = $this->getTitle();
1527 $user = $this->getContext()->getUser();
1530 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1531 if ( count( $permission_errors ) ) {
1532 throw new PermissionsError( 'delete', $permission_errors );
1535 # Read-only check...
1536 if ( wfReadOnly() ) {
1537 throw new ReadOnlyError
;
1540 # Better double-check that it hasn't been deleted yet!
1541 $this->mPage
->loadPageData( 'fromdbmaster' );
1542 if ( !$this->mPage
->exists() ) {
1543 $deleteLogPage = new LogPage( 'delete' );
1544 $outputPage = $this->getContext()->getOutput();
1545 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1546 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1547 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1549 $outputPage->addHTML(
1550 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1552 LogEventsList
::showLogExtract(
1561 $request = $this->getContext()->getRequest();
1562 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1563 $deleteReason = $request->getText( 'wpReason' );
1565 if ( $deleteReasonList == 'other' ) {
1566 $reason = $deleteReason;
1567 } elseif ( $deleteReason != '' ) {
1568 // Entry from drop down menu + additional comment
1569 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1570 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1572 $reason = $deleteReasonList;
1575 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1576 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1578 # Flag to hide all contents of the archived revisions
1579 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1581 $this->doDelete( $reason, $suppress );
1583 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1588 // Generate deletion reason
1589 $hasHistory = false;
1592 $reason = $this->generateReason( $hasHistory );
1593 } catch ( MWException
$e ) {
1594 # if a page is horribly broken, we still want to be able to
1595 # delete it. So be lenient about errors here.
1596 wfDebug( "Error while building auto delete summary: $e" );
1601 // If the page has a history, insert a warning
1602 if ( $hasHistory ) {
1603 $revisions = $this->mTitle
->estimateRevisionCount();
1604 // @todo FIXME: i18n issue/patchwork message
1605 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1606 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1607 wfMessage( 'word-separator' )->plain() . Linker
::linkKnown( $title,
1608 wfMessage( 'history' )->escaped(),
1609 array( 'rel' => 'archives' ),
1610 array( 'action' => 'history' ) ) .
1614 if ( $this->mTitle
->isBigDeletion() ) {
1615 global $wgDeleteRevisionsLimit;
1616 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1618 'delete-warning-toobig',
1619 $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1625 $this->confirmDelete( $reason );
1629 * Output deletion confirmation dialog
1630 * @todo FIXME: Move to another file?
1631 * @param string $reason Prefilled reason
1633 public function confirmDelete( $reason ) {
1634 wfDebug( "Article::confirmDelete\n" );
1636 $outputPage = $this->getContext()->getOutput();
1637 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1638 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1639 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1640 $backlinkCache = $this->getTitle()->getBacklinkCache();
1641 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1642 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1643 'deleting-backlinks-warning' );
1645 $outputPage->addWikiMsg( 'confirmdeletetext' );
1647 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1649 $user = $this->getContext()->getUser();
1651 if ( $user->isAllowed( 'suppressrevision' ) ) {
1652 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1654 <td class='mw-input'><strong>" .
1655 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1656 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1662 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $this->getTitle() );
1664 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1665 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1666 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1667 Xml
::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1668 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1669 "<tr id=\"wpDeleteReasonListRow\">
1670 <td class='mw-label'>" .
1671 Xml
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1673 <td class='mw-input'>" .
1675 'wpDeleteReasonList',
1676 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1677 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1684 <tr id=\"wpDeleteReasonRow\">
1685 <td class='mw-label'>" .
1686 Xml
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1688 <td class='mw-input'>" .
1689 Html
::input( 'wpReason', $reason, 'text', array(
1691 'maxlength' => '255',
1699 # Disallow watching if user is not logged in
1700 if ( $user->isLoggedIn() ) {
1704 <td class='mw-input'>" .
1705 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1706 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1715 <td class='mw-submit'>" .
1716 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1717 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1720 Xml
::closeElement( 'table' ) .
1721 Xml
::closeElement( 'fieldset' ) .
1724 $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) )
1726 Xml
::closeElement( 'form' );
1728 if ( $user->isAllowed( 'editinterface' ) ) {
1729 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1730 $link = Linker
::link(
1732 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1734 array( 'action' => 'edit' )
1736 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1739 $outputPage->addHTML( $form );
1741 $deleteLogPage = new LogPage( 'delete' );
1742 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1743 LogEventsList
::showLogExtract( $outputPage, 'delete',
1749 * Perform a deletion and output success or failure messages
1750 * @param string $reason
1751 * @param bool $suppress
1753 public function doDelete( $reason, $suppress = false ) {
1755 $outputPage = $this->getContext()->getOutput();
1756 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1758 if ( $status->isGood() ) {
1759 $deleted = $this->getTitle()->getPrefixedText();
1761 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1762 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1764 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1766 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1767 $outputPage->returnToMain( false );
1769 $outputPage->setPageTitle(
1770 wfMessage( 'cannotdelete-title',
1771 $this->getTitle()->getPrefixedText() )
1774 if ( $error == '' ) {
1775 $outputPage->addWikiText(
1776 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1778 $deleteLogPage = new LogPage( 'delete' );
1779 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1781 LogEventsList
::showLogExtract(
1787 $outputPage->addHTML( $error );
1792 /* Caching functions */
1795 * checkLastModified returns true if it has taken care of all
1796 * output to the client that is necessary for this request.
1797 * (that is, it has sent a cached version of the page)
1799 * @return bool true if cached version send, false otherwise
1801 protected function tryFileCache() {
1802 static $called = false;
1805 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1810 if ( $this->isFileCacheable() ) {
1811 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1812 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1813 wfDebug( "Article::tryFileCache(): about to load file\n" );
1814 $cache->loadFromFileCache( $this->getContext() );
1817 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1818 ob_start( array( &$cache, 'saveToFileCache' ) );
1821 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1828 * Check if the page can be cached
1831 public function isFileCacheable() {
1834 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1835 $cacheable = $this->mPage
->getID()
1836 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1837 // Extension may have reason to disable file caching on some pages.
1839 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1849 * Lightweight method to get the parser output for a page, checking the parser cache
1850 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1851 * consider, so it's not appropriate to use there.
1853 * @since 1.16 (r52326) for LiquidThreads
1855 * @param int|null $oldid Revision ID or null
1856 * @param User $user The relevant user
1857 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1859 public function getParserOutput( $oldid = null, User
$user = null ) {
1860 //XXX: bypasses mParserOptions and thus setParserOptions()
1862 if ( $user === null ) {
1863 $parserOptions = $this->getParserOptions();
1865 $parserOptions = $this->mPage
->makeParserOptions( $user );
1868 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1872 * Override the ParserOptions used to render the primary article wikitext.
1874 * @param ParserOptions $options
1875 * @throws MWException if the parser options where already initialized.
1877 public function setParserOptions( ParserOptions
$options ) {
1878 if ( $this->mParserOptions
) {
1879 throw new MWException( "can't change parser options after they have already been set" );
1882 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1883 $this->mParserOptions
= clone $options;
1887 * Get parser options suitable for rendering the primary article wikitext
1888 * @return ParserOptions
1890 public function getParserOptions() {
1891 if ( !$this->mParserOptions
) {
1892 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1894 // Clone to allow modifications of the return value without affecting cache
1895 return clone $this->mParserOptions
;
1899 * Sets the context this Article is executed in
1901 * @param IContextSource $context
1904 public function setContext( $context ) {
1905 $this->mContext
= $context;
1909 * Gets the context this Article is executed in
1911 * @return IContextSource
1914 public function getContext() {
1915 if ( $this->mContext
instanceof IContextSource
) {
1916 return $this->mContext
;
1918 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1919 "Return RequestContext::getMain(); for sanity\n" );
1920 return RequestContext
::getMain();
1925 * Use PHP's magic __get handler to handle accessing of
1926 * raw WikiPage fields for backwards compatibility.
1928 * @param string $fname Field name
1930 public function __get( $fname ) {
1931 if ( property_exists( $this->mPage
, $fname ) ) {
1932 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1933 return $this->mPage
->$fname;
1935 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1939 * Use PHP's magic __set handler to handle setting of
1940 * raw WikiPage fields for backwards compatibility.
1942 * @param string $fname Field name
1943 * @param mixed $fvalue New value
1945 public function __set( $fname, $fvalue ) {
1946 if ( property_exists( $this->mPage
, $fname ) ) {
1947 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1948 $this->mPage
->$fname = $fvalue;
1949 // Note: extensions may want to toss on new fields
1950 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1951 $this->mPage
->$fname = $fvalue;
1953 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1958 * Use PHP's magic __call handler to transform instance calls to
1959 * WikiPage functions for backwards compatibility.
1961 * @param string $fname Name of called method
1962 * @param array $args Arguments to the method
1965 public function __call( $fname, $args ) {
1966 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1967 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1968 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1970 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1973 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1976 * @param array $limit
1977 * @param array $expiry
1978 * @param bool $cascade
1979 * @param string $reason
1983 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
1986 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1990 * @param array $limit
1991 * @param string $reason
1992 * @param int $cascade
1993 * @param array $expiry
1996 public function updateRestrictions( $limit = array(), $reason = '',
1997 &$cascade = 0, $expiry = array()
1999 return $this->mPage
->doUpdateRestrictions(
2004 $this->getContext()->getUser()
2009 * @param string $reason
2010 * @param bool $suppress
2012 * @param bool $commit
2013 * @param string $error
2016 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2017 $commit = true, &$error = ''
2019 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2023 * @param string $fromP
2024 * @param string $summary
2025 * @param string $token
2027 * @param array $resultDetails
2028 * @param User|null $user
2031 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2032 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2033 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2037 * @param string $fromP
2038 * @param string $summary
2040 * @param array $resultDetails
2041 * @param User|null $guser
2044 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2045 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2046 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2050 * @param bool $hasHistory
2053 public function generateReason( &$hasHistory ) {
2054 $title = $this->mPage
->getTitle();
2055 $handler = ContentHandler
::getForTitle( $title );
2056 return $handler->getAutoDeleteReason( $title, $hasHistory );
2059 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2064 * @deprecated since 1.24, use WikiPage::selectFields() instead
2066 public static function selectFields() {
2067 wfDeprecated( __METHOD__
, '1.24' );
2068 return WikiPage
::selectFields();
2072 * @param Title $title
2074 * @deprecated since 1.24, use WikiPage::onArticleCreate() instead
2076 public static function onArticleCreate( $title ) {
2077 wfDeprecated( __METHOD__
, '1.24' );
2078 WikiPage
::onArticleCreate( $title );
2082 * @param Title $title
2084 * @deprecated since 1.24, use WikiPage::onArticleDelete() instead
2086 public static function onArticleDelete( $title ) {
2087 wfDeprecated( __METHOD__
, '1.24' );
2088 WikiPage
::onArticleDelete( $title );
2092 * @param Title $title
2094 * @deprecated since 1.24, use WikiPage::onArticleEdit() instead
2096 public static function onArticleEdit( $title ) {
2097 wfDeprecated( __METHOD__
, '1.24' );
2098 WikiPage
::onArticleEdit( $title );
2102 * @param string $oldtext
2103 * @param string $newtext
2106 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2108 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2109 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );