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