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