FU r98421: forgot to move mParserOptions field
[lhc/web/wiklou.git] / includes / Article.php
1 <?php
2 /**
3 * File for articles
4 * @file
5 */
6
7 /**
8 * Class for viewing MediaWiki article and history.
9 *
10 * This maintains WikiPage functions for backwards compatibility.
11 *
12 * @TODO: move and rewrite code to an Action class
13 *
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.
17 *
18 * @internal documentation reviewed 15 Mar 2010
19 */
20 class Article extends Page {
21 /**@{{
22 * @private
23 */
24
25 /**
26 * @var IContextSource
27 */
28 protected $mContext;
29
30 /**
31 * @var WikiPage
32 */
33 protected $mPage;
34
35 /**
36 * @protected
37 * @var ParserOptions: ParserOptions object for $wgUser articles
38 */
39 public $mParserOptions;
40
41 var $mContent; // !<
42 var $mContentLoaded = false; // !<
43 var $mOldId; // !<
44
45 /**
46 * @var Title
47 */
48 var $mRedirectedFrom = null;
49
50 /**
51 * @var mixed: boolean false or URL string
52 */
53 var $mRedirectUrl = false; // !<
54 var $mRevIdFetched = 0; // !<
55
56 /**
57 * @var Revision
58 */
59 var $mRevision = null;
60
61 /**
62 * @var ParserOutput
63 */
64 var $mParserOutput;
65
66 /**@}}*/
67
68 /**
69 * Constructor and clear the article
70 * @param $title Title Reference to a Title object.
71 * @param $oldId Integer revision ID, null to fetch from request, zero for current
72 */
73 public function __construct( Title $title, $oldId = null ) {
74 $this->mOldId = $oldId;
75 $this->mPage = $this->newPage( $title );
76 }
77
78 protected function newPage( Title $title ) {
79 return new WikiPage( $title );
80 }
81
82 /**
83 * Constructor from a page id
84 * @param $id Int article ID to load
85 */
86 public static function newFromID( $id ) {
87 $t = Title::newFromID( $id );
88 # @todo FIXME: Doesn't inherit right
89 return $t == null ? null : new self( $t );
90 # return $t == null ? null : new static( $t ); // PHP 5.3
91 }
92
93 /**
94 * Create an Article object of the appropriate class for the given page.
95 *
96 * @param $title Title
97 * @param $context IContextSource
98 * @return Article object
99 */
100 public static function newFromTitle( $title, IContextSource $context ) {
101 if ( NS_MEDIA == $title->getNamespace() ) {
102 // FIXME: where should this go?
103 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
104 }
105
106 $page = null;
107 wfRunHooks( 'ArticleFromTitle', array( &$title, &$page ) );
108 if ( !$page ) {
109 switch( $title->getNamespace() ) {
110 case NS_FILE:
111 $page = new ImagePage( $title );
112 break;
113 case NS_CATEGORY:
114 $page = new CategoryPage( $title );
115 break;
116 default:
117 $page = new Article( $title );
118 }
119 }
120 $page->setContext( $context );
121
122 return $page;
123 }
124
125 /**
126 * Tell the page view functions that this view was redirected
127 * from another page on the wiki.
128 * @param $from Title object.
129 */
130 public function setRedirectedFrom( Title $from ) {
131 $this->mRedirectedFrom = $from;
132 }
133
134 /**
135 * Get the title object of the article
136 * @return Title object of this page
137 */
138 public function getTitle() {
139 return $this->mPage->getTitle();
140 }
141
142 /**
143 * Clear the object
144 * @todo FIXME: Shouldn't this be public?
145 * @private
146 */
147 public function clear() {
148 $this->mContentLoaded = false;
149
150 $this->mRedirectedFrom = null; # Title object if set
151 $this->mRevIdFetched = 0;
152 $this->mRedirectUrl = false;
153
154 $this->mPage->clear();
155 }
156
157 /**
158 * Note that getContent/loadContent do not follow redirects anymore.
159 * If you need to fetch redirectable content easily, try
160 * the shortcut in Article::followRedirect()
161 *
162 * This function has side effects! Do not use this function if you
163 * only want the real revision text if any.
164 *
165 * @return Return the text of this revision
166 */
167 public function getContent() {
168 global $wgUser;
169
170 wfProfileIn( __METHOD__ );
171
172 if ( $this->mPage->getID() === 0 ) {
173 # If this is a MediaWiki:x message, then load the messages
174 # and return the message value for x.
175 if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
176 $text = $this->getTitle()->getDefaultMessageText();
177 if ( $text === false ) {
178 $text = '';
179 }
180 } else {
181 $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' );
182 }
183 wfProfileOut( __METHOD__ );
184
185 return $text;
186 } else {
187 $this->loadContent();
188 wfProfileOut( __METHOD__ );
189
190 return $this->mContent;
191 }
192 }
193
194 /**
195 * @return int The oldid of the article that is to be shown, 0 for the
196 * current revision
197 */
198 public function getOldID() {
199 if ( is_null( $this->mOldId ) ) {
200 $this->mOldId = $this->getOldIDFromRequest();
201 }
202
203 return $this->mOldId;
204 }
205
206 /**
207 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
208 *
209 * @return int The old id for the request
210 */
211 public function getOldIDFromRequest() {
212 global $wgRequest;
213
214 $this->mRedirectUrl = false;
215
216 $oldid = $wgRequest->getVal( 'oldid' );
217
218 if ( isset( $oldid ) ) {
219 $oldid = intval( $oldid );
220 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
221 $nextid = $this->getTitle()->getNextRevisionID( $oldid );
222 if ( $nextid ) {
223 $oldid = $nextid;
224 } else {
225 $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
226 }
227 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
228 $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
229 if ( $previd ) {
230 $oldid = $previd;
231 }
232 }
233 }
234
235 if ( !$oldid ) {
236 $oldid = 0;
237 }
238
239 return $oldid;
240 }
241
242 /**
243 * Load the revision (including text) into this object
244 */
245 function loadContent() {
246 if ( $this->mContentLoaded ) {
247 return;
248 }
249
250 wfProfileIn( __METHOD__ );
251
252 $this->fetchContent( $this->getOldID() );
253
254 wfProfileOut( __METHOD__ );
255 }
256
257 /**
258 * Get text of an article from database
259 * Does *NOT* follow redirects.
260 *
261 * @param $oldid Int: 0 for whatever the latest revision is
262 * @return mixed string containing article contents, or false if null
263 */
264 function fetchContent( $oldid = 0 ) {
265 if ( $this->mContentLoaded ) {
266 return $this->mContent;
267 }
268
269 # Pre-fill content with error message so that if something
270 # fails we'll have something telling us what we intended.
271 $t = $this->getTitle()->getPrefixedText();
272 $d = $oldid ? wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid ) : '';
273 $this->mContent = wfMsgNoTrans( 'missing-article', $t, $d ) ;
274
275 if ( $oldid ) {
276 $revision = Revision::newFromId( $oldid );
277 if ( !$revision ) {
278 wfDebug( __METHOD__ . " failed to retrieve specified revision, id $oldid\n" );
279 return false;
280 }
281 // Revision title doesn't match the page title given?
282 if ( $this->mPage->getID() != $revision->getPage() ) {
283 $function = array( get_class( $this->mPage ), 'newFromID' );
284 $this->mPage = call_user_func( $function, $revision->getPage() );
285 if ( !$this->mPage->getId() ) {
286 wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" );
287 return false;
288 }
289 }
290 } else {
291 if ( !$this->mPage->getLatest() ) {
292 wfDebug( __METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n" );
293 return false;
294 }
295
296 $revision = $this->mPage->getRevision();
297 if ( !$revision ) {
298 wfDebug( __METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n" );
299 return false;
300 }
301 }
302
303 // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
304 // We should instead work with the Revision object when we need it...
305 $this->mContent = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed
306
307 $this->mRevIdFetched = $revision->getId();
308 $this->mContentLoaded = true;
309 $this->mRevision =& $revision;
310
311 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
312
313 return $this->mContent;
314 }
315
316 /**
317 * No-op
318 * @deprecated since 1.18
319 */
320 public function forUpdate() {
321 wfDeprecated( __METHOD__ );
322 }
323
324 /**
325 * Returns true if the currently-referenced revision is the current edit
326 * to this page (and it exists).
327 * @return bool
328 */
329 public function isCurrent() {
330 # If no oldid, this is the current version.
331 if ( $this->getOldID() == 0 ) {
332 return true;
333 }
334
335 return $this->mPage->exists() && $this->mRevision && $this->mRevision->isCurrent();
336 }
337
338 /**
339 * Use this to fetch the rev ID used on page views
340 *
341 * @return int revision ID of last article revision
342 */
343 public function getRevIdFetched() {
344 if ( $this->mRevIdFetched ) {
345 return $this->mRevIdFetched;
346 } else {
347 return $this->mPage->getLatest();
348 }
349 }
350
351 /**
352 * This is the default action of the index.php entry point: just view the
353 * page of the given title.
354 */
355 public function view() {
356 global $wgUser, $wgOut, $wgRequest, $wgParser;
357 global $wgUseFileCache, $wgUseETag;
358
359 wfProfileIn( __METHOD__ );
360
361 # Get variables from query string
362 $oldid = $this->getOldID();
363
364 # getOldID may want us to redirect somewhere else
365 if ( $this->mRedirectUrl ) {
366 $wgOut->redirect( $this->mRedirectUrl );
367 wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
368 wfProfileOut( __METHOD__ );
369
370 return;
371 }
372
373 # Set page title (may be overridden by DISPLAYTITLE)
374 $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() );
375
376 # If we got diff in the query, we want to see a diff page instead of the article.
377 if ( $wgRequest->getCheck( 'diff' ) ) {
378 wfDebug( __METHOD__ . ": showing diff page\n" );
379 $this->showDiffPage();
380 wfProfileOut( __METHOD__ );
381
382 return;
383 }
384
385 $wgOut->setArticleFlag( true );
386 # Allow frames by default
387 $wgOut->allowClickjacking();
388
389 $parserCache = ParserCache::singleton();
390
391 $parserOptions = $this->getParserOptions();
392 # Render printable version, use printable version cache
393 if ( $wgOut->isPrintable() ) {
394 $parserOptions->setIsPrintable( true );
395 $parserOptions->setEditSection( false );
396 } elseif ( $wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
397 $parserOptions->setEditSection( false );
398 }
399
400 # Try client and file cache
401 if ( $oldid === 0 && $this->mPage->checkTouched() ) {
402 if ( $wgUseETag ) {
403 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
404 }
405
406 # Is it client cached?
407 if ( $wgOut->checkLastModified( $this->mPage->getTouched() ) ) {
408 wfDebug( __METHOD__ . ": done 304\n" );
409 wfProfileOut( __METHOD__ );
410
411 return;
412 # Try file cache
413 } elseif ( $wgUseFileCache && $this->tryFileCache() ) {
414 wfDebug( __METHOD__ . ": done file cache\n" );
415 # tell wgOut that output is taken care of
416 $wgOut->disable();
417 $this->mPage->viewUpdates();
418 wfProfileOut( __METHOD__ );
419
420 return;
421 }
422 }
423
424 if ( !$wgUseETag && !$this->getTitle()->quickUserCan( 'edit' ) ) {
425 $parserOptions->setEditSection( false );
426 }
427
428 # Should the parser cache be used?
429 $useParserCache = $this->useParserCache( $oldid );
430 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
431 if ( $wgUser->getStubThreshold() ) {
432 wfIncrStats( 'pcache_miss_stub' );
433 }
434
435 $wasRedirected = $this->showRedirectedFromHeader();
436 $this->showNamespaceHeader();
437
438 # Iterate through the possible ways of constructing the output text.
439 # Keep going until $outputDone is set, or we run out of things to do.
440 $pass = 0;
441 $outputDone = false;
442 $this->mParserOutput = false;
443
444 while ( !$outputDone && ++$pass ) {
445 switch( $pass ) {
446 case 1:
447 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$useParserCache ) );
448 break;
449 case 2:
450 # Try the parser cache
451 if ( $useParserCache ) {
452 $this->mParserOutput = $parserCache->get( $this, $parserOptions );
453
454 if ( $this->mParserOutput !== false ) {
455 wfDebug( __METHOD__ . ": showing parser cache contents\n" );
456 $wgOut->addParserOutput( $this->mParserOutput );
457 # Ensure that UI elements requiring revision ID have
458 # the correct version information.
459 $wgOut->setRevisionId( $this->mPage->getLatest() );
460 $outputDone = true;
461 # Preload timestamp to avoid a DB hit
462 if ( isset( $this->mParserOutput->mTimestamp ) ) {
463 $this->mPage->setTimestamp( $this->mParserOutput->mTimestamp );
464 }
465 }
466 }
467 break;
468 case 3:
469 $text = $this->getContent();
470 if ( $text === false || $this->mPage->getID() == 0 ) {
471 wfDebug( __METHOD__ . ": showing missing article\n" );
472 $this->showMissingArticle();
473 wfProfileOut( __METHOD__ );
474 return;
475 }
476
477 # Another whitelist check in case oldid is altering the title
478 if ( !$this->getTitle()->userCanRead() ) {
479 wfDebug( __METHOD__ . ": denied on secondary read check\n" );
480 $wgOut->loginToUse();
481 $wgOut->output();
482 $wgOut->disable();
483 wfProfileOut( __METHOD__ );
484 return;
485 }
486
487 # Are we looking at an old revision
488 if ( $oldid && !is_null( $this->mRevision ) ) {
489 $this->setOldSubtitle( $oldid );
490
491 if ( !$this->showDeletedRevisionHeader() ) {
492 wfDebug( __METHOD__ . ": cannot view deleted revision\n" );
493 wfProfileOut( __METHOD__ );
494 return;
495 }
496
497 # If this "old" version is the current, then try the parser cache...
498 if ( $oldid === $this->mPage->getLatest() && $this->useParserCache( false ) ) {
499 $this->mParserOutput = $parserCache->get( $this, $parserOptions );
500 if ( $this->mParserOutput ) {
501 wfDebug( __METHOD__ . ": showing parser cache for current rev permalink\n" );
502 $wgOut->addParserOutput( $this->mParserOutput );
503 $wgOut->setRevisionId( $this->mPage->getLatest() );
504 $outputDone = true;
505 break;
506 }
507 }
508 }
509
510 # Ensure that UI elements requiring revision ID have
511 # the correct version information.
512 $wgOut->setRevisionId( $this->getRevIdFetched() );
513
514 # Pages containing custom CSS or JavaScript get special treatment
515 if ( $this->getTitle()->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
516 wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
517 $this->showCssOrJsPage();
518 $outputDone = true;
519 } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
520 # Allow extensions do their own custom view for certain pages
521 $outputDone = true;
522 } else {
523 $rt = Title::newFromRedirectArray( $text );
524 if ( $rt ) {
525 wfDebug( __METHOD__ . ": showing redirect=no page\n" );
526 # Viewing a redirect page (e.g. with parameter redirect=no)
527 # Don't append the subtitle if this was an old revision
528 $wgOut->addHTML( $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ) );
529 # Parse just to get categories, displaytitle, etc.
530 $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(), $parserOptions );
531 $wgOut->addParserOutputNoText( $this->mParserOutput );
532 $outputDone = true;
533 }
534 }
535 break;
536 case 4:
537 # Run the parse, protected by a pool counter
538 wfDebug( __METHOD__ . ": doing uncached parse\n" );
539
540 $key = $parserCache->getKey( $this, $parserOptions );
541 $poolArticleView = new PoolWorkArticleView( $this, $key, $useParserCache, $parserOptions );
542
543 if ( !$poolArticleView->execute() ) {
544 # Connection or timeout error
545 wfProfileOut( __METHOD__ );
546 return;
547 } else {
548 $outputDone = true;
549 }
550 break;
551 # Should be unreachable, but just in case...
552 default:
553 break 2;
554 }
555 }
556
557 # Get the ParserOutput actually *displayed* here.
558 # Note that $this->mParserOutput is the *current* version output.
559 $pOutput = ( $outputDone instanceof ParserOutput )
560 ? $outputDone // object fetched by hook
561 : $this->mParserOutput;
562
563 # Adjust title for main page & pages with displaytitle
564 if ( $pOutput ) {
565 $this->adjustDisplayTitle( $pOutput );
566 }
567
568 # For the main page, overwrite the <title> element with the con-
569 # tents of 'pagetitle-view-mainpage' instead of the default (if
570 # that's not empty).
571 # This message always exists because it is in the i18n files
572 if ( $this->getTitle()->isMainPage() ) {
573 $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
574 if ( !$msg->isDisabled() ) {
575 $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
576 }
577 }
578
579 # Check for any __NOINDEX__ tags on the page using $pOutput
580 $policy = $this->getRobotPolicy( 'view', $pOutput );
581 $wgOut->setIndexPolicy( $policy['index'] );
582 $wgOut->setFollowPolicy( $policy['follow'] );
583
584 $this->showViewFooter();
585 $this->mPage->viewUpdates();
586
587 wfProfileOut( __METHOD__ );
588 }
589
590 /*
591 * Adjust title for pages with displaytitle, -{T|}- or language conversion
592 * @param $pOutput ParserOutput
593 */
594 public function adjustDisplayTitle( ParserOutput $pOutput ) {
595 global $wgOut;
596 # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
597 $titleText = $pOutput->getTitleText();
598 if ( strval( $titleText ) !== '' ) {
599 $wgOut->setPageTitle( $titleText );
600 }
601 }
602
603 /**
604 * Show a diff page according to current request variables. For use within
605 * Article::view() only, other callers should use the DifferenceEngine class.
606 */
607 public function showDiffPage() {
608 global $wgRequest, $wgUser;
609
610 $diff = $wgRequest->getVal( 'diff' );
611 $rcid = $wgRequest->getVal( 'rcid' );
612 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
613 $purge = $wgRequest->getVal( 'action' ) == 'purge';
614 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
615 $oldid = $this->getOldID();
616
617 $de = new DifferenceEngine( $this->getTitle(), $oldid, $diff, $rcid, $purge, $unhide );
618 // DifferenceEngine directly fetched the revision:
619 $this->mRevIdFetched = $de->mNewid;
620 $de->showDiffPage( $diffOnly );
621
622 if ( $diff == 0 || $diff == $this->mPage->getLatest() ) {
623 # Run view updates for current revision only
624 $this->mPage->viewUpdates();
625 }
626 }
627
628 /**
629 * Show a page view for a page formatted as CSS or JavaScript. To be called by
630 * Article::view() only.
631 *
632 * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
633 * page views.
634 */
635 protected function showCssOrJsPage() {
636 global $wgOut;
637
638 $dir = $this->getContext()->getLang()->getDir();
639 $lang = $this->getContext()->getLang()->getCode();
640
641 $wgOut->wrapWikiMsg( "<div id='mw-clearyourcache' lang='$lang' dir='$dir' class='mw-content-$dir'>\n$1\n</div>",
642 'clearyourcache' );
643
644 // Give hooks a chance to customise the output
645 if ( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
646 // Wrap the whole lot in a <pre> and don't parse
647 $m = array();
648 preg_match( '!\.(css|js)$!u', $this->getTitle()->getText(), $m );
649 $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
650 $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
651 $wgOut->addHTML( "\n</pre>\n" );
652 }
653 }
654
655 /**
656 * Get the robot policy to be used for the current view
657 * @param $action String the action= GET parameter
658 * @param $pOutput ParserOutput
659 * @return Array the policy that should be set
660 * TODO: actions other than 'view'
661 */
662 public function getRobotPolicy( $action, $pOutput ) {
663 global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
664 global $wgDefaultRobotPolicy, $wgRequest;
665
666 $ns = $this->getTitle()->getNamespace();
667
668 if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
669 # Don't index user and user talk pages for blocked users (bug 11443)
670 if ( !$this->getTitle()->isSubpage() ) {
671 if ( Block::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block ) {
672 return array(
673 'index' => 'noindex',
674 'follow' => 'nofollow'
675 );
676 }
677 }
678 }
679
680 if ( $this->mPage->getID() === 0 || $this->getOldID() ) {
681 # Non-articles (special pages etc), and old revisions
682 return array(
683 'index' => 'noindex',
684 'follow' => 'nofollow'
685 );
686 } elseif ( $wgOut->isPrintable() ) {
687 # Discourage indexing of printable versions, but encourage following
688 return array(
689 'index' => 'noindex',
690 'follow' => 'follow'
691 );
692 } elseif ( $wgRequest->getInt( 'curid' ) ) {
693 # For ?curid=x urls, disallow indexing
694 return array(
695 'index' => 'noindex',
696 'follow' => 'follow'
697 );
698 }
699
700 # Otherwise, construct the policy based on the various config variables.
701 $policy = self::formatRobotPolicy( $wgDefaultRobotPolicy );
702
703 if ( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
704 # Honour customised robot policies for this namespace
705 $policy = array_merge(
706 $policy,
707 self::formatRobotPolicy( $wgNamespaceRobotPolicies[$ns] )
708 );
709 }
710 if ( $this->getTitle()->canUseNoindex() && is_object( $pOutput ) && $pOutput->getIndexPolicy() ) {
711 # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
712 # a final sanity check that we have really got the parser output.
713 $policy = array_merge(
714 $policy,
715 array( 'index' => $pOutput->getIndexPolicy() )
716 );
717 }
718
719 if ( isset( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] ) ) {
720 # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
721 $policy = array_merge(
722 $policy,
723 self::formatRobotPolicy( $wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()] )
724 );
725 }
726
727 return $policy;
728 }
729
730 /**
731 * Converts a String robot policy into an associative array, to allow
732 * merging of several policies using array_merge().
733 * @param $policy Mixed, returns empty array on null/false/'', transparent
734 * to already-converted arrays, converts String.
735 * @return Array: 'index' => <indexpolicy>, 'follow' => <followpolicy>
736 */
737 public static function formatRobotPolicy( $policy ) {
738 if ( is_array( $policy ) ) {
739 return $policy;
740 } elseif ( !$policy ) {
741 return array();
742 }
743
744 $policy = explode( ',', $policy );
745 $policy = array_map( 'trim', $policy );
746
747 $arr = array();
748 foreach ( $policy as $var ) {
749 if ( in_array( $var, array( 'index', 'noindex' ) ) ) {
750 $arr['index'] = $var;
751 } elseif ( in_array( $var, array( 'follow', 'nofollow' ) ) ) {
752 $arr['follow'] = $var;
753 }
754 }
755
756 return $arr;
757 }
758
759 /**
760 * If this request is a redirect view, send "redirected from" subtitle to
761 * $wgOut. Returns true if the header was needed, false if this is not a
762 * redirect view. Handles both local and remote redirects.
763 *
764 * @return boolean
765 */
766 public function showRedirectedFromHeader() {
767 global $wgOut, $wgRequest, $wgRedirectSources;
768
769 $rdfrom = $wgRequest->getVal( 'rdfrom' );
770
771 if ( isset( $this->mRedirectedFrom ) ) {
772 // This is an internally redirected page view.
773 // We'll need a backlink to the source page for navigation.
774 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
775 $redir = Linker::link(
776 $this->mRedirectedFrom,
777 null,
778 array(),
779 array( 'redirect' => 'no' ),
780 array( 'known', 'noclasses' )
781 );
782
783 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
784 $wgOut->setSubtitle( $s );
785
786 // Set the fragment if one was specified in the redirect
787 if ( strval( $this->getTitle()->getFragment() ) != '' ) {
788 $fragment = Xml::escapeJsString( $this->getTitle()->getFragmentForURL() );
789 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
790 }
791
792 // Add a <link rel="canonical"> tag
793 $wgOut->addLink( array( 'rel' => 'canonical',
794 'href' => $this->getTitle()->getLocalURL() )
795 );
796
797 return true;
798 }
799 } elseif ( $rdfrom ) {
800 // This is an externally redirected view, from some other wiki.
801 // If it was reported from a trusted site, supply a backlink.
802 if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
803 $redir = Linker::makeExternalLink( $rdfrom, $rdfrom );
804 $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
805 $wgOut->setSubtitle( $s );
806
807 return true;
808 }
809 }
810
811 return false;
812 }
813
814 /**
815 * Show a header specific to the namespace currently being viewed, like
816 * [[MediaWiki:Talkpagetext]]. For Article::view().
817 */
818 public function showNamespaceHeader() {
819 global $wgOut;
820
821 if ( $this->getTitle()->isTalkPage() ) {
822 if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
823 $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
824 }
825 }
826 }
827
828 /**
829 * Show the footer section of an ordinary page view
830 */
831 public function showViewFooter() {
832 global $wgOut, $wgUseTrackbacks;
833
834 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
835 if ( $this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid( $this->getTitle()->getText() ) ) {
836 $wgOut->addWikiMsg( 'anontalkpagetext' );
837 }
838
839 # If we have been passed an &rcid= parameter, we want to give the user a
840 # chance to mark this new article as patrolled.
841 $this->showPatrolFooter();
842
843 # Trackbacks
844 if ( $wgUseTrackbacks ) {
845 $this->addTrackbacks();
846 }
847
848 wfRunHooks( 'ArticleViewFooter', array( $this ) );
849
850 }
851
852 /**
853 * If patrol is possible, output a patrol UI box. This is called from the
854 * footer section of ordinary page views. If patrol is not possible or not
855 * desired, does nothing.
856 */
857 public function showPatrolFooter() {
858 global $wgOut, $wgRequest, $wgUser;
859
860 $rcid = $wgRequest->getVal( 'rcid' );
861
862 if ( !$rcid || !$this->getTitle()->quickUserCan( 'patrol' ) ) {
863 return;
864 }
865
866 $token = $wgUser->editToken( $rcid );
867 $wgOut->preventClickjacking();
868
869 $wgOut->addHTML(
870 "<div class='patrollink'>" .
871 wfMsgHtml(
872 'markaspatrolledlink',
873 Linker::link(
874 $this->getTitle(),
875 wfMsgHtml( 'markaspatrolledtext' ),
876 array(),
877 array(
878 'action' => 'markpatrolled',
879 'rcid' => $rcid,
880 'token' => $token,
881 ),
882 array( 'known', 'noclasses' )
883 )
884 ) .
885 '</div>'
886 );
887 }
888
889 /**
890 * Show the error text for a missing article. For articles in the MediaWiki
891 * namespace, show the default message text. To be called from Article::view().
892 */
893 public function showMissingArticle() {
894 global $wgOut, $wgRequest, $wgUser;
895
896 # Show info in user (talk) namespace. Does the user exist? Is he blocked?
897 if ( $this->getTitle()->getNamespace() == NS_USER || $this->getTitle()->getNamespace() == NS_USER_TALK ) {
898 $parts = explode( '/', $this->getTitle()->getText() );
899 $rootPart = $parts[0];
900 $user = User::newFromName( $rootPart, false /* allow IP users*/ );
901 $ip = User::isIP( $rootPart );
902
903 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
904 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n\$1\n</div>",
905 array( 'userpage-userdoesnotexist-view', wfEscapeWikiText( $rootPart ) ) );
906 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
907 LogEventsList::showLogExtract(
908 $wgOut,
909 'block',
910 $user->getUserPage()->getPrefixedText(),
911 '',
912 array(
913 'lim' => 1,
914 'showIfEmpty' => false,
915 'msgKey' => array(
916 'blocked-notice-logextract',
917 $user->getName() # Support GENDER in notice
918 )
919 )
920 );
921 }
922 }
923
924 wfRunHooks( 'ShowMissingArticle', array( $this ) );
925
926 # Show delete and move logs
927 LogEventsList::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->getTitle()->getPrefixedText(), '',
928 array( 'lim' => 10,
929 'conds' => array( "log_action != 'revision'" ),
930 'showIfEmpty' => false,
931 'msgKey' => array( 'moveddeleted-notice' ) )
932 );
933
934 # Show error message
935 $oldid = $this->getOldID();
936 if ( $oldid ) {
937 $text = wfMsgNoTrans( 'missing-article',
938 $this->getTitle()->getPrefixedText(),
939 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
940 } elseif ( $this->getTitle()->getNamespace() === NS_MEDIAWIKI ) {
941 // Use the default message text
942 $text = $this->getTitle()->getDefaultMessageText();
943 } else {
944 $createErrors = $this->getTitle()->getUserPermissionsErrors( 'create', $wgUser );
945 $editErrors = $this->getTitle()->getUserPermissionsErrors( 'edit', $wgUser );
946 $errors = array_merge( $createErrors, $editErrors );
947
948 if ( !count( $errors ) ) {
949 $text = wfMsgNoTrans( 'noarticletext' );
950 } else {
951 $text = wfMsgNoTrans( 'noarticletext-nopermission' );
952 }
953 }
954 $text = "<div class='noarticletext'>\n$text\n</div>";
955
956 if ( !$this->mPage->hasViewableContent() ) {
957 // If there's no backing content, send a 404 Not Found
958 // for better machine handling of broken links.
959 $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
960 }
961
962 $wgOut->addWikiText( $text );
963 }
964
965 /**
966 * If the revision requested for view is deleted, check permissions.
967 * Send either an error message or a warning header to $wgOut.
968 *
969 * @return boolean true if the view is allowed, false if not.
970 */
971 public function showDeletedRevisionHeader() {
972 global $wgOut, $wgRequest;
973
974 if ( !$this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
975 // Not deleted
976 return true;
977 }
978
979 // If the user is not allowed to see it...
980 if ( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
981 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
982 'rev-deleted-text-permission' );
983
984 return false;
985 // If the user needs to confirm that they want to see it...
986 } elseif ( $wgRequest->getInt( 'unhide' ) != 1 ) {
987 # Give explanation and add a link to view the revision...
988 $oldid = intval( $this->getOldID() );
989 $link = $this->getTitle()->getFullUrl( "oldid={$oldid}&unhide=1" );
990 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
991 'rev-suppressed-text-unhide' : 'rev-deleted-text-unhide';
992 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n",
993 array( $msg, $link ) );
994
995 return false;
996 // We are allowed to see...
997 } else {
998 $msg = $this->mRevision->isDeleted( Revision::DELETED_RESTRICTED ) ?
999 'rev-suppressed-text-view' : 'rev-deleted-text-view';
1000 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", $msg );
1001
1002 return true;
1003 }
1004 }
1005
1006 /**
1007 * Execute the uncached parse for action=view
1008 */
1009 public function doViewParse() {
1010 global $wgOut;
1011
1012 $oldid = $this->getOldID();
1013 $parserOptions = $this->getParserOptions();
1014
1015 # Render printable version, use printable version cache
1016 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
1017
1018 # Don't show section-edit links on old revisions... this way lies madness.
1019 if ( !$this->isCurrent() || $wgOut->isPrintable() || !$this->getTitle()->quickUserCan( 'edit' ) ) {
1020 $parserOptions->setEditSection( false );
1021 }
1022
1023 $useParserCache = $this->useParserCache( $oldid );
1024 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
1025
1026 return true;
1027 }
1028
1029 /**
1030 * Try to fetch an expired entry from the parser cache. If it is present,
1031 * output it and return true. If it is not present, output nothing and
1032 * return false. This is used as a callback function for
1033 * PoolCounter::executeProtected().
1034 *
1035 * @return boolean
1036 */
1037 public function tryDirtyCache() {
1038 global $wgOut;
1039 $parserCache = ParserCache::singleton();
1040 $options = $this->getParserOptions();
1041
1042 if ( $wgOut->isPrintable() ) {
1043 $options->setIsPrintable( true );
1044 $options->setEditSection( false );
1045 }
1046
1047 $output = $parserCache->getDirty( $this, $options );
1048
1049 if ( $output ) {
1050 wfDebug( __METHOD__ . ": sending dirty output\n" );
1051 wfDebugLog( 'dirty', "dirty output " . $parserCache->getKey( $this, $options ) . "\n" );
1052 $wgOut->setSquidMaxage( 0 );
1053 $this->mParserOutput = $output;
1054 $wgOut->addParserOutput( $output );
1055 $wgOut->addHTML( "<!-- parser cache is expired, sending anyway due to pool overload-->\n" );
1056
1057 return true;
1058 } else {
1059 wfDebugLog( 'dirty', "dirty missing\n" );
1060 wfDebug( __METHOD__ . ": no dirty cache\n" );
1061
1062 return false;
1063 }
1064 }
1065
1066 /**
1067 * View redirect
1068 *
1069 * @param $target Title|Array of destination(s) to redirect
1070 * @param $appendSubtitle Boolean [optional]
1071 * @param $forceKnown Boolean: should the image be shown as a bluelink regardless of existence?
1072 * @return string containing HMTL with redirect link
1073 */
1074 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1075 global $wgOut, $wgStylePath;
1076
1077 if ( !is_array( $target ) ) {
1078 $target = array( $target );
1079 }
1080
1081 $lang = $this->getTitle()->getPageLanguage();
1082 $imageDir = $lang->getDir();
1083
1084 if ( $appendSubtitle ) {
1085 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
1086 }
1087
1088 // the loop prepends the arrow image before the link, so the first case needs to be outside
1089 $title = array_shift( $target );
1090
1091 if ( $forceKnown ) {
1092 $link = Linker::linkKnown( $title, htmlspecialchars( $title->getFullText() ) );
1093 } else {
1094 $link = Linker::link( $title, htmlspecialchars( $title->getFullText() ) );
1095 }
1096
1097 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1098 $alt = $lang->isRTL() ? '←' : '→';
1099 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
1100 foreach ( $target as $rt ) {
1101 $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
1102 if ( $forceKnown ) {
1103 $link .= Linker::linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) );
1104 } else {
1105 $link .= Linker::link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) );
1106 }
1107 }
1108
1109 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
1110 return '<div class="redirectMsg">' .
1111 Html::element( 'img', array( 'src' => $imageUrl, 'alt' => '#REDIRECT' ) ) .
1112 '<span class="redirectText">' . $link . '</span></div>';
1113 }
1114
1115 /**
1116 * Builds trackback links for article display if $wgUseTrackbacks is set to true
1117 */
1118 public function addTrackbacks() {
1119 global $wgOut;
1120
1121 $dbr = wfGetDB( DB_SLAVE );
1122 $tbs = $dbr->select( 'trackbacks',
1123 array( 'tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name' ),
1124 array( 'tb_page' => $this->mPage->getID() )
1125 );
1126
1127 if ( !$dbr->numRows( $tbs ) ) {
1128 return;
1129 }
1130
1131 $wgOut->preventClickjacking();
1132
1133 $tbtext = "";
1134 foreach ( $tbs as $o ) {
1135 $rmvtxt = "";
1136
1137 if ( $this->getContext()->getUser()->isAllowed( 'trackback' ) ) {
1138 $delurl = $this->getTitle()->getFullURL( "action=deletetrackback&tbid=" .
1139 $o->tb_id . "&token=" . urlencode( $this->getContext()->getUser()->editToken() ) );
1140 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
1141 }
1142
1143 $tbtext .= "\n";
1144 $tbtext .= wfMsgNoTrans( strlen( $o->tb_ex ) ? 'trackbackexcerpt' : 'trackback',
1145 $o->tb_title,
1146 $o->tb_url,
1147 $o->tb_ex,
1148 $o->tb_name,
1149 $rmvtxt );
1150 }
1151
1152 $wgOut->wrapWikiMsg( "<div id='mw_trackbacks'>\n$1\n</div>\n", array( 'trackbackbox', $tbtext ) );
1153 }
1154
1155 /**
1156 * Removes trackback record for current article from trackbacks table
1157 * @deprecated since 1.18
1158 */
1159 public function deletetrackback() {
1160 return Action::factory( 'deletetrackback', $this )->show();
1161 }
1162
1163 /**
1164 * Handle action=render
1165 */
1166
1167 public function render() {
1168 global $wgOut;
1169
1170 $wgOut->setArticleBodyOnly( true );
1171 $this->view();
1172 }
1173
1174 /**
1175 * Handle action=purge
1176 */
1177 public function purge() {
1178 return Action::factory( 'purge', $this )->show();
1179 }
1180
1181 /**
1182 * Mark this particular edit/page as patrolled
1183 * @deprecated since 1.18
1184 */
1185 public function markpatrolled() {
1186 Action::factory( 'markpatrolled', $this )->show();
1187 }
1188
1189 /**
1190 * User-interface handler for the "watch" action.
1191 * Requires Request to pass a token as of 1.18.
1192 * @deprecated since 1.18
1193 */
1194 public function watch() {
1195 Action::factory( 'watch', $this )->show();
1196 }
1197
1198 /**
1199 * Add this page to $wgUser's watchlist
1200 *
1201 * This is safe to be called multiple times
1202 *
1203 * @return bool true on successful watch operation
1204 * @deprecated since 1.18
1205 */
1206 public function doWatch() {
1207 global $wgUser;
1208 return WatchAction::doWatch( $this->getTitle(), $wgUser );
1209 }
1210
1211 /**
1212 * User interface handler for the "unwatch" action.
1213 * Requires Request to pass a token as of 1.18.
1214 * @deprecated since 1.18
1215 */
1216 public function unwatch() {
1217 Action::factory( 'unwatch', $this )->show();
1218 }
1219
1220 /**
1221 * Stop watching a page
1222 * @return bool true on successful unwatch
1223 * @deprecated since 1.18
1224 */
1225 public function doUnwatch() {
1226 global $wgUser;
1227 return WatchAction::doUnwatch( $this->getTitle(), $wgUser );
1228 }
1229
1230 /**
1231 * action=protect handler
1232 */
1233 public function protect() {
1234 $form = new ProtectionForm( $this );
1235 $form->execute();
1236 }
1237
1238 /**
1239 * action=unprotect handler (alias)
1240 */
1241 public function unprotect() {
1242 $this->protect();
1243 }
1244
1245 /**
1246 * Info about this page
1247 * Called for ?action=info when $wgAllowPageInfo is on.
1248 */
1249 public function info() {
1250 Action::factory( 'info', $this )->show();
1251 }
1252
1253 /**
1254 * Overriden by ImagePage class, only present here to avoid a fatal error
1255 * Called for ?action=revert
1256 */
1257 public function revert() {
1258 Action::factory( 'revert', $this )->show();
1259 }
1260
1261 /**
1262 * User interface for rollback operations
1263 */
1264 public function rollback() {
1265 Action::factory( 'rollback', $this )->show();
1266 }
1267
1268 /**
1269 * Output a redirect back to the article.
1270 * This is typically used after an edit.
1271 *
1272 * @deprecated in 1.18; call $wgOut->redirect() directly
1273 * @param $noRedir Boolean: add redirect=no
1274 * @param $sectionAnchor String: section to redirect to, including "#"
1275 * @param $extraQuery String: extra query params
1276 */
1277 public function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
1278 wfDeprecated( __METHOD__ );
1279 global $wgOut;
1280
1281 if ( $noRedir ) {
1282 $query = 'redirect=no';
1283 if ( $extraQuery )
1284 $query .= "&$extraQuery";
1285 } else {
1286 $query = $extraQuery;
1287 }
1288
1289 $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
1290 }
1291
1292 /**
1293 * UI entry point for page deletion
1294 */
1295 public function delete() {
1296 global $wgOut, $wgRequest;
1297
1298 $confirm = $wgRequest->wasPosted() &&
1299 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1300
1301 $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1302 $this->DeleteReason = $wgRequest->getText( 'wpReason' );
1303
1304 $reason = $this->DeleteReasonList;
1305
1306 if ( $reason != 'other' && $this->DeleteReason != '' ) {
1307 // Entry from drop down menu + additional comment
1308 $reason .= wfMsgForContent( 'colon-separator' ) . $this->DeleteReason;
1309 } elseif ( $reason == 'other' ) {
1310 $reason = $this->DeleteReason;
1311 }
1312
1313 # Flag to hide all contents of the archived revisions
1314 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
1315
1316 # This code desperately needs to be totally rewritten
1317
1318 # Read-only check...
1319 if ( wfReadOnly() ) {
1320 $wgOut->readOnlyPage();
1321
1322 return;
1323 }
1324
1325 # Check permissions
1326 $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1327
1328 if ( count( $permission_errors ) > 0 ) {
1329 $wgOut->showPermissionsErrorPage( $permission_errors );
1330
1331 return;
1332 }
1333
1334 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
1335
1336 # Better double-check that it hasn't been deleted yet!
1337 $dbw = wfGetDB( DB_MASTER );
1338 $conds = $this->getTitle()->pageCond();
1339 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
1340 if ( $latest === false ) {
1341 $wgOut->showFatalError(
1342 Html::rawElement(
1343 'div',
1344 array( 'class' => 'error mw-error-cannotdelete' ),
1345 wfMsgExt( 'cannotdelete', array( 'parse' ),
1346 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1347 )
1348 );
1349 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
1350 LogEventsList::showLogExtract(
1351 $wgOut,
1352 'delete',
1353 $this->getTitle()->getPrefixedText()
1354 );
1355
1356 return;
1357 }
1358
1359 # Hack for big sites
1360 $bigHistory = $this->mPage->isBigDeletion();
1361 if ( $bigHistory && !$this->getTitle()->userCan( 'bigdelete' ) ) {
1362 global $wgLang, $wgDeleteRevisionsLimit;
1363
1364 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1365 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1366
1367 return;
1368 }
1369
1370 if ( $confirm ) {
1371 $this->doDelete( $reason, $suppress );
1372
1373 if ( $wgRequest->getCheck( 'wpWatch' ) && $this->getContext()->getUser()->isLoggedIn() ) {
1374 $this->doWatch();
1375 } elseif ( $this->getTitle()->userIsWatching() ) {
1376 $this->doUnwatch();
1377 }
1378
1379 return;
1380 }
1381
1382 // Generate deletion reason
1383 $hasHistory = false;
1384 if ( !$reason ) {
1385 $reason = $this->generateReason( $hasHistory );
1386 }
1387
1388 // If the page has a history, insert a warning
1389 if ( $hasHistory && !$confirm ) {
1390 global $wgLang;
1391
1392 $revisions = $this->mPage->estimateRevisionCount();
1393 // @todo FIXME: i18n issue/patchwork message
1394 $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
1395 wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
1396 wfMsgHtml( 'word-separator' ) . Linker::link( $this->getTitle(),
1397 wfMsgHtml( 'history' ),
1398 array( 'rel' => 'archives' ),
1399 array( 'action' => 'history' ) ) .
1400 '</strong>'
1401 );
1402
1403 if ( $bigHistory ) {
1404 global $wgDeleteRevisionsLimit;
1405 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n",
1406 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
1407 }
1408 }
1409
1410 return $this->confirmDelete( $reason );
1411 }
1412
1413 /**
1414 * Output deletion confirmation dialog
1415 * @todo FIXME: Move to another file?
1416 * @param $reason String: prefilled reason
1417 */
1418 public function confirmDelete( $reason ) {
1419 global $wgOut;
1420
1421 wfDebug( "Article::confirmDelete\n" );
1422
1423 $deleteBackLink = Linker::linkKnown( $this->getTitle() );
1424 $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
1425 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1426 $wgOut->addWikiMsg( 'confirmdeletetext' );
1427
1428 wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
1429
1430 if ( $this->getContext()->getUser()->isAllowed( 'suppressrevision' ) ) {
1431 $suppress = "<tr id=\"wpDeleteSuppressRow\">
1432 <td></td>
1433 <td class='mw-input'><strong>" .
1434 Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
1435 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
1436 "</strong></td>
1437 </tr>";
1438 } else {
1439 $suppress = '';
1440 }
1441 $checkWatch = $this->getContext()->getUser()->getBoolOption( 'watchdeletion' ) || $this->getTitle()->userIsWatching();
1442
1443 $form = Xml::openElement( 'form', array( 'method' => 'post',
1444 'action' => $this->getTitle()->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
1445 Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
1446 Xml::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
1447 Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
1448 "<tr id=\"wpDeleteReasonListRow\">
1449 <td class='mw-label'>" .
1450 Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
1451 "</td>
1452 <td class='mw-input'>" .
1453 Xml::listDropDown( 'wpDeleteReasonList',
1454 wfMsgForContent( 'deletereason-dropdown' ),
1455 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
1456 "</td>
1457 </tr>
1458 <tr id=\"wpDeleteReasonRow\">
1459 <td class='mw-label'>" .
1460 Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
1461 "</td>
1462 <td class='mw-input'>" .
1463 Html::input( 'wpReason', $reason, 'text', array(
1464 'size' => '60',
1465 'maxlength' => '255',
1466 'tabindex' => '2',
1467 'id' => 'wpReason',
1468 'autofocus'
1469 ) ) .
1470 "</td>
1471 </tr>";
1472
1473 # Disallow watching if user is not logged in
1474 if ( $this->getContext()->getUser()->isLoggedIn() ) {
1475 $form .= "
1476 <tr>
1477 <td></td>
1478 <td class='mw-input'>" .
1479 Xml::checkLabel( wfMsg( 'watchthis' ),
1480 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
1481 "</td>
1482 </tr>";
1483 }
1484
1485 $form .= "
1486 $suppress
1487 <tr>
1488 <td></td>
1489 <td class='mw-submit'>" .
1490 Xml::submitButton( wfMsg( 'deletepage' ),
1491 array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
1492 "</td>
1493 </tr>" .
1494 Xml::closeElement( 'table' ) .
1495 Xml::closeElement( 'fieldset' ) .
1496 Html::hidden( 'wpEditToken', $this->getContext()->getUser()->editToken() ) .
1497 Xml::closeElement( 'form' );
1498
1499 if ( $this->getContext()->getUser()->isAllowed( 'editinterface' ) ) {
1500 $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
1501 $link = Linker::link(
1502 $title,
1503 wfMsgHtml( 'delete-edit-reasonlist' ),
1504 array(),
1505 array( 'action' => 'edit' )
1506 );
1507 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
1508 }
1509
1510 $wgOut->addHTML( $form );
1511 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
1512 LogEventsList::showLogExtract( $wgOut, 'delete',
1513 $this->getTitle()->getPrefixedText()
1514 );
1515 }
1516
1517 /**
1518 * Perform a deletion and output success or failure messages
1519 */
1520 public function doDelete( $reason, $suppress = false ) {
1521 global $wgOut;
1522
1523 $id = $this->getTitle()->getArticleID( Title::GAID_FOR_UPDATE );
1524
1525 $error = '';
1526 if ( $this->mPage->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
1527 $deleted = $this->getTitle()->getPrefixedText();
1528
1529 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1530 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1531
1532 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
1533
1534 $wgOut->addWikiMsg( 'deletedtext', wfEscapeWikiText( $deleted ), $loglink );
1535 $wgOut->returnToMain( false );
1536 } else {
1537 if ( $error == '' ) {
1538 $wgOut->showFatalError(
1539 Html::rawElement(
1540 'div',
1541 array( 'class' => 'error mw-error-cannotdelete' ),
1542 wfMsgExt( 'cannotdelete', array( 'parse' ),
1543 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) )
1544 )
1545 );
1546
1547 $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
1548
1549 LogEventsList::showLogExtract(
1550 $wgOut,
1551 'delete',
1552 $this->getTitle()->getPrefixedText()
1553 );
1554 } else {
1555 $wgOut->showFatalError( $error );
1556 }
1557 }
1558 }
1559
1560 /**
1561 * Generate the navigation links when browsing through an article revisions
1562 * It shows the information as:
1563 * Revision as of \<date\>; view current revision
1564 * \<- Previous version | Next Version -\>
1565 *
1566 * @param $oldid String: revision ID of this article revision
1567 */
1568 public function setOldSubtitle( $oldid = 0 ) {
1569 global $wgLang, $wgOut, $wgUser, $wgRequest;
1570
1571 if ( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) {
1572 return;
1573 }
1574
1575 $unhide = $wgRequest->getInt( 'unhide' ) == 1;
1576
1577 # Cascade unhide param in links for easy deletion browsing
1578 $extraParams = array();
1579 if ( $wgRequest->getVal( 'unhide' ) ) {
1580 $extraParams['unhide'] = 1;
1581 }
1582
1583 $revision = Revision::newFromId( $oldid );
1584 $timestamp = $revision->getTimestamp();
1585
1586 $current = ( $oldid == $this->mPage->getLatest() );
1587 $td = $wgLang->timeanddate( $timestamp, true );
1588 $tddate = $wgLang->date( $timestamp, true );
1589 $tdtime = $wgLang->time( $timestamp, true );
1590
1591 $lnk = $current
1592 ? wfMsgHtml( 'currentrevisionlink' )
1593 : Linker::link(
1594 $this->getTitle(),
1595 wfMsgHtml( 'currentrevisionlink' ),
1596 array(),
1597 $extraParams,
1598 array( 'known', 'noclasses' )
1599 );
1600 $curdiff = $current
1601 ? wfMsgHtml( 'diff' )
1602 : Linker::link(
1603 $this->getTitle(),
1604 wfMsgHtml( 'diff' ),
1605 array(),
1606 array(
1607 'diff' => 'cur',
1608 'oldid' => $oldid
1609 ) + $extraParams,
1610 array( 'known', 'noclasses' )
1611 );
1612 $prev = $this->getTitle()->getPreviousRevisionID( $oldid ) ;
1613 $prevlink = $prev
1614 ? Linker::link(
1615 $this->getTitle(),
1616 wfMsgHtml( 'previousrevision' ),
1617 array(),
1618 array(
1619 'direction' => 'prev',
1620 'oldid' => $oldid
1621 ) + $extraParams,
1622 array( 'known', 'noclasses' )
1623 )
1624 : wfMsgHtml( 'previousrevision' );
1625 $prevdiff = $prev
1626 ? Linker::link(
1627 $this->getTitle(),
1628 wfMsgHtml( 'diff' ),
1629 array(),
1630 array(
1631 'diff' => 'prev',
1632 'oldid' => $oldid
1633 ) + $extraParams,
1634 array( 'known', 'noclasses' )
1635 )
1636 : wfMsgHtml( 'diff' );
1637 $nextlink = $current
1638 ? wfMsgHtml( 'nextrevision' )
1639 : Linker::link(
1640 $this->getTitle(),
1641 wfMsgHtml( 'nextrevision' ),
1642 array(),
1643 array(
1644 'direction' => 'next',
1645 'oldid' => $oldid
1646 ) + $extraParams,
1647 array( 'known', 'noclasses' )
1648 );
1649 $nextdiff = $current
1650 ? wfMsgHtml( 'diff' )
1651 : Linker::link(
1652 $this->getTitle(),
1653 wfMsgHtml( 'diff' ),
1654 array(),
1655 array(
1656 'diff' => 'next',
1657 'oldid' => $oldid
1658 ) + $extraParams,
1659 array( 'known', 'noclasses' )
1660 );
1661
1662 $cdel = '';
1663
1664 // User can delete revisions or view deleted revisions...
1665 $canHide = $wgUser->isAllowed( 'deleterevision' );
1666 if ( $canHide || ( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1667 if ( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
1668 $cdel = Linker::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1669 } else {
1670 $query = array(
1671 'type' => 'revision',
1672 'target' => $this->getTitle()->getPrefixedDbkey(),
1673 'ids' => $oldid
1674 );
1675 $cdel = Linker::revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
1676 }
1677 $cdel .= ' ';
1678 }
1679
1680 # Show user links if allowed to see them. If hidden, then show them only if requested...
1681 $userlinks = Linker::revUserTools( $revision, !$unhide );
1682
1683 $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
1684 ? 'revision-info-current'
1685 : 'revision-info';
1686
1687 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
1688 wfMsgExt(
1689 $infomsg,
1690 array( 'parseinline', 'replaceafter' ),
1691 $td,
1692 $userlinks,
1693 $revision->getID(),
1694 $tddate,
1695 $tdtime,
1696 $revision->getUser()
1697 ) .
1698 "</div>\n" .
1699 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsgExt( 'revision-nav', array( 'escapenoentities', 'parsemag', 'replaceafter' ),
1700 $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
1701
1702 $wgOut->setSubtitle( $r );
1703 }
1704
1705 /* Caching functions */
1706
1707 /**
1708 * checkLastModified returns true if it has taken care of all
1709 * output to the client that is necessary for this request.
1710 * (that is, it has sent a cached version of the page)
1711 *
1712 * @return boolean true if cached version send, false otherwise
1713 */
1714 protected function tryFileCache() {
1715 static $called = false;
1716
1717 if ( $called ) {
1718 wfDebug( "Article::tryFileCache(): called twice!?\n" );
1719 return false;
1720 }
1721
1722 $called = true;
1723 if ( $this->isFileCacheable() ) {
1724 $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'view' );
1725 if ( $cache->isCacheGood( $this->mPage->getTouched() ) ) {
1726 wfDebug( "Article::tryFileCache(): about to load file\n" );
1727 $cache->loadFromFileCache( $this->getContext() );
1728 return true;
1729 } else {
1730 wfDebug( "Article::tryFileCache(): starting buffer\n" );
1731 ob_start( array( &$cache, 'saveToFileCache' ) );
1732 }
1733 } else {
1734 wfDebug( "Article::tryFileCache(): not cacheable\n" );
1735 }
1736
1737 return false;
1738 }
1739
1740 /**
1741 * Check if the page can be cached
1742 * @return bool
1743 */
1744 public function isFileCacheable() {
1745 $cacheable = false;
1746
1747 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
1748 $cacheable = $this->mPage->getID()
1749 && !$this->mRedirectedFrom && !$this->getTitle()->isRedirect();
1750 // Extension may have reason to disable file caching on some pages.
1751 if ( $cacheable ) {
1752 $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
1753 }
1754 }
1755
1756 return $cacheable;
1757 }
1758
1759 /**#@-*/
1760
1761 /**
1762 * Add the primary page-view wikitext to the output buffer
1763 * Saves the text into the parser cache if possible.
1764 * Updates templatelinks if it is out of date.
1765 *
1766 * @param $text String
1767 * @param $cache Boolean
1768 * @param $parserOptions mixed ParserOptions object, or boolean false
1769 */
1770 public function outputWikiText( $text, $cache = true, $parserOptions = false ) {
1771 global $wgOut;
1772
1773 $this->mParserOutput = $this->getOutputFromWikitext( $text, $cache, $parserOptions );
1774
1775 $this->doCascadeProtectionUpdates( $this->mParserOutput );
1776
1777 $wgOut->addParserOutput( $this->mParserOutput );
1778 }
1779
1780 /**
1781 * Lightweight method to get the parser output for a page, checking the parser cache
1782 * and so on. Doesn't consider most of the stuff that WikiPage::view is forced to
1783 * consider, so it's not appropriate to use there.
1784 *
1785 * @since 1.16 (r52326) for LiquidThreads
1786 *
1787 * @param $oldid mixed integer Revision ID or null
1788 * @param $user User The relevant user
1789 * @return ParserOutput or false if the given revsion ID is not found
1790 */
1791 public function getParserOutput( $oldid = null, User $user = null ) {
1792 global $wgEnableParserCache, $wgUser;
1793 $user = is_null( $user ) ? $wgUser : $user;
1794
1795 wfProfileIn( __METHOD__ );
1796 // Should the parser cache be used?
1797 $useParserCache = $wgEnableParserCache &&
1798 $user->getStubThreshold() == 0 &&
1799 $this->mPage->exists() &&
1800 $oldid === null;
1801
1802 wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
1803
1804 if ( $user->getStubThreshold() ) {
1805 wfIncrStats( 'pcache_miss_stub' );
1806 }
1807
1808 if ( $useParserCache ) {
1809 $options = $this->mPage->makeParserOptions( $user );
1810 $parserOutput = ParserCache::singleton()->get( $this, $options );
1811 if ( $parserOutput !== false ) {
1812 wfProfileOut( __METHOD__ );
1813 return $parserOutput;
1814 }
1815 }
1816
1817 // Cache miss; parse and output it.
1818 if ( $oldid === null ) {
1819 $text = $this->mPage->getRawText();
1820 } else {
1821 $rev = Revision::newFromTitle( $this->getTitle(), $oldid );
1822 if ( $rev === null ) {
1823 wfProfileOut( __METHOD__ );
1824 return false;
1825 }
1826 $text = $rev->getText();
1827 }
1828
1829 $output = $this->getOutputFromWikitext( $text, $useParserCache );
1830 wfProfileOut( __METHOD__ );
1831 return $output;
1832 }
1833
1834 /**
1835 * This does all the heavy lifting for outputWikitext, except it returns the parser
1836 * output instead of sending it straight to $wgOut. Makes things nice and simple for,
1837 * say, embedding thread pages within a discussion system (LiquidThreads)
1838 *
1839 * @param $text string
1840 * @param $cache boolean
1841 * @param $parserOptions parsing options, defaults to false
1842 * @return ParserOutput
1843 */
1844 public function getOutputFromWikitext( $text, $cache = true, $parserOptions = false ) {
1845 global $wgParser, $wgEnableParserCache, $wgUseFileCache;
1846
1847 if ( !$parserOptions ) {
1848 $parserOptions = $this->getParserOptions();
1849 }
1850
1851 $time = - wfTime();
1852 $this->mParserOutput = $wgParser->parse( $text, $this->getTitle(),
1853 $parserOptions, true, true, $this->getRevIdFetched() );
1854 $time += wfTime();
1855
1856 # Timing hack
1857 if ( $time > 3 ) {
1858 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
1859 $this->getTitle()->getPrefixedDBkey() ) );
1860 }
1861
1862 if ( $wgEnableParserCache && $cache && $this->mParserOutput->isCacheable() ) {
1863 $parserCache = ParserCache::singleton();
1864 $parserCache->save( $this->mParserOutput, $this, $parserOptions );
1865 }
1866
1867 // Make sure file cache is not used on uncacheable content.
1868 // Output that has magic words in it can still use the parser cache
1869 // (if enabled), though it will generally expire sooner.
1870 if ( !$this->mParserOutput->isCacheable() || $this->mParserOutput->containsOldMagic() ) {
1871 $wgUseFileCache = false;
1872 }
1873
1874 if ( $this->isCurrent() ) {
1875 $this->mPage->doCascadeProtectionUpdates( $this->mParserOutput );
1876 }
1877
1878 return $this->mParserOutput;
1879 }
1880
1881 /**
1882 * Get parser options suitable for rendering the primary article wikitext
1883 * @return mixed ParserOptions object or boolean false
1884 */
1885 public function getParserOptions() {
1886 global $wgUser;
1887 if ( !$this->mParserOptions ) {
1888 $this->mParserOptions = $this->mPage->makeParserOptions( $wgUser );
1889 }
1890 // Clone to allow modifications of the return value without affecting cache
1891 return clone $this->mParserOptions;
1892 }
1893
1894 /**
1895 * Sets the context this Article is executed in
1896 *
1897 * @param $context IContextSource
1898 * @since 1.18
1899 */
1900 public function setContext( $context ) {
1901 $this->mContext = $context;
1902 }
1903
1904 /**
1905 * Gets the context this Article is executed in
1906 *
1907 * @return IContextSource
1908 * @since 1.18
1909 */
1910 public function getContext() {
1911 if ( $this->mContext instanceof IContextSource ) {
1912 return $this->mContext;
1913 } else {
1914 wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
1915 return RequestContext::getMain();
1916 }
1917 }
1918
1919 /**
1920 * Use PHP's magic __get handler to handle accessing of
1921 * raw WikiPage fields for backwards compatibility.
1922 *
1923 * @param $fname String Field name
1924 */
1925 public function __get( $fname ) {
1926 if ( property_exists( $this->mPage, $fname ) ) {
1927 #wfWarn( "Access to raw $fname field " . __CLASS__ );
1928 return $this->mPage->$fname;
1929 }
1930 trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
1931 }
1932
1933 /**
1934 * Use PHP's magic __set handler to handle setting of
1935 * raw WikiPage fields for backwards compatibility.
1936 *
1937 * @param $fname String Field name
1938 * @param $fvalue mixed New value
1939 */
1940 public function __set( $fname, $fvalue ) {
1941 if ( property_exists( $this->mPage, $fname ) ) {
1942 #wfWarn( "Access to raw $fname field of " . __CLASS__ );
1943 $this->mPage->$fname = $fvalue;
1944 // Note: extensions may want to toss on new fields
1945 } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
1946 $this->mPage->$fname = $fvalue;
1947 } else {
1948 trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
1949 }
1950 }
1951
1952 /**
1953 * Use PHP's magic __call handler to transform instance calls to
1954 * WikiPage functions for backwards compatibility.
1955 *
1956 * @param $fname String Name of called method
1957 * @param $args Array Arguments to the method
1958 */
1959 public function __call( $fname, $args ) {
1960 if ( is_callable( array( $this->mPage, $fname ) ) ) {
1961 #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
1962 return call_user_func_array( array( $this->mPage, $fname ), $args );
1963 }
1964 trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
1965 }
1966
1967 // ****** B/C functions to work-around PHP silliness with __call and references ****** //
1968 public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
1969 return $this->mPage->updateRestrictions( $limit, $reason, $cascade, $expiry );
1970 }
1971
1972 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
1973 return $this->mPage->doDeleteArticle( $reason, $suppress, $id, $commit, $error );
1974 }
1975
1976 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user = null ) {
1977 global $wgUser;
1978 $user = is_null( $user ) ? $wgUser : $user;
1979 return $this->mPage->doRollback( $fromP, $summary, $token, $bot, $resultDetails, $user );
1980 }
1981
1982 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser = null ) {
1983 global $wgUser;
1984 $guser = is_null( $guser ) ? $wgUser : $guser;
1985 return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
1986 }
1987
1988 public function generateReason( &$hasHistory ) {
1989 return $this->mPage->getAutoDeleteReason( $hasHistory );
1990 }
1991
1992 // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
1993 public static function selectFields() {
1994 return WikiPage::selectFields();
1995 }
1996
1997 public static function onArticleCreate( $title ) {
1998 return WikiPage::onArticleCreate( $title );
1999 }
2000
2001 public static function onArticleDelete( $title ) {
2002 return WikiPage::onArticleDelete( $title );
2003 }
2004
2005 public static function onArticleEdit( $title ) {
2006 return WikiPage::onArticleEdit( $title );
2007 }
2008
2009 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2010 return WikiPage::getAutosummary( $oldtext, $newtext, $flags );
2011 }
2012 // ******
2013 }
2014
2015 class PoolWorkArticleView extends PoolCounterWork {
2016
2017 /**
2018 * @var Article
2019 */
2020 private $mArticle;
2021
2022 function __construct( $article, $key, $useParserCache, $parserOptions ) {
2023 parent::__construct( 'ArticleView', $key );
2024 $this->mArticle = $article;
2025 $this->cacheable = $useParserCache;
2026 $this->parserOptions = $parserOptions;
2027 }
2028
2029 function doWork() {
2030 return $this->mArticle->doViewParse();
2031 }
2032
2033 function getCachedWork() {
2034 global $wgOut;
2035
2036 $parserCache = ParserCache::singleton();
2037 $this->mArticle->mParserOutput = $parserCache->get( $this->mArticle, $this->parserOptions );
2038
2039 if ( $this->mArticle->mParserOutput !== false ) {
2040 wfDebug( __METHOD__ . ": showing contents parsed by someone else\n" );
2041 $wgOut->addParserOutput( $this->mArticle->mParserOutput );
2042 # Ensure that UI elements requiring revision ID have
2043 # the correct version information.
2044 $wgOut->setRevisionId( $this->mArticle->getLatest() );
2045 return true;
2046 }
2047 return false;
2048 }
2049
2050 function fallback() {
2051 return $this->mArticle->tryDirtyCache();
2052 }
2053
2054 /**
2055 * @param $status Status
2056 */
2057 function error( $status ) {
2058 global $wgOut;
2059
2060 $wgOut->clearHTML(); // for release() errors
2061 $wgOut->enableClientCache( false );
2062 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2063
2064 $errortext = $status->getWikiText( false, 'view-pool-error' );
2065 $wgOut->addWikiText( '<div class="errorbox">' . $errortext . '</div>' );
2066
2067 return false;
2068 }
2069 }