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