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