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