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