revert r113117 per CR
[mediawiki.git] / includes / Article.php
blob6356f1a654897d1252ade29b4d7ed80472437da8
1 <?php
2 /**
3 * File for articles
4 * @file
5 */
7 /**
8 * Class for viewing MediaWiki article and history.
10 * This maintains WikiPage functions for backwards compatibility.
12 * @TODO: move and rewrite code to an Action class
14 * See design.txt for an overview.
15 * Note: edit user interface and cache support functions have been
16 * moved to separate EditPage and HTMLFileCache classes.
18 * @internal documentation reviewed 15 Mar 2010
20 class Article extends Page {
21 /**@{{
22 * @private
25 /**
26 * @var IContextSource
28 protected $mContext;
30 /**
31 * @var WikiPage
33 protected $mPage;
35 /**
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
40 var $mContent; // !<
41 var $mContentLoaded = false; // !<
42 var $mOldId; // !<
44 /**
45 * @var Title
47 var $mRedirectedFrom = null;
49 /**
50 * @var mixed: boolean false or URL string
52 var $mRedirectUrl = false; // !<
53 var $mRevIdFetched = 0; // !<
55 /**
56 * @var Revision
58 var $mRevision = null;
60 /**
61 * @var ParserOutput
63 var $mParserOutput;
65 /**@}}*/
67 /**
68 * Constructor and clear the article
69 * @param $title Title Reference to a Title object.
70 * @param $oldId Integer revision ID, null to fetch from request, zero for current
72 public function __construct( Title $title, $oldId = null ) {
73 $this->mOldId = $oldId;
74 $this->mPage = $this->newPage( $title );
77 /**
78 * @param $title Title
79 * @return WikiPage
81 protected function newPage( Title $title ) {
82 return new WikiPage( $title );
85 /**
86 * Constructor from a page id
87 * @param $id Int article ID to load
88 * @return Article|null
90 public static function newFromID( $id ) {
91 $t = Title::newFromID( $id );
92 # @todo FIXME: Doesn't inherit right
93 return $t == null ? null : new self( $t );
94 # return $t == null ? null : new static( $t ); // PHP 5.3
97 /**
98 * Create an Article object of the appropriate class for the given page.
100 * @param $title Title
101 * @param $context IContextSource
102 * @return Article object
104 public static function newFromTitle( $title, IContextSource $context ) {
105 if ( NS_MEDIA == $title->getNamespace() ) {
106 // FIXME: where should this go?
107 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
110 $page = null;
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
112 if ( !$page ) {
113 switch( $title->getNamespace() ) {
114 case NS_FILE:
115 $page = new ImagePage( $title );
116 break;
117 case NS_CATEGORY:
118 $page = new CategoryPage( $title );
119 break;
120 default:
121 $page = new Article( $title );
124 $page->setContext( $context );
126 return $page;
130 * Create an Article object of the appropriate class for the given page.
132 * @param $page WikiPage
133 * @param $context IContextSource
134 * @return Article object
136 public static function newFromWikiPage( WikiPage $page, IContextSource $context ) {
137 $article = self::newFromTitle( $page->getTitle(), $context );
138 $article->mPage = $page; // override to keep process cached vars
139 return $article;
143 * Tell the page view functions that this view was redirected
144 * from another page on the wiki.
145 * @param $from Title object.
147 public function setRedirectedFrom( Title $from ) {
148 $this->mRedirectedFrom = $from;
152 * Get the title object of the article
154 * @return Title object of this page
156 public function getTitle() {
157 return $this->mPage->getTitle();
161 * Get the WikiPage object of this instance
163 * @since 1.19
164 * @return WikiPage
166 public function getPage() {
167 return $this->mPage;
171 * Clear the object
173 public function clear() {
174 $this->mContentLoaded = false;
176 $this->mRedirectedFrom = null; # Title object if set
177 $this->mRevIdFetched = 0;
178 $this->mRedirectUrl = false;
180 $this->mPage->clear();
184 * Note that getContent/loadContent do not follow redirects anymore.
185 * If you need to fetch redirectable content easily, try
186 * the shortcut in WikiPage::getRedirectTarget()
188 * This function has side effects! Do not use this function if you
189 * only want the real revision text if any.
191 * @return string Return the text of this revision
193 public function getContent() {
194 global $wgUser;
196 wfProfileIn( __METHOD__ );
198 if ( $this->mPage->getID() === 0 ) {
199 # If this is a MediaWiki:x message, then load the messages
200 # and return the message value for x.
201 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
202 $text = $this->getTitle()->getDefaultMessageText();
203 if ( $text === false ) {
204 $text = '';
206 } else {
207 $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' );
209 wfProfileOut( __METHOD__ );
211 return $text;
212 } else {
213 $this->fetchContent();
214 wfProfileOut( __METHOD__ );
216 return $this->mContent;
221 * @return int The oldid of the article that is to be shown, 0 for the
222 * current revision
224 public function getOldID() {
225 if ( is_null( $this->mOldId ) ) {
226 $this->mOldId = $this->getOldIDFromRequest();
229 return $this->mOldId;
233 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
235 * @return int The old id for the request
237 public function getOldIDFromRequest() {
238 global $wgRequest;
240 $this->mRedirectUrl = false;
242 $oldid = $wgRequest->getIntOrNull( 'oldid' );
244 if ( $oldid === null ) {
245 return 0;
248 if ( $oldid !== 0 ) {
249 # Load the given revision and check whether the page is another one.
250 # In that case, update this instance to reflect the change.
251 $this->mRevision = Revision::newFromId( $oldid );
252 if ( $this->mRevision !== null ) {
253 // Revision title doesn't match the page title given?
254 if ( $this->mPage->getID() != $this->mRevision->getPage() ) {
255 $function = array( get_class( $this->mPage ), 'newFromID' );
256 $this->mPage = call_user_func( $function, $this->mRevision->getPage() );
261 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
262 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
263 if ( $nextid ) {
264 $oldid = $nextid;
265 $this->mRevision = null;
266 } else {
267 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
269 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
270 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
271 if ( $previd ) {
272 $oldid = $previd;
273 $this->mRevision = null;
277 return $oldid;
281 * Load the revision (including text) into this object
283 * @deprecated in 1.19; use fetchContent()
285 function loadContent() {
286 wfDeprecated( __METHOD__, '1.19' );
287 $this->fetchContent();
291 * Get text of an article from database
292 * Does *NOT* follow redirects.
294 * @return mixed string containing article contents, or false if null
296 function fetchContent() {
297 if ( $this->mContentLoaded ) {
298 return $this->mContent;
301 wfProfileIn( __METHOD__ );
303 $this->mContentLoaded = true;
305 $oldid = $this->getOldID();
307 # Pre-fill content with error message so that if something
308 # fails we'll have something telling us what we intended.
309 $t = $this->getTitle()->getPrefixedText();
310 $d = $oldid ? wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
311 $this->mContent = wfMsgNoTrans( 'missing-article', $t, $d ) ;
313 if ( $oldid ) {
314 # $this->mRevision might already be fetched by getOldIDFromRequest()
315 if ( !$this->mRevision ) {
316 $this->mRevision = Revision::newFromId( $oldid );
317 if ( !$this->mRevision ) {
318 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
319 wfProfileOut( __METHOD__ );
320 return false;
323 } else {
324 if ( !$this->mPage->getLatest() ) {
325 wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
326 wfProfileOut( __METHOD__ );
327 return false;
330 $this->mRevision = $this->mPage->getRevision();
331 if ( !$this->mRevision ) {
332 wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n" );
333 wfProfileOut( __METHOD__ );
334 return false;
338 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
339 // We should instead work with the Revision object when we need it...
340 $this->mContent = $this->mRevision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
341 $this->mRevIdFetched = $this->mRevision->getId();
343 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
345 wfProfileOut( __METHOD__ );
347 return $this->mContent;
351 * No-op
352 * @deprecated since 1.18
354 public function forUpdate() {
355 wfDeprecated( __METHOD__, '1.18' );
359 * Returns true if the currently-referenced revision is the current edit
360 * to this page (and it exists).
361 * @return bool
363 public function isCurrent() {
364 # If no oldid, this is the current version.
365 if ( $this->getOldID() == 0 ) {
366 return true;
369 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
373 * Get the fetched Revision object depending on request parameters or null
374 * on failure.
376 * @since 1.19
377 * @return Revision|null
379 public function getRevisionFetched() {
380 $this->fetchContent();
382 return $this->mRevision;
386 * Use this to fetch the rev ID used on page views
388 * @return int revision ID of last article revision
390 public function getRevIdFetched() {
391 if ( $this->mRevIdFetched ) {
392 return $this->mRevIdFetched;
393 } else {
394 return $this->mPage->getLatest();
399 * This is the default action of the index.php entry point: just view the
400 * page of the given title.
402 public function view() {
403 global $wgUser, $wgOut, $wgRequest, $wgParser;
404 global $wgUseFileCache, $wgUseETag, $wgDebugToolbar;
406 wfProfileIn( __METHOD__ );
408 # Get variables from query string
409 # As side effect this will load the revision and update the title
410 # in a revision ID is passed in the request, so this should remain
411 # the first call of this method even if $oldid is used way below.
412 $oldid = $this->getOldID();
414 # Another whitelist check in case getOldID() is altering the title
415 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
416 if ( count( $permErrors ) ) {
417 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
418 wfProfileOut( __METHOD__ );
419 throw new PermissionsError( 'read', $permErrors );
422 # getOldID() may as well want us to redirect somewhere else
423 if ( $this->mRedirectUrl ) {
424 $wgOut->redirect( $this->mRedirectUrl );
425 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
426 wfProfileOut( __METHOD__ );
428 return;
431 # If we got diff in the query, we want to see a diff page instead of the article.
432 if ( $wgRequest->getCheck( 'diff' ) ) {
433 wfDebug( __METHOD__ . ": showing diff page\n" );
434 $this->showDiffPage();
435 wfProfileOut( __METHOD__ );
437 return;
440 # Set page title (may be overridden by DISPLAYTITLE)
441 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
443 $wgOut->setArticleFlag( true );
444 # Allow frames by default
445 $wgOut->allowClickjacking();
447 $parserCache = ParserCache::singleton();
449 $parserOptions = $this->getParserOptions();
450 # Render printable version, use printable version cache
451 if ( $wgOut->isPrintable() ) {
452 $parserOptions->setIsPrintable( true );
453 $parserOptions->setEditSection( false );
454 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
455 $parserOptions->setEditSection( false );
458 # Try client and file cache
459 if ( !$wgDebugToolbar && $oldid === 0 && $this->mPage->checkTouched() ) {
460 if ( $wgUseETag ) {
461 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
464 # Is it client cached?
465 if ( $wgOut->checkLastModified( $this->mPage->getTouched() ) ) {
466 wfDebug( __METHOD__ . ": done 304\n" );
467 wfProfileOut( __METHOD__ );
469 return;
470 # Try file cache
471 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
472 wfDebug( __METHOD__ . ": done file cache\n" );
473 # tell wgOut that output is taken care of
474 $wgOut->disable();
475 $this->mPage->doViewUpdates( $wgUser );
476 wfProfileOut( __METHOD__ );
478 return;
482 # Should the parser cache be used?
483 $useParserCache = $this->mPage->isParserCacheUsed( $parserOptions, $oldid );
484 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
485 if ( $wgUser->getStubThreshold() ) {
486 wfIncrStats( 'pcache_miss_stub' );
489 $this->showRedirectedFromHeader();
490 $this->showNamespaceHeader();
492 # Iterate through the possible ways of constructing the output text.
493 # Keep going until $outputDone is set, or we run out of things to do.
494 $pass = 0;
495 $outputDone = false;
496 $this->mParserOutput = false;
498 while ( !$outputDone && ++$pass ) {
499 switch( $pass ) {
500 case 1:
501 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
502 break;
503 case 2:
504 # Early abort if the page doesn't exist
505 if ( !$this->mPage->exists() ) {
506 wfDebug( __METHOD__ . ": showing missing article\n" );
507 $this->showMissingArticle();
508 wfProfileOut( __METHOD__ );
509 return;
512 # Try the parser cache
513 if ( $useParserCache ) {
514 $this->mParserOutput = $parserCache->get( $this, $parserOptions );
516 if ( $this->mParserOutput !== false ) {
517 if ( $oldid ) {
518 wfDebug( __METHOD__ . ": showing parser cache contents for current rev permalink\n" );
519 $this->setOldSubtitle( $oldid );
520 } else {
521 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
523 $wgOut->addParserOutput( $this->mParserOutput );
524 # Ensure that UI elements requiring revision ID have
525 # the correct version information.
526 $wgOut->setRevisionId( $this->mPage->getLatest() );
527 # Preload timestamp to avoid a DB hit
528 $cachedTimestamp = $this->mParserOutput->getTimestamp();
529 if ( $cachedTimestamp !== null ) {
530 $wgOut->setRevisionTimestamp( $cachedTimestamp );
531 $this->mPage->setTimestamp( $cachedTimestamp );
533 $outputDone = true;
536 break;
537 case 3:
538 # This will set $this->mRevision if needed
539 $this->fetchContent();
541 # Are we looking at an old revision
542 if ( $oldid && $this->mRevision ) {
543 $this->setOldSubtitle( $oldid );
545 if ( !$this->showDeletedRevisionHeader() ) {
546 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
547 wfProfileOut( __METHOD__ );
548 return;
552 # Ensure that UI elements requiring revision ID have
553 # the correct version information.
554 $wgOut->setRevisionId( $this->getRevIdFetched() );
555 # Preload timestamp to avoid a DB hit
556 $wgOut->setRevisionTimestamp( $this->getTimestamp() );
558 # Pages containing custom CSS or JavaScript get special treatment
559 if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
560 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
561 $this->showCssOrJsPage();
562 $outputDone = true;
563 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
564 # Allow extensions do their own custom view for certain pages
565 $outputDone = true;
566 } else {
567 $text = $this->getContent();
568 $rt = Title::newFromRedirectArray( $text );
569 if ( $rt ) {
570 wfDebug( __METHOD__ . ": showing redirect=no page\n" );
571 # Viewing a redirect page (e.g. with parameter redirect=no)
572 $wgOut->addHTML( $this->viewRedirect( $rt ) );
573 # Parse just to get categories, displaytitle, etc.
574 $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(), $parserOptions );
575 $wgOut->addParserOutputNoText( $this->mParserOutput );
576 $outputDone = true;
579 break;
580 case 4:
581 # Run the parse, protected by a pool counter
582 wfDebug( __METHOD__ . ": doing uncached parse\n" );
584 $poolArticleView = new PoolWorkArticleView( $this, $parserOptions,
585 $this->getRevIdFetched(), $useParserCache, $this->getContent() );
587 if ( !$poolArticleView->execute() ) {
588 $error = $poolArticleView->getError();
589 if ( $error ) {
590 $wgOut->clearHTML(); // for release() errors
591 $wgOut->enableClientCache( false );
592 $wgOut->setRobotPolicy( 'noindex,nofollow' );
594 $errortext = $error->getWikiText( false, 'view-pool-error' );
595 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
597 # Connection or timeout error
598 wfProfileOut( __METHOD__ );
599 return;
602 $this->mParserOutput = $poolArticleView->getParserOutput();
603 $wgOut->addParserOutput( $this->mParserOutput );
605 # Don't cache a dirty ParserOutput object
606 if ( $poolArticleView->getIsDirty() ) {
607 $wgOut->setSquidMaxage( 0 );
608 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
611 $outputDone = true;
612 break;
613 # Should be unreachable, but just in case...
614 default:
615 break 2;
619 # Get the ParserOutput actually *displayed* here.
620 # Note that $this->mParserOutput is the *current* version output.
621 $pOutput = ( $outputDone instanceof ParserOutput )
622 ? $outputDone // object fetched by hook
623 : $this->mParserOutput;
625 # Adjust title for main page & pages with displaytitle
626 if ( $pOutput ) {
627 $this->adjustDisplayTitle( $pOutput );
630 # For the main page, overwrite the <title> element with the con-
631 # tents of 'pagetitle-view-mainpage' instead of the default (if
632 # that's not empty).
633 # This message always exists because it is in the i18n files
634 if ( $this->getTitle()->isMainPage() ) {
635 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
636 if ( !$msg->isDisabled() ) {
637 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
641 # Check for any __NOINDEX__ tags on the page using $pOutput
642 $policy = $this->getRobotPolicy( 'view', $pOutput );
643 $wgOut->setIndexPolicy( $policy['index'] );
644 $wgOut->setFollowPolicy( $policy['follow'] );
646 $this->showViewFooter();
647 $this->mPage->doViewUpdates( $wgUser );
649 wfProfileOut( __METHOD__ );
653 * Adjust title for pages with displaytitle, -{T|}- or language conversion
654 * @param $pOutput ParserOutput
656 public function adjustDisplayTitle( ParserOutput $pOutput ) {
657 global $wgOut;
658 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
659 $titleText = $pOutput->getTitleText();
660 if ( strval( $titleText ) !== '' ) {
661 $wgOut->setPageTitle( $titleText );
666 * Show a diff page according to current request variables. For use within
667 * Article::view() only, other callers should use the DifferenceEngine class.
669 public function showDiffPage() {
670 global $wgRequest, $wgUser;
672 $diff = $wgRequest->getVal( 'diff' );
673 $rcid = $wgRequest->getVal( 'rcid' );
674 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
675 $purge = $wgRequest->getVal( 'action' ) == 'purge';
676 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
677 $oldid = $this->getOldID();
679 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
680 // DifferenceEngine directly fetched the revision:
681 $this->mRevIdFetched = $de->mNewid;
682 $de->showDiffPage( $diffOnly );
684 if ( $diff == 0 || $diff == $this->mPage->getLatest() ) {
685 # Run view updates for current revision only
686 $this->mPage->doViewUpdates( $wgUser );
691 * Show a page view for a page formatted as CSS or JavaScript. To be called by
692 * Article::view() only.
694 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
695 * page views.
697 protected function showCssOrJsPage() {
698 global $wgOut;
700 $dir = $this->getContext()->getLanguage()->getDir();
701 $lang = $this->getContext()->getLanguage()->getCode();
703 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
704 'clearyourcache' );
706 // Give hooks a chance to customise the output
707 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
708 // Wrap the whole lot in a <pre> and don't parse
709 $m = array();
710 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
711 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
712 $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
713 $wgOut->addHTML( "\n</pre>\n" );
718 * Get the robot policy to be used for the current view
719 * @param $action String the action= GET parameter
720 * @param $pOutput ParserOutput
721 * @return Array the policy that should be set
722 * TODO: actions other than 'view'
724 public function getRobotPolicy( $action, $pOutput ) {
725 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
726 global $wgDefaultRobotPolicy, $wgRequest;
728 $ns = $this->getTitle()->getNamespace();
730 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
731 # Don't index user and user talk pages for blocked users (bug 11443)
732 if ( !$this->getTitle()->isSubpage() ) {
733 if ( Block::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block ) {
734 return array(
735 'index' => 'noindex',
736 'follow' => 'nofollow'
742 if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
743 # Non-articles (special pages etc), and old revisions
744 return array(
745 'index' => 'noindex',
746 'follow' => 'nofollow'
748 } elseif ( $wgOut->isPrintable() ) {
749 # Discourage indexing of printable versions, but encourage following
750 return array(
751 'index' => 'noindex',
752 'follow' => 'follow'
754 } elseif ( $wgRequest->getInt( 'curid' ) ) {
755 # For ?curid=x urls, disallow indexing
756 return array(
757 'index' => 'noindex',
758 'follow' => 'follow'
762 # Otherwise, construct the policy based on the various config variables.
763 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
765 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
766 # Honour customised robot policies for this namespace
767 $policy = array_merge(
768 $policy,
769 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
772 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
773 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
774 # a final sanity check that we have really got the parser output.
775 $policy = array_merge(
776 $policy,
777 array( 'index' => $pOutput->getIndexPolicy() )
781 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
782 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
783 $policy = array_merge(
784 $policy,
785 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
789 return $policy;
793 * Converts a String robot policy into an associative array, to allow
794 * merging of several policies using array_merge().
795 * @param $policy Mixed, returns empty array on null/false/'', transparent
796 * to already-converted arrays, converts String.
797 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
799 public static function formatRobotPolicy( $policy ) {
800 if ( is_array( $policy ) ) {
801 return $policy;
802 } elseif ( !$policy ) {
803 return array();
806 $policy = explode( ',', $policy );
807 $policy = array_map( 'trim', $policy );
809 $arr = array();
810 foreach ( $policy as $var ) {
811 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
812 $arr['index'] = $var;
813 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
814 $arr['follow'] = $var;
818 return $arr;
822 * If this request is a redirect view, send "redirected from" subtitle to
823 * $wgOut. Returns true if the header was needed, false if this is not a
824 * redirect view. Handles both local and remote redirects.
826 * @return boolean
828 public function showRedirectedFromHeader() {
829 global $wgOut, $wgRequest, $wgRedirectSources;
831 $rdfrom = $wgRequest->getVal( 'rdfrom' );
833 if ( isset( $this->mRedirectedFrom ) ) {
834 // This is an internally redirected page view.
835 // We'll need a backlink to the source page for navigation.
836 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
837 $redir = Linker::linkKnown(
838 $this->mRedirectedFrom,
839 null,
840 array(),
841 array( 'redirect' => 'no' )
844 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
846 // Set the fragment if one was specified in the redirect
847 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
848 $fragment = Xml::escapeJsString( $this->getTitle()->getFragmentForURL() );
849 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
852 // Add a <link rel="canonical"> tag
853 $wgOut->addLink( array( 'rel' => 'canonical',
854 'href' => $this->getTitle()->getLocalURL() )
857 // Tell $wgOut the user arrived at this article through a redirect
858 $wgOut->setRedirectedFrom( $this->mRedirectedFrom );
860 return true;
862 } elseif ( $rdfrom ) {
863 // This is an externally redirected view, from some other wiki.
864 // If it was reported from a trusted site, supply a backlink.
865 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
866 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
867 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
869 return true;
873 return false;
877 * Show a header specific to the namespace currently being viewed, like
878 * [[MediaWiki:Talkpagetext]]. For Article::view().
880 public function showNamespaceHeader() {
881 global $wgOut;
883 if ( $this->getTitle()->isTalkPage() ) {
884 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
885 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
891 * Show the footer section of an ordinary page view
893 public function showViewFooter() {
894 global $wgOut;
896 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
897 if ( $this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid( $this->getTitle()->getText() ) ) {
898 $wgOut->addWikiMsg( 'anontalkpagetext' );
901 # If we have been passed an &rcid= parameter, we want to give the user a
902 # chance to mark this new article as patrolled.
903 $this->showPatrolFooter();
905 wfRunHooks( 'ArticleViewFooter', array( $this ) );
910 * If patrol is possible, output a patrol UI box. This is called from the
911 * footer section of ordinary page views. If patrol is not possible or not
912 * desired, does nothing.
914 public function showPatrolFooter() {
915 global $wgOut, $wgRequest, $wgUser;
917 $rcid = $wgRequest->getVal( 'rcid' );
919 if ( !$rcid || !$this->getTitle()->quickUserCan( 'patrol' ) ) {
920 return;
923 $token = $wgUser->getEditToken( $rcid );
924 $wgOut->preventClickjacking();
926 $wgOut->addHTML(
927 "<div class='patrollink'>" .
928 wfMsgHtml(
929 'markaspatrolledlink',
930 Linker::link(
931 $this->getTitle(),
932 wfMsgHtml( 'markaspatrolledtext' ),
933 array(),
934 array(
935 'action' => 'markpatrolled',
936 'rcid' => $rcid,
937 'token' => $token,
939 array( 'known', 'noclasses' )
942 '</div>'
947 * Show the error text for a missing article. For articles in the MediaWiki
948 * namespace, show the default message text. To be called from Article::view().
950 public function showMissingArticle() {
951 global $wgOut, $wgRequest, $wgUser, $wgSend404Code;
953 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
954 if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) {
955 $parts = explode( '/', $this->getTitle()->getText() );
956 $rootPart = $parts[0];
957 $user = User::newFromName( $rootPart, false /* allow IP users*/ );
958 $ip = User::isIP( $rootPart );
960 if ( !($user && $user->isLoggedIn()) && !$ip ) { # User does not exist
961 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
962 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
963 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
964 LogEventsList::showLogExtract(
965 $wgOut,
966 'block',
967 $user->getUserPage()->getPrefixedText(),
969 array(
970 'lim' => 1,
971 'showIfEmpty' => false,
972 'msgKey' => array(
973 'blocked-notice-logextract',
974 $user->getName() # Support GENDER in notice
981 wfRunHooks( 'ShowMissingArticle', array( $this ) );
983 # Show delete and move logs
984 LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
985 array( 'lim' => 10,
986 'conds' => array( "log_action != 'revision'" ),
987 'showIfEmpty' => false,
988 'msgKey' => array( 'moveddeleted-notice' ) )
991 if ( !$this->mPage->hasViewableContent() && $wgSend404Code ) {
992 // If there's no backing content, send a 404 Not Found
993 // for better machine handling of broken links.
994 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
997 $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
999 if ( ! $hookResult ) {
1000 return;
1003 # Show error message
1004 $oldid = $this->getOldID();
1005 if ( $oldid ) {
1006 $text = wfMsgNoTrans( 'missing-article',
1007 $this->getTitle()->getPrefixedText(),
1008 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
1009 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI ) {
1010 // Use the default message text
1011 $text = $this->getTitle()->getDefaultMessageText();
1012 } else {
1013 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
1014 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
1015 $errors = array_merge( $createErrors, $editErrors );
1017 if ( !count( $errors ) ) {
1018 $text = wfMsgNoTrans( 'noarticletext' );
1019 } else {
1020 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
1023 $text = "<div class='noarticletext'>\n$text\n</div>";
1025 $wgOut->addWikiText( $text );
1029 * If the revision requested for view is deleted, check permissions.
1030 * Send either an error message or a warning header to $wgOut.
1032 * @return boolean true if the view is allowed, false if not.
1034 public function showDeletedRevisionHeader() {
1035 global $wgOut, $wgRequest;
1037 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1038 // Not deleted
1039 return true;
1042 // If the user is not allowed to see it...
1043 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
1044 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1045 'rev-deleted-text-permission' );
1047 return false;
1048 // If the user needs to confirm that they want to see it...
1049 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
1050 # Give explanation and add a link to view the revision...
1051 $oldid = intval( $this->getOldID() );
1052 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
1053 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1054 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
1055 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
1056 array( $msg, $link ) );
1058 return false;
1059 // We are allowed to see...
1060 } else {
1061 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
1062 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1063 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1065 return true;
1070 * Generate the navigation links when browsing through an article revisions
1071 * It shows the information as:
1072 * Revision as of \<date\>; view current revision
1073 * \<- Previous version | Next Version -\>
1075 * @param $oldid String: revision ID of this article revision
1077 public function setOldSubtitle( $oldid = 0 ) {
1078 global $wgLang, $wgOut, $wgUser, $wgRequest;
1080 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1081 return;
1084 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1086 # Cascade unhide param in links for easy deletion browsing
1087 $extraParams = array();
1088 if ( $wgRequest->getVal( 'unhide' ) ) {
1089 $extraParams['unhide'] = 1;
1092 $revision = Revision::newFromId( $oldid );
1093 $timestamp = $revision->getTimestamp();
1095 $current = ( $oldid == $this->mPage->getLatest() );
1096 $td = $wgLang->timeanddate( $timestamp, true );
1097 $tddate = $wgLang->date( $timestamp, true );
1098 $tdtime = $wgLang->time( $timestamp, true );
1100 # Show user links if allowed to see them. If hidden, then show them only if requested...
1101 $userlinks = Linker::revUserTools( $revision, !$unhide );
1103 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1104 ? 'revision-info-current'
1105 : 'revision-info';
1107 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1108 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1109 $tdtime, $revision->getUser() )->parse() . "</div>" );
1111 $lnk = $current
1112 ? wfMsgHtml( 'currentrevisionlink' )
1113 : Linker::link(
1114 $this->getTitle(),
1115 wfMsgHtml( 'currentrevisionlink' ),
1116 array(),
1117 $extraParams,
1118 array( 'known', 'noclasses' )
1120 $curdiff = $current
1121 ? wfMsgHtml( 'diff' )
1122 : Linker::link(
1123 $this->getTitle(),
1124 wfMsgHtml( 'diff' ),
1125 array(),
1126 array(
1127 'diff' => 'cur',
1128 'oldid' => $oldid
1129 ) + $extraParams,
1130 array( 'known', 'noclasses' )
1132 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1133 $prevlink = $prev
1134 ? Linker::link(
1135 $this->getTitle(),
1136 wfMsgHtml( 'previousrevision' ),
1137 array(),
1138 array(
1139 'direction' => 'prev',
1140 'oldid' => $oldid
1141 ) + $extraParams,
1142 array( 'known', 'noclasses' )
1144 : wfMsgHtml( 'previousrevision' );
1145 $prevdiff = $prev
1146 ? Linker::link(
1147 $this->getTitle(),
1148 wfMsgHtml( 'diff' ),
1149 array(),
1150 array(
1151 'diff' => 'prev',
1152 'oldid' => $oldid
1153 ) + $extraParams,
1154 array( 'known', 'noclasses' )
1156 : wfMsgHtml( 'diff' );
1157 $nextlink = $current
1158 ? wfMsgHtml( 'nextrevision' )
1159 : Linker::link(
1160 $this->getTitle(),
1161 wfMsgHtml( 'nextrevision' ),
1162 array(),
1163 array(
1164 'direction' => 'next',
1165 'oldid' => $oldid
1166 ) + $extraParams,
1167 array( 'known', 'noclasses' )
1169 $nextdiff = $current
1170 ? wfMsgHtml( 'diff' )
1171 : Linker::link(
1172 $this->getTitle(),
1173 wfMsgHtml( 'diff' ),
1174 array(),
1175 array(
1176 'diff' => 'next',
1177 'oldid' => $oldid
1178 ) + $extraParams,
1179 array( 'known', 'noclasses' )
1182 $cdel = Linker::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
1183 if ( $cdel !== '' ) {
1184 $cdel .= ' ';
1187 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1188 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1189 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1193 * View redirect
1195 * @param $target Title|Array of destination(s) to redirect
1196 * @param $appendSubtitle Boolean [optional]
1197 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1198 * @return string containing HMTL with redirect link
1200 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1201 global $wgOut, $wgStylePath;
1203 if ( !is_array( $target ) ) {
1204 $target = array( $target );
1207 $lang = $this->getTitle()->getPageLanguage();
1208 $imageDir = $lang->getDir();
1210 if ( $appendSubtitle ) {
1211 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1214 // the loop prepends the arrow image before the link, so the first case needs to be outside
1217 * @var $title Title
1219 $title = array_shift( $target );
1221 if ( $forceKnown ) {
1222 $link = Linker::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1223 } else {
1224 $link = Linker::link( $title, htmlspecialchars( $title->getFullText() ) );
1227 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1228 $alt = $lang->isRTL() ? '←' : '→';
1229 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1230 foreach ( $target as $rt ) {
1231 $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1232 if ( $forceKnown ) {
1233 $link .= Linker::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1234 } else {
1235 $link .= Linker::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1239 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1240 return '<div class="redirectMsg">' .
1241 Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1242 '<span class="redirectText">' . $link . '</span></div>';
1246 * Handle action=render
1248 public function render() {
1249 global $wgOut;
1251 $wgOut->setArticleBodyOnly( true );
1252 $this->view();
1256 * action=protect handler
1258 public function protect() {
1259 $form = new ProtectionForm( $this );
1260 $form->execute();
1264 * action=unprotect handler (alias)
1266 public function unprotect() {
1267 $this->protect();
1271 * UI entry point for page deletion
1273 public function delete() {
1274 global $wgOut, $wgRequest, $wgLang;
1276 # This code desperately needs to be totally rewritten
1278 $title = $this->getTitle();
1279 $user = $this->getContext()->getUser();
1281 # Check permissions
1282 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1283 if ( count( $permission_errors ) ) {
1284 throw new PermissionsError( 'delete', $permission_errors );
1287 # Read-only check...
1288 if ( wfReadOnly() ) {
1289 throw new ReadOnlyError;
1292 # Better double-check that it hasn't been deleted yet!
1293 $dbw = wfGetDB( DB_MASTER );
1294 $conds = $title->pageCond();
1295 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
1296 if ( $latest === false ) {
1297 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1298 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1299 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1301 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
1302 LogEventsList::showLogExtract(
1303 $wgOut,
1304 'delete',
1305 $title->getPrefixedText()
1308 return;
1311 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1312 $deleteReason = $wgRequest->getText( 'wpReason' );
1314 if ( $deleteReasonList == 'other' ) {
1315 $reason = $deleteReason;
1316 } elseif ( $deleteReason != '' ) {
1317 // Entry from drop down menu + additional comment
1318 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1319 } else {
1320 $reason = $deleteReasonList;
1323 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1324 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1326 # Flag to hide all contents of the archived revisions
1327 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1329 $this->doDelete( $reason, $suppress );
1331 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1332 $this->doWatch();
1333 } elseif ( $title->userIsWatching() ) {
1334 $this->doUnwatch();
1337 return;
1340 // Generate deletion reason
1341 $hasHistory = false;
1342 if ( !$reason ) {
1343 $reason = $this->generateReason( $hasHistory );
1346 // If the page has a history, insert a warning
1347 if ( $hasHistory ) {
1348 $revisions = $this->mTitle->estimateRevisionCount();
1349 // @todo FIXME: i18n issue/patchwork message
1350 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1351 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1352 wfMsgHtml( 'word-separator' ) . Linker::link( $title,
1353 wfMsgHtml( 'history' ),
1354 array( 'rel' => 'archives' ),
1355 array( 'action' => 'history' ) ) .
1356 '</strong>'
1359 if ( $this->mTitle->isBigDeletion() ) {
1360 global $wgDeleteRevisionsLimit;
1361 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1362 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1366 return $this->confirmDelete( $reason );
1370 * Output deletion confirmation dialog
1371 * @todo FIXME: Move to another file?
1372 * @param $reason String: prefilled reason
1374 public function confirmDelete( $reason ) {
1375 global $wgOut;
1377 wfDebug( "Article::confirmDelete\n" );
1379 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1380 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1381 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1382 $wgOut->addWikiMsg( 'confirmdeletetext' );
1384 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1386 $user = $this->getContext()->getUser();
1388 if ( $user->isAllowed( 'suppressrevision' ) ) {
1389 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1390 <td></td>
1391 <td class='mw-input'><strong>" .
1392 Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
1393 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1394 "</strong></td>
1395 </tr>";
1396 } else {
1397 $suppress = '';
1399 $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $this->getTitle()->userIsWatching();
1401 $form = Xml::openElement( 'form', array( 'method' => 'post',
1402 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1403 Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1404 Xml::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1405 Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1406 "<tr id=\"wpDeleteReasonListRow\">
1407 <td class='mw-label'>" .
1408 Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1409 "</td>
1410 <td class='mw-input'>" .
1411 Xml::listDropDown( 'wpDeleteReasonList',
1412 wfMsgForContent( 'deletereason-dropdown' ),
1413 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1414 "</td>
1415 </tr>
1416 <tr id=\"wpDeleteReasonRow\">
1417 <td class='mw-label'>" .
1418 Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1419 "</td>
1420 <td class='mw-input'>" .
1421 Html::input( 'wpReason', $reason, 'text', array(
1422 'size' => '60',
1423 'maxlength' => '255',
1424 'tabindex' => '2',
1425 'id' => 'wpReason',
1426 'autofocus'
1427 ) ) .
1428 "</td>
1429 </tr>";
1431 # Disallow watching if user is not logged in
1432 if ( $user->isLoggedIn() ) {
1433 $form .= "
1434 <tr>
1435 <td></td>
1436 <td class='mw-input'>" .
1437 Xml::checkLabel( wfMsg( 'watchthis' ),
1438 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1439 "</td>
1440 </tr>";
1443 $form .= "
1444 $suppress
1445 <tr>
1446 <td></td>
1447 <td class='mw-submit'>" .
1448 Xml::submitButton( wfMsg( 'deletepage' ),
1449 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1450 "</td>
1451 </tr>" .
1452 Xml::closeElement( 'table' ) .
1453 Xml::closeElement( 'fieldset' ) .
1454 Html::hidden( 'wpEditToken', $user->getEditToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1455 Xml::closeElement( 'form' );
1457 if ( $user->isAllowed( 'editinterface' ) ) {
1458 $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
1459 $link = Linker::link(
1460 $title,
1461 wfMsgHtml( 'delete-edit-reasonlist' ),
1462 array(),
1463 array( 'action' => 'edit' )
1465 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1468 $wgOut->addHTML( $form );
1469 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
1470 LogEventsList::showLogExtract( $wgOut, 'delete',
1471 $this->getTitle()->getPrefixedText()
1476 * Perform a deletion and output success or failure messages
1477 * @param $reason
1478 * @param $suppress bool
1480 public function doDelete( $reason, $suppress = false ) {
1481 global $wgOut;
1483 $error = '';
1484 if ( $this->mPage->doDeleteArticle( $reason, $suppress, 0, true, $error ) ) {
1485 $deleted = $this->getTitle()->getPrefixedText();
1487 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1488 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1490 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1492 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1493 $wgOut->returnToMain( false );
1494 } else {
1495 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1496 if ( $error == '' ) {
1497 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1498 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1500 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
1502 LogEventsList::showLogExtract(
1503 $wgOut,
1504 'delete',
1505 $this->getTitle()->getPrefixedText()
1507 } else {
1508 $wgOut->addHTML( $error );
1513 /* Caching functions */
1516 * checkLastModified returns true if it has taken care of all
1517 * output to the client that is necessary for this request.
1518 * (that is, it has sent a cached version of the page)
1520 * @return boolean true if cached version send, false otherwise
1522 protected function tryFileCache() {
1523 static $called = false;
1525 if ( $called ) {
1526 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1527 return false;
1530 $called = true;
1531 if ( $this->isFileCacheable() ) {
1532 $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'view' );
1533 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1534 wfDebug( "Article::tryFileCache(): about to load file\n" );
1535 $cache->loadFromFileCache( $this->getContext() );
1536 return true;
1537 } else {
1538 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1539 ob_start( array( &$cache, 'saveToFileCache' ) );
1541 } else {
1542 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1545 return false;
1549 * Check if the page can be cached
1550 * @return bool
1552 public function isFileCacheable() {
1553 $cacheable = false;
1555 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
1556 $cacheable = $this->mPage->getID()
1557 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
1558 // Extension may have reason to disable file caching on some pages.
1559 if ( $cacheable ) {
1560 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1564 return $cacheable;
1567 /**#@-*/
1570 * Lightweight method to get the parser output for a page, checking the parser cache
1571 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1572 * consider, so it's not appropriate to use there.
1574 * @since 1.16 (r52326) for LiquidThreads
1576 * @param $oldid mixed integer Revision ID or null
1577 * @param $user User The relevant user
1578 * @return ParserOutput or false if the given revsion ID is not found
1580 public function getParserOutput( $oldid = null, User $user = null ) {
1581 global $wgUser;
1583 $user = is_null( $user ) ? $wgUser : $user;
1584 $parserOptions = $this->mPage->makeParserOptions( $user );
1586 return $this->mPage->getParserOutput( $parserOptions, $oldid );
1590 * Get parser options suitable for rendering the primary article wikitext
1591 * @return ParserOptions
1593 public function getParserOptions() {
1594 global $wgUser;
1595 if ( !$this->mParserOptions ) {
1596 $this->mParserOptions = $this->mPage->makeParserOptions( $wgUser );
1598 // Clone to allow modifications of the return value without affecting cache
1599 return clone $this->mParserOptions;
1603 * Sets the context this Article is executed in
1605 * @param $context IContextSource
1606 * @since 1.18
1608 public function setContext( $context ) {
1609 $this->mContext = $context;
1613 * Gets the context this Article is executed in
1615 * @return IContextSource
1616 * @since 1.18
1618 public function getContext() {
1619 if ( $this->mContext instanceof IContextSource ) {
1620 return $this->mContext;
1621 } else {
1622 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1623 return RequestContext::getMain();
1628 * Info about this page
1629 * @deprecated since 1.19
1631 public function info() {
1632 wfDeprecated( __METHOD__, '1.19' );
1633 Action::factory( 'info', $this )->show();
1637 * Mark this particular edit/page as patrolled
1638 * @deprecated since 1.18
1640 public function markpatrolled() {
1641 wfDeprecated( __METHOD__, '1.18' );
1642 Action::factory( 'markpatrolled', $this )->show();
1646 * Handle action=purge
1647 * @deprecated since 1.19
1649 public function purge() {
1650 return Action::factory( 'purge', $this )->show();
1654 * Handle action=revert
1655 * @deprecated since 1.19
1657 public function revert() {
1658 wfDeprecated( __METHOD__, '1.19' );
1659 Action::factory( 'revert', $this )->show();
1663 * Handle action=rollback
1664 * @deprecated since 1.19
1666 public function rollback() {
1667 wfDeprecated( __METHOD__, '1.19' );
1668 Action::factory( 'rollback', $this )->show();
1672 * User-interface handler for the "watch" action.
1673 * Requires Request to pass a token as of 1.18.
1674 * @deprecated since 1.18
1676 public function watch() {
1677 wfDeprecated( __METHOD__, '1.18' );
1678 Action::factory( 'watch', $this )->show();
1682 * Add this page to $wgUser's watchlist
1684 * This is safe to be called multiple times
1686 * @return bool true on successful watch operation
1687 * @deprecated since 1.18
1689 public function doWatch() {
1690 global $wgUser;
1691 wfDeprecated( __METHOD__, '1.18' );
1692 return WatchAction::doWatch( $this->getTitle(), $wgUser );
1696 * User interface handler for the "unwatch" action.
1697 * Requires Request to pass a token as of 1.18.
1698 * @deprecated since 1.18
1700 public function unwatch() {
1701 wfDeprecated( __METHOD__, '1.18' );
1702 Action::factory( 'unwatch', $this )->show();
1706 * Stop watching a page
1707 * @return bool true on successful unwatch
1708 * @deprecated since 1.18
1710 public function doUnwatch() {
1711 global $wgUser;
1712 wfDeprecated( __METHOD__, '1.18' );
1713 return WatchAction::doUnwatch( $this->getTitle(), $wgUser );
1717 * Output a redirect back to the article.
1718 * This is typically used after an edit.
1720 * @deprecated in 1.18; call $wgOut->redirect() directly
1721 * @param $noRedir Boolean: add redirect=no
1722 * @param $sectionAnchor String: section to redirect to, including "#"
1723 * @param $extraQuery String: extra query params
1725 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1726 wfDeprecated( __METHOD__, '1.18' );
1727 global $wgOut;
1729 if ( $noRedir ) {
1730 $query = 'redirect=no';
1731 if ( $extraQuery )
1732 $query .= "&$extraQuery";
1733 } else {
1734 $query = $extraQuery;
1737 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1741 * Use PHP's magic __get handler to handle accessing of
1742 * raw WikiPage fields for backwards compatibility.
1744 * @param $fname String Field name
1746 public function __get( $fname ) {
1747 if ( property_exists( $this->mPage, $fname ) ) {
1748 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1749 return $this->mPage->$fname;
1751 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
1755 * Use PHP's magic __set handler to handle setting of
1756 * raw WikiPage fields for backwards compatibility.
1758 * @param $fname String Field name
1759 * @param $fvalue mixed New value
1761 public function __set( $fname, $fvalue ) {
1762 if ( property_exists( $this->mPage, $fname ) ) {
1763 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1764 $this->mPage->$fname = $fvalue;
1765 // Note: extensions may want to toss on new fields
1766 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1767 $this->mPage->$fname = $fvalue;
1768 } else {
1769 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
1774 * Use PHP's magic __call handler to transform instance calls to
1775 * WikiPage functions for backwards compatibility.
1777 * @param $fname String Name of called method
1778 * @param $args Array Arguments to the method
1779 * @return mixed
1781 public function __call( $fname, $args ) {
1782 if ( is_callable( array( $this->mPage, $fname ) ) ) {
1783 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1784 return call_user_func_array( array( $this->mPage, $fname ), $args );
1786 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
1789 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1792 * @param $limit array
1793 * @param $expiry array
1794 * @param $cascade bool
1795 * @param $reason string
1796 * @param $user User
1797 * @return Status
1799 public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User $user ) {
1800 return $this->mPage->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user );
1804 * @param $limit array
1805 * @param $reason string
1806 * @param $cascade int
1807 * @param $expiry array
1808 * @return bool
1810 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1811 return $this->mPage->updateRestrictions( $limit, $reason, $cascade, $expiry );
1815 * @param $reason string
1816 * @param $suppress bool
1817 * @param $id int
1818 * @param $commit bool
1819 * @param $error string
1820 * @return bool
1822 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1823 return $this->mPage->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1827 * @param $fromP
1828 * @param $summary
1829 * @param $token
1830 * @param $bot
1831 * @param $resultDetails
1832 * @param $user User
1833 * @return array
1835 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
1836 global $wgUser;
1837 $user = is_null( $user ) ? $wgUser : $user;
1838 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1842 * @param $fromP
1843 * @param $summary
1844 * @param $bot
1845 * @param $resultDetails
1846 * @param $guser User
1847 * @return array
1849 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
1850 global $wgUser;
1851 $guser = is_null( $guser ) ? $wgUser : $guser;
1852 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1856 * @param $hasHistory bool
1857 * @return mixed
1859 public function generateReason( &$hasHistory ) {
1860 return $this->mPage->getAutoDeleteReason( $hasHistory );
1863 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1866 * @return array
1868 public static function selectFields() {
1869 return WikiPage::selectFields();
1873 * @param $title Title
1875 public static function onArticleCreate( $title ) {
1876 WikiPage::onArticleCreate( $title );
1880 * @param $title Title
1882 public static function onArticleDelete( $title ) {
1883 WikiPage::onArticleDelete( $title );
1887 * @param $title Title
1889 public static function onArticleEdit( $title ) {
1890 WikiPage::onArticleEdit( $title );
1894 * @param $oldtext
1895 * @param $newtext
1896 * @param $flags
1897 * @return string
1899 public static function getAutosummary( $oldtext, $newtext, $flags ) {
1900 return WikiPage::getAutosummary( $oldtext, $newtext, $flags );
1902 // ******