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