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