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