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