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