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