5fbfc3b7766bbbac3aec5d0120e35f7192a81f51
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
{
36 * @var ParserOptions: ParserOptions object for $wgUser articles
38 public $mParserOptions;
41 var $mContentLoaded = false; // !<
47 var $mRedirectedFrom = null;
50 * @var mixed: boolean false or URL string
52 var $mRedirectUrl = false; // !<
53 var $mRevIdFetched = 0; // !<
58 var $mRevision = null;
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 );
81 protected function newPage( Title
$title ) {
82 return new WikiPage( $title );
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
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() );
111 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
113 switch( $title->getNamespace() ) {
115 $page = new ImagePage( $title );
118 $page = new CategoryPage( $title );
121 $page = new Article( $title );
124 $page->setContext( $context );
130 * Tell the page view functions that this view was redirected
131 * from another page on the wiki.
132 * @param $from Title object.
134 public function setRedirectedFrom( Title
$from ) {
135 $this->mRedirectedFrom
= $from;
139 * Get the title object of the article
140 * @return Title object of this page
142 public function getTitle() {
143 return $this->mPage
->getTitle();
149 public function clear() {
150 $this->mContentLoaded
= false;
152 $this->mRedirectedFrom
= null; # Title object if set
153 $this->mRevIdFetched
= 0;
154 $this->mRedirectUrl
= false;
156 $this->mPage
->clear();
160 * Note that getContent/loadContent do not follow redirects anymore.
161 * If you need to fetch redirectable content easily, try
162 * the shortcut in Article::followRedirect()
164 * This function has side effects! Do not use this function if you
165 * only want the real revision text if any.
167 * @return Return the text of this revision
169 public function getContent() {
172 wfProfileIn( __METHOD__
);
174 if ( $this->mPage
->getID() === 0 ) {
175 # If this is a MediaWiki:x message, then load the messages
176 # and return the message value for x.
177 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI
) {
178 $text = $this->getTitle()->getDefaultMessageText();
179 if ( $text === false ) {
183 $text = wfMsgExt( $wgUser->isLoggedIn() ?
'noarticletext' : 'noarticletextanon', 'parsemag' );
185 wfProfileOut( __METHOD__
);
189 $this->fetchContent();
190 wfProfileOut( __METHOD__
);
192 return $this->mContent
;
197 * @return int The oldid of the article that is to be shown, 0 for the
200 public function getOldID() {
201 if ( is_null( $this->mOldId
) ) {
202 $this->mOldId
= $this->getOldIDFromRequest();
205 return $this->mOldId
;
209 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
211 * @return int The old id for the request
213 public function getOldIDFromRequest() {
216 $this->mRedirectUrl
= false;
218 $oldid = $wgRequest->getIntOrNull( 'oldid' );
220 if ( $oldid === null ) {
224 if ( $oldid !== 0 ) {
225 # Load the given revision and check whether the page is another one.
226 # In that case, update this instance to reflect the change.
227 $this->mRevision
= Revision
::newFromId( $oldid );
228 if ( $this->mRevision
!== null ) {
229 // Revision title doesn't match the page title given?
230 if ( $this->mPage
->getID() != $this->mRevision
->getPage() ) {
231 $function = array( get_class( $this->mPage
), 'newFromID' );
232 $this->mPage
= call_user_func( $function, $this->mRevision
->getPage() );
237 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
238 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
242 $this->mRedirectUrl
= $this->getTitle()->getFullURL( 'redirect=no' );
244 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
245 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
255 * Load the revision (including text) into this object
257 * @deprecated in 1.19; use fetchContent()
259 function loadContent() {
260 $this->fetchContent();
264 * Get text of an article from database
265 * Does *NOT* follow redirects.
267 * @return mixed string containing article contents, or false if null
269 function fetchContent() {
270 if ( $this->mContentLoaded
) {
271 return $this->mContent
;
274 wfProfileIn( __METHOD__
);
276 $this->mContentLoaded
= true;
278 $oldid = $this->getOldID();
280 # Pre-fill content with error message so that if something
281 # fails we'll have something telling us what we intended.
282 $t = $this->getTitle()->getPrefixedText();
283 $d = $oldid ?
wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
284 $this->mContent
= wfMsgNoTrans( 'missing-article', $t, $d ) ;
287 # $this->mRevision might already be fetched by getOldIDFromRequest()
288 if ( !$this->mRevision
) {
289 $this->mRevision
= Revision
::newFromId( $oldid );
290 if ( !$this->mRevision
) {
291 wfDebug( __METHOD__
. " failed to retrieve specified revision, id $oldid\n" );
296 if ( !$this->mPage
->getLatest() ) {
297 wfDebug( __METHOD__
. " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
301 $this->mRevision
= $this->mPage
->getRevision();
302 if ( !$this->mRevision
) {
303 wfDebug( __METHOD__
. " failed to retrieve current page, rev_id " . $this->mPage
->getLatest() . "\n" );
308 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
309 // We should instead work with the Revision object when we need it...
310 $this->mContent
= $this->mRevision
->getText( Revision
::FOR_THIS_USER
); // Loads if user is allowed
311 $this->mRevIdFetched
= $this->mRevision
->getId();
313 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent
) );
315 wfProfileOut( __METHOD__
);
317 return $this->mContent
;
322 * @deprecated since 1.18
324 public function forUpdate() {
325 wfDeprecated( __METHOD__
);
329 * Returns true if the currently-referenced revision is the current edit
330 * to this page (and it exists).
333 public function isCurrent() {
334 # If no oldid, this is the current version.
335 if ( $this->getOldID() == 0 ) {
339 return $this->mPage
->exists() && $this->mRevision
&& $this->mRevision
->isCurrent();
343 * Use this to fetch the rev ID used on page views
345 * @return int revision ID of last article revision
347 public function getRevIdFetched() {
348 if ( $this->mRevIdFetched
) {
349 return $this->mRevIdFetched
;
351 return $this->mPage
->getLatest();
356 * This is the default action of the index.php entry point: just view the
357 * page of the given title.
359 public function view() {
360 global $wgUser, $wgOut, $wgRequest, $wgParser;
361 global $wgUseFileCache, $wgUseETag;
363 wfProfileIn( __METHOD__
);
365 # Get variables from query string
366 # As side effect this will load the revision and update the title
367 # in a revision ID is passed in the request, so this should remain
368 # the first call of this method even if $oldid is used way below.
369 $oldid = $this->getOldID();
371 # Another whitelist check in case getOldID() is altering the title
372 $permErrors = $this->getTitle()->getUserPermissionsErrors( 'read', $wgUser );
373 if ( count( $permErrors ) ) {
374 wfDebug( __METHOD__
. ": denied on secondary read check\n" );
375 wfProfileOut( __METHOD__
);
376 throw new PermissionsError( 'read', $permErrors );
379 # getOldID() may as well want us to redirect somewhere else
380 if ( $this->mRedirectUrl
) {
381 $wgOut->redirect( $this->mRedirectUrl
);
382 wfDebug( __METHOD__
. ": redirecting due to oldid\n" );
383 wfProfileOut( __METHOD__
);
388 # If we got diff in the query, we want to see a diff page instead of the article.
389 if ( $wgRequest->getCheck( 'diff' ) ) {
390 wfDebug( __METHOD__
. ": showing diff page\n" );
391 $this->showDiffPage();
392 wfProfileOut( __METHOD__
);
397 # Set page title (may be overridden by DISPLAYTITLE)
398 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
400 $wgOut->setArticleFlag( true );
401 # Allow frames by default
402 $wgOut->allowClickjacking();
404 $parserCache = ParserCache
::singleton();
406 $parserOptions = $this->getParserOptions();
407 # Render printable version, use printable version cache
408 if ( $wgOut->isPrintable() ) {
409 $parserOptions->setIsPrintable( true );
410 $parserOptions->setEditSection( false );
411 } elseif ( !$this->getTitle()->quickUserCan( 'edit' ) ) {
412 $parserOptions->setEditSection( false );
415 # Try client and file cache
416 if ( $oldid === 0 && $this->mPage
->checkTouched() ) {
418 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
421 # Is it client cached?
422 if ( $wgOut->checkLastModified( $this->mPage
->getTouched() ) ) {
423 wfDebug( __METHOD__
. ": done 304\n" );
424 wfProfileOut( __METHOD__
);
428 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
429 wfDebug( __METHOD__
. ": done file cache\n" );
430 # tell wgOut that output is taken care of
432 $this->mPage
->viewUpdates();
433 wfProfileOut( __METHOD__
);
439 # Should the parser cache be used?
440 $useParserCache = $this->mPage
->isParserCacheUsed( $wgUser, $oldid );
441 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
442 if ( $wgUser->getStubThreshold() ) {
443 wfIncrStats( 'pcache_miss_stub' );
446 $this->showRedirectedFromHeader();
447 $this->showNamespaceHeader();
449 # Iterate through the possible ways of constructing the output text.
450 # Keep going until $outputDone is set, or we run out of things to do.
453 $this->mParserOutput
= false;
455 while ( !$outputDone && ++
$pass ) {
458 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
461 # Early abort if the page doesn't exist
462 if ( !$this->mPage
->exists() ) {
463 wfDebug( __METHOD__
. ": showing missing article\n" );
464 $this->showMissingArticle();
465 wfProfileOut( __METHOD__
);
469 # Try the parser cache
470 if ( $useParserCache ) {
471 $this->mParserOutput
= $parserCache->get( $this, $parserOptions );
473 if ( $this->mParserOutput
!== false ) {
475 wfDebug( __METHOD__
. ": showing parser cache contents for current rev permalink\n" );
476 $this->setOldSubtitle( $oldid );
478 wfDebug( __METHOD__
. ": showing parser cache contents\n" );
480 $wgOut->addParserOutput( $this->mParserOutput
);
481 # Ensure that UI elements requiring revision ID have
482 # the correct version information.
483 $wgOut->setRevisionId( $this->mPage
->getLatest() );
485 # Preload timestamp to avoid a DB hit
486 if ( isset( $this->mParserOutput
->mTimestamp
) ) {
487 $this->mPage
->setTimestamp( $this->mParserOutput
->mTimestamp
);
493 # This will set $this->mRevision if needed
494 $this->fetchContent();
496 # Are we looking at an old revision
497 if ( $oldid && $this->mRevision
) {
498 $this->setOldSubtitle( $oldid );
500 if ( !$this->showDeletedRevisionHeader() ) {
501 wfDebug( __METHOD__
. ": cannot view deleted revision\n" );
502 wfProfileOut( __METHOD__
);
507 # Ensure that UI elements requiring revision ID have
508 # the correct version information.
509 $wgOut->setRevisionId( $this->getRevIdFetched() );
511 # Pages containing custom CSS or JavaScript get special treatment
512 if ( $this->getTitle()->isCssOrJsPage() ||
$this->getTitle()->isCssJsSubpage() ) {
513 wfDebug( __METHOD__
. ": showing CSS/JS source\n" );
514 $this->showCssOrJsPage();
516 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
517 # Allow extensions do their own custom view for certain pages
520 $text = $this->getContent();
521 $rt = Title
::newFromRedirectArray( $text );
523 wfDebug( __METHOD__
. ": showing redirect=no page\n" );
524 # Viewing a redirect page (e.g. with parameter redirect=no)
525 $wgOut->addHTML( $this->viewRedirect( $rt ) );
526 # Parse just to get categories, displaytitle, etc.
527 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(), $parserOptions );
528 $wgOut->addParserOutputNoText( $this->mParserOutput
);
534 # Run the parse, protected by a pool counter
535 wfDebug( __METHOD__
. ": doing uncached parse\n" );
537 $key = $parserCache->getKey( $this, $parserOptions );
538 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
540 if ( !$poolArticleView->execute() ) {
541 # Connection or timeout error
542 wfProfileOut( __METHOD__
);
548 # Should be unreachable, but just in case...
554 # Get the ParserOutput actually *displayed* here.
555 # Note that $this->mParserOutput is the *current* version output.
556 $pOutput = ( $outputDone instanceof ParserOutput
)
557 ?
$outputDone // object fetched by hook
558 : $this->mParserOutput
;
560 # Adjust title for main page & pages with displaytitle
562 $this->adjustDisplayTitle( $pOutput );
565 # For the main page, overwrite the <title> element with the con-
566 # tents of 'pagetitle-view-mainpage' instead of the default (if
568 # This message always exists because it is in the i18n files
569 if ( $this->getTitle()->isMainPage() ) {
570 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
571 if ( !$msg->isDisabled() ) {
572 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
576 # Check for any __NOINDEX__ tags on the page using $pOutput
577 $policy = $this->getRobotPolicy( 'view', $pOutput );
578 $wgOut->setIndexPolicy( $policy['index'] );
579 $wgOut->setFollowPolicy( $policy['follow'] );
581 $this->showViewFooter();
582 $this->mPage
->viewUpdates();
584 wfProfileOut( __METHOD__
);
588 * Adjust title for pages with displaytitle, -{T|}- or language conversion
589 * @param $pOutput ParserOutput
591 public function adjustDisplayTitle( ParserOutput
$pOutput ) {
593 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
594 $titleText = $pOutput->getTitleText();
595 if ( strval( $titleText ) !== '' ) {
596 $wgOut->setPageTitle( $titleText );
601 * Show a diff page according to current request variables. For use within
602 * Article::view() only, other callers should use the DifferenceEngine class.
604 public function showDiffPage() {
605 global $wgRequest, $wgUser;
607 $diff = $wgRequest->getVal( 'diff' );
608 $rcid = $wgRequest->getVal( 'rcid' );
609 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
610 $purge = $wgRequest->getVal( 'action' ) == 'purge';
611 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
612 $oldid = $this->getOldID();
614 $de = new DifferenceEngine( $this->getContext(), $oldid, $diff, $rcid, $purge, $unhide );
615 // DifferenceEngine directly fetched the revision:
616 $this->mRevIdFetched
= $de->mNewid
;
617 $de->showDiffPage( $diffOnly );
619 if ( $diff == 0 ||
$diff == $this->mPage
->getLatest() ) {
620 # Run view updates for current revision only
621 $this->mPage
->viewUpdates();
626 * Show a page view for a page formatted as CSS or JavaScript. To be called by
627 * Article::view() only.
629 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
632 protected function showCssOrJsPage() {
635 $dir = $this->getContext()->getLang()->getDir();
636 $lang = $this->getContext()->getLang()->getCode();
638 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
641 // Give hooks a chance to customise the output
642 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent
, $this->getTitle(), $wgOut ) ) ) {
643 // Wrap the whole lot in a <pre> and don't parse
645 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
646 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
647 $wgOut->addHTML( htmlspecialchars( $this->mContent
) );
648 $wgOut->addHTML( "\n</pre>\n" );
653 * Get the robot policy to be used for the current view
654 * @param $action String the action= GET parameter
655 * @param $pOutput ParserOutput
656 * @return Array the policy that should be set
657 * TODO: actions other than 'view'
659 public function getRobotPolicy( $action, $pOutput ) {
660 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
661 global $wgDefaultRobotPolicy, $wgRequest;
663 $ns = $this->getTitle()->getNamespace();
665 if ( $ns == NS_USER ||
$ns == NS_USER_TALK
) {
666 # Don't index user and user talk pages for blocked users (bug 11443)
667 if ( !$this->getTitle()->isSubpage() ) {
668 if ( Block
::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block
) {
670 'index' => 'noindex',
671 'follow' => 'nofollow'
677 if ( $this->mPage
->getID() === 0 ||
$this->getOldID() ) {
678 # Non-articles (special pages etc), and old revisions
680 'index' => 'noindex',
681 'follow' => 'nofollow'
683 } elseif ( $wgOut->isPrintable() ) {
684 # Discourage indexing of printable versions, but encourage following
686 'index' => 'noindex',
689 } elseif ( $wgRequest->getInt( 'curid' ) ) {
690 # For ?curid=x urls, disallow indexing
692 'index' => 'noindex',
697 # Otherwise, construct the policy based on the various config variables.
698 $policy = self
::formatRobotPolicy( $wgDefaultRobotPolicy );
700 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
701 # Honour customised robot policies for this namespace
702 $policy = array_merge(
704 self
::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
707 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
708 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
709 # a final sanity check that we have really got the parser output.
710 $policy = array_merge(
712 array( 'index' => $pOutput->getIndexPolicy() )
716 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
717 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
718 $policy = array_merge(
720 self
::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
728 * Converts a String robot policy into an associative array, to allow
729 * merging of several policies using array_merge().
730 * @param $policy Mixed, returns empty array on null/false/'', transparent
731 * to already-converted arrays, converts String.
732 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
734 public static function formatRobotPolicy( $policy ) {
735 if ( is_array( $policy ) ) {
737 } elseif ( !$policy ) {
741 $policy = explode( ',', $policy );
742 $policy = array_map( 'trim', $policy );
745 foreach ( $policy as $var ) {
746 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
747 $arr['index'] = $var;
748 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
749 $arr['follow'] = $var;
757 * If this request is a redirect view, send "redirected from" subtitle to
758 * $wgOut. Returns true if the header was needed, false if this is not a
759 * redirect view. Handles both local and remote redirects.
763 public function showRedirectedFromHeader() {
764 global $wgOut, $wgRequest, $wgRedirectSources;
766 $rdfrom = $wgRequest->getVal( 'rdfrom' );
768 if ( isset( $this->mRedirectedFrom
) ) {
769 // This is an internally redirected page view.
770 // We'll need a backlink to the source page for navigation.
771 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
772 $redir = Linker
::linkKnown(
773 $this->mRedirectedFrom
,
776 array( 'redirect' => 'no' )
779 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
781 // Set the fragment if one was specified in the redirect
782 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
783 $fragment = Xml
::escapeJsString( $this->getTitle()->getFragmentForURL() );
784 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
787 // Add a <link rel="canonical"> tag
788 $wgOut->addLink( array( 'rel' => 'canonical',
789 'href' => $this->getTitle()->getLocalURL() )
794 } elseif ( $rdfrom ) {
795 // This is an externally redirected view, from some other wiki.
796 // If it was reported from a trusted site, supply a backlink.
797 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
798 $redir = Linker
::makeExternalLink( $rdfrom, $rdfrom );
799 $wgOut->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
809 * Show a header specific to the namespace currently being viewed, like
810 * [[MediaWiki:Talkpagetext]]. For Article::view().
812 public function showNamespaceHeader() {
815 if ( $this->getTitle()->isTalkPage() ) {
816 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
817 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
823 * Show the footer section of an ordinary page view
825 public function showViewFooter() {
826 global $wgOut, $wgUseTrackbacks;
828 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
829 if ( $this->getTitle()->getNamespace() == NS_USER_TALK
&& IP
::isValid( $this->getTitle()->getText() ) ) {
830 $wgOut->addWikiMsg( 'anontalkpagetext' );
833 # If we have been passed an &rcid= parameter, we want to give the user a
834 # chance to mark this new article as patrolled.
835 $this->showPatrolFooter();
838 if ( $wgUseTrackbacks ) {
839 $this->addTrackbacks();
842 wfRunHooks( 'ArticleViewFooter', array( $this ) );
847 * If patrol is possible, output a patrol UI box. This is called from the
848 * footer section of ordinary page views. If patrol is not possible or not
849 * desired, does nothing.
851 public function showPatrolFooter() {
852 global $wgOut, $wgRequest, $wgUser;
854 $rcid = $wgRequest->getVal( 'rcid' );
856 if ( !$rcid ||
!$this->getTitle()->quickUserCan( 'patrol' ) ) {
860 $token = $wgUser->editToken( $rcid );
861 $wgOut->preventClickjacking();
864 "<div class='patrollink'>" .
866 'markaspatrolledlink',
869 wfMsgHtml( 'markaspatrolledtext' ),
872 'action' => 'markpatrolled',
876 array( 'known', 'noclasses' )
884 * Show the error text for a missing article. For articles in the MediaWiki
885 * namespace, show the default message text. To be called from Article::view().
887 public function showMissingArticle() {
888 global $wgOut, $wgRequest, $wgUser;
890 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
891 if ( $this->getTitle()->getNamespace() == NS_USER ||
$this->getTitle()->getNamespace() == NS_USER_TALK
) {
892 $parts = explode( '/', $this->getTitle()->getText() );
893 $rootPart = $parts[0];
894 $user = User
::newFromName( $rootPart, false /* allow IP users*/ );
895 $ip = User
::isIP( $rootPart );
897 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
898 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
899 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
900 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
901 LogEventsList
::showLogExtract(
904 $user->getUserPage()->getPrefixedText(),
908 'showIfEmpty' => false,
910 'blocked-notice-logextract',
911 $user->getName() # Support GENDER in notice
918 wfRunHooks( 'ShowMissingArticle', array( $this ) );
920 # Show delete and move logs
921 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
923 'conds' => array( "log_action != 'revision'" ),
924 'showIfEmpty' => false,
925 'msgKey' => array( 'moveddeleted-notice' ) )
929 $oldid = $this->getOldID();
931 $text = wfMsgNoTrans( 'missing-article',
932 $this->getTitle()->getPrefixedText(),
933 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
934 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI
) {
935 // Use the default message text
936 $text = $this->getTitle()->getDefaultMessageText();
938 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
939 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
940 $errors = array_merge( $createErrors, $editErrors );
942 if ( !count( $errors ) ) {
943 $text = wfMsgNoTrans( 'noarticletext' );
945 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
948 $text = "<div class='noarticletext'>\n$text\n</div>";
950 if ( !$this->mPage
->hasViewableContent() ) {
951 // If there's no backing content, send a 404 Not Found
952 // for better machine handling of broken links.
953 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
956 $wgOut->addWikiText( $text );
960 * If the revision requested for view is deleted, check permissions.
961 * Send either an error message or a warning header to $wgOut.
963 * @return boolean true if the view is allowed, false if not.
965 public function showDeletedRevisionHeader() {
966 global $wgOut, $wgRequest;
968 if ( !$this->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
973 // If the user is not allowed to see it...
974 if ( !$this->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
975 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
976 'rev-deleted-text-permission' );
979 // If the user needs to confirm that they want to see it...
980 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
981 # Give explanation and add a link to view the revision...
982 $oldid = intval( $this->getOldID() );
983 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
984 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
985 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
986 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
987 array( $msg, $link ) );
990 // We are allowed to see...
992 $msg = $this->mRevision
->isDeleted( Revision
::DELETED_RESTRICTED
) ?
993 'rev-suppressed-text-view' : 'rev-deleted-text-view';
994 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1001 * Generate the navigation links when browsing through an article revisions
1002 * It shows the information as:
1003 * Revision as of \<date\>; view current revision
1004 * \<- Previous version | Next Version -\>
1006 * @param $oldid String: revision ID of this article revision
1008 public function setOldSubtitle( $oldid = 0 ) {
1009 global $wgLang, $wgOut, $wgUser, $wgRequest;
1011 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1015 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1017 # Cascade unhide param in links for easy deletion browsing
1018 $extraParams = array();
1019 if ( $wgRequest->getVal( 'unhide' ) ) {
1020 $extraParams['unhide'] = 1;
1023 $revision = Revision
::newFromId( $oldid );
1024 $timestamp = $revision->getTimestamp();
1026 $current = ( $oldid == $this->mPage
->getLatest() );
1027 $td = $wgLang->timeanddate( $timestamp, true );
1028 $tddate = $wgLang->date( $timestamp, true );
1029 $tdtime = $wgLang->time( $timestamp, true );
1031 # Show user links if allowed to see them. If hidden, then show them only if requested...
1032 $userlinks = Linker
::revUserTools( $revision, !$unhide );
1034 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1035 ?
'revision-info-current'
1038 $wgOut->addSubtitle( "<div id=\"mw-{$infomsg}\">" . wfMessage( $infomsg,
1039 $td )->rawParams( $userlinks )->params( $revision->getID(), $tddate,
1040 $tdtime, $revision->getUser() )->parse() . "</div>" );
1043 ?
wfMsgHtml( 'currentrevisionlink' )
1046 wfMsgHtml( 'currentrevisionlink' ),
1049 array( 'known', 'noclasses' )
1052 ?
wfMsgHtml( 'diff' )
1055 wfMsgHtml( 'diff' ),
1061 array( 'known', 'noclasses' )
1063 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1067 wfMsgHtml( 'previousrevision' ),
1070 'direction' => 'prev',
1073 array( 'known', 'noclasses' )
1075 : wfMsgHtml( 'previousrevision' );
1079 wfMsgHtml( 'diff' ),
1085 array( 'known', 'noclasses' )
1087 : wfMsgHtml( 'diff' );
1088 $nextlink = $current
1089 ?
wfMsgHtml( 'nextrevision' )
1092 wfMsgHtml( 'nextrevision' ),
1095 'direction' => 'next',
1098 array( 'known', 'noclasses' )
1100 $nextdiff = $current
1101 ?
wfMsgHtml( 'diff' )
1104 wfMsgHtml( 'diff' ),
1110 array( 'known', 'noclasses' )
1115 // User can delete revisions or view deleted revisions...
1116 $canHide = $wgUser->isAllowed( 'deleterevision' );
1117 if ( $canHide ||
( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1118 if ( !$revision->userCan( Revision
::DELETED_RESTRICTED
) ) {
1119 $cdel = Linker
::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1122 'type' => 'revision',
1123 'target' => $this->getTitle()->getPrefixedDbkey(),
1126 $cdel = Linker
::revDeleteLink( $query, $revision->isDeleted( File
::DELETED_RESTRICTED
), $canHide );
1131 $wgOut->addSubtitle( "<div id=\"mw-revision-nav\">" . $cdel .
1132 wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1133 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>" );
1137 * Execute the uncached parse for action=view
1140 public function doViewParse() {
1143 $oldid = $this->getOldID();
1144 $parserOptions = $this->getParserOptions();
1146 # Render printable version, use printable version cache
1147 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1149 # Don't show section-edit links on old revisions... this way lies madness.
1150 if ( !$this->isCurrent() ||
$wgOut->isPrintable() ||
!$this->getTitle()->quickUserCan( 'edit' ) ) {
1151 $parserOptions->setEditSection( false );
1154 $useParserCache = $this->useParserCache( $oldid );
1155 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1161 * Try to fetch an expired entry from the parser cache. If it is present,
1162 * output it and return true. If it is not present, output nothing and
1163 * return false. This is used as a callback function for
1164 * PoolCounter::executeProtected().
1168 public function tryDirtyCache() {
1170 $parserCache = ParserCache
::singleton();
1171 $options = $this->getParserOptions();
1173 if ( $wgOut->isPrintable() ) {
1174 $options->setIsPrintable( true );
1175 $options->setEditSection( false );
1178 $output = $parserCache->getDirty( $this, $options );
1181 wfDebug( __METHOD__
. ": sending dirty output\n" );
1182 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1183 $wgOut->setSquidMaxage( 0 );
1184 $this->mParserOutput
= $output;
1185 $wgOut->addParserOutput( $output );
1186 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1190 wfDebugLog( 'dirty', "dirty missing\n" );
1191 wfDebug( __METHOD__
. ": no dirty cache\n" );
1200 * @param $target Title|Array of destination(s) to redirect
1201 * @param $appendSubtitle Boolean [optional]
1202 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1203 * @return string containing HMTL with redirect link
1205 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1206 global $wgOut, $wgStylePath;
1208 if ( !is_array( $target ) ) {
1209 $target = array( $target );
1212 $lang = $this->getTitle()->getPageLanguage();
1213 $imageDir = $lang->getDir();
1215 if ( $appendSubtitle ) {
1216 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1219 // the loop prepends the arrow image before the link, so the first case needs to be outside
1224 $title = array_shift( $target );
1226 if ( $forceKnown ) {
1227 $link = Linker
::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1229 $link = Linker
::link( $title, htmlspecialchars( $title->getFullText() ) );
1232 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1233 $alt = $lang->isRTL() ?
'←' : '→';
1234 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1235 foreach ( $target as $rt ) {
1236 $link .= Html
::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1237 if ( $forceKnown ) {
1238 $link .= Linker
::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1240 $link .= Linker
::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1244 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1245 return '<div class="redirectMsg">' .
1246 Html
::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1247 '<span class="redirectText">' . $link . '</span></div>';
1251 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1253 public function addTrackbacks() {
1256 $dbr = wfGetDB( DB_SLAVE
);
1257 $tbs = $dbr->select( 'trackbacks',
1258 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1259 array( 'tb_page' => $this->mPage
->getID() )
1262 if ( !$dbr->numRows( $tbs ) ) {
1266 $wgOut->preventClickjacking();
1269 foreach ( $tbs as $o ) {
1272 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1273 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1274 $o->tb_id
. "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1275 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1279 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex
) ?
'trackbackexcerpt' : 'trackback',
1287 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1291 * Handle action=render
1293 public function render() {
1296 $wgOut->setArticleBodyOnly( true );
1301 * action=protect handler
1303 public function protect() {
1304 $form = new ProtectionForm( $this );
1309 * action=unprotect handler (alias)
1311 public function unprotect() {
1316 * UI entry point for page deletion
1318 public function delete() {
1319 global $wgOut, $wgRequest, $wgLang;
1321 # This code desperately needs to be totally rewritten
1323 $title = $this->getTitle();
1324 $user = $this->getContext()->getUser();
1327 $permission_errors = $title->getUserPermissionsErrors( 'delete', $user );
1328 if ( count( $permission_errors ) ) {
1329 throw new PermissionsError( 'delete', $permission_errors );
1332 # Read-only check...
1333 if ( wfReadOnly() ) {
1334 throw new ReadOnlyError
;
1337 # Better double-check that it hasn't been deleted yet!
1338 $dbw = wfGetDB( DB_MASTER
);
1339 $conds = $title->pageCond();
1340 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__
);
1341 if ( $latest === false ) {
1342 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1343 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1344 array( 'cannotdelete', wfEscapeWikiText( $title->getPrefixedText() ) )
1346 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1347 LogEventsList
::showLogExtract(
1350 $title->getPrefixedText()
1356 # Hack for big sites
1357 $bigHistory = $this->mPage
->isBigDeletion();
1358 if ( $bigHistory && !$title->userCan( 'bigdelete' ) ) {
1359 global $wgDeleteRevisionsLimit;
1361 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $title->getPrefixedText() ) );
1362 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1363 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1368 $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1369 $deleteReason = $wgRequest->getText( 'wpReason' );
1371 if ( $deleteReasonList == 'other' ) {
1372 $reason = $deleteReason;
1373 } elseif ( $deleteReason != '' ) {
1374 // Entry from drop down menu + additional comment
1375 $reason = $deleteReasonList . wfMsgForContent( 'colon-separator' ) . $deleteReason;
1377 $reason = $deleteReasonList;
1380 if ( $wgRequest->wasPosted() && $user->matchEditToken( $wgRequest->getVal( 'wpEditToken' ),
1381 array( 'delete', $this->getTitle()->getPrefixedText() ) ) )
1383 # Flag to hide all contents of the archived revisions
1384 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
1386 $this->doDelete( $reason, $suppress );
1388 if ( $wgRequest->getCheck( 'wpWatch' ) && $user->isLoggedIn() ) {
1390 } elseif ( $title->userIsWatching() ) {
1397 // Generate deletion reason
1398 $hasHistory = false;
1400 $reason = $this->generateReason( $hasHistory );
1403 // If the page has a history, insert a warning
1404 if ( $hasHistory ) {
1405 $revisions = $this->mPage
->estimateRevisionCount();
1406 // @todo FIXME: i18n issue/patchwork message
1407 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1408 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1409 wfMsgHtml( 'word-separator' ) . Linker
::link( $title,
1410 wfMsgHtml( 'history' ),
1411 array( 'rel' => 'archives' ),
1412 array( 'action' => 'history' ) ) .
1416 if ( $bigHistory ) {
1417 global $wgDeleteRevisionsLimit;
1418 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1419 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1423 return $this->confirmDelete( $reason );
1427 * Output deletion confirmation dialog
1428 * @todo FIXME: Move to another file?
1429 * @param $reason String: prefilled reason
1431 public function confirmDelete( $reason ) {
1434 wfDebug( "Article::confirmDelete\n" );
1436 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1437 $wgOut->addBacklinkSubtitle( $this->getTitle() );
1438 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1439 $wgOut->addWikiMsg( 'confirmdeletetext' );
1441 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1443 $user = $this->getContext()->getUser();
1445 if ( $user->isAllowed( 'suppressrevision' ) ) {
1446 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1448 <td class='mw-input'><strong>" .
1449 Xml
::checkLabel( wfMsg( 'revdelete-suppress' ),
1450 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1456 $checkWatch = $user->getBoolOption( 'watchdeletion' ) ||
$this->getTitle()->userIsWatching();
1458 $form = Xml
::openElement( 'form', array( 'method' => 'post',
1459 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1460 Xml
::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1461 Xml
::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1462 Xml
::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1463 "<tr id=\"wpDeleteReasonListRow\">
1464 <td class='mw-label'>" .
1465 Xml
::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1467 <td class='mw-input'>" .
1468 Xml
::listDropDown( 'wpDeleteReasonList',
1469 wfMsgForContent( 'deletereason-dropdown' ),
1470 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1473 <tr id=\"wpDeleteReasonRow\">
1474 <td class='mw-label'>" .
1475 Xml
::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1477 <td class='mw-input'>" .
1478 Html
::input( 'wpReason', $reason, 'text', array(
1480 'maxlength' => '255',
1488 # Disallow watching if user is not logged in
1489 if ( $user->isLoggedIn() ) {
1493 <td class='mw-input'>" .
1494 Xml
::checkLabel( wfMsg( 'watchthis' ),
1495 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1504 <td class='mw-submit'>" .
1505 Xml
::submitButton( wfMsg( 'deletepage' ),
1506 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1509 Xml
::closeElement( 'table' ) .
1510 Xml
::closeElement( 'fieldset' ) .
1511 Html
::hidden( 'wpEditToken', $user->editToken( array( 'delete', $this->getTitle()->getPrefixedText() ) ) ) .
1512 Xml
::closeElement( 'form' );
1514 if ( $user->isAllowed( 'editinterface' ) ) {
1515 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'Deletereason-dropdown' );
1516 $link = Linker
::link(
1518 wfMsgHtml( 'delete-edit-reasonlist' ),
1520 array( 'action' => 'edit' )
1522 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1525 $wgOut->addHTML( $form );
1526 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1527 LogEventsList
::showLogExtract( $wgOut, 'delete',
1528 $this->getTitle()->getPrefixedText()
1533 * Perform a deletion and output success or failure messages
1535 * @param $suppress bool
1537 public function doDelete( $reason, $suppress = false ) {
1540 $id = $this->getTitle()->getArticleID( Title
::GAID_FOR_UPDATE
);
1543 if ( $this->mPage
->doDeleteArticle( $reason, $suppress, $id, true, $error ) ) {
1544 $deleted = $this->getTitle()->getPrefixedText();
1546 $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
1547 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1549 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1551 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1552 $wgOut->returnToMain( false );
1554 $wgOut->setPageTitle( wfMessage( 'cannotdelete-title', $this->getTitle()->getPrefixedText() ) );
1555 if ( $error == '' ) {
1556 $wgOut->wrapWikiMsg( "<div class=\"error mw-error-cannotdelete\">\n$1\n</div>",
1557 array( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1559 $wgOut->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'delete' ) ) );
1561 LogEventsList
::showLogExtract(
1564 $this->getTitle()->getPrefixedText()
1567 $wgOut->addHTML( $error );
1572 /* Caching functions */
1575 * checkLastModified returns true if it has taken care of all
1576 * output to the client that is necessary for this request.
1577 * (that is, it has sent a cached version of the page)
1579 * @return boolean true if cached version send, false otherwise
1581 protected function tryFileCache() {
1582 static $called = false;
1585 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1590 if ( $this->isFileCacheable() ) {
1591 $cache = HTMLFileCache
::newFromTitle( $this->getTitle(), 'view' );
1592 if ( $cache->isCacheGood( $this->mPage
->getTouched() ) ) {
1593 wfDebug( "Article::tryFileCache(): about to load file\n" );
1594 $cache->loadFromFileCache( $this->getContext() );
1597 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1598 ob_start( array( &$cache, 'saveToFileCache' ) );
1601 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1608 * Check if the page can be cached
1611 public function isFileCacheable() {
1614 if ( HTMLFileCache
::useFileCache( $this->getContext() ) ) {
1615 $cacheable = $this->mPage
->getID()
1616 && !$this->mRedirectedFrom
&& !$this->getTitle()->isRedirect();
1617 // Extension may have reason to disable file caching on some pages.
1619 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1629 * Add the primary page-view wikitext to the output buffer
1630 * Saves the text into the parser cache if possible.
1631 * Updates templatelinks if it is out of date.
1633 * @param $text String
1634 * @param $cache Boolean
1635 * @param $parserOptions mixed ParserOptions object, or boolean false
1637 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1640 $this->mParserOutput
= $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1642 $this->doCascadeProtectionUpdates( $this->mParserOutput
);
1644 $wgOut->addParserOutput( $this->mParserOutput
);
1648 * Lightweight method to get the parser output for a page, checking the parser cache
1649 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1650 * consider, so it's not appropriate to use there.
1652 * @since 1.16 (r52326) for LiquidThreads
1654 * @param $oldid mixed integer Revision ID or null
1655 * @param $user User The relevant user
1656 * @return ParserOutput or false if the given revsion ID is not found
1658 public function getParserOutput( $oldid = null, User
$user = null ) {
1659 global $wgEnableParserCache, $wgUser;
1660 $user = is_null( $user ) ?
$wgUser : $user;
1662 wfProfileIn( __METHOD__
);
1663 // Should the parser cache be used?
1664 $useParserCache = $wgEnableParserCache &&
1665 $user->getStubThreshold() == 0 &&
1666 $this->mPage
->exists() &&
1669 wfDebug( __METHOD__
. ': using parser cache: ' . ( $useParserCache ?
'yes' : 'no' ) . "\n" );
1671 if ( $user->getStubThreshold() ) {
1672 wfIncrStats( 'pcache_miss_stub' );
1675 if ( $useParserCache ) {
1676 $options = $this->mPage
->makeParserOptions( $user );
1677 $parserOutput = ParserCache
::singleton()->get( $this, $options );
1678 if ( $parserOutput !== false ) {
1679 wfProfileOut( __METHOD__
);
1680 return $parserOutput;
1684 // Cache miss; parse and output it.
1685 if ( $oldid === null ) {
1686 $text = $this->mPage
->getRawText();
1688 $rev = Revision
::newFromTitle( $this->getTitle(), $oldid );
1689 if ( $rev === null ) {
1690 wfProfileOut( __METHOD__
);
1693 $text = $rev->getText();
1696 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1697 wfProfileOut( __METHOD__
);
1702 * This does all the heavy lifting for outputWikitext, except it returns the parser
1703 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1704 * say, embedding thread pages within a discussion system (LiquidThreads)
1706 * @param $text string
1707 * @param $cache boolean
1708 * @param $parserOptions parsing options, defaults to false
1709 * @return ParserOutput
1711 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1712 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1714 if ( !$parserOptions ) {
1715 $parserOptions = $this->getParserOptions();
1719 $this->mParserOutput
= $wgParser->parse( $text, $this->getTitle(),
1720 $parserOptions, true, true, $this->getRevIdFetched() );
1725 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1726 $this->getTitle()->getPrefixedDBkey() ) );
1729 if ( $wgEnableParserCache && $cache && $this->mParserOutput
->isCacheable() ) {
1730 $parserCache = ParserCache
::singleton();
1731 $parserCache->save( $this->mParserOutput
, $this, $parserOptions );
1734 // Make sure file cache is not used on uncacheable content.
1735 // Output that has magic words in it can still use the parser cache
1736 // (if enabled), though it will generally expire sooner.
1737 if ( !$this->mParserOutput
->isCacheable() ||
$this->mParserOutput
->containsOldMagic() ) {
1738 $wgUseFileCache = false;
1741 if ( $this->isCurrent() ) {
1742 $this->mPage
->doCascadeProtectionUpdates( $this->mParserOutput
);
1745 return $this->mParserOutput
;
1749 * Get parser options suitable for rendering the primary article wikitext
1750 * @return ParserOptions|false
1752 public function getParserOptions() {
1754 if ( !$this->mParserOptions
) {
1755 $this->mParserOptions
= $this->mPage
->makeParserOptions( $wgUser );
1757 // Clone to allow modifications of the return value without affecting cache
1758 return clone $this->mParserOptions
;
1762 * Sets the context this Article is executed in
1764 * @param $context IContextSource
1767 public function setContext( $context ) {
1768 $this->mContext
= $context;
1772 * Gets the context this Article is executed in
1774 * @return IContextSource
1777 public function getContext() {
1778 if ( $this->mContext
instanceof IContextSource
) {
1779 return $this->mContext
;
1781 wfDebug( __METHOD__
. " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1782 return RequestContext
::getMain();
1787 * Removes trackback record for current article from trackbacks table
1788 * @deprecated since 1.18
1790 public function deletetrackback() {
1791 return Action
::factory( 'deletetrackback', $this )->show();
1795 * Info about this page
1796 * @deprecated since 1.19
1798 public function info() {
1799 Action
::factory( 'info', $this )->show();
1803 * Mark this particular edit/page as patrolled
1804 * @deprecated since 1.18
1806 public function markpatrolled() {
1807 Action
::factory( 'markpatrolled', $this )->show();
1811 * Handle action=purge
1812 * @deprecated since 1.19
1814 public function purge() {
1815 return Action
::factory( 'purge', $this )->show();
1819 * Handle action=revert
1820 * @deprecated since 1.19
1822 public function revert() {
1823 Action
::factory( 'revert', $this )->show();
1827 * Handle action=rollback
1828 * @deprecated since 1.19
1830 public function rollback() {
1831 Action
::factory( 'rollback', $this )->show();
1835 * User-interface handler for the "watch" action.
1836 * Requires Request to pass a token as of 1.18.
1837 * @deprecated since 1.18
1839 public function watch() {
1840 Action
::factory( 'watch', $this )->show();
1844 * Add this page to $wgUser's watchlist
1846 * This is safe to be called multiple times
1848 * @return bool true on successful watch operation
1849 * @deprecated since 1.18
1851 public function doWatch() {
1853 return WatchAction
::doWatch( $this->getTitle(), $wgUser );
1857 * User interface handler for the "unwatch" action.
1858 * Requires Request to pass a token as of 1.18.
1859 * @deprecated since 1.18
1861 public function unwatch() {
1862 Action
::factory( 'unwatch', $this )->show();
1866 * Stop watching a page
1867 * @return bool true on successful unwatch
1868 * @deprecated since 1.18
1870 public function doUnwatch() {
1872 return WatchAction
::doUnwatch( $this->getTitle(), $wgUser );
1876 * Output a redirect back to the article.
1877 * This is typically used after an edit.
1879 * @deprecated in 1.18; call $wgOut->redirect() directly
1880 * @param $noRedir Boolean: add redirect=no
1881 * @param $sectionAnchor String: section to redirect to, including "#"
1882 * @param $extraQuery String: extra query params
1884 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1885 wfDeprecated( __METHOD__
);
1889 $query = 'redirect=no';
1891 $query .= "&$extraQuery";
1893 $query = $extraQuery;
1896 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1900 * Use PHP's magic __get handler to handle accessing of
1901 * raw WikiPage fields for backwards compatibility.
1903 * @param $fname String Field name
1905 public function __get( $fname ) {
1906 if ( property_exists( $this->mPage
, $fname ) ) {
1907 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1908 return $this->mPage
->$fname;
1910 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE
);
1914 * Use PHP's magic __set handler to handle setting of
1915 * raw WikiPage fields for backwards compatibility.
1917 * @param $fname String Field name
1918 * @param $fvalue mixed New value
1920 public function __set( $fname, $fvalue ) {
1921 if ( property_exists( $this->mPage
, $fname ) ) {
1922 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1923 $this->mPage
->$fname = $fvalue;
1924 // Note: extensions may want to toss on new fields
1925 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1926 $this->mPage
->$fname = $fvalue;
1928 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE
);
1933 * Use PHP's magic __call handler to transform instance calls to
1934 * WikiPage functions for backwards compatibility.
1936 * @param $fname String Name of called method
1937 * @param $args Array Arguments to the method
1939 public function __call( $fname, $args ) {
1940 if ( is_callable( array( $this->mPage
, $fname ) ) ) {
1941 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1942 return call_user_func_array( array( $this->mPage
, $fname ), $args );
1944 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR
);
1947 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1950 * @param $limit array
1951 * @param $reason string
1952 * @param $cascade int
1953 * @param $expiry array
1956 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1957 return $this->mPage
->updateRestrictions( $limit, $reason, $cascade, $expiry );
1961 * @param $reason string
1962 * @param $suppress bool
1964 * @param $commit bool
1965 * @param $error string
1968 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1969 return $this->mPage
->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1977 * @param $resultDetails
1981 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User
$user = null ) {
1983 $user = is_null( $user ) ?
$wgUser : $user;
1984 return $this->mPage
->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1991 * @param $resultDetails
1992 * @param $guser User
1995 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser = null ) {
1997 $guser = is_null( $guser ) ?
$wgUser : $guser;
1998 return $this->mPage
->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
2002 * @param $hasHistory bool
2005 public function generateReason( &$hasHistory ) {
2006 return $this->mPage
->getAutoDeleteReason( $hasHistory );
2009 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
2014 public static function selectFields() {
2015 return WikiPage
::selectFields();
2019 * @param $title Title
2021 public static function onArticleCreate( $title ) {
2022 WikiPage
::onArticleCreate( $title );
2026 * @param $title Title
2028 public static function onArticleDelete( $title ) {
2029 WikiPage
::onArticleDelete( $title );
2033 * @param $title Title
2035 public static function onArticleEdit( $title ) {
2036 WikiPage
::onArticleEdit( $title );
2045 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2046 return WikiPage
::getAutosummary( $oldtext, $newtext, $flags );
2051 class PoolWorkArticleView
extends PoolCounterWork
{
2058 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2059 parent
::__construct( 'ArticleView', $key );
2060 $this->mArticle
= $article;
2061 $this->cacheable
= $useParserCache;
2062 $this->parserOptions
= $parserOptions;
2069 return $this->mArticle
->doViewParse();
2075 function getCachedWork() {
2078 $parserCache = ParserCache
::singleton();
2079 $this->mArticle
->mParserOutput
= $parserCache->get( $this->mArticle
, $this->parserOptions
);
2081 if ( $this->mArticle
->mParserOutput
!== false ) {
2082 wfDebug( __METHOD__
. ": showing contents parsed by someone else\n" );
2083 $wgOut->addParserOutput( $this->mArticle
->mParserOutput
);
2084 # Ensure that UI elements requiring revision ID have
2085 # the correct version information.
2086 $wgOut->setRevisionId( $this->mArticle
->getLatest() );
2095 function fallback() {
2096 return $this->mArticle
->tryDirtyCache();
2100 * @param $status Status
2102 function error( $status ) {
2105 $wgOut->clearHTML(); // for release() errors
2106 $wgOut->enableClientCache( false );
2107 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2109 $errortext = $status->getWikiText( false, 'view-pool-error' );
2110 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );