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