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