0a4b5ee30e33cfc94550873507a8a48544a48b10
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
{
42 * The context this Article is executed in
43 * @var IContextSource $mContext
48 * The WikiPage object of this instance
49 * @var WikiPage $mPage
54 * ParserOptions object for $wgUser articles
55 * @var ParserOptions $mParserOptions
57 public $mParserOptions;
60 * Text of the revision we are working on
61 * @var string $mContent
63 var $mContent; // !< #BC cruft
66 * Content of the revision we are working on
70 var $mContentObject; // !<
73 * Is the content ($mContent) already loaded?
74 * @var bool $mContentLoaded
76 var $mContentLoaded = false; // !<
79 * The oldid of the article that is to be shown, 0 for the
81 * @var int|null $mOldId
86 * Title from which we were redirected here
87 * @var Title $mRedirectedFrom
89 var $mRedirectedFrom = null;
92 * URL to redirect to or false if none
93 * @var string|bool $mRedirectUrl
95 var $mRedirectUrl = false; // !<
98 * Revision ID of revision we are working on
99 * @var int $mRevIdFetched
101 var $mRevIdFetched = 0; // !<
104 * Revision we are working on
105 * @var Revision $mRevision
107 var $mRevision = null;
110 * ParserOutput object
111 * @var ParserOutput $mParserOutput
118 * Constructor and clear the article
119 * @param Title $title Reference to a Title object.
120 * @param int $oldId Revision ID, null to fetch from request, zero for current
122 public function __construct( Title
$title, $oldId = null ) {
123 $this->mOldId
= $oldId;
124 $this->mPage
= $this->newPage( $title );
128 * @param Title $title
131 protected function newPage( Title
$title ) {
132 return new WikiPage( $title );
136 * Constructor from a page id
137 * @param int $id Article ID to load
138 * @return Article|null
140 public static function newFromID( $id ) {
141 $t = Title
::newFromID( $id );
142 # @todo FIXME: Doesn't inherit right
143 return $t == null ?
null : new self( $t );
144 # return $t == null ? null : new static( $t ); // PHP 5.3
148 * Create an Article object of the appropriate class for the given page.
150 * @param Title $title
151 * @param IContextSource $context
154 public static function newFromTitle( $title, IContextSource
$context ) {
155 if ( NS_MEDIA
== $title->getNamespace() ) {
156 // FIXME: where should this go?
157 $title = Title
::makeTitle( NS_FILE
, $title->getDBkey() );
161 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page, $context ) );
163 switch ( $title->getNamespace() ) {
165 $page = new ImagePage( $title );
168 $page = new CategoryPage( $title );
171 $page = new Article( $title );
174 $page->setContext( $context );
180 * Create an Article object of the appropriate class for the given page.
182 * @param WikiPage $page
183 * @param IContextSource $context
186 public static function newFromWikiPage( WikiPage
$page, IContextSource
$context ) {
187 $article = self
::newFromTitle( $page->getTitle(), $context );
188 $article->mPage
= $page; // override to keep process cached vars
193 * Tell the page view functions that this view was redirected
194 * from another page on the wiki.
197 public function setRedirectedFrom( Title
$from ) {
198 $this->mRedirectedFrom
= $from;
202 * Get the title object of the article
204 * @return Title Title object of this page
206 public function getTitle() {
207 return $this->mPage
->getTitle();
211 * Get the WikiPage object of this instance
216 public function getPage() {
223 public function clear() {
224 $this->mContentLoaded
= false;
226 $this->mRedirectedFrom
= null; # Title object if set
227 $this->mRevIdFetched
= 0;
228 $this->mRedirectUrl
= false;
230 $this->mPage
->clear();
234 * Note that getContent/loadContent do not follow redirects anymore.
235 * If you need to fetch redirectable content easily, try
236 * the shortcut in WikiPage::getRedirectTarget()
238 * This function has side effects! Do not use this function if you
239 * only want the real revision text if any.
241 * @deprecated since 1.21; use WikiPage::getContent() instead
243 * @return string Return the text of this revision
245 public function getContent() {
246 ContentHandler
::deprecated( __METHOD__
, '1.21' );
247 $content = $this->getContentObject();
248 return ContentHandler
::getContentText( $content );
252 * Returns a Content object representing the pages effective display content,
253 * not necessarily the revision's content!
255 * Note that getContent/loadContent do not follow redirects anymore.
256 * If you need to fetch redirectable content easily, try
257 * the shortcut in WikiPage::getRedirectTarget()
259 * This function has side effects! Do not use this function if you
260 * only want the real revision text if any.
262 * @return Content Return the content of this revision
266 protected function getContentObject() {
267 wfProfileIn( __METHOD__
);
269 if ( $this->mPage
->getID() === 0 ) {
270 # If this is a MediaWiki:x message, then load the messages
271 # and return the message value for x.
272 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
273 $text = $this->getTitle()->getDefaultMessageText();
274 if ( $text === false ) {
278 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
280 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
281 $content = new MessageContent( $message, null, 'parsemag' );
284 $this->fetchContentObject();
285 $content = $this->mContentObject
;
288 wfProfileOut( __METHOD__
);
293 * @return int The oldid of the article that is to be shown, 0 for the current revision
295 public function getOldID() {
296 if ( is_null( $this->mOldId
) ) {
297 $this->mOldId
= $this->getOldIDFromRequest();
300 return $this->mOldId
;
304 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
306 * @return int The old id for the request
308 public function getOldIDFromRequest() {
309 $this->mRedirectUrl
= false;
311 $request = $this->getContext()->getRequest();
312 $oldid = $request->getIntOrNull( 'oldid' );
314 if ( $oldid === null ) {
318 if ( $oldid !== 0 ) {
319 # Load the given revision and check whether the page is another one.
320 # In that case, update this instance to reflect the change.
321 if ( $oldid === $this->mPage
->getLatest() ) {
322 $this->mRevision
= $this->mPage
->getRevision();
324 $this->mRevision
= Revision
::newFromId( $oldid );
325 if ( $this->mRevision
!== null ) {
326 // Revision title doesn't match the page title given?
327 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
328 $function = array( get_class( $this->mPage
), 'newFromID' );
329 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
335 if ( $request->getVal( 'direction' ) == 'next' ) {
336 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
339 $this->mRevision
= null;
341 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
343 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
344 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
347 $this->mRevision
= null;
355 * Load the revision (including text) into this object
357 * @deprecated since 1.19; use fetchContent()
359 function loadContent() {
360 wfDeprecated( __METHOD__
, '1.19' );
361 $this->fetchContent();
365 * Get text of an article from database
366 * Does *NOT* follow redirects.
369 * @note This is really internal functionality that should really NOT be
370 * used by other functions. For accessing article content, use the WikiPage
371 * class, especially WikiBase::getContent(). However, a lot of legacy code
372 * uses this method to retrieve page text from the database, so the function
373 * has to remain public for now.
375 * @return string|bool String containing article contents, or false if null
376 * @deprecated since 1.21, use WikiPage::getContent() instead
378 function fetchContent() { #BC cruft!
379 ContentHandler
::deprecated( __METHOD__
, '1.21' );
381 if ( $this->mContentLoaded
&& $this->mContent
) {
382 return $this->mContent
;
385 wfProfileIn( __METHOD__
);
387 $content = $this->fetchContentObject();
390 wfProfileOut( __METHOD__
);
394 // @todo Get rid of mContent everywhere!
395 $this->mContent
= ContentHandler
::getContentText( $content );
396 ContentHandler
::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
398 wfProfileOut( __METHOD__
);
400 return $this->mContent
;
404 * Get text content object
405 * Does *NOT* follow redirects.
406 * @todo When is this null?
408 * @note Code that wants to retrieve page content from the database should
409 * use WikiPage::getContent().
411 * @return Content|null|bool
415 protected function fetchContentObject() {
416 if ( $this->mContentLoaded
) {
417 return $this->mContentObject
;
420 wfProfileIn( __METHOD__
);
422 $this->mContentLoaded
= true;
423 $this->mContent
= null;
425 $oldid = $this->getOldID();
427 # Pre-fill content with error message so that if something
428 # fails we'll have something telling us what we intended.
429 //XXX: this isn't page content but a UI message. horrible.
430 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ), array() );
433 # $this->mRevision might already be fetched by getOldIDFromRequest()
434 if ( !$this->mRevision
) {
435 $this->mRevision
= Revision
::newFromId( $oldid );
436 if ( !$this->mRevision
) {
437 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
438 wfProfileOut( __METHOD__
);
443 if ( !$this->mPage
->getLatest() ) {
444 wfDebug( __METHOD__
. " failed to find page data for title " .
445 $this->getTitle()->getPrefixedText() . "\n" );
446 wfProfileOut( __METHOD__
);
450 $this->mRevision
= $this->mPage
->getRevision();
452 if ( !$this->mRevision
) {
453 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " .
454 $this->mPage
->getLatest() . "\n" );
455 wfProfileOut( __METHOD__
);
460 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
461 // We should instead work with the Revision object when we need it...
462 // Loads if user is allowed
463 $this->mContentObject
= $this->mRevision
->getContent(
464 Revision
::FOR_THIS_USER
,
465 $this->getContext()->getUser()
467 $this->mRevIdFetched
= $this->mRevision
->getId();
469 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
471 wfProfileOut( __METHOD__
);
473 return $this->mContentObject
;
477 * Returns true if the currently-referenced revision is the current edit
478 * to this page (and it exists).
481 public function isCurrent() {
482 # If no oldid, this is the current version.
483 if ( $this->getOldID() == 0 ) {
487 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
491 * Get the fetched Revision object depending on request parameters or null
495 * @return Revision|null
497 public function getRevisionFetched() {
498 $this->fetchContentObject();
500 return $this->mRevision
;
504 * Use this to fetch the rev ID used on page views
506 * @return int Revision ID of last article revision
508 public function getRevIdFetched() {
509 if ( $this->mRevIdFetched
) {
510 return $this->mRevIdFetched
;
512 return $this->mPage
->getLatest();
517 * This is the default action of the index.php entry point: just view the
518 * page of the given title.
520 public function view() {
521 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
523 wfProfileIn( __METHOD__
);
525 # Get variables from query string
526 # As side effect this will load the revision and update the title
527 # in a revision ID is passed in the request, so this should remain
528 # the first call of this method even if $oldid is used way below.
529 $oldid = $this->getOldID();
531 $user = $this->getContext()->getUser();
532 # Another whitelist check in case getOldID() is altering the title
533 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
534 if ( count( $permErrors ) ) {
535 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
536 wfProfileOut( __METHOD__
);
537 throw new PermissionsError( 'read', $permErrors );
540 $outputPage = $this->getContext()->getOutput();
541 # getOldID() may as well want us to redirect somewhere else
542 if ( $this->mRedirectUrl
) {
543 $outputPage->redirect( $this->mRedirectUrl
);
544 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
545 wfProfileOut( __METHOD__
);
550 # If we got diff in the query, we want to see a diff page instead of the article.
551 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
552 wfDebug( __METHOD__
. ": showing diff page\n" );
553 $this->showDiffPage();
554 wfProfileOut( __METHOD__
);
559 # Set page title (may be overridden by DISPLAYTITLE)
560 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
562 $outputPage->setArticleFlag( true );
563 # Allow frames by default
564 $outputPage->allowClickjacking();
566 $parserCache = ParserCache
::singleton();
568 $parserOptions = $this->getParserOptions();
569 # Render printable version, use printable version cache
570 if ( $outputPage->isPrintable() ) {
571 $parserOptions->setIsPrintable( true );
572 $parserOptions->setEditSection( false );
573 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
574 $parserOptions->setEditSection( false );
577 # Try client and file cache
578 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
580 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
583 # Is it client cached?
584 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
585 wfDebug( __METHOD__
. ": done 304\n" );
586 wfProfileOut( __METHOD__
);
590 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
591 wfDebug( __METHOD__
. ": done file cache\n" );
592 # tell wgOut that output is taken care of
593 $outputPage->disable();
594 $this->mPage
->doViewUpdates( $user, $oldid );
595 wfProfileOut( __METHOD__
);
601 # Should the parser cache be used?
602 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
603 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
604 if ( $user->getStubThreshold() ) {
605 wfIncrStats( 'pcache_miss_stub' );
608 $this->showRedirectedFromHeader();
609 $this->showNamespaceHeader();
611 # Iterate through the possible ways of constructing the output text.
612 # Keep going until $outputDone is set, or we run out of things to do.
615 $this->mParserOutput
= false;
617 while ( !$outputDone && ++
$pass ) {
620 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
623 # Early abort if the page doesn't exist
624 if ( !$this->mPage
->exists() ) {
625 wfDebug( __METHOD__
. ": showing missing article\n" );
626 $this->showMissingArticle();
627 $this->mPage
->doViewUpdates( $user );
628 wfProfileOut( __METHOD__
);
632 # Try the parser cache
633 if ( $useParserCache ) {
634 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
636 if ( $this->mParserOutput
!== false ) {
638 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
639 $this->setOldSubtitle( $oldid );
641 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
643 $outputPage->addParserOutput( $this->mParserOutput
);
644 # Ensure that UI elements requiring revision ID have
645 # the correct version information.
646 $outputPage->setRevisionId( $this->mPage
->getLatest() );
647 # Preload timestamp to avoid a DB hit
648 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
649 if ( $cachedTimestamp !== null ) {
650 $outputPage->setRevisionTimestamp( $cachedTimestamp );
651 $this->mPage
->setTimestamp( $cachedTimestamp );
658 # This will set $this->mRevision if needed
659 $this->fetchContentObject();
661 # Are we looking at an old revision
662 if ( $oldid && $this->mRevision
) {
663 $this->setOldSubtitle( $oldid );
665 if ( !$this->showDeletedRevisionHeader() ) {
666 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
667 wfProfileOut( __METHOD__
);
672 # Ensure that UI elements requiring revision ID have
673 # the correct version information.
674 $outputPage->setRevisionId( $this->getRevIdFetched() );
675 # Preload timestamp to avoid a DB hit
676 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
678 # Pages containing custom CSS or JavaScript get special treatment
679 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
680 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
681 $this->showCssOrJsPage();
683 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
684 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
686 # Allow extensions do their own custom view for certain pages
688 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
689 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
691 # Allow extensions do their own custom view for certain pages
696 # Run the parse, protected by a pool counter
697 wfDebug( __METHOD__
. ": doing uncached parse\n" );
699 $content = $this->getContentObject();
700 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
701 $this->getRevIdFetched(), $useParserCache, $content );
703 if ( !$poolArticleView->execute() ) {
704 $error = $poolArticleView->getError();
706 $outputPage->clearHTML(); // for release() errors
707 $outputPage->enableClientCache( false );
708 $outputPage->setRobotPolicy( 'noindex,nofollow' );
710 $errortext = $error->getWikiText( false, 'view-pool-error' );
711 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
713 # Connection or timeout error
714 wfProfileOut( __METHOD__
);
718 $this->mParserOutput
= $poolArticleView->getParserOutput();
719 $outputPage->addParserOutput( $this->mParserOutput
);
720 if ( $content->getRedirectTarget() ) {
721 $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
724 # Don't cache a dirty ParserOutput object
725 if ( $poolArticleView->getIsDirty() ) {
726 $outputPage->setSquidMaxage( 0 );
727 $outputPage->addHTML( "<!-- parser cache is expired, " .
728 "sending anyway due to pool overload-->\n" );
733 # Should be unreachable, but just in case...
739 # Get the ParserOutput actually *displayed* here.
740 # Note that $this->mParserOutput is the *current* version output.
741 $pOutput = ( $outputDone instanceof ParserOutput
)
742 ?
$outputDone // object fetched by hook
743 : $this->mParserOutput
;
745 # Adjust title for main page & pages with displaytitle
747 $this->adjustDisplayTitle( $pOutput );
750 # For the main page, overwrite the <title> element with the con-
751 # tents of 'pagetitle-view-mainpage' instead of the default (if
753 # This message always exists because it is in the i18n files
754 if ( $this->getTitle()->isMainPage() ) {
755 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
756 if ( !$msg->isDisabled() ) {
757 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
761 # Check for any __NOINDEX__ tags on the page using $pOutput
762 $policy = $this->getRobotPolicy( 'view', $pOutput );
763 $outputPage->setIndexPolicy( $policy['index'] );
764 $outputPage->setFollowPolicy( $policy['follow'] );
766 $this->showViewFooter();
767 $this->mPage
->doViewUpdates( $user, $oldid );
769 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
771 wfProfileOut( __METHOD__
);
775 * Adjust title for pages with displaytitle, -{T|}- or language conversion
776 * @param ParserOutput $pOutput
778 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
779 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
780 $titleText = $pOutput->getTitleText();
781 if ( strval( $titleText ) !== '' ) {
782 $this->getContext()->getOutput()->setPageTitle( $titleText );
787 * Show a diff page according to current request variables. For use within
788 * Article::view() only, other callers should use the DifferenceEngine class.
790 * @todo Make protected
792 public function showDiffPage() {
793 $request = $this->getContext()->getRequest();
794 $user = $this->getContext()->getUser();
795 $diff = $request->getVal( 'diff' );
796 $rcid = $request->getVal( 'rcid' );
797 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
798 $purge = $request->getVal( 'action' ) == 'purge';
799 $unhide = $request->getInt( 'unhide' ) == 1;
800 $oldid = $this->getOldID();
802 $rev = $this->getRevisionFetched();
805 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
806 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
810 $contentHandler = $rev->getContentHandler();
811 $de = $contentHandler->createDifferenceEngine(
820 // DifferenceEngine directly fetched the revision:
821 $this->mRevIdFetched
= $de->mNewid
;
822 $de->showDiffPage( $diffOnly );
824 // Run view updates for the newer revision being diffed (and shown
825 // below the diff if not $diffOnly).
826 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
827 // New can be false, convert it to 0 - this conveniently means the latest revision
828 $this->mPage
->doViewUpdates( $user, (int)$new );
832 * Show a page view for a page formatted as CSS or JavaScript. To be called by
833 * Article::view() only.
835 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
838 * @param bool $showCacheHint Whether to show a message telling the user
839 * to clear the browser cache (default: true).
841 protected function showCssOrJsPage( $showCacheHint = true ) {
842 $outputPage = $this->getContext()->getOutput();
844 if ( $showCacheHint ) {
845 $dir = $this->getContext()->getLanguage()->getDir();
846 $lang = $this->getContext()->getLanguage()->getCode();
848 $outputPage->wrapWikiMsg(
849 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
854 $this->fetchContentObject();
856 if ( $this->mContentObject
) {
857 // Give hooks a chance to customise the output
858 if ( ContentHandler
::runLegacyHooks(
860 array( $this->mContentObject
, $this->getTitle(), $outputPage ) )
862 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
863 $outputPage->addHTML( $po->getText() );
869 * Get the robot policy to be used for the current view
870 * @param string $action The action= GET parameter
871 * @param ParserOutput|null $pOutput
872 * @return array The policy that should be set
873 * @todo: actions other than 'view'
875 public function getRobotPolicy( $action, $pOutput = null ) {
876 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
878 $ns = $this->getTitle()->getNamespace();
880 # Don't index user and user talk pages for blocked users (bug 11443)
881 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
882 $specificTarget = null;
884 $titleText = $this->getTitle()->getText();
885 if ( IP
::isValid( $titleText ) ) {
886 $vagueTarget = $titleText;
888 $specificTarget = $titleText;
890 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
892 'index' => 'noindex',
893 'follow' => 'nofollow'
898 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
899 # Non-articles (special pages etc), and old revisions
901 'index' => 'noindex',
902 'follow' => 'nofollow'
904 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
905 # Discourage indexing of printable versions, but encourage following
907 'index' => 'noindex',
910 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
911 # For ?curid=x urls, disallow indexing
913 'index' => 'noindex',
918 # Otherwise, construct the policy based on the various config variables.
919 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
921 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
922 # Honour customised robot policies for this namespace
923 $policy = array_merge(
925 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
928 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
929 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
930 # a final sanity check that we have really got the parser output.
931 $policy = array_merge(
933 array( 'index' => $pOutput->getIndexPolicy() )
937 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
938 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
939 $policy = array_merge(
941 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
949 * Converts a String robot policy into an associative array, to allow
950 * merging of several policies using array_merge().
951 * @param array|string $policy Returns empty array on null/false/'', transparent
952 * to already-converted arrays, converts string.
953 * @return array 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
955 public static function formatRobotPolicy( $policy ) {
956 if ( is_array( $policy ) ) {
958 } elseif ( !$policy ) {
962 $policy = explode( ',', $policy );
963 $policy = array_map( 'trim', $policy );
966 foreach ( $policy as $var ) {
967 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
968 $arr['index'] = $var;
969 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
970 $arr['follow'] = $var;
978 * If this request is a redirect view, send "redirected from" subtitle to
979 * the output. Returns true if the header was needed, false if this is not
980 * a redirect view. Handles both local and remote redirects.
984 public function showRedirectedFromHeader() {
985 global $wgRedirectSources;
986 $outputPage = $this->getContext()->getOutput();
988 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
990 if ( isset( $this->mRedirectedFrom
) ) {
991 // This is an internally redirected page view.
992 // We'll need a backlink to the source page for navigation.
993 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
994 $redir = Linker
::linkKnown(
995 $this->mRedirectedFrom
,
998 array( 'redirect' => 'no' )
1001 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1003 // Set the fragment if one was specified in the redirect
1004 if ( $this->getTitle()->hasFragment() ) {
1005 $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
1006 $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
1009 // Add a <link rel="canonical"> tag
1010 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
1012 // Tell the output object that the user arrived at this article through a redirect
1013 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1017 } elseif ( $rdfrom ) {
1018 // This is an externally redirected view, from some other wiki.
1019 // If it was reported from a trusted site, supply a backlink.
1020 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1021 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1022 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1032 * Show a header specific to the namespace currently being viewed, like
1033 * [[MediaWiki:Talkpagetext]]. For Article::view().
1035 public function showNamespaceHeader() {
1036 if ( $this->getTitle()->isTalkPage() ) {
1037 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1038 $this->getContext()->getOutput()->wrapWikiMsg(
1039 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1040 array( 'talkpageheader' )
1047 * Show the footer section of an ordinary page view
1049 public function showViewFooter() {
1050 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1051 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1052 && IP
::isValid( $this->getTitle()->getText() )
1054 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1057 // Show a footer allowing the user to patrol the shown revision or page if possible
1058 $patrolFooterShown = $this->showPatrolFooter();
1060 wfRunHooks( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1064 * If patrol is possible, output a patrol UI box. This is called from the
1065 * footer section of ordinary page views. If patrol is not possible or not
1066 * desired, does nothing.
1067 * Side effect: When the patrol link is build, this method will call
1068 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1072 public function showPatrolFooter() {
1073 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1075 $outputPage = $this->getContext()->getOutput();
1076 $user = $this->getContext()->getUser();
1077 $cache = wfGetMainCache();
1080 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1081 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1083 // Patrolling is disabled or the user isn't allowed to
1087 wfProfileIn( __METHOD__
);
1089 // New page patrol: Get the timestamp of the oldest revison which
1090 // the revision table holds for the given page. Then we look
1091 // whether it's within the RC lifespan and if it is, we try
1092 // to get the recentchanges row belonging to that entry
1093 // (with rc_new = 1).
1095 // Check for cached results
1096 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1097 wfProfileOut( __METHOD__
);
1101 if ( $this->mRevision
1102 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1104 // The current revision is already older than what could be in the RC table
1105 // 6h tolerance because the RC might not be cleaned out regularly
1106 wfProfileOut( __METHOD__
);
1110 $dbr = wfGetDB( DB_SLAVE
);
1111 $oldestRevisionTimestamp = $dbr->selectField(
1113 'MIN( rev_timestamp )',
1114 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1118 if ( $oldestRevisionTimestamp
1119 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1121 // 6h tolerance because the RC might not be cleaned out regularly
1122 $rc = RecentChange
::newFromConds(
1125 'rc_timestamp' => $oldestRevisionTimestamp,
1126 'rc_namespace' => $this->getTitle()->getNamespace(),
1127 'rc_cur_id' => $this->getTitle()->getArticleID(),
1131 array( 'USE INDEX' => 'new_name_timestamp' )
1136 // No RC entry around
1138 // Cache the information we gathered above in case we can't patrol
1139 // Don't cache in case we can patrol as this could change
1140 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1142 wfProfileOut( __METHOD__
);
1146 if ( $rc->getPerformer()->getName() == $user->getName() ) {
1147 // Don't show a patrol link for own creations. If the user could
1148 // patrol them, they already would be patrolled
1149 wfProfileOut( __METHOD__
);
1153 $rcid = $rc->getAttribute( 'rc_id' );
1155 $token = $user->getEditToken( $rcid );
1157 $outputPage->preventClickjacking();
1158 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1159 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1162 $link = Linker
::linkKnown(
1164 wfMessage( 'markaspatrolledtext' )->escaped(),
1167 'action' => 'markpatrolled',
1173 $outputPage->addHTML(
1174 "<div class='patrollink'>" .
1175 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1179 wfProfileOut( __METHOD__
);
1184 * Show the error text for a missing article. For articles in the MediaWiki
1185 * namespace, show the default message text. To be called from Article::view().
1187 public function showMissingArticle() {
1188 global $wgSend404Code;
1189 $outputPage = $this->getContext()->getOutput();
1190 // Whether the page is a root user page of an existing user (but not a subpage)
1191 $validUserPage = false;
1193 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1194 if ( $this->getTitle()->getNamespace() == NS_USER
1195 ||
$this->getTitle()->getNamespace() == NS_USER_TALK
1197 $parts = explode( '/', $this->getTitle()->getText() );
1198 $rootPart = $parts[0];
1199 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1200 $ip = User
::isIP( $rootPart );
1202 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1203 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1204 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1205 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1206 LogEventsList
::showLogExtract(
1209 $user->getUserPage(),
1213 'showIfEmpty' => false,
1215 'blocked-notice-logextract',
1216 $user->getName() # Support GENDER in notice
1220 $validUserPage = !$this->getTitle()->isSubpage();
1222 $validUserPage = !$this->getTitle()->isSubpage();
1226 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1228 // Give extensions a chance to hide their (unrelated) log entries
1229 $logTypes = array( 'delete', 'move' );
1230 $conds = array( "log_action != 'revision'" );
1231 wfRunHooks( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1233 # Show delete and move logs
1234 LogEventsList
::showLogExtract( $outputPage, $logTypes, $this->getTitle(), '',
1237 'showIfEmpty' => false,
1238 'msgKey' => array( 'moveddeleted-notice' ) )
1241 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1242 // If there's no backing content, send a 404 Not Found
1243 // for better machine handling of broken links.
1244 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1247 if ( $validUserPage ) {
1248 // Also apply the robot policy for nonexisting user pages (as those aren't served as 404)
1249 $policy = $this->getRobotPolicy( 'view' );
1250 $outputPage->setIndexPolicy( $policy['index'] );
1251 $outputPage->setFollowPolicy( $policy['follow'] );
1254 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1256 if ( ! $hookResult ) {
1260 # Show error message
1261 $oldid = $this->getOldID();
1263 $text = wfMessage( 'missing-revision', $oldid )->plain();
1264 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1265 // Use the default message text
1266 $text = $this->getTitle()->getDefaultMessageText();
1267 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1268 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1270 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1271 $text = wfMessage( $message )->plain();
1273 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1275 $text = "<div class='noarticletext'>\n$text\n</div>";
1277 $outputPage->addWikiText( $text );
1281 * If the revision requested for view is deleted, check permissions.
1282 * Send either an error message or a warning header to the output.
1284 * @return bool true if the view is allowed, false if not.
1286 public function showDeletedRevisionHeader() {
1287 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1292 $outputPage = $this->getContext()->getOutput();
1293 $user = $this->getContext()->getUser();
1294 // If the user is not allowed to see it...
1295 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1296 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1297 'rev-deleted-text-permission' );
1300 // If the user needs to confirm that they want to see it...
1301 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1302 # Give explanation and add a link to view the revision...
1303 $oldid = intval( $this->getOldID() );
1304 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1305 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1306 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1307 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1308 array( $msg, $link ) );
1311 // We are allowed to see...
1313 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1314 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1315 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1322 * Generate the navigation links when browsing through an article revisions
1323 * It shows the information as:
1324 * Revision as of \<date\>; view current revision
1325 * \<- Previous version | Next Version -\>
1327 * @param int $oldid Revision ID of this article revision
1329 public function setOldSubtitle( $oldid = 0 ) {
1330 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1334 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1336 # Cascade unhide param in links for easy deletion browsing
1337 $extraParams = array();
1339 $extraParams['unhide'] = 1;
1342 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1343 $revision = $this->mRevision
;
1345 $revision = Revision
::newFromId( $oldid );
1348 $timestamp = $revision->getTimestamp();
1350 $current = ( $oldid == $this->mPage
->getLatest() );
1351 $language = $this->getContext()->getLanguage();
1352 $user = $this->getContext()->getUser();
1354 $td = $language->userTimeAndDate( $timestamp, $user );
1355 $tddate = $language->userDate( $timestamp, $user );
1356 $tdtime = $language->userTime( $timestamp, $user );
1358 # Show user links if allowed to see them. If hidden, then show them only if requested...
1359 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1361 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1362 ?
'revision-info-current'
1365 $outputPage = $this->getContext()->getOutput();
1366 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1367 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1368 $tdtime, $revision->getUser() )->parse() . "</div>" );
1371 ?
wfMessage( 'currentrevisionlink' )->escaped()
1372 : Linker
::linkKnown(
1374 wfMessage( 'currentrevisionlink' )->escaped(),
1379 ?
wfMessage( 'diff' )->escaped()
1380 : Linker
::linkKnown(
1382 wfMessage( 'diff' )->escaped(),
1389 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1391 ? Linker
::linkKnown(
1393 wfMessage( 'previousrevision' )->escaped(),
1396 'direction' => 'prev',
1400 : wfMessage( 'previousrevision' )->escaped();
1402 ? Linker
::linkKnown(
1404 wfMessage( 'diff' )->escaped(),
1411 : wfMessage( 'diff' )->escaped();
1412 $nextlink = $current
1413 ?
wfMessage( 'nextrevision' )->escaped()
1414 : Linker
::linkKnown(
1416 wfMessage( 'nextrevision' )->escaped(),
1419 'direction' => 'next',
1423 $nextdiff = $current
1424 ?
wfMessage( 'diff' )->escaped()
1425 : Linker
::linkKnown(
1427 wfMessage( 'diff' )->escaped(),
1435 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1436 if ( $cdel !== '' ) {
1440 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1441 wfMessage( '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 HMTL with redirect link
1457 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1458 $lang = $this->getTitle()->getPageLanguage();
1459 if ( $appendSubtitle ) {
1460 $out = $this->getContext()->getOutput();
1461 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1463 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1467 * Return the HTML for the top of a redirect page
1469 * Chances are you should just be using the ParserOutput from
1470 * WikitextContent::getParserOutput instead of calling this for redirects.
1473 * @param Language $lang
1474 * @param Title|array $target Destination(s) to redirect
1475 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1476 * @return string Containing HMTL with redirect link
1478 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1479 global $wgStylePath;
1481 if ( !is_array( $target ) ) {
1482 $target = array( $target );
1485 $imageDir = $lang->getDir();
1487 // the loop prepends the arrow image before the link, so the first case needs to be outside
1489 /** @var $title Title */
1490 $title = array_shift( $target );
1492 if ( $forceKnown ) {
1493 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1495 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1498 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1499 $alt = $lang->isRTL() ?
'←' : '→';
1501 // Automatically append redirect=no to each link, since most of them are
1502 // redirect pages themselves.
1503 /** @var Title $rt */
1504 foreach ( $target as $rt ) {
1505 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1506 if ( $forceKnown ) {
1507 $link .= Linker
::linkKnown(
1509 htmlspecialchars( $rt->getFullText(),
1511 array( 'redirect' => 'no' )
1515 $link .= Linker
::link(
1517 htmlspecialchars( $rt->getFullText() ),
1519 array( 'redirect' => 'no' )
1524 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1525 return '<div class="redirectMsg">' .
1526 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1527 '<span class="redirectText">' . $link . '</span></div>';
1531 * Handle action=render
1533 public function render() {
1534 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1535 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1540 * action=protect handler
1542 public function protect() {
1543 $form = new ProtectionForm( $this );
1548 * action=unprotect handler (alias)
1550 public function unprotect() {
1555 * UI entry point for page deletion
1557 public function delete() {
1558 # This code desperately needs to be totally rewritten
1560 $title = $this->getTitle();
1561 $user = $this->getContext()->getUser();
1564 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1565 if ( count( $permission_errors ) ) {
1566 throw new PermissionsError( 'delete', $permission_errors );
1569 # Read-only check...
1570 if ( wfReadOnly() ) {
1571 throw new ReadOnlyError
;
1574 # Better double-check that it hasn't been deleted yet!
1575 $this->mPage
->loadPageData( 'fromdbmaster' );
1576 if ( !$this->mPage
->exists() ) {
1577 $deleteLogPage = new LogPage( 'delete' );
1578 $outputPage = $this->getContext()->getOutput();
1579 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1580 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1581 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1583 $outputPage->addHTML(
1584 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1586 LogEventsList
::showLogExtract(
1595 $request = $this->getContext()->getRequest();
1596 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1597 $deleteReason = $request->getText( 'wpReason' );
1599 if ( $deleteReasonList == 'other' ) {
1600 $reason = $deleteReason;
1601 } elseif ( $deleteReason != '' ) {
1602 // Entry from drop down menu + additional comment
1603 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1604 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1606 $reason = $deleteReasonList;
1609 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1610 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1612 # Flag to hide all contents of the archived revisions
1613 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1615 $this->doDelete( $reason, $suppress );
1617 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1622 // Generate deletion reason
1623 $hasHistory = false;
1626 $reason = $this->generateReason( $hasHistory );
1627 } catch ( MWException
$e ) {
1628 # if a page is horribly broken, we still want to be able to
1629 # delete it. So be lenient about errors here.
1630 wfDebug( "Error while building auto delete summary: $e" );
1635 // If the page has a history, insert a warning
1636 if ( $hasHistory ) {
1637 $revisions = $this->mTitle
->estimateRevisionCount();
1638 // @todo FIXME: i18n issue/patchwork message
1639 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1640 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1641 wfMessage( 'word-separator' )->plain() . Linker
::linkKnown( $title,
1642 wfMessage( 'history' )->escaped(),
1643 array( 'rel' => 'archives' ),
1644 array( 'action' => 'history' ) ) .
1648 if ( $this->mTitle
->isBigDeletion() ) {
1649 global $wgDeleteRevisionsLimit;
1650 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1652 'delete-warning-toobig',
1653 $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1659 $this->confirmDelete( $reason );
1663 * Output deletion confirmation dialog
1664 * @todo FIXME: Move to another file?
1665 * @param string $reason Prefilled reason
1667 public function confirmDelete( $reason ) {
1668 wfDebug( "Article::confirmDelete\n" );
1670 $outputPage = $this->getContext()->getOutput();
1671 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1672 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1673 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1674 $backlinkCache = $this->getTitle()->getBacklinkCache();
1675 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1676 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1677 'deleting-backlinks-warning' );
1679 $outputPage->addWikiMsg( 'confirmdeletetext' );
1681 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1683 $user = $this->getContext()->getUser();
1685 if ( $user->isAllowed( 'suppressrevision' ) ) {
1686 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1688 <td class='mw-input'><strong>" .
1689 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1690 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1696 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $this->getTitle() );
1698 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1699 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1700 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1701 Xml
::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1702 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1703 "<tr id=\"wpDeleteReasonListRow\">
1704 <td class='mw-label'>" .
1705 Xml
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1707 <td class='mw-input'>" .
1709 'wpDeleteReasonList',
1710 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1711 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1718 <tr id=\"wpDeleteReasonRow\">
1719 <td class='mw-label'>" .
1720 Xml
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1722 <td class='mw-input'>" .
1723 Html
::input( 'wpReason', $reason, 'text', array(
1725 'maxlength' => '255',
1733 # Disallow watching if user is not logged in
1734 if ( $user->isLoggedIn() ) {
1738 <td class='mw-input'>" .
1739 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1740 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1749 <td class='mw-submit'>" .
1750 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1751 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1754 Xml
::closeElement( 'table' ) .
1755 Xml
::closeElement( 'fieldset' ) .
1758 $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) )
1760 Xml
::closeElement( 'form' );
1762 if ( $user->isAllowed( 'editinterface' ) ) {
1763 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1764 $link = Linker
::link(
1766 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1768 array( 'action' => 'edit' )
1770 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1773 $outputPage->addHTML( $form );
1775 $deleteLogPage = new LogPage( 'delete' );
1776 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1777 LogEventsList
::showLogExtract( $outputPage, 'delete',
1783 * Perform a deletion and output success or failure messages
1784 * @param string $reason
1785 * @param bool $suppress
1787 public function doDelete( $reason, $suppress = false ) {
1789 $outputPage = $this->getContext()->getOutput();
1790 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1792 if ( $status->isGood() ) {
1793 $deleted = $this->getTitle()->getPrefixedText();
1795 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1796 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1798 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1800 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1801 $outputPage->returnToMain( false );
1803 $outputPage->setPageTitle(
1804 wfMessage( 'cannotdelete-title',
1805 $this->getTitle()->getPrefixedText() )
1808 if ( $error == '' ) {
1809 $outputPage->addWikiText(
1810 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1812 $deleteLogPage = new LogPage( 'delete' );
1813 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1815 LogEventsList
::showLogExtract(
1821 $outputPage->addHTML( $error );
1826 /* Caching functions */
1829 * checkLastModified returns true if it has taken care of all
1830 * output to the client that is necessary for this request.
1831 * (that is, it has sent a cached version of the page)
1833 * @return bool true if cached version send, false otherwise
1835 protected function tryFileCache() {
1836 static $called = false;
1839 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1844 if ( $this->isFileCacheable() ) {
1845 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1846 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1847 wfDebug( "Article::tryFileCache(): about to load file\n" );
1848 $cache->loadFromFileCache( $this->getContext() );
1851 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1852 ob_start( array( &$cache, 'saveToFileCache' ) );
1855 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1862 * Check if the page can be cached
1865 public function isFileCacheable() {
1868 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1869 $cacheable = $this->mPage
->getID()
1870 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1871 // Extension may have reason to disable file caching on some pages.
1873 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1883 * Lightweight method to get the parser output for a page, checking the parser cache
1884 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1885 * consider, so it's not appropriate to use there.
1887 * @since 1.16 (r52326) for LiquidThreads
1889 * @param int|null $oldid Revision ID or null
1890 * @param User $user The relevant user
1891 * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
1893 public function getParserOutput( $oldid = null, User
$user = null ) {
1894 //XXX: bypasses mParserOptions and thus setParserOptions()
1896 if ( $user === null ) {
1897 $parserOptions = $this->getParserOptions();
1899 $parserOptions = $this->mPage
->makeParserOptions( $user );
1902 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1906 * Override the ParserOptions used to render the primary article wikitext.
1908 * @param ParserOptions $options
1909 * @throws MWException if the parser options where already initialized.
1911 public function setParserOptions( ParserOptions
$options ) {
1912 if ( $this->mParserOptions
) {
1913 throw new MWException( "can't change parser options after they have already been set" );
1916 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1917 $this->mParserOptions
= clone $options;
1921 * Get parser options suitable for rendering the primary article wikitext
1922 * @return ParserOptions
1924 public function getParserOptions() {
1925 if ( !$this->mParserOptions
) {
1926 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1928 // Clone to allow modifications of the return value without affecting cache
1929 return clone $this->mParserOptions
;
1933 * Sets the context this Article is executed in
1935 * @param IContextSource $context
1938 public function setContext( $context ) {
1939 $this->mContext
= $context;
1943 * Gets the context this Article is executed in
1945 * @return IContextSource
1948 public function getContext() {
1949 if ( $this->mContext
instanceof IContextSource
) {
1950 return $this->mContext
;
1952 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1953 "Return RequestContext::getMain(); for sanity\n" );
1954 return RequestContext
::getMain();
1959 * Info about this page
1960 * @deprecated since 1.19
1962 public function info() {
1963 wfDeprecated( __METHOD__
, '1.19' );
1964 Action
::factory( 'info', $this )->show();
1968 * Handle action=purge
1969 * @deprecated since 1.19
1970 * @return Action|bool|null false if the action is disabled, null if it is not recognised
1972 public function purge() {
1973 return Action
::factory( 'purge', $this )->show();
1977 * Handle action=revert
1978 * @deprecated since 1.19
1980 public function revert() {
1981 wfDeprecated( __METHOD__
, '1.19' );
1982 Action
::factory( 'revert', $this )->show();
1986 * Handle action=rollback
1987 * @deprecated since 1.19
1989 public function rollback() {
1990 wfDeprecated( __METHOD__
, '1.19' );
1991 Action
::factory( 'rollback', $this )->show();
1995 * Use PHP's magic __get handler to handle accessing of
1996 * raw WikiPage fields for backwards compatibility.
1998 * @param string $fname Field name
2000 public function __get( $fname ) {
2001 if ( property_exists( $this->mPage
, $fname ) ) {
2002 #wfWarn( "Access to raw $fname field " . __CLASS__ );
2003 return $this->mPage
->$fname;
2005 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2009 * Use PHP's magic __set handler to handle setting of
2010 * raw WikiPage fields for backwards compatibility.
2012 * @param string $fname Field name
2013 * @param mixed $fvalue New value
2015 public function __set( $fname, $fvalue ) {
2016 if ( property_exists( $this->mPage
, $fname ) ) {
2017 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
2018 $this->mPage
->$fname = $fvalue;
2019 // Note: extensions may want to toss on new fields
2020 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2021 $this->mPage
->$fname = $fvalue;
2023 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2028 * Use PHP's magic __call handler to transform instance calls to
2029 * WikiPage functions for backwards compatibility.
2031 * @param string $fname Name of called method
2032 * @param array $args Arguments to the method
2035 public function __call( $fname, $args ) {
2036 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2037 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2038 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2040 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2043 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2046 * @param array $limit
2047 * @param array $expiry
2048 * @param bool $cascade
2049 * @param string $reason
2053 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2056 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2060 * @param array $limit
2061 * @param string $reason
2062 * @param int $cascade
2063 * @param array $expiry
2066 public function updateRestrictions( $limit = array(), $reason = '',
2067 &$cascade = 0, $expiry = array()
2069 return $this->mPage
->doUpdateRestrictions(
2074 $this->getContext()->getUser()
2079 * @param string $reason
2080 * @param bool $suppress
2082 * @param bool $commit
2083 * @param string $error
2086 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2087 $commit = true, &$error = ''
2089 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2093 * @param string $fromP
2094 * @param string $summary
2095 * @param string $token
2097 * @param array $resultDetails
2098 * @param User|null $user
2101 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2102 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2103 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2107 * @param string $fromP
2108 * @param string $summary
2110 * @param array $resultDetails
2111 * @param User|null $guser
2114 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2115 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2116 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2120 * @param bool $hasHistory
2123 public function generateReason( &$hasHistory ) {
2124 $title = $this->mPage
->getTitle();
2125 $handler = ContentHandler
::getForTitle( $title );
2126 return $handler->getAutoDeleteReason( $title, $hasHistory );
2129 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2134 public static function selectFields() {
2135 return WikiPage
::selectFields();
2139 * @param Title $title
2141 public static function onArticleCreate( $title ) {
2142 WikiPage
::onArticleCreate( $title );
2146 * @param Title $title
2148 public static function onArticleDelete( $title ) {
2149 WikiPage
::onArticleDelete( $title );
2153 * @param Title $title
2155 public static function onArticleEdit( $title ) {
2156 WikiPage
::onArticleEdit( $title );
2160 * @param string $oldtext
2161 * @param string $newtext
2164 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2166 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2167 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );