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