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