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|false $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 $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
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() );
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 $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
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
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 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
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
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 ) {
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();
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 );
340 $this->mRevision
= null;
342 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
344 } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
345 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
348 $this->mRevision
= null;
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.
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 // @todo Get rid of mContent everywhere!
389 $this->mContent
= ContentHandler
::getContentText( $content );
390 ContentHandler
::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
392 wfProfileOut( __METHOD__
);
394 return $this->mContent
;
398 * Get text content object
399 * Does *NOT* follow redirects.
400 * TODO: when is this null?
402 * @note code that wants to retrieve page content from the database should use WikiPage::getContent().
404 * @return Content|null|boolean false
408 protected function fetchContentObject() {
409 if ( $this->mContentLoaded
) {
410 return $this->mContentObject
;
413 wfProfileIn( __METHOD__
);
415 $this->mContentLoaded
= true;
416 $this->mContent
= null;
418 $oldid = $this->getOldID();
420 # Pre-fill content with error message so that if something
421 # fails we'll have something telling us what we intended.
422 //XXX: this isn't page content but a UI message. horrible.
423 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ), array() );
426 # $this->mRevision might already be fetched by getOldIDFromRequest()
427 if ( !$this->mRevision
) {
428 $this->mRevision
= Revision
::newFromId( $oldid );
429 if ( !$this->mRevision
) {
430 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
431 wfProfileOut( __METHOD__
);
436 if ( !$this->mPage
->getLatest() ) {
437 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
438 wfProfileOut( __METHOD__
);
442 $this->mRevision
= $this->mPage
->getRevision();
444 if ( !$this->mRevision
) {
445 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
446 wfProfileOut( __METHOD__
);
451 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
452 // We should instead work with the Revision object when we need it...
453 $this->mContentObject
= $this->mRevision
->getContent( Revision
::FOR_THIS_USER
, $this->getContext()->getUser() ); // Loads if user is allowed
454 $this->mRevIdFetched
= $this->mRevision
->getId();
456 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
458 wfProfileOut( __METHOD__
);
460 return $this->mContentObject
;
464 * Returns true if the currently-referenced revision is the current edit
465 * to this page (and it exists).
468 public function isCurrent() {
469 # If no oldid, this is the current version.
470 if ( $this->getOldID() == 0 ) {
474 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
478 * Get the fetched Revision object depending on request parameters or null
482 * @return Revision|null
484 public function getRevisionFetched() {
485 $this->fetchContentObject();
487 return $this->mRevision
;
491 * Use this to fetch the rev ID used on page views
493 * @return int revision ID of last article revision
495 public function getRevIdFetched() {
496 if ( $this->mRevIdFetched
) {
497 return $this->mRevIdFetched
;
499 return $this->mPage
->getLatest();
504 * This is the default action of the index.php entry point: just view the
505 * page of the given title.
507 public function view() {
508 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
510 wfProfileIn( __METHOD__
);
512 # Get variables from query string
513 # As side effect this will load the revision and update the title
514 # in a revision ID is passed in the request, so this should remain
515 # the first call of this method even if $oldid is used way below.
516 $oldid = $this->getOldID();
518 $user = $this->getContext()->getUser();
519 # Another whitelist check in case getOldID() is altering the title
520 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
521 if ( count( $permErrors ) ) {
522 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
523 wfProfileOut( __METHOD__
);
524 throw new PermissionsError( 'read', $permErrors );
527 $outputPage = $this->getContext()->getOutput();
528 # getOldID() may as well want us to redirect somewhere else
529 if ( $this->mRedirectUrl
) {
530 $outputPage->redirect( $this->mRedirectUrl
);
531 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
532 wfProfileOut( __METHOD__
);
537 # If we got diff in the query, we want to see a diff page instead of the article.
538 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
539 wfDebug( __METHOD__
. ": showing diff page\n" );
540 $this->showDiffPage();
541 wfProfileOut( __METHOD__
);
546 # Set page title (may be overridden by DISPLAYTITLE)
547 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
549 $outputPage->setArticleFlag( true );
550 # Allow frames by default
551 $outputPage->allowClickjacking();
553 $parserCache = ParserCache
::singleton();
555 $parserOptions = $this->getParserOptions();
556 # Render printable version, use printable version cache
557 if ( $outputPage->isPrintable() ) {
558 $parserOptions->setIsPrintable( true );
559 $parserOptions->setEditSection( false );
560 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
561 $parserOptions->setEditSection( false );
564 # Try client and file cache
565 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
567 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
570 # Is it client cached?
571 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
572 wfDebug( __METHOD__
. ": done 304\n" );
573 wfProfileOut( __METHOD__
);
577 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
578 wfDebug( __METHOD__
. ": done file cache\n" );
579 # tell wgOut that output is taken care of
580 $outputPage->disable();
581 $this->mPage
->doViewUpdates( $user, $oldid );
582 wfProfileOut( __METHOD__
);
588 # Should the parser cache be used?
589 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
590 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
591 if ( $user->getStubThreshold() ) {
592 wfIncrStats( 'pcache_miss_stub' );
595 $this->showRedirectedFromHeader();
596 $this->showNamespaceHeader();
598 # Iterate through the possible ways of constructing the output text.
599 # Keep going until $outputDone is set, or we run out of things to do.
602 $this->mParserOutput
= false;
604 while ( !$outputDone && ++
$pass ) {
607 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
610 # Early abort if the page doesn't exist
611 if ( !$this->mPage
->exists() ) {
612 wfDebug( __METHOD__
. ": showing missing article\n" );
613 $this->showMissingArticle();
614 wfProfileOut( __METHOD__
);
618 # Try the parser cache
619 if ( $useParserCache ) {
620 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
622 if ( $this->mParserOutput
!== false ) {
624 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
625 $this->setOldSubtitle( $oldid );
627 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
629 $outputPage->addParserOutput( $this->mParserOutput
);
630 # Ensure that UI elements requiring revision ID have
631 # the correct version information.
632 $outputPage->setRevisionId( $this->mPage
->getLatest() );
633 # Preload timestamp to avoid a DB hit
634 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
635 if ( $cachedTimestamp !== null ) {
636 $outputPage->setRevisionTimestamp( $cachedTimestamp );
637 $this->mPage
->setTimestamp( $cachedTimestamp );
644 # This will set $this->mRevision if needed
645 $this->fetchContentObject();
647 # Are we looking at an old revision
648 if ( $oldid && $this->mRevision
) {
649 $this->setOldSubtitle( $oldid );
651 if ( !$this->showDeletedRevisionHeader() ) {
652 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
653 wfProfileOut( __METHOD__
);
658 # Ensure that UI elements requiring revision ID have
659 # the correct version information.
660 $outputPage->setRevisionId( $this->getRevIdFetched() );
661 # Preload timestamp to avoid a DB hit
662 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
664 # Pages containing custom CSS or JavaScript get special treatment
665 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
666 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
667 $this->showCssOrJsPage();
669 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
670 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
672 # Allow extensions do their own custom view for certain pages
674 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
675 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
677 # Allow extensions do their own custom view for certain pages
682 # Run the parse, protected by a pool counter
683 wfDebug( __METHOD__
. ": doing uncached parse\n" );
685 $content = $this->getContentObject();
686 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
687 $this->getRevIdFetched(), $useParserCache, $content );
689 if ( !$poolArticleView->execute() ) {
690 $error = $poolArticleView->getError();
692 $outputPage->clearHTML(); // for release() errors
693 $outputPage->enableClientCache( false );
694 $outputPage->setRobotPolicy( 'noindex,nofollow' );
696 $errortext = $error->getWikiText( false, 'view-pool-error' );
697 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
699 # Connection or timeout error
700 wfProfileOut( __METHOD__
);
704 $this->mParserOutput
= $poolArticleView->getParserOutput();
705 $outputPage->addParserOutput( $this->mParserOutput
);
706 if ( $content->getRedirectTarget() ) {
707 $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
710 # Don't cache a dirty ParserOutput object
711 if ( $poolArticleView->getIsDirty() ) {
712 $outputPage->setSquidMaxage( 0 );
713 $outputPage->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
718 # Should be unreachable, but just in case...
724 # Get the ParserOutput actually *displayed* here.
725 # Note that $this->mParserOutput is the *current* version output.
726 $pOutput = ( $outputDone instanceof ParserOutput
)
727 ?
$outputDone // object fetched by hook
728 : $this->mParserOutput
;
730 # Adjust title for main page & pages with displaytitle
732 $this->adjustDisplayTitle( $pOutput );
735 # For the main page, overwrite the <title> element with the con-
736 # tents of 'pagetitle-view-mainpage' instead of the default (if
738 # This message always exists because it is in the i18n files
739 if ( $this->getTitle()->isMainPage() ) {
740 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
741 if ( !$msg->isDisabled() ) {
742 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
746 # Check for any __NOINDEX__ tags on the page using $pOutput
747 $policy = $this->getRobotPolicy( 'view', $pOutput );
748 $outputPage->setIndexPolicy( $policy['index'] );
749 $outputPage->setFollowPolicy( $policy['follow'] );
751 $this->showViewFooter();
752 $this->mPage
->doViewUpdates( $user, $oldid );
754 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
756 wfProfileOut( __METHOD__
);
760 * Adjust title for pages with displaytitle, -{T|}- or language conversion
761 * @param $pOutput ParserOutput
763 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
764 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
765 $titleText = $pOutput->getTitleText();
766 if ( strval( $titleText ) !== '' ) {
767 $this->getContext()->getOutput()->setPageTitle( $titleText );
772 * Show a diff page according to current request variables. For use within
773 * Article::view() only, other callers should use the DifferenceEngine class.
775 * @todo Make protected
777 public function showDiffPage() {
778 $request = $this->getContext()->getRequest();
779 $user = $this->getContext()->getUser();
780 $diff = $request->getVal( 'diff' );
781 $rcid = $request->getVal( 'rcid' );
782 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
783 $purge = $request->getVal( 'action' ) == 'purge';
784 $unhide = $request->getInt( 'unhide' ) == 1;
785 $oldid = $this->getOldID();
787 $rev = $this->getRevisionFetched();
790 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
791 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
795 $contentHandler = $rev->getContentHandler();
796 $de = $contentHandler->createDifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
798 // DifferenceEngine directly fetched the revision:
799 $this->mRevIdFetched
= $de->mNewid
;
800 $de->showDiffPage( $diffOnly );
802 // Run view updates for the newer revision being diffed (and shown below the diff if not $diffOnly)
803 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
804 // New can be false, convert it to 0 - this conveniently means the latest revision
805 $this->mPage
->doViewUpdates( $user, (int)$new );
809 * Show a page view for a page formatted as CSS or JavaScript. To be called by
810 * Article::view() only.
812 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
815 * @param bool $showCacheHint whether to show a message telling the user to clear the browser cache (default: true).
817 protected function showCssOrJsPage( $showCacheHint = true ) {
818 $outputPage = $this->getContext()->getOutput();
820 if ( $showCacheHint ) {
821 $dir = $this->getContext()->getLanguage()->getDir();
822 $lang = $this->getContext()->getLanguage()->getCode();
824 $outputPage->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
828 $this->fetchContentObject();
830 if ( $this->mContentObject
) {
831 // Give hooks a chance to customise the output
832 if ( ContentHandler
::runLegacyHooks( 'ShowRawCssJs', array( $this->mContentObject
, $this->getTitle(), $outputPage ) ) ) {
833 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
834 $outputPage->addHTML( $po->getText() );
840 * Get the robot policy to be used for the current view
841 * @param string $action the action= GET parameter
842 * @param $pOutput ParserOutput|null
843 * @return Array the policy that should be set
844 * TODO: actions other than 'view'
846 public function getRobotPolicy( $action, $pOutput = null ) {
847 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
849 $ns = $this->getTitle()->getNamespace();
851 # Don't index user and user talk pages for blocked users (bug 11443)
852 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
853 $specificTarget = null;
855 $titleText = $this->getTitle()->getText();
856 if ( IP
::isValid( $titleText ) ) {
857 $vagueTarget = $titleText;
859 $specificTarget = $titleText;
861 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
863 'index' => 'noindex',
864 'follow' => 'nofollow'
869 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
870 # Non-articles (special pages etc), and old revisions
872 'index' => 'noindex',
873 'follow' => 'nofollow'
875 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
876 # Discourage indexing of printable versions, but encourage following
878 'index' => 'noindex',
881 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
882 # For ?curid=x urls, disallow indexing
884 'index' => 'noindex',
889 # Otherwise, construct the policy based on the various config variables.
890 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
892 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
893 # Honour customised robot policies for this namespace
894 $policy = array_merge(
896 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
899 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
900 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
901 # a final sanity check that we have really got the parser output.
902 $policy = array_merge(
904 array( 'index' => $pOutput->getIndexPolicy() )
908 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
909 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
910 $policy = array_merge(
912 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
920 * Converts a String robot policy into an associative array, to allow
921 * merging of several policies using array_merge().
922 * @param $policy Mixed, returns empty array on null/false/'', transparent
923 * to already-converted arrays, converts String.
924 * @return Array: 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
926 public static function formatRobotPolicy( $policy ) {
927 if ( is_array( $policy ) ) {
929 } elseif ( !$policy ) {
933 $policy = explode( ',', $policy );
934 $policy = array_map( 'trim', $policy );
937 foreach ( $policy as $var ) {
938 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
939 $arr['index'] = $var;
940 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
941 $arr['follow'] = $var;
949 * If this request is a redirect view, send "redirected from" subtitle to
950 * the output. Returns true if the header was needed, false if this is not
951 * a redirect view. Handles both local and remote redirects.
955 public function showRedirectedFromHeader() {
956 global $wgRedirectSources;
957 $outputPage = $this->getContext()->getOutput();
959 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
961 if ( isset( $this->mRedirectedFrom
) ) {
962 // This is an internally redirected page view.
963 // We'll need a backlink to the source page for navigation.
964 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
965 $redir = Linker
::linkKnown(
966 $this->mRedirectedFrom
,
969 array( 'redirect' => 'no' )
972 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
974 // Set the fragment if one was specified in the redirect
975 if ( $this->getTitle()->hasFragment() ) {
976 $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
977 $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
980 // Add a <link rel="canonical"> tag
981 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
983 // Tell the output object that the user arrived at this article through a redirect
984 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
988 } elseif ( $rdfrom ) {
989 // This is an externally redirected view, from some other wiki.
990 // If it was reported from a trusted site, supply a backlink.
991 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
992 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
993 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1003 * Show a header specific to the namespace currently being viewed, like
1004 * [[MediaWiki:Talkpagetext]]. For Article::view().
1006 public function showNamespaceHeader() {
1007 if ( $this->getTitle()->isTalkPage() ) {
1008 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1009 $this->getContext()->getOutput()->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
1015 * Show the footer section of an ordinary page view
1017 public function showViewFooter() {
1018 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1019 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
1020 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1023 // Show a footer allowing the user to patrol the shown revision or page if possible
1024 $patrolFooterShown = $this->showPatrolFooter();
1026 wfRunHooks( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1031 * If patrol is possible, output a patrol UI box. This is called from the
1032 * footer section of ordinary page views. If patrol is not possible or not
1033 * desired, does nothing.
1034 * Side effect: When the patrol link is build, this method will call
1035 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1039 public function showPatrolFooter() {
1040 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1042 $outputPage = $this->getContext()->getOutput();
1043 $user = $this->getContext()->getUser();
1044 $cache = wfGetMainCache();
1047 if ( !$this->getTitle()->quickUserCan( 'patrol', $user ) ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol ) ) {
1048 // Patrolling is disabled or the user isn't allowed to
1052 wfProfileIn( __METHOD__
);
1054 // New page patrol: Get the timestamp of the oldest revison which
1055 // the revision table holds for the given page. Then we look
1056 // whether it's within the RC lifespan and if it is, we try
1057 // to get the recentchanges row belonging to that entry
1058 // (with rc_new = 1).
1060 // Check for cached results
1061 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1062 wfProfileOut( __METHOD__
);
1066 if ( $this->mRevision
&& !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 ) ) {
1067 // The current revision is already older than what could be in the RC table
1068 // 6h tolerance because the RC might not be cleaned out regularly
1069 wfProfileOut( __METHOD__
);
1073 $dbr = wfGetDB( DB_SLAVE
);
1074 $oldestRevisionTimestamp = $dbr->selectField(
1076 'MIN( rev_timestamp )',
1077 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1081 if ( $oldestRevisionTimestamp && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 ) ) {
1082 // 6h tolerance because the RC might not be cleaned out regularly
1083 $rc = RecentChange
::newFromConds(
1086 'rc_timestamp' => $oldestRevisionTimestamp,
1087 'rc_namespace' => $this->getTitle()->getNamespace(),
1088 'rc_cur_id' => $this->getTitle()->getArticleID(),
1092 array( 'USE INDEX' => 'new_name_timestamp' )
1097 // No RC entry around
1099 // Cache the information we gathered above in case we can't patrol
1100 // Don't cache in case we can patrol as this could change
1101 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1103 wfProfileOut( __METHOD__
);
1107 if ( $rc->getPerformer()->getName() == $user->getName() ) {
1108 // Don't show a patrol link for own creations. If the user could
1109 // patrol them, they already would be patrolled
1110 wfProfileOut( __METHOD__
);
1114 $rcid = $rc->getAttribute( 'rc_id' );
1116 $token = $user->getEditToken( $rcid );
1118 $outputPage->preventClickjacking();
1119 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1120 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1123 $link = Linker
::linkKnown(
1125 wfMessage( 'markaspatrolledtext' )->escaped(),
1128 'action' => 'markpatrolled',
1134 $outputPage->addHTML(
1135 "<div class='patrollink'>" .
1136 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1140 wfProfileOut( __METHOD__
);
1145 * Show the error text for a missing article. For articles in the MediaWiki
1146 * namespace, show the default message text. To be called from Article::view().
1148 public function showMissingArticle() {
1149 global $wgSend404Code;
1150 $outputPage = $this->getContext()->getOutput();
1151 // Whether the page is a root user page of an existing user (but not a subpage)
1152 $validUserPage = false;
1154 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1155 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
1156 $parts = explode( '/', $this->getTitle()->getText() );
1157 $rootPart = $parts[0];
1158 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1159 $ip = User
::isIP( $rootPart );
1161 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1162 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1163 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1164 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1165 LogEventsList
::showLogExtract(
1168 $user->getUserPage(),
1172 'showIfEmpty' => false,
1174 'blocked-notice-logextract',
1175 $user->getName() # Support GENDER in notice
1179 $validUserPage = !$this->getTitle()->isSubpage();
1181 $validUserPage = !$this->getTitle()->isSubpage();
1185 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1187 // Give extensions a chance to hide their (unrelated) log entries
1188 $logTypes = array( 'delete', 'move' );
1189 $conds = array( "log_action != 'revision'" );
1190 wfRunHooks( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1192 # Show delete and move logs
1193 LogEventsList
::showLogExtract( $outputPage, $logTypes, $this->getTitle(), '',
1196 'showIfEmpty' => false,
1197 'msgKey' => array( 'moveddeleted-notice' ) )
1200 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1201 // If there's no backing content, send a 404 Not Found
1202 // for better machine handling of broken links.
1203 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1206 if ( $validUserPage ) {
1207 // Also apply the robot policy for nonexisting user pages (as those aren't served as 404)
1208 $policy = $this->getRobotPolicy( 'view' );
1209 $outputPage->setIndexPolicy( $policy['index'] );
1210 $outputPage->setFollowPolicy( $policy['follow'] );
1213 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1215 if ( ! $hookResult ) {
1219 # Show error message
1220 $oldid = $this->getOldID();
1222 $text = wfMessage( 'missing-revision', $oldid )->plain();
1223 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1224 // Use the default message text
1225 $text = $this->getTitle()->getDefaultMessageText();
1226 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1227 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1229 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1230 $text = wfMessage( $message )->plain();
1232 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1234 $text = "<div class='noarticletext'>\n$text\n</div>";
1236 $outputPage->addWikiText( $text );
1240 * If the revision requested for view is deleted, check permissions.
1241 * Send either an error message or a warning header to the output.
1243 * @return boolean true if the view is allowed, false if not.
1245 public function showDeletedRevisionHeader() {
1246 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1251 $outputPage = $this->getContext()->getOutput();
1252 $user = $this->getContext()->getUser();
1253 // If the user is not allowed to see it...
1254 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1255 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1256 'rev-deleted-text-permission' );
1259 // If the user needs to confirm that they want to see it...
1260 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1261 # Give explanation and add a link to view the revision...
1262 $oldid = intval( $this->getOldID() );
1263 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1264 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1265 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1266 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1267 array( $msg, $link ) );
1270 // We are allowed to see...
1272 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1273 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1274 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1281 * Generate the navigation links when browsing through an article revisions
1282 * It shows the information as:
1283 * Revision as of \<date\>; view current revision
1284 * \<- Previous version | Next Version -\>
1286 * @param int $oldid revision ID of this article revision
1288 public function setOldSubtitle( $oldid = 0 ) {
1289 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1293 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1295 # Cascade unhide param in links for easy deletion browsing
1296 $extraParams = array();
1298 $extraParams['unhide'] = 1;
1301 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1302 $revision = $this->mRevision
;
1304 $revision = Revision
::newFromId( $oldid );
1307 $timestamp = $revision->getTimestamp();
1309 $current = ( $oldid == $this->mPage
->getLatest() );
1310 $language = $this->getContext()->getLanguage();
1311 $user = $this->getContext()->getUser();
1313 $td = $language->userTimeAndDate( $timestamp, $user );
1314 $tddate = $language->userDate( $timestamp, $user );
1315 $tdtime = $language->userTime( $timestamp, $user );
1317 # Show user links if allowed to see them. If hidden, then show them only if requested...
1318 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1320 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1321 ?
'revision-info-current'
1324 $outputPage = $this->getContext()->getOutput();
1325 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1326 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1327 $tdtime, $revision->getUser() )->parse() . "</div>" );
1330 ?
wfMessage( 'currentrevisionlink' )->escaped()
1331 : Linker
::linkKnown(
1333 wfMessage( 'currentrevisionlink' )->escaped(),
1338 ?
wfMessage( 'diff' )->escaped()
1339 : Linker
::linkKnown(
1341 wfMessage( 'diff' )->escaped(),
1348 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1350 ? Linker
::linkKnown(
1352 wfMessage( 'previousrevision' )->escaped(),
1355 'direction' => 'prev',
1359 : wfMessage( 'previousrevision' )->escaped();
1361 ? Linker
::linkKnown(
1363 wfMessage( 'diff' )->escaped(),
1370 : wfMessage( 'diff' )->escaped();
1371 $nextlink = $current
1372 ?
wfMessage( 'nextrevision' )->escaped()
1373 : Linker
::linkKnown(
1375 wfMessage( 'nextrevision' )->escaped(),
1378 'direction' => 'next',
1382 $nextdiff = $current
1383 ?
wfMessage( 'diff' )->escaped()
1384 : Linker
::linkKnown(
1386 wfMessage( 'diff' )->escaped(),
1394 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1395 if ( $cdel !== '' ) {
1399 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1400 wfMessage( 'revision-nav' )->rawParams(
1401 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1402 )->escaped() . "</div>" );
1406 * Return the HTML for the top of a redirect page
1408 * Chances are you should just be using the ParserOutput from
1409 * WikitextContent::getParserOutput instead of calling this for redirects.
1411 * @param $target Title|Array of destination(s) to redirect
1412 * @param $appendSubtitle Boolean [optional]
1413 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1414 * @return string containing HMTL with redirect link
1416 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1417 $lang = $this->getTitle()->getPageLanguage();
1418 if ( $appendSubtitle ) {
1419 $out = $this->getContext()->getOutput();
1420 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1422 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1426 * Return the HTML for the top of a redirect page
1428 * Chances are you should just be using the ParserOutput from
1429 * WikitextContent::getParserOutput instead of calling this for redirects.
1432 * @param Language $lang
1433 * @param Title|array $target destination(s) to redirect
1434 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1435 * @return string containing HMTL with redirect link
1437 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1438 global $wgStylePath;
1440 if ( !is_array( $target ) ) {
1441 $target = array( $target );
1444 $imageDir = $lang->getDir();
1446 // the loop prepends the arrow image before the link, so the first case needs to be outside
1451 $title = array_shift( $target );
1453 if ( $forceKnown ) {
1454 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1456 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1459 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1460 $alt = $lang->isRTL() ?
'←' : '→';
1461 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1462 foreach ( $target as $rt ) {
1463 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1464 if ( $forceKnown ) {
1465 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1467 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1471 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1472 return '<div class="redirectMsg">' .
1473 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1474 '<span class="redirectText">' . $link . '</span></div>';
1478 * Handle action=render
1480 public function render() {
1481 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1486 * action=protect handler
1488 public function protect() {
1489 $form = new ProtectionForm( $this );
1494 * action=unprotect handler (alias)
1496 public function unprotect() {
1501 * UI entry point for page deletion
1503 public function delete() {
1504 # This code desperately needs to be totally rewritten
1506 $title = $this->getTitle();
1507 $user = $this->getContext()->getUser();
1510 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1511 if ( count( $permission_errors ) ) {
1512 throw new PermissionsError( 'delete', $permission_errors );
1515 # Read-only check...
1516 if ( wfReadOnly() ) {
1517 throw new ReadOnlyError
;
1520 # Better double-check that it hasn't been deleted yet!
1521 $this->mPage
->loadPageData( 'fromdbmaster' );
1522 if ( !$this->mPage
->exists() ) {
1523 $deleteLogPage = new LogPage( 'delete' );
1524 $outputPage = $this->getContext()->getOutput();
1525 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1526 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1527 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1529 $outputPage->addHTML(
1530 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1532 LogEventsList
::showLogExtract(
1541 $request = $this->getContext()->getRequest();
1542 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1543 $deleteReason = $request->getText( 'wpReason' );
1545 if ( $deleteReasonList == 'other' ) {
1546 $reason = $deleteReason;
1547 } elseif ( $deleteReason != '' ) {
1548 // Entry from drop down menu + additional comment
1549 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1550 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1552 $reason = $deleteReasonList;
1555 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1556 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1558 # Flag to hide all contents of the archived revisions
1559 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1561 $this->doDelete( $reason, $suppress );
1563 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1568 // Generate deletion reason
1569 $hasHistory = false;
1572 $reason = $this->generateReason( $hasHistory );
1573 } catch ( MWException
$e ) {
1574 # if a page is horribly broken, we still want to be able to delete it. so be lenient about errors here.
1575 wfDebug( "Error while building auto delete summary: $e" );
1580 // If the page has a history, insert a warning
1581 if ( $hasHistory ) {
1582 $revisions = $this->mTitle
->estimateRevisionCount();
1583 // @todo FIXME: i18n issue/patchwork message
1584 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1585 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1586 wfMessage( 'word-separator' )->plain() . Linker
::linkKnown( $title,
1587 wfMessage( 'history' )->escaped(),
1588 array( 'rel' => 'archives' ),
1589 array( 'action' => 'history' ) ) .
1593 if ( $this->mTitle
->isBigDeletion() ) {
1594 global $wgDeleteRevisionsLimit;
1595 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1596 array( 'delete-warning-toobig', $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit ) ) );
1600 $this->confirmDelete( $reason );
1604 * Output deletion confirmation dialog
1605 * @todo FIXME: Move to another file?
1606 * @param string $reason prefilled reason
1608 public function confirmDelete( $reason ) {
1609 wfDebug( "Article::confirmDelete\n" );
1611 $outputPage = $this->getContext()->getOutput();
1612 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1613 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1614 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1615 $backlinkCache = $this->getTitle()->getBacklinkCache();
1616 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1617 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1618 'deleting-backlinks-warning' );
1620 $outputPage->addWikiMsg( 'confirmdeletetext' );
1622 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1624 $user = $this->getContext()->getUser();
1626 if ( $user->isAllowed( 'suppressrevision' ) ) {
1627 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1629 <td class='mw-input'><strong>" .
1630 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1631 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1637 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $this->getTitle() );
1639 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1640 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1641 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1642 Xml
::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1643 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1644 "<tr id=\"wpDeleteReasonListRow\">
1645 <td class='mw-label'>" .
1646 Xml
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1648 <td class='mw-input'>" .
1649 Xml
::listDropDown( 'wpDeleteReasonList',
1650 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1651 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(), '', 'wpReasonDropDown', 1 ) .
1654 <tr id=\"wpDeleteReasonRow\">
1655 <td class='mw-label'>" .
1656 Xml
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1658 <td class='mw-input'>" .
1659 Html
::input( 'wpReason', $reason, 'text', array(
1661 'maxlength' => '255',
1669 # Disallow watching if user is not logged in
1670 if ( $user->isLoggedIn() ) {
1674 <td class='mw-input'>" .
1675 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1676 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1685 <td class='mw-submit'>" .
1686 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1687 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1690 Xml
::closeElement( 'table' ) .
1691 Xml
::closeElement( 'fieldset' ) .
1692 Html
::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1693 Xml
::closeElement( 'form' );
1695 if ( $user->isAllowed( 'editinterface' ) ) {
1696 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1697 $link = Linker
::link(
1699 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1701 array( 'action' => 'edit' )
1703 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1706 $outputPage->addHTML( $form );
1708 $deleteLogPage = new LogPage( 'delete' );
1709 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1710 LogEventsList
::showLogExtract( $outputPage, 'delete',
1716 * Perform a deletion and output success or failure messages
1718 * @param $suppress bool
1720 public function doDelete( $reason, $suppress = false ) {
1722 $outputPage = $this->getContext()->getOutput();
1723 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1724 if ( $status->isGood() ) {
1725 $deleted = $this->getTitle()->getPrefixedText();
1727 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1728 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1730 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1732 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1733 $outputPage->returnToMain( false );
1735 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1736 if ( $error == '' ) {
1737 $outputPage->addWikiText(
1738 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1740 $deleteLogPage = new LogPage( 'delete' );
1741 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1743 LogEventsList
::showLogExtract(
1749 $outputPage->addHTML( $error );
1754 /* Caching functions */
1757 * checkLastModified returns true if it has taken care of all
1758 * output to the client that is necessary for this request.
1759 * (that is, it has sent a cached version of the page)
1761 * @return boolean true if cached version send, false otherwise
1763 protected function tryFileCache() {
1764 static $called = false;
1767 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1772 if ( $this->isFileCacheable() ) {
1773 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1774 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1775 wfDebug( "Article::tryFileCache(): about to load file\n" );
1776 $cache->loadFromFileCache( $this->getContext() );
1779 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1780 ob_start( array( &$cache, 'saveToFileCache' ) );
1783 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1790 * Check if the page can be cached
1793 public function isFileCacheable() {
1796 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1797 $cacheable = $this->mPage
->getID()
1798 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1799 // Extension may have reason to disable file caching on some pages.
1801 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1811 * Lightweight method to get the parser output for a page, checking the parser cache
1812 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1813 * consider, so it's not appropriate to use there.
1815 * @since 1.16 (r52326) for LiquidThreads
1817 * @param $oldid mixed integer Revision ID or null
1818 * @param $user User The relevant user
1819 * @return ParserOutput or false if the given revision ID is not found
1821 public function getParserOutput( $oldid = null, User
$user = null ) {
1822 //XXX: bypasses mParserOptions and thus setParserOptions()
1824 if ( $user === null ) {
1825 $parserOptions = $this->getParserOptions();
1827 $parserOptions = $this->mPage
->makeParserOptions( $user );
1830 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1834 * Override the ParserOptions used to render the primary article wikitext.
1836 * @param ParserOptions $options
1837 * @throws MWException if the parser options where already initialized.
1839 public function setParserOptions( ParserOptions
$options ) {
1840 if ( $this->mParserOptions
) {
1841 throw new MWException( "can't change parser options after they have already been set" );
1844 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1845 $this->mParserOptions
= clone $options;
1849 * Get parser options suitable for rendering the primary article wikitext
1850 * @return ParserOptions
1852 public function getParserOptions() {
1853 if ( !$this->mParserOptions
) {
1854 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1856 // Clone to allow modifications of the return value without affecting cache
1857 return clone $this->mParserOptions
;
1861 * Sets the context this Article is executed in
1863 * @param $context IContextSource
1866 public function setContext( $context ) {
1867 $this->mContext
= $context;
1871 * Gets the context this Article is executed in
1873 * @return IContextSource
1876 public function getContext() {
1877 if ( $this->mContext
instanceof IContextSource
) {
1878 return $this->mContext
;
1880 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1881 return RequestContext
::getMain();
1886 * Info about this page
1887 * @deprecated since 1.19
1889 public function info() {
1890 wfDeprecated( __METHOD__
, '1.19' );
1891 Action
::factory( 'info', $this )->show();
1895 * Handle action=purge
1896 * @deprecated since 1.19
1897 * @return Action|bool|null false if the action is disabled, null if it is not recognised
1899 public function purge() {
1900 return Action
::factory( 'purge', $this )->show();
1904 * Handle action=revert
1905 * @deprecated since 1.19
1907 public function revert() {
1908 wfDeprecated( __METHOD__
, '1.19' );
1909 Action
::factory( 'revert', $this )->show();
1913 * Handle action=rollback
1914 * @deprecated since 1.19
1916 public function rollback() {
1917 wfDeprecated( __METHOD__
, '1.19' );
1918 Action
::factory( 'rollback', $this )->show();
1922 * Use PHP's magic __get handler to handle accessing of
1923 * raw WikiPage fields for backwards compatibility.
1925 * @param string $fname Field name
1927 public function __get( $fname ) {
1928 if ( property_exists( $this->mPage
, $fname ) ) {
1929 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1930 return $this->mPage
->$fname;
1932 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1936 * Use PHP's magic __set handler to handle setting of
1937 * raw WikiPage fields for backwards compatibility.
1939 * @param string $fname Field name
1940 * @param $fvalue mixed New value
1942 public function __set( $fname, $fvalue ) {
1943 if ( property_exists( $this->mPage
, $fname ) ) {
1944 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1945 $this->mPage
->$fname = $fvalue;
1946 // Note: extensions may want to toss on new fields
1947 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1948 $this->mPage
->$fname = $fvalue;
1950 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1955 * Use PHP's magic __call handler to transform instance calls to
1956 * WikiPage functions for backwards compatibility.
1958 * @param string $fname Name of called method
1959 * @param array $args Arguments to the method
1962 public function __call( $fname, $args ) {
1963 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1964 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1965 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1967 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1970 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1973 * @param $limit array
1974 * @param $expiry array
1975 * @param $cascade bool
1976 * @param $reason string
1980 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User
$user ) {
1981 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1985 * @param $limit array
1986 * @param $reason string
1987 * @param $cascade int
1988 * @param $expiry array
1991 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1992 return $this->mPage
->doUpdateRestrictions(
1997 $this->getContext()->getUser()
2002 * @param $reason string
2003 * @param $suppress bool
2005 * @param $commit bool
2006 * @param $error string
2009 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
2010 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2018 * @param $resultDetails
2022 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2023 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2024 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2031 * @param $resultDetails
2032 * @param $guser User
2035 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2036 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2037 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2041 * @param $hasHistory bool
2044 public function generateReason( &$hasHistory ) {
2045 $title = $this->mPage
->getTitle();
2046 $handler = ContentHandler
::getForTitle( $title );
2047 return $handler->getAutoDeleteReason( $title, $hasHistory );
2050 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2055 public static function selectFields() {
2056 return WikiPage
::selectFields();
2060 * @param $title Title
2062 public static function onArticleCreate( $title ) {
2063 WikiPage
::onArticleCreate( $title );
2067 * @param $title Title
2069 public static function onArticleDelete( $title ) {
2070 WikiPage
::onArticleDelete( $title );
2074 * @param $title Title
2076 public static function onArticleEdit( $title ) {
2077 WikiPage
::onArticleEdit( $title );
2085 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2087 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2088 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );