Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / Article.php
blob87b94ae97584cfbc3845b72be1806f5ea4c8d845
1 <?php
2 /**
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
20 * @file
23 /**
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 /**@{{
38 * @private
41 /**
42 * The context this Article is executed in
43 * @var IContextSource $mContext
45 protected $mContext;
47 /**
48 * The WikiPage object of this instance
49 * @var WikiPage $mPage
51 protected $mPage;
53 /**
54 * ParserOptions object for $wgUser articles
55 * @var ParserOptions $mParserOptions
57 public $mParserOptions;
59 /**
60 * Text of the revision we are working on
61 * @var string $mContent
63 var $mContent; // !< #BC cruft
65 /**
66 * Content of the revision we are working on
67 * @var Content
68 * @since 1.21
70 var $mContentObject; // !<
72 /**
73 * Is the content ($mContent) already loaded?
74 * @var bool $mContentLoaded
76 var $mContentLoaded = false; // !<
78 /**
79 * The oldid of the article that is to be shown, 0 for the
80 * current revision
81 * @var int|null $mOldId
83 var $mOldId; // !<
85 /**
86 * Title from which we were redirected here
87 * @var Title $mRedirectedFrom
89 var $mRedirectedFrom = null;
91 /**
92 * URL to redirect to or false if none
93 * @var string|false $mRedirectUrl
95 var $mRedirectUrl = false; // !<
97 /**
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
113 var $mParserOutput;
115 /**@}}*/
118 * Constructor and clear the article
119 * @param $title Title Reference to a Title object.
120 * @param $oldId Integer 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
129 * @return WikiPage
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 $context IContextSource
152 * @return Article object
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() );
160 $page = null;
161 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
162 if ( !$page ) {
163 switch ( $title->getNamespace() ) {
164 case NS_FILE:
165 $page = new ImagePage( $title );
166 break;
167 case NS_CATEGORY:
168 $page = new CategoryPage( $title );
169 break;
170 default:
171 $page = new Article( $title );
174 $page->setContext( $context );
176 return $page;
180 * Create an Article object of the appropriate class for the given page.
182 * @param $page WikiPage
183 * @param $context IContextSource
184 * @return Article object
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
189 return $article;
193 * Tell the page view functions that this view was redirected
194 * from another page on the wiki.
195 * @param $from Title object.
197 public function setRedirectedFrom( Title $from ) {
198 $this->mRedirectedFrom = $from;
202 * Get the title object of the article
204 * @return Title object of this page
206 public function getTitle() {
207 return $this->mPage->getTitle();
211 * Get the WikiPage object of this instance
213 * @since 1.19
214 * @return WikiPage
216 public function getPage() {
217 return $this->mPage;
221 * Clear the object
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 in 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
264 * @since 1.21
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 ) {
275 $text = '';
278 $content = ContentHandler::makeContent( $text, $this->getTitle() );
279 } else {
280 $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
281 $content = new MessageContent( $message, null, 'parsemag' );
283 } else {
284 $this->fetchContentObject();
285 $content = $this->mContentObject;
288 wfProfileOut( __METHOD__ );
289 return $content;
293 * @return int The oldid of the article that is to be shown, 0 for the
294 * current revision
296 public function getOldID() {
297 if ( is_null( $this->mOldId ) ) {
298 $this->mOldId = $this->getOldIDFromRequest();
301 return $this->mOldId;
305 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
307 * @return int The old id for the request
309 public function getOldIDFromRequest() {
310 $this->mRedirectUrl = false;
312 $request = $this->getContext()->getRequest();
313 $oldid = $request->getIntOrNull( 'oldid' );
315 if ( $oldid === null ) {
316 return 0;
319 if ( $oldid !== 0 ) {
320 # Load the given revision and check whether the page is another one.
321 # In that case, update this instance to reflect the change.
322 if ( $oldid === $this->mPage->getLatest() ) {
323 $this->mRevision = $this->mPage->getRevision();
324 } else {
325 $this->mRevision = Revision::newFromId( $oldid );
326 if ( $this->mRevision !== null ) {
327 // Revision title doesn't match the page title given?
328 if ( $this->mPage->getID() != $this->mRevision->getPage() ) {
329 $function = array( get_class( $this->mPage ), 'newFromID' );
330 $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
336 if ( $request->getVal( 'direction' ) == 'next' ) {
337 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
338 if ( $nextid ) {
339 $oldid = $nextid;
340 $this->mRevision = null;
341 } else {
342 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
344 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
345 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
346 if ( $previd ) {
347 $oldid = $previd;
348 $this->mRevision = null;
352 return $oldid;
356 * Load the revision (including text) into this object
358 * @deprecated in 1.19; use fetchContent()
360 function loadContent() {
361 wfDeprecated( __METHOD__, '1.19' );
362 $this->fetchContent();
366 * Get text of an article from database
367 * Does *NOT* follow redirects.
369 * @protected
370 * @note this is really internal functionality that should really NOT be used by other functions. For accessing
371 * article content, use the WikiPage class, especially WikiBase::getContent(). However, a lot of legacy code
372 * uses this method to retrieve page text from the database, so the function has to remain public for now.
374 * @return mixed string containing article contents, or false if null
375 * @deprecated in 1.21, use WikiPage::getContent() instead
377 function fetchContent() { #BC cruft!
378 ContentHandler::deprecated( __METHOD__, '1.21' );
380 if ( $this->mContentLoaded && $this->mContent ) {
381 return $this->mContent;
384 wfProfileIn( __METHOD__ );
386 $content = $this->fetchContentObject();
388 $this->mContent = ContentHandler::getContentText( $content ); #@todo: get rid of mContent everywhere!
389 ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
391 wfProfileOut( __METHOD__ );
393 return $this->mContent;
397 * Get text content object
398 * Does *NOT* follow redirects.
399 * TODO: when is this null?
401 * @note code that wants to retrieve page content from the database should use WikiPage::getContent().
403 * @return Content|null|boolean false
405 * @since 1.21
407 protected function fetchContentObject() {
408 if ( $this->mContentLoaded ) {
409 return $this->mContentObject;
412 wfProfileIn( __METHOD__ );
414 $this->mContentLoaded = true;
415 $this->mContent = null;
417 $oldid = $this->getOldID();
419 # Pre-fill content with error message so that if something
420 # fails we'll have something telling us what we intended.
421 //XXX: this isn't page content but a UI message. horrible.
422 $this->mContentObject = new MessageContent( 'missing-revision', array( $oldid ), array() );
424 if ( $oldid ) {
425 # $this->mRevision might already be fetched by getOldIDFromRequest()
426 if ( !$this->mRevision ) {
427 $this->mRevision = Revision::newFromId( $oldid );
428 if ( !$this->mRevision ) {
429 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
430 wfProfileOut( __METHOD__ );
431 return false;
434 } else {
435 if ( !$this->mPage->getLatest() ) {
436 wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
437 wfProfileOut( __METHOD__ );
438 return false;
441 $this->mRevision = $this->mPage->getRevision();
443 if ( !$this->mRevision ) {
444 wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n" );
445 wfProfileOut( __METHOD__ );
446 return false;
450 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
451 // We should instead work with the Revision object when we need it...
452 $this->mContentObject = $this->mRevision->getContent( Revision::FOR_THIS_USER, $this->getContext()->getUser() ); // Loads if user is allowed
453 $this->mRevIdFetched = $this->mRevision->getId();
455 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) );
457 wfProfileOut( __METHOD__ );
459 return $this->mContentObject;
463 * No-op
464 * @deprecated since 1.18
466 public function forUpdate() {
467 wfDeprecated( __METHOD__, '1.18' );
471 * Returns true if the currently-referenced revision is the current edit
472 * to this page (and it exists).
473 * @return bool
475 public function isCurrent() {
476 # If no oldid, this is the current version.
477 if ( $this->getOldID() == 0 ) {
478 return true;
481 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
485 * Get the fetched Revision object depending on request parameters or null
486 * on failure.
488 * @since 1.19
489 * @return Revision|null
491 public function getRevisionFetched() {
492 $this->fetchContentObject();
494 return $this->mRevision;
498 * Use this to fetch the rev ID used on page views
500 * @return int revision ID of last article revision
502 public function getRevIdFetched() {
503 if ( $this->mRevIdFetched ) {
504 return $this->mRevIdFetched;
505 } else {
506 return $this->mPage->getLatest();
511 * This is the default action of the index.php entry point: just view the
512 * page of the given title.
514 public function view() {
515 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
517 wfProfileIn( __METHOD__ );
519 # Get variables from query string
520 # As side effect this will load the revision and update the title
521 # in a revision ID is passed in the request, so this should remain
522 # the first call of this method even if $oldid is used way below.
523 $oldid = $this->getOldID();
525 $user = $this->getContext()->getUser();
526 # Another whitelist check in case getOldID() is altering the title
527 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
528 if ( count( $permErrors ) ) {
529 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
530 wfProfileOut( __METHOD__ );
531 throw new PermissionsError( 'read', $permErrors );
534 $outputPage = $this->getContext()->getOutput();
535 # getOldID() may as well want us to redirect somewhere else
536 if ( $this->mRedirectUrl ) {
537 $outputPage->redirect( $this->mRedirectUrl );
538 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
539 wfProfileOut( __METHOD__ );
541 return;
544 # If we got diff in the query, we want to see a diff page instead of the article.
545 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
546 wfDebug( __METHOD__ . ": showing diff page\n" );
547 $this->showDiffPage();
548 wfProfileOut( __METHOD__ );
550 return;
553 # Set page title (may be overridden by DISPLAYTITLE)
554 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
556 $outputPage->setArticleFlag( true );
557 # Allow frames by default
558 $outputPage->allowClickjacking();
560 $parserCache = ParserCache::singleton();
562 $parserOptions = $this->getParserOptions();
563 # Render printable version, use printable version cache
564 if ( $outputPage->isPrintable() ) {
565 $parserOptions->setIsPrintable( true );
566 $parserOptions->setEditSection( false );
567 } elseif ( !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user ) ) {
568 $parserOptions->setEditSection( false );
571 # Try client and file cache
572 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
573 if ( $wgUseETag ) {
574 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
577 # Is it client cached?
578 if ( $outputPage->checkLastModified( $this->mPage->getTouched() ) ) {
579 wfDebug( __METHOD__ . ": done 304\n" );
580 wfProfileOut( __METHOD__ );
582 return;
583 # Try file cache
584 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
585 wfDebug( __METHOD__ . ": done file cache\n" );
586 # tell wgOut that output is taken care of
587 $outputPage->disable();
588 $this->mPage->doViewUpdates( $user );
589 wfProfileOut( __METHOD__ );
591 return;
595 # Should the parser cache be used?
596 $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
597 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
598 if ( $user->getStubThreshold() ) {
599 wfIncrStats( 'pcache_miss_stub' );
602 $this->showRedirectedFromHeader();
603 $this->showNamespaceHeader();
605 # Iterate through the possible ways of constructing the output text.
606 # Keep going until $outputDone is set, or we run out of things to do.
607 $pass = 0;
608 $outputDone = false;
609 $this->mParserOutput = false;
611 while ( !$outputDone && ++$pass ) {
612 switch ( $pass ) {
613 case 1:
614 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
615 break;
616 case 2:
617 # Early abort if the page doesn't exist
618 if ( !$this->mPage->exists() ) {
619 wfDebug( __METHOD__ . ": showing missing article\n" );
620 $this->showMissingArticle();
621 wfProfileOut( __METHOD__ );
622 return;
625 # Try the parser cache
626 if ( $useParserCache ) {
627 $this->mParserOutput = $parserCache->get( $this, $parserOptions );
629 if ( $this->mParserOutput !== false ) {
630 if ( $oldid ) {
631 wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" );
632 $this->setOldSubtitle( $oldid );
633 } else {
634 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
636 $outputPage->addParserOutput( $this->mParserOutput );
637 # Ensure that UI elements requiring revision ID have
638 # the correct version information.
639 $outputPage->setRevisionId( $this->mPage->getLatest() );
640 # Preload timestamp to avoid a DB hit
641 $cachedTimestamp = $this->mParserOutput->getTimestamp();
642 if ( $cachedTimestamp !== null ) {
643 $outputPage->setRevisionTimestamp( $cachedTimestamp );
644 $this->mPage->setTimestamp( $cachedTimestamp );
646 $outputDone = true;
649 break;
650 case 3:
651 # This will set $this->mRevision if needed
652 $this->fetchContentObject();
654 # Are we looking at an old revision
655 if ( $oldid && $this->mRevision ) {
656 $this->setOldSubtitle( $oldid );
658 if ( !$this->showDeletedRevisionHeader() ) {
659 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
660 wfProfileOut( __METHOD__ );
661 return;
665 # Ensure that UI elements requiring revision ID have
666 # the correct version information.
667 $outputPage->setRevisionId( $this->getRevIdFetched() );
668 # Preload timestamp to avoid a DB hit
669 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
671 # Pages containing custom CSS or JavaScript get special treatment
672 if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
673 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
674 $this->showCssOrJsPage();
675 $outputDone = true;
676 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
677 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
679 # Allow extensions do their own custom view for certain pages
680 $outputDone = true;
681 } elseif ( !ContentHandler::runLegacyHooks( 'ArticleViewCustom',
682 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
684 # Allow extensions do their own custom view for certain pages
685 $outputDone = true;
686 } else {
687 $content = $this->getContentObject();
688 $rt = $content ? $content->getRedirectChain() : null;
689 if ( $rt ) {
690 wfDebug( __METHOD__ . ": showing redirect=no page\n" );
691 # Viewing a redirect page (e.g. with parameter redirect=no)
692 $outputPage->addHTML( $this->viewRedirect( $rt ) );
693 # Parse just to get categories, displaytitle, etc.
694 $this->mParserOutput = $content->getParserOutput( $this->getTitle(), $oldid, $parserOptions, false );
695 $outputPage->addParserOutputNoText( $this->mParserOutput );
696 $outputDone = true;
699 break;
700 case 4:
701 # Run the parse, protected by a pool counter
702 wfDebug( __METHOD__ . ": doing uncached parse\n" );
704 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
705 $this->getRevIdFetched(), $useParserCache, $this->getContentObject() );
707 if ( !$poolArticleView->execute() ) {
708 $error = $poolArticleView->getError();
709 if ( $error ) {
710 $outputPage->clearHTML(); // for release() errors
711 $outputPage->enableClientCache( false );
712 $outputPage->setRobotPolicy( 'noindex,nofollow' );
714 $errortext = $error->getWikiText( false, 'view-pool-error' );
715 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
717 # Connection or timeout error
718 wfProfileOut( __METHOD__ );
719 return;
722 $this->mParserOutput = $poolArticleView->getParserOutput();
723 $outputPage->addParserOutput( $this->mParserOutput );
725 # Don't cache a dirty ParserOutput object
726 if ( $poolArticleView->getIsDirty() ) {
727 $outputPage->setSquidMaxage( 0 );
728 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
731 $outputDone = true;
732 break;
733 # Should be unreachable, but just in case...
734 default:
735 break 2;
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
746 if ( $pOutput ) {
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
752 # that's not empty).
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 );
769 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
771 wfProfileOut( __METHOD__ );
775 * Adjust title for pages with displaytitle, -{T|}- or language conversion
776 * @param $pOutput ParserOutput
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();
804 if ( !$rev ) {
805 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
806 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
807 return;
810 $contentHandler = $rev->getContentHandler();
811 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
813 // DifferenceEngine directly fetched the revision:
814 $this->mRevIdFetched = $de->mNewid;
815 $de->showDiffPage( $diffOnly );
817 if ( $diff == 0 || $diff == $this->mPage->getLatest() ) {
818 # Run view updates for current revision only
819 $this->mPage->doViewUpdates( $user );
824 * Show a page view for a page formatted as CSS or JavaScript. To be called by
825 * Article::view() only.
827 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
828 * page views.
830 * @param bool $showCacheHint whether to show a message telling the user to clear the browser cache (default: true).
832 protected function showCssOrJsPage( $showCacheHint = true ) {
833 $outputPage = $this->getContext()->getOutput();
835 if ( $showCacheHint ) {
836 $dir = $this->getContext()->getLanguage()->getDir();
837 $lang = $this->getContext()->getLanguage()->getCode();
839 $outputPage->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
840 'clearyourcache' );
843 $this->fetchContentObject();
845 if ( $this->mContentObject ) {
846 // Give hooks a chance to customise the output
847 if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mContentObject, $this->getTitle(), $outputPage ) ) ) {
848 $po = $this->mContentObject->getParserOutput( $this->getTitle() );
849 $outputPage->addHTML( $po->getText() );
855 * Get the robot policy to be used for the current view
856 * @param string $action the action= GET parameter
857 * @param $pOutput ParserOutput
858 * @return Array the policy that should be set
859 * TODO: actions other than 'view'
861 public function getRobotPolicy( $action, $pOutput ) {
862 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
864 $ns = $this->getTitle()->getNamespace();
866 # Don't index user and user talk pages for blocked users (bug 11443)
867 if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
868 $specificTarget = null;
869 $vagueTarget = null;
870 $titleText = $this->getTitle()->getText();
871 if ( IP::isValid( $titleText ) ) {
872 $vagueTarget = $titleText;
873 } else {
874 $specificTarget = $titleText;
876 if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
877 return array(
878 'index' => 'noindex',
879 'follow' => 'nofollow'
884 if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
885 # Non-articles (special pages etc), and old revisions
886 return array(
887 'index' => 'noindex',
888 'follow' => 'nofollow'
890 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
891 # Discourage indexing of printable versions, but encourage following
892 return array(
893 'index' => 'noindex',
894 'follow' => 'follow'
896 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
897 # For ?curid=x urls, disallow indexing
898 return array(
899 'index' => 'noindex',
900 'follow' => 'follow'
904 # Otherwise, construct the policy based on the various config variables.
905 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
907 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
908 # Honour customised robot policies for this namespace
909 $policy = array_merge(
910 $policy,
911 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
914 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
915 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
916 # a final sanity check that we have really got the parser output.
917 $policy = array_merge(
918 $policy,
919 array( 'index' => $pOutput->getIndexPolicy() )
923 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
924 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
925 $policy = array_merge(
926 $policy,
927 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
931 return $policy;
935 * Converts a String robot policy into an associative array, to allow
936 * merging of several policies using array_merge().
937 * @param $policy Mixed, returns empty array on null/false/'', transparent
938 * to already-converted arrays, converts String.
939 * @return Array: 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
941 public static function formatRobotPolicy( $policy ) {
942 if ( is_array( $policy ) ) {
943 return $policy;
944 } elseif ( !$policy ) {
945 return array();
948 $policy = explode( ',', $policy );
949 $policy = array_map( 'trim', $policy );
951 $arr = array();
952 foreach ( $policy as $var ) {
953 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
954 $arr['index'] = $var;
955 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
956 $arr['follow'] = $var;
960 return $arr;
964 * If this request is a redirect view, send "redirected from" subtitle to
965 * the output. Returns true if the header was needed, false if this is not
966 * a redirect view. Handles both local and remote redirects.
968 * @return boolean
970 public function showRedirectedFromHeader() {
971 global $wgRedirectSources;
972 $outputPage = $this->getContext()->getOutput();
974 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
976 if ( isset( $this->mRedirectedFrom ) ) {
977 // This is an internally redirected page view.
978 // We'll need a backlink to the source page for navigation.
979 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
980 $redir = Linker::linkKnown(
981 $this->mRedirectedFrom,
982 null,
983 array(),
984 array( 'redirect' => 'no' )
987 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
989 // Set the fragment if one was specified in the redirect
990 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
991 $outputPage->addInlineScript( Xml::encodeJsCall(
992 'redirectToFragment', array( $this->getTitle()->getFragmentForURL() )
993 ) );
996 // Add a <link rel="canonical"> tag
997 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
999 // Tell the output object that the user arrived at this article through a redirect
1000 $outputPage->setRedirectedFrom( $this->mRedirectedFrom );
1002 return true;
1004 } elseif ( $rdfrom ) {
1005 // This is an externally redirected view, from some other wiki.
1006 // If it was reported from a trusted site, supply a backlink.
1007 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1008 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
1009 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1011 return true;
1015 return false;
1019 * Show a header specific to the namespace currently being viewed, like
1020 * [[MediaWiki:Talkpagetext]]. For Article::view().
1022 public function showNamespaceHeader() {
1023 if ( $this->getTitle()->isTalkPage() ) {
1024 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1025 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
1031 * Show the footer section of an ordinary page view
1033 public function showViewFooter() {
1034 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1035 if ( $this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid( $this->getTitle()->getText() ) ) {
1036 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1039 # If we have been passed an &rcid= parameter, we want to give the user a
1040 # chance to mark this new article as patrolled.
1041 $this->showPatrolFooter();
1043 wfRunHooks( 'ArticleViewFooter', array( $this ) );
1048 * If patrol is possible, output a patrol UI box. This is called from the
1049 * footer section of ordinary page views. If patrol is not possible or not
1050 * desired, does nothing.
1051 * Side effect: When the patrol link is build, this method will call
1052 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1054 public function showPatrolFooter() {
1055 $request = $this->getContext()->getRequest();
1056 $outputPage = $this->getContext()->getOutput();
1057 $user = $this->getContext()->getUser();
1058 $rcid = $request->getVal( 'rcid' );
1060 if ( !$rcid || !$this->getTitle()->quickUserCan( 'patrol', $user ) ) {
1061 return;
1064 $token = $user->getEditToken( $rcid );
1066 $outputPage->preventClickjacking();
1067 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1069 $link = Linker::linkKnown(
1070 $this->getTitle(),
1071 wfMessage( 'markaspatrolledtext' )->escaped(),
1072 array(),
1073 array(
1074 'action' => 'markpatrolled',
1075 'rcid' => $rcid,
1076 'token' => $token,
1080 $outputPage->addHTML(
1081 "<div class='patrollink'>" .
1082 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1083 '</div>'
1088 * Show the error text for a missing article. For articles in the MediaWiki
1089 * namespace, show the default message text. To be called from Article::view().
1091 public function showMissingArticle() {
1092 global $wgSend404Code;
1093 $outputPage = $this->getContext()->getOutput();
1094 $validUserPage = false;
1096 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1097 if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) {
1098 $parts = explode( '/', $this->getTitle()->getText() );
1099 $rootPart = $parts[0];
1100 $user = User::newFromName( $rootPart, false /* allow IP users*/ );
1101 $ip = User::isIP( $rootPart );
1103 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1104 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1105 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1106 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1107 LogEventsList::showLogExtract(
1108 $outputPage,
1109 'block',
1110 $user->getUserPage(),
1112 array(
1113 'lim' => 1,
1114 'showIfEmpty' => false,
1115 'msgKey' => array(
1116 'blocked-notice-logextract',
1117 $user->getName() # Support GENDER in notice
1121 $validUserPage = true;
1122 } else {
1123 $validUserPage = true;
1127 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1129 # Show delete and move logs
1130 LogEventsList::showLogExtract( $outputPage, array( 'delete', 'move' ), $this->getTitle(), '',
1131 array( 'lim' => 10,
1132 'conds' => array( "log_action != 'revision'" ),
1133 'showIfEmpty' => false,
1134 'msgKey' => array( 'moveddeleted-notice' ) )
1137 if ( !$this->mPage->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1138 // If there's no backing content, send a 404 Not Found
1139 // for better machine handling of broken links.
1140 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1143 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1145 if ( ! $hookResult ) {
1146 return;
1149 # Show error message
1150 $oldid = $this->getOldID();
1151 if ( $oldid ) {
1152 $text = wfMessage( 'missing-revision', $oldid )->plain();
1153 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI ) {
1154 // Use the default message text
1155 $text = $this->getTitle()->getDefaultMessageText();
1156 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1157 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1159 $text = wfMessage( 'noarticletext' )->plain();
1160 } else {
1161 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1163 $text = "<div class='noarticletext'>\n$text\n</div>";
1165 $outputPage->addWikiText( $text );
1169 * If the revision requested for view is deleted, check permissions.
1170 * Send either an error message or a warning header to the output.
1172 * @return boolean true if the view is allowed, false if not.
1174 public function showDeletedRevisionHeader() {
1175 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1176 // Not deleted
1177 return true;
1180 $outputPage = $this->getContext()->getOutput();
1181 $user = $this->getContext()->getUser();
1182 // If the user is not allowed to see it...
1183 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT, $user ) ) {
1184 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1185 'rev-deleted-text-permission' );
1187 return false;
1188 // If the user needs to confirm that they want to see it...
1189 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1190 # Give explanation and add a link to view the revision...
1191 $oldid = intval( $this->getOldID() );
1192 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1193 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1194 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1195 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1196 array( $msg, $link ) );
1198 return false;
1199 // We are allowed to see...
1200 } else {
1201 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1202 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1203 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1205 return true;
1210 * Generate the navigation links when browsing through an article revisions
1211 * It shows the information as:
1212 * Revision as of \<date\>; view current revision
1213 * \<- Previous version | Next Version -\>
1215 * @param int $oldid revision ID of this article revision
1217 public function setOldSubtitle( $oldid = 0 ) {
1218 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1219 return;
1222 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1224 # Cascade unhide param in links for easy deletion browsing
1225 $extraParams = array();
1226 if ( $unhide ) {
1227 $extraParams['unhide'] = 1;
1230 if ( $this->mRevision && $this->mRevision->getId() === $oldid ) {
1231 $revision = $this->mRevision;
1232 } else {
1233 $revision = Revision::newFromId( $oldid );
1236 $timestamp = $revision->getTimestamp();
1238 $current = ( $oldid == $this->mPage->getLatest() );
1239 $language = $this->getContext()->getLanguage();
1240 $user = $this->getContext()->getUser();
1242 $td = $language->userTimeAndDate( $timestamp, $user );
1243 $tddate = $language->userDate( $timestamp, $user );
1244 $tdtime = $language->userTime( $timestamp, $user );
1246 # Show user links if allowed to see them. If hidden, then show them only if requested...
1247 $userlinks = Linker::revUserTools( $revision, !$unhide );
1249 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1250 ? 'revision-info-current'
1251 : 'revision-info';
1253 $outputPage = $this->getContext()->getOutput();
1254 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1255 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1256 $tdtime, $revision->getUser() )->parse() . "</div>" );
1258 $lnk = $current
1259 ? wfMessage( 'currentrevisionlink' )->escaped()
1260 : Linker::linkKnown(
1261 $this->getTitle(),
1262 wfMessage( 'currentrevisionlink' )->escaped(),
1263 array(),
1264 $extraParams
1266 $curdiff = $current
1267 ? wfMessage( 'diff' )->escaped()
1268 : Linker::linkKnown(
1269 $this->getTitle(),
1270 wfMessage( 'diff' )->escaped(),
1271 array(),
1272 array(
1273 'diff' => 'cur',
1274 'oldid' => $oldid
1275 ) + $extraParams
1277 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1278 $prevlink = $prev
1279 ? Linker::linkKnown(
1280 $this->getTitle(),
1281 wfMessage( 'previousrevision' )->escaped(),
1282 array(),
1283 array(
1284 'direction' => 'prev',
1285 'oldid' => $oldid
1286 ) + $extraParams
1288 : wfMessage( 'previousrevision' )->escaped();
1289 $prevdiff = $prev
1290 ? Linker::linkKnown(
1291 $this->getTitle(),
1292 wfMessage( 'diff' )->escaped(),
1293 array(),
1294 array(
1295 'diff' => 'prev',
1296 'oldid' => $oldid
1297 ) + $extraParams
1299 : wfMessage( 'diff' )->escaped();
1300 $nextlink = $current
1301 ? wfMessage( 'nextrevision' )->escaped()
1302 : Linker::linkKnown(
1303 $this->getTitle(),
1304 wfMessage( 'nextrevision' )->escaped(),
1305 array(),
1306 array(
1307 'direction' => 'next',
1308 'oldid' => $oldid
1309 ) + $extraParams
1311 $nextdiff = $current
1312 ? wfMessage( 'diff' )->escaped()
1313 : Linker::linkKnown(
1314 $this->getTitle(),
1315 wfMessage( 'diff' )->escaped(),
1316 array(),
1317 array(
1318 'diff' => 'next',
1319 'oldid' => $oldid
1320 ) + $extraParams
1323 $cdel = Linker::getRevDeleteLink( $user, $revision, $this->getTitle() );
1324 if ( $cdel !== '' ) {
1325 $cdel .= ' ';
1328 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1329 wfMessage( 'revision-nav' )->rawParams(
1330 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1331 )->escaped() . "</div>" );
1335 * View redirect
1337 * @param $target Title|Array of destination(s) to redirect
1338 * @param $appendSubtitle Boolean [optional]
1339 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1340 * @return string containing HMTL with redirect link
1342 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1343 global $wgStylePath;
1345 if ( !is_array( $target ) ) {
1346 $target = array( $target );
1349 $lang = $this->getTitle()->getPageLanguage();
1350 $imageDir = $lang->getDir();
1352 if ( $appendSubtitle ) {
1353 $out = $this->getContext()->getOutput();
1354 $out->addSubtitle( wfMessage( 'redirectpagesub' )->escaped() );
1357 // the loop prepends the arrow image before the link, so the first case needs to be outside
1360 * @var $title Title
1362 $title = array_shift( $target );
1364 if ( $forceKnown ) {
1365 $link = Linker::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1366 } else {
1367 $link = Linker::link( $title, htmlspecialchars( $title->getFullText() ) );
1370 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1371 $alt = $lang->isRTL() ? '←' : '→';
1372 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1373 foreach ( $target as $rt ) {
1374 $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1375 if ( $forceKnown ) {
1376 $link .= Linker::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1377 } else {
1378 $link .= Linker::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1382 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1383 return '<div class="redirectMsg">' .
1384 Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1385 '<span class="redirectText">' . $link . '</span></div>';
1389 * Handle action=render
1391 public function render() {
1392 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1393 $this->view();
1397 * action=protect handler
1399 public function protect() {
1400 $form = new ProtectionForm( $this );
1401 $form->execute();
1405 * action=unprotect handler (alias)
1407 public function unprotect() {
1408 $this->protect();
1412 * UI entry point for page deletion
1414 public function delete() {
1415 # This code desperately needs to be totally rewritten
1417 $title = $this->getTitle();
1418 $user = $this->getContext()->getUser();
1420 # Check permissions
1421 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1422 if ( count( $permission_errors ) ) {
1423 throw new PermissionsError( 'delete', $permission_errors );
1426 # Read-only check...
1427 if ( wfReadOnly() ) {
1428 throw new ReadOnlyError;
1431 # Better double-check that it hasn't been deleted yet!
1432 $this->mPage->loadPageData( 'fromdbmaster' );
1433 if ( !$this->mPage->exists() ) {
1434 $deleteLogPage = new LogPage( 'delete' );
1435 $outputPage = $this->getContext()->getOutput();
1436 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1437 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1438 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1440 $outputPage->addHTML(
1441 Xml::element( 'h2', null, $deleteLogPage->getName()->text() )
1443 LogEventsList::showLogExtract(
1444 $outputPage,
1445 'delete',
1446 $title
1449 return;
1452 $request = $this->getContext()->getRequest();
1453 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1454 $deleteReason = $request->getText( 'wpReason' );
1456 if ( $deleteReasonList == 'other' ) {
1457 $reason = $deleteReason;
1458 } elseif ( $deleteReason != '' ) {
1459 // Entry from drop down menu + additional comment
1460 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1461 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1462 } else {
1463 $reason = $deleteReasonList;
1466 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1467 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1469 # Flag to hide all contents of the archived revisions
1470 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1472 $this->doDelete( $reason, $suppress );
1474 if ( $user->isLoggedIn() && $request->getCheck( 'wpWatch' ) != $user->isWatched( $title ) ) {
1475 if ( $request->getCheck( 'wpWatch' ) ) {
1476 WatchAction::doWatch( $title, $user );
1477 } else {
1478 WatchAction::doUnwatch( $title, $user );
1482 return;
1485 // Generate deletion reason
1486 $hasHistory = false;
1487 if ( !$reason ) {
1488 try {
1489 $reason = $this->generateReason( $hasHistory );
1490 } catch ( MWException $e ) {
1491 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1492 wfDebug( "Error while building auto delete summary: $e" );
1493 $reason = '';
1497 // If the page has a history, insert a warning
1498 if ( $hasHistory ) {
1499 $revisions = $this->mTitle->estimateRevisionCount();
1500 // @todo FIXME: i18n issue/patchwork message
1501 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1502 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1503 wfMessage( 'word-separator' )->plain() . Linker::linkKnown( $title,
1504 wfMessage( 'history' )->escaped(),
1505 array( 'rel' => 'archives' ),
1506 array( 'action' => 'history' ) ) .
1507 '</strong>'
1510 if ( $this->mTitle->isBigDeletion() ) {
1511 global $wgDeleteRevisionsLimit;
1512 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1513 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1517 $this->confirmDelete( $reason );
1521 * Output deletion confirmation dialog
1522 * @todo FIXME: Move to another file?
1523 * @param string $reason prefilled reason
1525 public function confirmDelete( $reason ) {
1526 wfDebug( "Article::confirmDelete\n" );
1528 $outputPage = $this->getContext()->getOutput();
1529 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1530 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1531 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1532 $outputPage->addWikiMsg( 'confirmdeletetext' );
1534 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1536 $user = $this->getContext()->getUser();
1538 if ( $user->isAllowed( 'suppressrevision' ) ) {
1539 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1540 <td></td>
1541 <td class='mw-input'><strong>" .
1542 Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1543 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1544 "</strong></td>
1545 </tr>";
1546 } else {
1547 $suppress = '';
1549 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $this->getTitle() );
1551 $form = Xml::openElement( 'form', array( 'method' => 'post',
1552 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1553 Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1554 Xml::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1555 Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1556 "<tr id=\"wpDeleteReasonListRow\">
1557 <td class='mw-label'>" .
1558 Xml::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1559 "</td>
1560 <td class='mw-input'>" .
1561 Xml::listDropDown( 'wpDeleteReasonList',
1562 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1563 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(), '', 'wpReasonDropDown', 1 ) .
1564 "</td>
1565 </tr>
1566 <tr id=\"wpDeleteReasonRow\">
1567 <td class='mw-label'>" .
1568 Xml::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1569 "</td>
1570 <td class='mw-input'>" .
1571 Html::input( 'wpReason', $reason, 'text', array(
1572 'size' => '60',
1573 'maxlength' => '255',
1574 'tabindex' => '2',
1575 'id' => 'wpReason',
1576 'autofocus'
1577 ) ) .
1578 "</td>
1579 </tr>";
1581 # Disallow watching if user is not logged in
1582 if ( $user->isLoggedIn() ) {
1583 $form .= "
1584 <tr>
1585 <td></td>
1586 <td class='mw-input'>" .
1587 Xml::checkLabel( wfMessage( 'watchthis' )->text(),
1588 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1589 "</td>
1590 </tr>";
1593 $form .= "
1594 $suppress
1595 <tr>
1596 <td></td>
1597 <td class='mw-submit'>" .
1598 Xml::submitButton( wfMessage( 'deletepage' )->text(),
1599 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1600 "</td>
1601 </tr>" .
1602 Xml::closeElement( 'table' ) .
1603 Xml::closeElement( 'fieldset' ) .
1604 Html::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1605 Xml::closeElement( 'form' );
1607 if ( $user->isAllowed( 'editinterface' ) ) {
1608 $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
1609 $link = Linker::link(
1610 $title,
1611 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1612 array(),
1613 array( 'action' => 'edit' )
1615 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1618 $outputPage->addHTML( $form );
1620 $deleteLogPage = new LogPage( 'delete' );
1621 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1622 LogEventsList::showLogExtract( $outputPage, 'delete',
1623 $this->getTitle()
1628 * Perform a deletion and output success or failure messages
1629 * @param $reason
1630 * @param $suppress bool
1632 public function doDelete( $reason, $suppress = false ) {
1633 $error = '';
1634 $outputPage = $this->getContext()->getOutput();
1635 $status = $this->mPage->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1636 if ( $status->isGood() ) {
1637 $deleted = $this->getTitle()->getPrefixedText();
1639 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1640 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1642 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1644 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1645 $outputPage->returnToMain( false );
1646 } else {
1647 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1648 if ( $error == '' ) {
1649 $outputPage->addWikiText(
1650 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1652 $deleteLogPage = new LogPage( 'delete' );
1653 $outputPage->addHTML( Xml::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1655 LogEventsList::showLogExtract(
1656 $outputPage,
1657 'delete',
1658 $this->getTitle()
1660 } else {
1661 $outputPage->addHTML( $error );
1666 /* Caching functions */
1669 * checkLastModified returns true if it has taken care of all
1670 * output to the client that is necessary for this request.
1671 * (that is, it has sent a cached version of the page)
1673 * @return boolean true if cached version send, false otherwise
1675 protected function tryFileCache() {
1676 static $called = false;
1678 if ( $called ) {
1679 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1680 return false;
1683 $called = true;
1684 if ( $this->isFileCacheable() ) {
1685 $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'view' );
1686 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1687 wfDebug( "Article::tryFileCache(): about to load file\n" );
1688 $cache->loadFromFileCache( $this->getContext() );
1689 return true;
1690 } else {
1691 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1692 ob_start( array( &$cache, 'saveToFileCache' ) );
1694 } else {
1695 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1698 return false;
1702 * Check if the page can be cached
1703 * @return bool
1705 public function isFileCacheable() {
1706 $cacheable = false;
1708 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
1709 $cacheable = $this->mPage->getID()
1710 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
1711 // Extension may have reason to disable file caching on some pages.
1712 if ( $cacheable ) {
1713 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1717 return $cacheable;
1720 /**#@-*/
1723 * Lightweight method to get the parser output for a page, checking the parser cache
1724 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1725 * consider, so it's not appropriate to use there.
1727 * @since 1.16 (r52326) for LiquidThreads
1729 * @param $oldid mixed integer Revision ID or null
1730 * @param $user User The relevant user
1731 * @return ParserOutput or false if the given revision ID is not found
1733 public function getParserOutput( $oldid = null, User $user = null ) {
1734 //XXX: bypasses mParserOptions and thus setParserOptions()
1736 if ( $user === null ) {
1737 $parserOptions = $this->getParserOptions();
1738 } else {
1739 $parserOptions = $this->mPage->makeParserOptions( $user );
1742 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1746 * Override the ParserOptions used to render the primary article wikitext.
1748 * @param ParserOptions $options
1749 * @throws MWException if the parser options where already initialized.
1751 public function setParserOptions( ParserOptions $options ) {
1752 if ( $this->mParserOptions ) {
1753 throw new MWException( "can't change parser options after they have already been set" );
1756 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1757 $this->mParserOptions = clone $options;
1761 * Get parser options suitable for rendering the primary article wikitext
1762 * @return ParserOptions
1764 public function getParserOptions() {
1765 if ( !$this->mParserOptions ) {
1766 $this->mParserOptions = $this->mPage->makeParserOptions( $this->getContext() );
1768 // Clone to allow modifications of the return value without affecting cache
1769 return clone $this->mParserOptions;
1773 * Sets the context this Article is executed in
1775 * @param $context IContextSource
1776 * @since 1.18
1778 public function setContext( $context ) {
1779 $this->mContext = $context;
1783 * Gets the context this Article is executed in
1785 * @return IContextSource
1786 * @since 1.18
1788 public function getContext() {
1789 if ( $this->mContext instanceof IContextSource ) {
1790 return $this->mContext;
1791 } else {
1792 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1793 return RequestContext::getMain();
1798 * Info about this page
1799 * @deprecated since 1.19
1801 public function info() {
1802 wfDeprecated( __METHOD__, '1.19' );
1803 Action::factory( 'info', $this )->show();
1807 * Mark this particular edit/page as patrolled
1808 * @deprecated since 1.18
1810 public function markpatrolled() {
1811 wfDeprecated( __METHOD__, '1.18' );
1812 Action::factory( 'markpatrolled', $this )->show();
1816 * Handle action=purge
1817 * @deprecated since 1.19
1818 * @return Action|bool|null false if the action is disabled, null if it is not recognised
1820 public function purge() {
1821 return Action::factory( 'purge', $this )->show();
1825 * Handle action=revert
1826 * @deprecated since 1.19
1828 public function revert() {
1829 wfDeprecated( __METHOD__, '1.19' );
1830 Action::factory( 'revert', $this )->show();
1834 * Handle action=rollback
1835 * @deprecated since 1.19
1837 public function rollback() {
1838 wfDeprecated( __METHOD__, '1.19' );
1839 Action::factory( 'rollback', $this )->show();
1843 * User-interface handler for the "watch" action.
1844 * Requires Request to pass a token as of 1.18.
1845 * @deprecated since 1.18
1847 public function watch() {
1848 wfDeprecated( __METHOD__, '1.18' );
1849 Action::factory( 'watch', $this )->show();
1853 * Add this page to the current user's watchlist
1855 * This is safe to be called multiple times
1857 * @return bool true on successful watch operation
1858 * @deprecated since 1.18
1860 public function doWatch() {
1861 wfDeprecated( __METHOD__, '1.18' );
1862 return WatchAction::doWatch( $this->getTitle(), $this->getContext()->getUser() );
1866 * User interface handler for the "unwatch" action.
1867 * Requires Request to pass a token as of 1.18.
1868 * @deprecated since 1.18
1870 public function unwatch() {
1871 wfDeprecated( __METHOD__, '1.18' );
1872 Action::factory( 'unwatch', $this )->show();
1876 * Stop watching a page
1877 * @return bool true on successful unwatch
1878 * @deprecated since 1.18
1880 public function doUnwatch() {
1881 wfDeprecated( __METHOD__, '1.18' );
1882 return WatchAction::doUnwatch( $this->getTitle(), $this->getContext()->getUser() );
1886 * Output a redirect back to the article.
1887 * This is typically used after an edit.
1889 * @deprecated in 1.18; call OutputPage::redirect() directly
1890 * @param $noRedir Boolean: add redirect=no
1891 * @param string $sectionAnchor section to redirect to, including "#"
1892 * @param string $extraQuery extra query params
1894 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1895 wfDeprecated( __METHOD__, '1.18' );
1896 if ( $noRedir ) {
1897 $query = 'redirect=no';
1898 if ( $extraQuery ) {
1899 $query .= "&$extraQuery";
1901 } else {
1902 $query = $extraQuery;
1905 $this->getContext()->getOutput()->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1909 * Use PHP's magic __get handler to handle accessing of
1910 * raw WikiPage fields for backwards compatibility.
1912 * @param string $fname Field name
1914 public function __get( $fname ) {
1915 if ( property_exists( $this->mPage, $fname ) ) {
1916 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1917 return $this->mPage->$fname;
1919 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
1923 * Use PHP's magic __set handler to handle setting of
1924 * raw WikiPage fields for backwards compatibility.
1926 * @param string $fname Field name
1927 * @param $fvalue mixed New value
1929 public function __set( $fname, $fvalue ) {
1930 if ( property_exists( $this->mPage, $fname ) ) {
1931 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1932 $this->mPage->$fname = $fvalue;
1933 // Note: extensions may want to toss on new fields
1934 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1935 $this->mPage->$fname = $fvalue;
1936 } else {
1937 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
1942 * Use PHP's magic __call handler to transform instance calls to
1943 * WikiPage functions for backwards compatibility.
1945 * @param string $fname Name of called method
1946 * @param array $args Arguments to the method
1947 * @return mixed
1949 public function __call( $fname, $args ) {
1950 if ( is_callable( array( $this->mPage, $fname ) ) ) {
1951 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1952 return call_user_func_array( array( $this->mPage, $fname ), $args );
1954 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
1957 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1960 * @param $limit array
1961 * @param $expiry array
1962 * @param $cascade bool
1963 * @param $reason string
1964 * @param $user User
1965 * @return Status
1967 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User $user ) {
1968 return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1972 * @param $limit array
1973 * @param $reason string
1974 * @param $cascade int
1975 * @param $expiry array
1976 * @return bool
1978 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1979 return $this->mPage->doUpdateRestrictions(
1980 $limit,
1981 $expiry,
1982 $cascade,
1983 $reason,
1984 $this->getContext()->getUser()
1989 * @param $reason string
1990 * @param $suppress bool
1991 * @param $id int
1992 * @param $commit bool
1993 * @param $error string
1994 * @return bool
1996 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1997 return $this->mPage->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2001 * @param $fromP
2002 * @param $summary
2003 * @param $token
2004 * @param $bot
2005 * @param $resultDetails
2006 * @param $user User
2007 * @return array
2009 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
2010 $user = is_null( $user ) ? $this->getContext()->getUser() : $user;
2011 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2015 * @param $fromP
2016 * @param $summary
2017 * @param $bot
2018 * @param $resultDetails
2019 * @param $guser User
2020 * @return array
2022 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
2023 $guser = is_null( $guser ) ? $this->getContext()->getUser() : $guser;
2024 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2028 * @param $hasHistory bool
2029 * @return mixed
2031 public function generateReason( &$hasHistory ) {
2032 $title = $this->mPage->getTitle();
2033 $handler = ContentHandler::getForTitle( $title );
2034 return $handler->getAutoDeleteReason( $title, $hasHistory );
2037 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2040 * @return array
2042 public static function selectFields() {
2043 return WikiPage::selectFields();
2047 * @param $title Title
2049 public static function onArticleCreate( $title ) {
2050 WikiPage::onArticleCreate( $title );
2054 * @param $title Title
2056 public static function onArticleDelete( $title ) {
2057 WikiPage::onArticleDelete( $title );
2061 * @param $title Title
2063 public static function onArticleEdit( $title ) {
2064 WikiPage::onArticleEdit( $title );
2068 * @param $oldtext
2069 * @param $newtext
2070 * @param $flags
2071 * @return string
2072 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2074 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2075 return WikiPage::getAutosummary( $oldtext, $newtext, $flags );
2077 // ******