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