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