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 since 1.21; use WikiPage::getContent() instead
243 * @return string Return the text of this revision
245 public function getContent() {
246 ContentHandler
::deprecated( __METHOD__
, '1.21' );
247 $content = $this->getContentObject();
248 return ContentHandler
::getContentText( $content );
252 * Returns a Content object representing the pages effective display content,
253 * not necessarily the revision's content!
255 * Note that getContent/loadContent do not follow redirects anymore.
256 * If you need to fetch redirectable content easily, try
257 * the shortcut in WikiPage::getRedirectTarget()
259 * This function has side effects! Do not use this function if you
260 * only want the real revision text if any.
262 * @return Content Return the content of this revision
266 protected function getContentObject() {
267 wfProfileIn( __METHOD__
);
269 if ( $this->mPage
->getID() === 0 ) {
270 # If this is a MediaWiki:x message, then load the messages
271 # and return the message value for x.
272 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
273 $text = $this->getTitle()->getDefaultMessageText();
274 if ( $text === false ) {
278 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
280 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
281 $content = new MessageContent( $message, null, 'parsemag' );
284 $this->fetchContentObject();
285 $content = $this->mContentObject
;
288 wfProfileOut( __METHOD__
);
293 * @return int The oldid of the article that is to be shown, 0 for the
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 since 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
371 * used by other functions. For accessing article content, use the WikiPage
372 * class, especially WikiBase::getContent(). However, a lot of legacy code
373 * uses this method to retrieve page text from the database, so the function
374 * has to remain public for now.
376 * @return mixed string containing article contents, or false if null
377 * @deprecated since 1.21, use WikiPage::getContent() instead
379 function fetchContent() { #BC cruft!
380 ContentHandler
::deprecated( __METHOD__
, '1.21' );
382 if ( $this->mContentLoaded
&& $this->mContent
) {
383 return $this->mContent
;
386 wfProfileIn( __METHOD__
);
388 $content = $this->fetchContentObject();
390 // @todo Get rid of mContent everywhere!
391 $this->mContent
= ContentHandler
::getContentText( $content );
392 ContentHandler
::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
394 wfProfileOut( __METHOD__
);
396 return $this->mContent
;
400 * Get text content object
401 * Does *NOT* follow redirects.
402 * @todo When is this null?
404 * @note Code that wants to retrieve page content from the database should
405 * use WikiPage::getContent().
407 * @return Content|null|boolean false
411 protected function fetchContentObject() {
412 if ( $this->mContentLoaded
) {
413 return $this->mContentObject
;
416 wfProfileIn( __METHOD__
);
418 $this->mContentLoaded
= true;
419 $this->mContent
= null;
421 $oldid = $this->getOldID();
423 # Pre-fill content with error message so that if something
424 # fails we'll have something telling us what we intended.
425 //XXX: this isn't page content but a UI message. horrible.
426 $this->mContentObject
= new MessageContent( 'missing-revision', array( $oldid ), array() );
429 # $this->mRevision might already be fetched by getOldIDFromRequest()
430 if ( !$this->mRevision
) {
431 $this->mRevision
= Revision
::newFromId( $oldid );
432 if ( !$this->mRevision
) {
433 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
434 wfProfileOut( __METHOD__
);
439 if ( !$this->mPage
->getLatest() ) {
440 wfDebug( __METHOD__
. " failed to find page data for title " .
441 $this->getTitle()->getPrefixedText() . "\n" );
442 wfProfileOut( __METHOD__
);
446 $this->mRevision
= $this->mPage
->getRevision();
448 if ( !$this->mRevision
) {
449 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " .
450 $this->mPage
->getLatest() . "\n" );
451 wfProfileOut( __METHOD__
);
456 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
457 // We should instead work with the Revision object when we need it...
458 // Loads if user is allowed
459 $this->mContentObject
= $this->mRevision
->getContent(
460 Revision
::FOR_THIS_USER
,
461 $this->getContext()->getUser()
463 $this->mRevIdFetched
= $this->mRevision
->getId();
465 wfRunHooks( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject
) );
467 wfProfileOut( __METHOD__
);
469 return $this->mContentObject
;
473 * Returns true if the currently-referenced revision is the current edit
474 * to this page (and it exists).
477 public function isCurrent() {
478 # If no oldid, this is the current version.
479 if ( $this->getOldID() == 0 ) {
483 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
487 * Get the fetched Revision object depending on request parameters or null
491 * @return Revision|null
493 public function getRevisionFetched() {
494 $this->fetchContentObject();
496 return $this->mRevision
;
500 * Use this to fetch the rev ID used on page views
502 * @return int revision ID of last article revision
504 public function getRevIdFetched() {
505 if ( $this->mRevIdFetched
) {
506 return $this->mRevIdFetched
;
508 return $this->mPage
->getLatest();
513 * This is the default action of the index.php entry point: just view the
514 * page of the given title.
516 public function view() {
517 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
519 wfProfileIn( __METHOD__
);
521 # Get variables from query string
522 # As side effect this will load the revision and update the title
523 # in a revision ID is passed in the request, so this should remain
524 # the first call of this method even if $oldid is used way below.
525 $oldid = $this->getOldID();
527 $user = $this->getContext()->getUser();
528 # Another whitelist check in case getOldID() is altering the title
529 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $user );
530 if ( count( $permErrors ) ) {
531 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
532 wfProfileOut( __METHOD__
);
533 throw new PermissionsError( 'read', $permErrors );
536 $outputPage = $this->getContext()->getOutput();
537 # getOldID() may as well want us to redirect somewhere else
538 if ( $this->mRedirectUrl
) {
539 $outputPage->redirect( $this->mRedirectUrl
);
540 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
541 wfProfileOut( __METHOD__
);
546 # If we got diff in the query, we want to see a diff page instead of the article.
547 if ( $this->getContext()->getRequest()->getCheck( 'diff' ) ) {
548 wfDebug( __METHOD__
. ": showing diff page\n" );
549 $this->showDiffPage();
550 wfProfileOut( __METHOD__
);
555 # Set page title (may be overridden by DISPLAYTITLE)
556 $outputPage->setPageTitle( $this->getTitle()->getPrefixedText() );
558 $outputPage->setArticleFlag( true );
559 # Allow frames by default
560 $outputPage->allowClickjacking();
562 $parserCache = ParserCache
::singleton();
564 $parserOptions = $this->getParserOptions();
565 # Render printable version, use printable version cache
566 if ( $outputPage->isPrintable() ) {
567 $parserOptions->setIsPrintable( true );
568 $parserOptions->setEditSection( false );
569 } elseif ( !$this->isCurrent() ||
!$this->getTitle()->quickUserCan( 'edit', $user ) ) {
570 $parserOptions->setEditSection( false );
573 # Try client and file cache
574 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage
->checkTouched() ) {
576 $outputPage->setETag( $parserCache->getETag( $this, $parserOptions ) );
579 # Is it client cached?
580 if ( $outputPage->checkLastModified( $this->mPage
->getTouched() ) ) {
581 wfDebug( __METHOD__
. ": done 304\n" );
582 wfProfileOut( __METHOD__
);
586 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
587 wfDebug( __METHOD__
. ": done file cache\n" );
588 # tell wgOut that output is taken care of
589 $outputPage->disable();
590 $this->mPage
->doViewUpdates( $user, $oldid );
591 wfProfileOut( __METHOD__
);
597 # Should the parser cache be used?
598 $useParserCache = $this->mPage
->isParserCacheUsed( $parserOptions, $oldid );
599 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
600 if ( $user->getStubThreshold() ) {
601 wfIncrStats( 'pcache_miss_stub' );
604 $this->showRedirectedFromHeader();
605 $this->showNamespaceHeader();
607 # Iterate through the possible ways of constructing the output text.
608 # Keep going until $outputDone is set, or we run out of things to do.
611 $this->mParserOutput
= false;
613 while ( !$outputDone && ++
$pass ) {
616 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
619 # Early abort if the page doesn't exist
620 if ( !$this->mPage
->exists() ) {
621 wfDebug( __METHOD__
. ": showing missing article\n" );
622 $this->showMissingArticle();
623 $this->mPage
->doViewUpdates( $user );
624 wfProfileOut( __METHOD__
);
628 # Try the parser cache
629 if ( $useParserCache ) {
630 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
632 if ( $this->mParserOutput
!== false ) {
634 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
635 $this->setOldSubtitle( $oldid );
637 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
639 $outputPage->addParserOutput( $this->mParserOutput
);
640 # Ensure that UI elements requiring revision ID have
641 # the correct version information.
642 $outputPage->setRevisionId( $this->mPage
->getLatest() );
643 # Preload timestamp to avoid a DB hit
644 $cachedTimestamp = $this->mParserOutput
->getTimestamp();
645 if ( $cachedTimestamp !== null ) {
646 $outputPage->setRevisionTimestamp( $cachedTimestamp );
647 $this->mPage
->setTimestamp( $cachedTimestamp );
654 # This will set $this->mRevision if needed
655 $this->fetchContentObject();
657 # Are we looking at an old revision
658 if ( $oldid && $this->mRevision
) {
659 $this->setOldSubtitle( $oldid );
661 if ( !$this->showDeletedRevisionHeader() ) {
662 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
663 wfProfileOut( __METHOD__
);
668 # Ensure that UI elements requiring revision ID have
669 # the correct version information.
670 $outputPage->setRevisionId( $this->getRevIdFetched() );
671 # Preload timestamp to avoid a DB hit
672 $outputPage->setRevisionTimestamp( $this->getTimestamp() );
674 # Pages containing custom CSS or JavaScript get special treatment
675 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
676 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
677 $this->showCssOrJsPage();
679 } elseif ( !wfRunHooks( 'ArticleContentViewCustom',
680 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
682 # Allow extensions do their own custom view for certain pages
684 } elseif ( !ContentHandler
::runLegacyHooks( 'ArticleViewCustom',
685 array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
687 # Allow extensions do their own custom view for certain pages
692 # Run the parse, protected by a pool counter
693 wfDebug( __METHOD__
. ": doing uncached parse\n" );
695 $content = $this->getContentObject();
696 $poolArticleView = new PoolWorkArticleView( $this->getPage(), $parserOptions,
697 $this->getRevIdFetched(), $useParserCache, $content );
699 if ( !$poolArticleView->execute() ) {
700 $error = $poolArticleView->getError();
702 $outputPage->clearHTML(); // for release() errors
703 $outputPage->enableClientCache( false );
704 $outputPage->setRobotPolicy( 'noindex,nofollow' );
706 $errortext = $error->getWikiText( false, 'view-pool-error' );
707 $outputPage->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
709 # Connection or timeout error
710 wfProfileOut( __METHOD__
);
714 $this->mParserOutput
= $poolArticleView->getParserOutput();
715 $outputPage->addParserOutput( $this->mParserOutput
);
716 if ( $content->getRedirectTarget() ) {
717 $outputPage->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
720 # Don't cache a dirty ParserOutput object
721 if ( $poolArticleView->getIsDirty() ) {
722 $outputPage->setSquidMaxage( 0 );
723 $outputPage->addHTML( "<!-- parser cache is expired, " .
724 "sending anyway due to pool overload-->\n" );
729 # Should be unreachable, but just in case...
735 # Get the ParserOutput actually *displayed* here.
736 # Note that $this->mParserOutput is the *current* version output.
737 $pOutput = ( $outputDone instanceof ParserOutput
)
738 ?
$outputDone // object fetched by hook
739 : $this->mParserOutput
;
741 # Adjust title for main page & pages with displaytitle
743 $this->adjustDisplayTitle( $pOutput );
746 # For the main page, overwrite the <title> element with the con-
747 # tents of 'pagetitle-view-mainpage' instead of the default (if
749 # This message always exists because it is in the i18n files
750 if ( $this->getTitle()->isMainPage() ) {
751 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
752 if ( !$msg->isDisabled() ) {
753 $outputPage->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
757 # Check for any __NOINDEX__ tags on the page using $pOutput
758 $policy = $this->getRobotPolicy( 'view', $pOutput );
759 $outputPage->setIndexPolicy( $policy['index'] );
760 $outputPage->setFollowPolicy( $policy['follow'] );
762 $this->showViewFooter();
763 $this->mPage
->doViewUpdates( $user, $oldid );
765 $outputPage->addModules( 'mediawiki.action.view.postEdit' );
767 wfProfileOut( __METHOD__
);
771 * Adjust title for pages with displaytitle, -{T|}- or language conversion
772 * @param $pOutput ParserOutput
774 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
775 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
776 $titleText = $pOutput->getTitleText();
777 if ( strval( $titleText ) !== '' ) {
778 $this->getContext()->getOutput()->setPageTitle( $titleText );
783 * Show a diff page according to current request variables. For use within
784 * Article::view() only, other callers should use the DifferenceEngine class.
786 * @todo Make protected
788 public function showDiffPage() {
789 $request = $this->getContext()->getRequest();
790 $user = $this->getContext()->getUser();
791 $diff = $request->getVal( 'diff' );
792 $rcid = $request->getVal( 'rcid' );
793 $diffOnly = $request->getBool( 'diffonly', $user->getOption( 'diffonly' ) );
794 $purge = $request->getVal( 'action' ) == 'purge';
795 $unhide = $request->getInt( 'unhide' ) == 1;
796 $oldid = $this->getOldID();
798 $rev = $this->getRevisionFetched();
801 $this->getContext()->getOutput()->setPageTitle( wfMessage( 'errorpagetitle' ) );
802 $this->getContext()->getOutput()->addWikiMsg( 'difference-missing-revision', $oldid, 1 );
806 $contentHandler = $rev->getContentHandler();
807 $de = $contentHandler->createDifferenceEngine(
816 // DifferenceEngine directly fetched the revision:
817 $this->mRevIdFetched
= $de->mNewid
;
818 $de->showDiffPage( $diffOnly );
820 // Run view updates for the newer revision being diffed (and shown
821 // below the diff if not $diffOnly).
822 list( $old, $new ) = $de->mapDiffPrevNext( $oldid, $diff );
823 // New can be false, convert it to 0 - this conveniently means the latest revision
824 $this->mPage
->doViewUpdates( $user, (int)$new );
828 * Show a page view for a page formatted as CSS or JavaScript. To be called by
829 * Article::view() only.
831 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
834 * @param bool $showCacheHint whether to show a message telling the user
835 * to clear the browser cache (default: true).
837 protected function showCssOrJsPage( $showCacheHint = true ) {
838 $outputPage = $this->getContext()->getOutput();
840 if ( $showCacheHint ) {
841 $dir = $this->getContext()->getLanguage()->getDir();
842 $lang = $this->getContext()->getLanguage()->getCode();
844 $outputPage->wrapWikiMsg(
845 "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
850 $this->fetchContentObject();
852 if ( $this->mContentObject
) {
853 // Give hooks a chance to customise the output
854 if ( ContentHandler
::runLegacyHooks(
856 array( $this->mContentObject
, $this->getTitle(), $outputPage ) )
858 $po = $this->mContentObject
->getParserOutput( $this->getTitle() );
859 $outputPage->addHTML( $po->getText() );
865 * Get the robot policy to be used for the current view
866 * @param string $action the action= GET parameter
867 * @param $pOutput ParserOutput|null
868 * @return Array the policy that should be set
869 * TODO: actions other than 'view'
871 public function getRobotPolicy( $action, $pOutput = null ) {
872 global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
874 $ns = $this->getTitle()->getNamespace();
876 # Don't index user and user talk pages for blocked users (bug 11443)
877 if ( ( $ns == NS_USER ||
$ns == NS_USER_TALK
) && !$this->getTitle()->isSubpage() ) {
878 $specificTarget = null;
880 $titleText = $this->getTitle()->getText();
881 if ( IP
::isValid( $titleText ) ) {
882 $vagueTarget = $titleText;
884 $specificTarget = $titleText;
886 if ( Block
::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block
) {
888 'index' => 'noindex',
889 'follow' => 'nofollow'
894 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
895 # Non-articles (special pages etc), and old revisions
897 'index' => 'noindex',
898 'follow' => 'nofollow'
900 } elseif ( $this->getContext()->getOutput()->isPrintable() ) {
901 # Discourage indexing of printable versions, but encourage following
903 'index' => 'noindex',
906 } elseif ( $this->getContext()->getRequest()->getInt( 'curid' ) ) {
907 # For ?curid=x urls, disallow indexing
909 'index' => 'noindex',
914 # Otherwise, construct the policy based on the various config variables.
915 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
917 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
918 # Honour customised robot policies for this namespace
919 $policy = array_merge(
921 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
924 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
925 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
926 # a final sanity check that we have really got the parser output.
927 $policy = array_merge(
929 array( 'index' => $pOutput->getIndexPolicy() )
933 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
934 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
935 $policy = array_merge(
937 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
945 * Converts a String robot policy into an associative array, to allow
946 * merging of several policies using array_merge().
947 * @param $policy Mixed, returns empty array on null/false/'', transparent
948 * to already-converted arrays, converts String.
949 * @return Array: 'index' => \<indexpolicy\>, 'follow' => \<followpolicy\>
951 public static function formatRobotPolicy( $policy ) {
952 if ( is_array( $policy ) ) {
954 } elseif ( !$policy ) {
958 $policy = explode( ',', $policy );
959 $policy = array_map( 'trim', $policy );
962 foreach ( $policy as $var ) {
963 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
964 $arr['index'] = $var;
965 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
966 $arr['follow'] = $var;
974 * If this request is a redirect view, send "redirected from" subtitle to
975 * the output. Returns true if the header was needed, false if this is not
976 * a redirect view. Handles both local and remote redirects.
980 public function showRedirectedFromHeader() {
981 global $wgRedirectSources;
982 $outputPage = $this->getContext()->getOutput();
984 $rdfrom = $this->getContext()->getRequest()->getVal( 'rdfrom' );
986 if ( isset( $this->mRedirectedFrom
) ) {
987 // This is an internally redirected page view.
988 // We'll need a backlink to the source page for navigation.
989 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
990 $redir = Linker
::linkKnown(
991 $this->mRedirectedFrom
,
994 array( 'redirect' => 'no' )
997 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
999 // Set the fragment if one was specified in the redirect
1000 if ( $this->getTitle()->hasFragment() ) {
1001 $outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
1002 $outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
1005 // Add a <link rel="canonical"> tag
1006 $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
1008 // Tell the output object that the user arrived at this article through a redirect
1009 $outputPage->setRedirectedFrom( $this->mRedirectedFrom
);
1013 } elseif ( $rdfrom ) {
1014 // This is an externally redirected view, from some other wiki.
1015 // If it was reported from a trusted site, supply a backlink.
1016 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
1017 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
1018 $outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
1028 * Show a header specific to the namespace currently being viewed, like
1029 * [[MediaWiki:Talkpagetext]]. For Article::view().
1031 public function showNamespaceHeader() {
1032 if ( $this->getTitle()->isTalkPage() ) {
1033 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
1034 $this->getContext()->getOutput()->wrapWikiMsg(
1035 "<div class=\"mw-talkpageheader\">\n$1\n</div>",
1036 array( 'talkpageheader' )
1043 * Show the footer section of an ordinary page view
1045 public function showViewFooter() {
1046 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
1047 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
1048 && IP
::isValid( $this->getTitle()->getText() )
1050 $this->getContext()->getOutput()->addWikiMsg( 'anontalkpagetext' );
1053 // Show a footer allowing the user to patrol the shown revision or page if possible
1054 $patrolFooterShown = $this->showPatrolFooter();
1056 wfRunHooks( 'ArticleViewFooter', array( $this, $patrolFooterShown ) );
1060 * If patrol is possible, output a patrol UI box. This is called from the
1061 * footer section of ordinary page views. If patrol is not possible or not
1062 * desired, does nothing.
1063 * Side effect: When the patrol link is build, this method will call
1064 * OutputPage::preventClickjacking() and load mediawiki.page.patrol.ajax.
1068 public function showPatrolFooter() {
1069 global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
1071 $outputPage = $this->getContext()->getOutput();
1072 $user = $this->getContext()->getUser();
1073 $cache = wfGetMainCache();
1076 if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
1077 ||
!( $wgUseRCPatrol ||
$wgUseNPPatrol )
1079 // Patrolling is disabled or the user isn't allowed to
1083 wfProfileIn( __METHOD__
);
1085 // New page patrol: Get the timestamp of the oldest revison which
1086 // the revision table holds for the given page. Then we look
1087 // whether it's within the RC lifespan and if it is, we try
1088 // to get the recentchanges row belonging to that entry
1089 // (with rc_new = 1).
1091 // Check for cached results
1092 if ( $cache->get( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ) ) ) {
1093 wfProfileOut( __METHOD__
);
1097 if ( $this->mRevision
1098 && !RecentChange
::isInRCLifespan( $this->mRevision
->getTimestamp(), 21600 )
1100 // The current revision is already older than what could be in the RC table
1101 // 6h tolerance because the RC might not be cleaned out regularly
1102 wfProfileOut( __METHOD__
);
1106 $dbr = wfGetDB( DB_SLAVE
);
1107 $oldestRevisionTimestamp = $dbr->selectField(
1109 'MIN( rev_timestamp )',
1110 array( 'rev_page' => $this->getTitle()->getArticleID() ),
1114 if ( $oldestRevisionTimestamp
1115 && RecentChange
::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
1117 // 6h tolerance because the RC might not be cleaned out regularly
1118 $rc = RecentChange
::newFromConds(
1121 'rc_timestamp' => $oldestRevisionTimestamp,
1122 'rc_namespace' => $this->getTitle()->getNamespace(),
1123 'rc_cur_id' => $this->getTitle()->getArticleID(),
1127 array( 'USE INDEX' => 'new_name_timestamp' )
1132 // No RC entry around
1134 // Cache the information we gathered above in case we can't patrol
1135 // Don't cache in case we can patrol as this could change
1136 $cache->set( wfMemcKey( 'NotPatrollablePage', $this->getTitle()->getArticleID() ), '1' );
1138 wfProfileOut( __METHOD__
);
1142 if ( $rc->getPerformer()->getName() == $user->getName() ) {
1143 // Don't show a patrol link for own creations. If the user could
1144 // patrol them, they already would be patrolled
1145 wfProfileOut( __METHOD__
);
1149 $rcid = $rc->getAttribute( 'rc_id' );
1151 $token = $user->getEditToken( $rcid );
1153 $outputPage->preventClickjacking();
1154 if ( $wgEnableAPI && $wgEnableWriteAPI && $user->isAllowed( 'writeapi' ) ) {
1155 $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
1158 $link = Linker
::linkKnown(
1160 wfMessage( 'markaspatrolledtext' )->escaped(),
1163 'action' => 'markpatrolled',
1169 $outputPage->addHTML(
1170 "<div class='patrollink'>" .
1171 wfMessage( 'markaspatrolledlink' )->rawParams( $link )->escaped() .
1175 wfProfileOut( __METHOD__
);
1180 * Show the error text for a missing article. For articles in the MediaWiki
1181 * namespace, show the default message text. To be called from Article::view().
1183 public function showMissingArticle() {
1184 global $wgSend404Code;
1185 $outputPage = $this->getContext()->getOutput();
1186 // Whether the page is a root user page of an existing user (but not a subpage)
1187 $validUserPage = false;
1189 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
1190 if ( $this->getTitle()->getNamespace() == NS_USER
1191 ||
$this->getTitle()->getNamespace() == NS_USER_TALK
1193 $parts = explode( '/', $this->getTitle()->getText() );
1194 $rootPart = $parts[0];
1195 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
1196 $ip = User
::isIP( $rootPart );
1198 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1199 $outputPage->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
1200 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
1201 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1202 LogEventsList
::showLogExtract(
1205 $user->getUserPage(),
1209 'showIfEmpty' => false,
1211 'blocked-notice-logextract',
1212 $user->getName() # Support GENDER in notice
1216 $validUserPage = !$this->getTitle()->isSubpage();
1218 $validUserPage = !$this->getTitle()->isSubpage();
1222 wfRunHooks( 'ShowMissingArticle', array( $this ) );
1224 // Give extensions a chance to hide their (unrelated) log entries
1225 $logTypes = array( 'delete', 'move' );
1226 $conds = array( "log_action != 'revision'" );
1227 wfRunHooks( 'Article::MissingArticleConditions', array( &$conds, $logTypes ) );
1229 # Show delete and move logs
1230 LogEventsList
::showLogExtract( $outputPage, $logTypes, $this->getTitle(), '',
1233 'showIfEmpty' => false,
1234 'msgKey' => array( 'moveddeleted-notice' ) )
1237 if ( !$this->mPage
->hasViewableContent() && $wgSend404Code && !$validUserPage ) {
1238 // If there's no backing content, send a 404 Not Found
1239 // for better machine handling of broken links.
1240 $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
1243 if ( $validUserPage ) {
1244 // Also apply the robot policy for nonexisting user pages (as those aren't served as 404)
1245 $policy = $this->getRobotPolicy( 'view' );
1246 $outputPage->setIndexPolicy( $policy['index'] );
1247 $outputPage->setFollowPolicy( $policy['follow'] );
1250 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
1252 if ( ! $hookResult ) {
1256 # Show error message
1257 $oldid = $this->getOldID();
1259 $text = wfMessage( 'missing-revision', $oldid )->plain();
1260 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
1261 // Use the default message text
1262 $text = $this->getTitle()->getDefaultMessageText();
1263 } elseif ( $this->getTitle()->quickUserCan( 'create', $this->getContext()->getUser() )
1264 && $this->getTitle()->quickUserCan( 'edit', $this->getContext()->getUser() )
1266 $message = $this->getContext()->getUser()->isLoggedIn() ?
'noarticletext' : 'noarticletextanon';
1267 $text = wfMessage( $message )->plain();
1269 $text = wfMessage( 'noarticletext-nopermission' )->plain();
1271 $text = "<div class='noarticletext'>\n$text\n</div>";
1273 $outputPage->addWikiText( $text );
1277 * If the revision requested for view is deleted, check permissions.
1278 * Send either an error message or a warning header to the output.
1280 * @return boolean true if the view is allowed, false if not.
1282 public function showDeletedRevisionHeader() {
1283 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1288 $outputPage = $this->getContext()->getOutput();
1289 $user = $this->getContext()->getUser();
1290 // If the user is not allowed to see it...
1291 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
, $user ) ) {
1292 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1293 'rev-deleted-text-permission' );
1296 // If the user needs to confirm that they want to see it...
1297 } elseif ( $this->getContext()->getRequest()->getInt( 'unhide' ) != 1 ) {
1298 # Give explanation and add a link to view the revision...
1299 $oldid = intval( $this->getOldID() );
1300 $link = $this->getTitle()->getFullURL( "oldid={$oldid}&unhide=1" );
1301 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1302 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1303 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1304 array( $msg, $link ) );
1307 // We are allowed to see...
1309 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
1310 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1311 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1318 * Generate the navigation links when browsing through an article revisions
1319 * It shows the information as:
1320 * Revision as of \<date\>; view current revision
1321 * \<- Previous version | Next Version -\>
1323 * @param int $oldid revision ID of this article revision
1325 public function setOldSubtitle( $oldid = 0 ) {
1326 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1330 $unhide = $this->getContext()->getRequest()->getInt( 'unhide' ) == 1;
1332 # Cascade unhide param in links for easy deletion browsing
1333 $extraParams = array();
1335 $extraParams['unhide'] = 1;
1338 if ( $this->mRevision
&& $this->mRevision
->getId() === $oldid ) {
1339 $revision = $this->mRevision
;
1341 $revision = Revision
::newFromId( $oldid );
1344 $timestamp = $revision->getTimestamp();
1346 $current = ( $oldid == $this->mPage
->getLatest() );
1347 $language = $this->getContext()->getLanguage();
1348 $user = $this->getContext()->getUser();
1350 $td = $language->userTimeAndDate( $timestamp, $user );
1351 $tddate = $language->userDate( $timestamp, $user );
1352 $tdtime = $language->userTime( $timestamp, $user );
1354 # Show user links if allowed to see them. If hidden, then show them only if requested...
1355 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1357 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1358 ?
'revision-info-current'
1361 $outputPage = $this->getContext()->getOutput();
1362 $outputPage->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1363 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1364 $tdtime, $revision->getUser() )->parse() . "</div>" );
1367 ?
wfMessage( 'currentrevisionlink' )->escaped()
1368 : Linker
::linkKnown(
1370 wfMessage( 'currentrevisionlink' )->escaped(),
1375 ?
wfMessage( 'diff' )->escaped()
1376 : Linker
::linkKnown(
1378 wfMessage( 'diff' )->escaped(),
1385 $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
1387 ? Linker
::linkKnown(
1389 wfMessage( 'previousrevision' )->escaped(),
1392 'direction' => 'prev',
1396 : wfMessage( 'previousrevision' )->escaped();
1398 ? Linker
::linkKnown(
1400 wfMessage( 'diff' )->escaped(),
1407 : wfMessage( 'diff' )->escaped();
1408 $nextlink = $current
1409 ?
wfMessage( 'nextrevision' )->escaped()
1410 : Linker
::linkKnown(
1412 wfMessage( 'nextrevision' )->escaped(),
1415 'direction' => 'next',
1419 $nextdiff = $current
1420 ?
wfMessage( 'diff' )->escaped()
1421 : Linker
::linkKnown(
1423 wfMessage( 'diff' )->escaped(),
1431 $cdel = Linker
::getRevDeleteLink( $user, $revision, $this->getTitle() );
1432 if ( $cdel !== '' ) {
1436 $outputPage->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1437 wfMessage( 'revision-nav' )->rawParams(
1438 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff
1439 )->escaped() . "</div>" );
1443 * Return the HTML for the top of a redirect page
1445 * Chances are you should just be using the ParserOutput from
1446 * WikitextContent::getParserOutput instead of calling this for redirects.
1448 * @param $target Title|Array of destination(s) to redirect
1449 * @param $appendSubtitle Boolean [optional]
1450 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1451 * @return string containing HMTL with redirect link
1453 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1454 $lang = $this->getTitle()->getPageLanguage();
1455 if ( $appendSubtitle ) {
1456 $out = $this->getContext()->getOutput();
1457 $out->addSubtitle( wfMessage( 'redirectpagesub' )->parse() );
1459 return static::getRedirectHeaderHtml( $lang, $target, $forceKnown );
1463 * Return the HTML for the top of a redirect page
1465 * Chances are you should just be using the ParserOutput from
1466 * WikitextContent::getParserOutput instead of calling this for redirects.
1469 * @param Language $lang
1470 * @param Title|array $target destination(s) to redirect
1471 * @param bool $forceKnown Should the image be shown as a bluelink regardless of existence?
1472 * @return string containing HMTL with redirect link
1474 public static function getRedirectHeaderHtml( Language
$lang, $target, $forceKnown = false ) {
1475 global $wgStylePath;
1477 if ( !is_array( $target ) ) {
1478 $target = array( $target );
1481 $imageDir = $lang->getDir();
1483 // the loop prepends the arrow image before the link, so the first case needs to be outside
1485 /** @var $title Title */
1486 $title = array_shift( $target );
1488 if ( $forceKnown ) {
1489 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1491 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1494 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1495 $alt = $lang->isRTL() ?
'←' : '→';
1497 // Automatically append redirect=no to each link, since most of them are
1498 // redirect pages themselves.
1499 /** @var Title $rt */
1500 foreach ( $target as $rt ) {
1501 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1502 if ( $forceKnown ) {
1503 $link .= Linker
::linkKnown(
1505 htmlspecialchars( $rt->getFullText(),
1507 array( 'redirect' => 'no' )
1511 $link .= Linker
::link(
1513 htmlspecialchars( $rt->getFullText() ),
1515 array( 'redirect' => 'no' )
1520 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1521 return '<div class="redirectMsg">' .
1522 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1523 '<span class="redirectText">' . $link . '</span></div>';
1527 * Handle action=render
1529 public function render() {
1530 $this->getContext()->getOutput()->setArticleBodyOnly( true );
1531 $this->getContext()->getOutput()->enableSectionEditLinks( false );
1536 * action=protect handler
1538 public function protect() {
1539 $form = new ProtectionForm( $this );
1544 * action=unprotect handler (alias)
1546 public function unprotect() {
1551 * UI entry point for page deletion
1553 public function delete() {
1554 # This code desperately needs to be totally rewritten
1556 $title = $this->getTitle();
1557 $user = $this->getContext()->getUser();
1560 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1561 if ( count( $permission_errors ) ) {
1562 throw new PermissionsError( 'delete', $permission_errors );
1565 # Read-only check...
1566 if ( wfReadOnly() ) {
1567 throw new ReadOnlyError
;
1570 # Better double-check that it hasn't been deleted yet!
1571 $this->mPage
->loadPageData( 'fromdbmaster' );
1572 if ( !$this->mPage
->exists() ) {
1573 $deleteLogPage = new LogPage( 'delete' );
1574 $outputPage = $this->getContext()->getOutput();
1575 $outputPage->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1576 $outputPage->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1577 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1579 $outputPage->addHTML(
1580 Xml
::element( 'h2', null, $deleteLogPage->getName()->text() )
1582 LogEventsList
::showLogExtract(
1591 $request = $this->getContext()->getRequest();
1592 $deleteReasonList = $request->getText( 'wpDeleteReasonList', 'other' );
1593 $deleteReason = $request->getText( 'wpReason' );
1595 if ( $deleteReasonList == 'other' ) {
1596 $reason = $deleteReason;
1597 } elseif ( $deleteReason != '' ) {
1598 // Entry from drop down menu + additional comment
1599 $colonseparator = wfMessage( 'colon-separator' )->inContentLanguage()->text();
1600 $reason = $deleteReasonList . $colonseparator . $deleteReason;
1602 $reason = $deleteReasonList;
1605 if ( $request->wasPosted() && $user->matchEditToken( $request->getVal( 'wpEditToken' ),
1606 array( 'delete', $this->getTitle()->getPrefixedText() ) )
1608 # Flag to hide all contents of the archived revisions
1609 $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1611 $this->doDelete( $reason, $suppress );
1613 WatchAction
::doWatchOrUnwatch( $request->getCheck( 'wpWatch' ), $title, $user );
1618 // Generate deletion reason
1619 $hasHistory = false;
1622 $reason = $this->generateReason( $hasHistory );
1623 } catch ( MWException
$e ) {
1624 # if a page is horribly broken, we still want to be able to
1625 # delete it. So be lenient about errors here.
1626 wfDebug( "Error while building auto delete summary: $e" );
1631 // If the page has a history, insert a warning
1632 if ( $hasHistory ) {
1633 $revisions = $this->mTitle
->estimateRevisionCount();
1634 // @todo FIXME: i18n issue/patchwork message
1635 $this->getContext()->getOutput()->addHTML( '<strong class="mw-delete-warning-revisions">' .
1636 wfMessage( 'historywarning' )->numParams( $revisions )->parse() .
1637 wfMessage( 'word-separator' )->plain() . Linker
::linkKnown( $title,
1638 wfMessage( 'history' )->escaped(),
1639 array( 'rel' => 'archives' ),
1640 array( 'action' => 'history' ) ) .
1644 if ( $this->mTitle
->isBigDeletion() ) {
1645 global $wgDeleteRevisionsLimit;
1646 $this->getContext()->getOutput()->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1648 'delete-warning-toobig',
1649 $this->getContext()->getLanguage()->formatNum( $wgDeleteRevisionsLimit )
1655 $this->confirmDelete( $reason );
1659 * Output deletion confirmation dialog
1660 * @todo FIXME: Move to another file?
1661 * @param string $reason prefilled reason
1663 public function confirmDelete( $reason ) {
1664 wfDebug( "Article::confirmDelete\n" );
1666 $outputPage = $this->getContext()->getOutput();
1667 $outputPage->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1668 $outputPage->addBacklinkSubtitle( $this->getTitle() );
1669 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1670 $backlinkCache = $this->getTitle()->getBacklinkCache();
1671 if ( $backlinkCache->hasLinks( 'pagelinks' ) ||
$backlinkCache->hasLinks( 'templatelinks' ) ) {
1672 $outputPage->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1673 'deleting-backlinks-warning' );
1675 $outputPage->addWikiMsg( 'confirmdeletetext' );
1677 wfRunHooks( 'ArticleConfirmDelete', array( $this, $outputPage, &$reason ) );
1679 $user = $this->getContext()->getUser();
1681 if ( $user->isAllowed( 'suppressrevision' ) ) {
1682 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1684 <td class='mw-input'><strong>" .
1685 Xml
::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
1686 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1692 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$user->isWatched( $this->getTitle() );
1694 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1695 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1696 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1697 Xml
::tags( 'legend', null, wfMessage( 'delete-legend' )->escaped() ) .
1698 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1699 "<tr id=\"wpDeleteReasonListRow\">
1700 <td class='mw-label'>" .
1701 Xml
::label( wfMessage( 'deletecomment' )->text(), 'wpDeleteReasonList' ) .
1703 <td class='mw-input'>" .
1705 'wpDeleteReasonList',
1706 wfMessage( 'deletereason-dropdown' )->inContentLanguage()->text(),
1707 wfMessage( 'deletereasonotherlist' )->inContentLanguage()->text(),
1714 <tr id=\"wpDeleteReasonRow\">
1715 <td class='mw-label'>" .
1716 Xml
::label( wfMessage( 'deleteotherreason' )->text(), 'wpReason' ) .
1718 <td class='mw-input'>" .
1719 Html
::input( 'wpReason', $reason, 'text', array(
1721 'maxlength' => '255',
1729 # Disallow watching if user is not logged in
1730 if ( $user->isLoggedIn() ) {
1734 <td class='mw-input'>" .
1735 Xml
::checkLabel( wfMessage( 'watchthis' )->text(),
1736 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1745 <td class='mw-submit'>" .
1746 Xml
::submitButton( wfMessage( 'deletepage' )->text(),
1747 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1750 Xml
::closeElement( 'table' ) .
1751 Xml
::closeElement( 'fieldset' ) .
1754 $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) )
1756 Xml
::closeElement( 'form' );
1758 if ( $user->isAllowed( 'editinterface' ) ) {
1759 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1760 $link = Linker
::link(
1762 wfMessage( 'delete-edit-reasonlist' )->escaped(),
1764 array( 'action' => 'edit' )
1766 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1769 $outputPage->addHTML( $form );
1771 $deleteLogPage = new LogPage( 'delete' );
1772 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1773 LogEventsList
::showLogExtract( $outputPage, 'delete',
1779 * Perform a deletion and output success or failure messages
1780 * @param string $reason
1781 * @param bool $suppress
1783 public function doDelete( $reason, $suppress = false ) {
1785 $outputPage = $this->getContext()->getOutput();
1786 $status = $this->mPage
->doDeleteArticleReal( $reason, $suppress, 0, true, $error );
1788 if ( $status->isGood() ) {
1789 $deleted = $this->getTitle()->getPrefixedText();
1791 $outputPage->setPageTitle( wfMessage( 'actioncomplete' ) );
1792 $outputPage->setRobotPolicy( 'noindex,nofollow' );
1794 $loglink = '[[Special:Log/delete|' . wfMessage( 'deletionlog' )->text() . ']]';
1796 $outputPage->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1797 $outputPage->returnToMain( false );
1799 $outputPage->setPageTitle(
1800 wfMessage( 'cannotdelete-title',
1801 $this->getTitle()->getPrefixedText() )
1804 if ( $error == '' ) {
1805 $outputPage->addWikiText(
1806 "<div class=\"error mw-error-cannotdelete\">\n" . $status->getWikiText() . "\n</div>"
1808 $deleteLogPage = new LogPage( 'delete' );
1809 $outputPage->addHTML( Xml
::element( 'h2', null, $deleteLogPage->getName()->text() ) );
1811 LogEventsList
::showLogExtract(
1817 $outputPage->addHTML( $error );
1822 /* Caching functions */
1825 * checkLastModified returns true if it has taken care of all
1826 * output to the client that is necessary for this request.
1827 * (that is, it has sent a cached version of the page)
1829 * @return boolean true if cached version send, false otherwise
1831 protected function tryFileCache() {
1832 static $called = false;
1835 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1840 if ( $this->isFileCacheable() ) {
1841 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1842 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1843 wfDebug( "Article::tryFileCache(): about to load file\n" );
1844 $cache->loadFromFileCache( $this->getContext() );
1847 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1848 ob_start( array( &$cache, 'saveToFileCache' ) );
1851 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1858 * Check if the page can be cached
1861 public function isFileCacheable() {
1864 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1865 $cacheable = $this->mPage
->getID()
1866 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1867 // Extension may have reason to disable file caching on some pages.
1869 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1879 * Lightweight method to get the parser output for a page, checking the parser cache
1880 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1881 * consider, so it's not appropriate to use there.
1883 * @since 1.16 (r52326) for LiquidThreads
1885 * @param $oldid mixed integer Revision ID or null
1886 * @param $user User The relevant user
1887 * @return ParserOutput or false if the given revision ID is not found
1889 public function getParserOutput( $oldid = null, User
$user = null ) {
1890 //XXX: bypasses mParserOptions and thus setParserOptions()
1892 if ( $user === null ) {
1893 $parserOptions = $this->getParserOptions();
1895 $parserOptions = $this->mPage
->makeParserOptions( $user );
1898 return $this->mPage
->getParserOutput( $parserOptions, $oldid );
1902 * Override the ParserOptions used to render the primary article wikitext.
1904 * @param ParserOptions $options
1905 * @throws MWException if the parser options where already initialized.
1907 public function setParserOptions( ParserOptions
$options ) {
1908 if ( $this->mParserOptions
) {
1909 throw new MWException( "can't change parser options after they have already been set" );
1912 // clone, so if $options is modified later, it doesn't confuse the parser cache.
1913 $this->mParserOptions
= clone $options;
1917 * Get parser options suitable for rendering the primary article wikitext
1918 * @return ParserOptions
1920 public function getParserOptions() {
1921 if ( !$this->mParserOptions
) {
1922 $this->mParserOptions
= $this->mPage
->makeParserOptions( $this->getContext() );
1924 // Clone to allow modifications of the return value without affecting cache
1925 return clone $this->mParserOptions
;
1929 * Sets the context this Article is executed in
1931 * @param $context IContextSource
1934 public function setContext( $context ) {
1935 $this->mContext
= $context;
1939 * Gets the context this Article is executed in
1941 * @return IContextSource
1944 public function getContext() {
1945 if ( $this->mContext
instanceof IContextSource
) {
1946 return $this->mContext
;
1948 wfDebug( __METHOD__
. " called and \$mContext is null. " .
1949 "Return RequestContext::getMain(); for sanity\n" );
1950 return RequestContext
::getMain();
1955 * Info about this page
1956 * @deprecated since 1.19
1958 public function info() {
1959 wfDeprecated( __METHOD__
, '1.19' );
1960 Action
::factory( 'info', $this )->show();
1964 * Handle action=purge
1965 * @deprecated since 1.19
1966 * @return Action|bool|null false if the action is disabled, null if it is not recognised
1968 public function purge() {
1969 return Action
::factory( 'purge', $this )->show();
1973 * Handle action=revert
1974 * @deprecated since 1.19
1976 public function revert() {
1977 wfDeprecated( __METHOD__
, '1.19' );
1978 Action
::factory( 'revert', $this )->show();
1982 * Handle action=rollback
1983 * @deprecated since 1.19
1985 public function rollback() {
1986 wfDeprecated( __METHOD__
, '1.19' );
1987 Action
::factory( 'rollback', $this )->show();
1991 * Use PHP's magic __get handler to handle accessing of
1992 * raw WikiPage fields for backwards compatibility.
1994 * @param string $fname Field name
1996 public function __get( $fname ) {
1997 if ( property_exists( $this->mPage
, $fname ) ) {
1998 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1999 return $this->mPage
->$fname;
2001 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
2005 * Use PHP's magic __set handler to handle setting of
2006 * raw WikiPage fields for backwards compatibility.
2008 * @param string $fname Field name
2009 * @param $fvalue mixed New value
2011 public function __set( $fname, $fvalue ) {
2012 if ( property_exists( $this->mPage
, $fname ) ) {
2013 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
2014 $this->mPage
->$fname = $fvalue;
2015 // Note: extensions may want to toss on new fields
2016 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
2017 $this->mPage
->$fname = $fvalue;
2019 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
2024 * Use PHP's magic __call handler to transform instance calls to
2025 * WikiPage functions for backwards compatibility.
2027 * @param string $fname Name of called method
2028 * @param array $args Arguments to the method
2031 public function __call( $fname, $args ) {
2032 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
2033 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
2034 return call_user_func_array( array( $this->mPage
, $fname ), $args );
2036 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
2039 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
2042 * @param $limit array
2043 * @param $expiry array
2044 * @param $cascade bool
2045 * @param $reason string
2049 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade,
2052 return $this->mPage
->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
2056 * @param $limit array
2057 * @param $reason string
2058 * @param $cascade int
2059 * @param $expiry array
2062 public function updateRestrictions( $limit = array(), $reason = '',
2063 &$cascade = 0, $expiry = array()
2065 return $this->mPage
->doUpdateRestrictions(
2070 $this->getContext()->getUser()
2075 * @param $reason string
2076 * @param $suppress bool
2078 * @param $commit bool
2079 * @param $error string
2082 public function doDeleteArticle( $reason, $suppress = false, $id = 0,
2083 $commit = true, &$error = ''
2085 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
2093 * @param $resultDetails
2097 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
2098 $user = is_null( $user ) ?
$this->getContext()->getUser() : $user;
2099 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
2106 * @param $resultDetails
2107 * @param $guser User
2110 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
2111 $guser = is_null( $guser ) ?
$this->getContext()->getUser() : $guser;
2112 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2116 * @param $hasHistory bool
2119 public function generateReason( &$hasHistory ) {
2120 $title = $this->mPage
->getTitle();
2121 $handler = ContentHandler
::getForTitle( $title );
2122 return $handler->getAutoDeleteReason( $title, $hasHistory );
2125 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2130 public static function selectFields() {
2131 return WikiPage
::selectFields();
2135 * @param $title Title
2137 public static function onArticleCreate( $title ) {
2138 WikiPage
::onArticleCreate( $title );
2142 * @param $title Title
2144 public static function onArticleDelete( $title ) {
2145 WikiPage
::onArticleDelete( $title );
2149 * @param $title Title
2151 public static function onArticleEdit( $title ) {
2152 WikiPage
::onArticleEdit( $title );
2160 * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
2162 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2163 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );