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