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