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