Replace imho ugly viewsourcefor subtitle with viewsourcetitle and viewsourceheader...
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) ) {
3 die( 1 );
4 }
5
6 /**
7 * @todo document
8 */
9 class OutputPage {
10 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
11 var $mExtStyles = array();
12 var $mPagetitle = '', $mBodytext = '';
13
14 /**
15 * Holds the debug lines that will be outputted as comments in page source if
16 * $wgDebugComments is enabled. See also $wgShowDebug.
17 * TODO: make a getter method for this
18 */
19 public $mDebugtext = '';
20
21 var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
22 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
23 var $mLastModified = '', $mETag = false;
24 var $mCategoryLinks = array(), $mCategories = array(), $mLanguageLinks = array();
25
26 var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
27 var $mModules = array(), $mModuleScripts = array(), $mModuleStyles = array(), $mModuleMessages = array();
28 var $mInlineMsg = array();
29
30 var $mTemplateIds = array();
31
32 var $mAllowUserJs;
33 var $mSuppressQuickbar = false;
34 var $mDoNothing = false;
35 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
36 var $mIsArticleRelated = true;
37 protected $mParserOptions = null; // lazy initialised, use parserOptions()
38
39 var $mFeedLinks = array();
40
41 var $mEnableClientCache = true;
42 var $mArticleBodyOnly = false;
43
44 var $mNewSectionLink = false;
45 var $mHideNewSectionLink = false;
46 var $mNoGallery = false;
47 var $mPageTitleActionText = '';
48 var $mParseWarnings = array();
49 var $mSquidMaxage = 0;
50 var $mRevisionId = null;
51 protected $mTitle = null;
52
53 /**
54 * An array of stylesheet filenames (relative from skins path), with options
55 * for CSS media, IE conditions, and RTL/LTR direction.
56 * For internal use; add settings in the skin via $this->addStyle()
57 */
58 var $styles = array();
59
60 /**
61 * Whether to load jQuery core.
62 */
63 protected $mJQueryDone = false;
64
65 private $mIndexPolicy = 'index';
66 private $mFollowPolicy = 'follow';
67 private $mVaryHeader = array(
68 'Accept-Encoding' => array( 'list-contains=gzip' ),
69 'Cookie' => null
70 );
71
72 /**
73 * Constructor
74 * Initialise private variables
75 */
76 function __construct() {
77 global $wgAllowUserJs;
78 $this->mAllowUserJs = $wgAllowUserJs;
79 }
80
81 /**
82 * Redirect to $url rather than displaying the normal page
83 *
84 * @param $url String: URL
85 * @param $responsecode String: HTTP status code
86 */
87 public function redirect( $url, $responsecode = '302' ) {
88 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
89 $this->mRedirect = str_replace( "\n", '', $url );
90 $this->mRedirectCode = $responsecode;
91 }
92
93 /**
94 * Get the URL to redirect to, or an empty string if not redirect URL set
95 *
96 * @return String
97 */
98 public function getRedirect() {
99 return $this->mRedirect;
100 }
101
102 /**
103 * Set the HTTP status code to send with the output.
104 *
105 * @param $statusCode Integer
106 * @return nothing
107 */
108 public function setStatusCode( $statusCode ) {
109 $this->mStatusCode = $statusCode;
110 }
111
112 /**
113 * Add a new <meta> tag
114 * To add an http-equiv meta tag, precede the name with "http:"
115 *
116 * @param $name tag name
117 * @param $val tag value
118 */
119 function addMeta( $name, $val ) {
120 array_push( $this->mMetatags, array( $name, $val ) );
121 }
122
123 /**
124 * Add a keyword or a list of keywords in the page header
125 *
126 * @param $text String or array of strings
127 */
128 function addKeyword( $text ) {
129 if( is_array( $text ) ) {
130 $this->mKeywords = array_merge( $this->mKeywords, $text );
131 } else {
132 array_push( $this->mKeywords, $text );
133 }
134 }
135
136 /**
137 * Add a new \<link\> tag to the page header
138 *
139 * @param $linkarr Array: associative array of attributes.
140 */
141 function addLink( $linkarr ) {
142 array_push( $this->mLinktags, $linkarr );
143 }
144
145 /**
146 * Add a new \<link\> with "rel" attribute set to "meta"
147 *
148 * @param $linkarr Array: associative array mapping attribute names to their
149 * values, both keys and values will be escaped, and the
150 * "rel" attribute will be automatically added
151 */
152 function addMetadataLink( $linkarr ) {
153 # note: buggy CC software only reads first "meta" link
154 static $haveMeta = false;
155 $linkarr['rel'] = $haveMeta ? 'alternate meta' : 'meta';
156 $this->addLink( $linkarr );
157 $haveMeta = true;
158 }
159
160 /**
161 * Add raw HTML to the list of scripts (including \<script\> tag, etc.)
162 *
163 * @param $script String: raw HTML
164 */
165 function addScript( $script ) {
166 $this->mScripts .= $script . "\n";
167 }
168
169 /**
170 * Register and add a stylesheet from an extension directory.
171 *
172 * @param $url String path to sheet. Provide either a full url (beginning
173 * with 'http', etc) or a relative path from the document root
174 * (beginning with '/'). Otherwise it behaves identically to
175 * addStyle() and draws from the /skins folder.
176 */
177 public function addExtensionStyle( $url ) {
178 array_push( $this->mExtStyles, $url );
179 }
180
181 /**
182 * Get all links added by extensions
183 *
184 * @return Array
185 */
186 function getExtStyle() {
187 return $this->mExtStyles;
188 }
189
190 /**
191 * Add a JavaScript file out of skins/common, or a given relative path.
192 *
193 * @param $file String: filename in skins/common or complete on-server path
194 * (/foo/bar.js)
195 * @param $version String: style version of the file. Defaults to $wgStyleVersion
196 */
197 public function addScriptFile( $file, $version = null ) {
198 global $wgStylePath, $wgStyleVersion;
199 // See if $file parameter is an absolute URL or begins with a slash
200 if( substr( $file, 0, 1 ) == '/' || preg_match( '#^[a-z]*://#i', $file ) ) {
201 $path = $file;
202 } else {
203 $path = "{$wgStylePath}/common/{$file}";
204 }
205 if ( is_null( $version ) )
206 $version = $wgStyleVersion;
207 $this->addScript( Html::linkedScript( wfAppendQuery( $path, $version ) ) );
208 }
209
210 /**
211 * Add a self-contained script tag with the given contents
212 *
213 * @param $script String: JavaScript text, no <script> tags
214 */
215 public function addInlineScript( $script ) {
216 $this->mScripts .= Html::inlineScript( "\n$script\n" ) . "\n";
217 }
218
219 /**
220 * Get all registered JS and CSS tags for the header.
221 *
222 * @return String
223 */
224 function getScript() {
225 return $this->mScripts . $this->getHeadItems();
226 }
227
228 /**
229 * Get the list of modules to include on this page
230 *
231 * @return Array of module names
232 */
233 public function getModules() {
234 return $this->mModules;
235 }
236
237 /**
238 * Add one or more modules recognized by the resource loader. Modules added
239 * through this function will be loaded by the resource loader when the
240 * page loads.
241 *
242 * @param $modules Mixed: module name (string) or array of module names
243 */
244 public function addModules( $modules ) {
245 $this->mModules = array_merge( $this->mModules, (array)$modules );
246 }
247
248 /**
249 * Get the list of module JS to include on this page
250 * @return array of module names
251 */
252 public function getModuleScripts() {
253 return $this->mModuleScripts;
254 }
255
256 /**
257 * Add only JS of one or more modules recognized by the resource loader. Module
258 * scripts added through this function will be loaded by the resource loader when
259 * the page loads.
260 *
261 * @param $modules Mixed: module name (string) or array of module names
262 */
263 public function addModuleScripts( $modules ) {
264 $this->mModuleScripts = array_merge( $this->mModuleScripts, (array)$modules );
265 }
266
267 /**
268 * Get the list of module CSS to include on this page
269 *
270 * @return Array of module names
271 */
272 public function getModuleStyles() {
273 return $this->mModuleStyles;
274 }
275
276 /**
277 * Add only CSS of one or more modules recognized by the resource loader. Module
278 * styles added through this function will be loaded by the resource loader when
279 * the page loads.
280 *
281 * @param $modules Mixed: module name (string) or array of module names
282 */
283 public function addModuleStyles( $modules ) {
284 $this->mModuleStyles = array_merge( $this->mModuleStyles, (array)$modules );
285 }
286
287 /**
288 * Get the list of module messages to include on this page
289 *
290 * @return Array of module names
291 */
292 public function getModuleMessages() {
293 return $this->mModuleMessages;
294 }
295
296 /**
297 * Add only messages of one or more modules recognized by the resource loader.
298 * Module messages added through this function will be loaded by the resource
299 * loader when the page loads.
300 *
301 * @param $modules Mixed: module name (string) or array of module names
302 */
303 public function addModuleMessages( $modules ) {
304 $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules );
305 }
306
307 /**
308 * Get all header items in a string
309 *
310 * @return String
311 */
312 function getHeadItems() {
313 $s = '';
314 foreach ( $this->mHeadItems as $item ) {
315 $s .= $item;
316 }
317 return $s;
318 }
319
320 /**
321 * Add or replace an header item to the output
322 *
323 * @param $name String: item name
324 * @param $value String: raw HTML
325 */
326 public function addHeadItem( $name, $value ) {
327 $this->mHeadItems[$name] = $value;
328 }
329
330 /**
331 * Check if the header item $name is already set
332 *
333 * @param $name String: item name
334 * @return Boolean
335 */
336 public function hasHeadItem( $name ) {
337 return isset( $this->mHeadItems[$name] );
338 }
339
340 /**
341 * Set the value of the ETag HTTP header, only used if $wgUseETag is true
342 *
343 * @param $tag String: value of "ETag" header
344 */
345 function setETag( $tag ) {
346 $this->mETag = $tag;
347 }
348
349 /**
350 * Set whether the output should only contain the body of the article,
351 * without any skin, sidebar, etc.
352 * Used e.g. when calling with "action=render".
353 *
354 * @param $only Boolean: whether to output only the body of the article
355 */
356 public function setArticleBodyOnly( $only ) {
357 $this->mArticleBodyOnly = $only;
358 }
359
360 /**
361 * Return whether the output will contain only the body of the article
362 *
363 * @return Boolean
364 */
365 public function getArticleBodyOnly() {
366 return $this->mArticleBodyOnly;
367 }
368
369 /**
370 * checkLastModified tells the client to use the client-cached page if
371 * possible. If sucessful, the OutputPage is disabled so that
372 * any future call to OutputPage->output() have no effect.
373 *
374 * Side effect: sets mLastModified for Last-Modified header
375 *
376 * @return Boolean: true iff cache-ok headers was sent.
377 */
378 public function checkLastModified( $timestamp ) {
379 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
380
381 if ( !$timestamp || $timestamp == '19700101000000' ) {
382 wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
383 return false;
384 }
385 if( !$wgCachePages ) {
386 wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
387 return false;
388 }
389 if( $wgUser->getOption( 'nocache' ) ) {
390 wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
391 return false;
392 }
393
394 $timestamp = wfTimestamp( TS_MW, $timestamp );
395 $modifiedTimes = array(
396 'page' => $timestamp,
397 'user' => $wgUser->getTouched(),
398 'epoch' => $wgCacheEpoch
399 );
400 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
401
402 $maxModified = max( $modifiedTimes );
403 $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified );
404
405 if( empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
406 wfDebug( __METHOD__ . ": client did not send If-Modified-Since header\n", false );
407 return false;
408 }
409
410 # Make debug info
411 $info = '';
412 foreach ( $modifiedTimes as $name => $value ) {
413 if ( $info !== '' ) {
414 $info .= ', ';
415 }
416 $info .= "$name=" . wfTimestamp( TS_ISO_8601, $value );
417 }
418
419 # IE sends sizes after the date like this:
420 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
421 # this breaks strtotime().
422 $clientHeader = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
423
424 wfSuppressWarnings(); // E_STRICT system time bitching
425 $clientHeaderTime = strtotime( $clientHeader );
426 wfRestoreWarnings();
427 if ( !$clientHeaderTime ) {
428 wfDebug( __METHOD__ . ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
429 return false;
430 }
431 $clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime );
432
433 wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
434 wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n", false );
435 wfDebug( __METHOD__ . ": effective Last-Modified: " .
436 wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", false );
437 if( $clientHeaderTime < $maxModified ) {
438 wfDebug( __METHOD__ . ": STALE, $info\n", false );
439 return false;
440 }
441
442 # Not modified
443 # Give a 304 response code and disable body output
444 wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", false );
445 ini_set( 'zlib.output_compression', 0 );
446 $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
447 $this->sendCacheControl();
448 $this->disable();
449
450 // Don't output a compressed blob when using ob_gzhandler;
451 // it's technically against HTTP spec and seems to confuse
452 // Firefox when the response gets split over two packets.
453 wfClearOutputBuffers();
454
455 return true;
456 }
457
458 /**
459 * Override the last modified timestamp
460 *
461 * @param $timestamp String: new timestamp, in a format readable by
462 * wfTimestamp()
463 */
464 public function setLastModified( $timestamp ) {
465 $this->mLastModified = wfTimestamp( TS_RFC2822, $timestamp );
466 }
467
468 /**
469 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
470 *
471 * @param $policy String: the literal string to output as the contents of
472 * the meta tag. Will be parsed according to the spec and output in
473 * standardized form.
474 * @return null
475 */
476 public function setRobotPolicy( $policy ) {
477 $policy = Article::formatRobotPolicy( $policy );
478
479 if( isset( $policy['index'] ) ) {
480 $this->setIndexPolicy( $policy['index'] );
481 }
482 if( isset( $policy['follow'] ) ) {
483 $this->setFollowPolicy( $policy['follow'] );
484 }
485 }
486
487 /**
488 * Set the index policy for the page, but leave the follow policy un-
489 * touched.
490 *
491 * @param $policy string Either 'index' or 'noindex'.
492 * @return null
493 */
494 public function setIndexPolicy( $policy ) {
495 $policy = trim( $policy );
496 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
497 $this->mIndexPolicy = $policy;
498 }
499 }
500
501 /**
502 * Set the follow policy for the page, but leave the index policy un-
503 * touched.
504 *
505 * @param $policy String: either 'follow' or 'nofollow'.
506 * @return null
507 */
508 public function setFollowPolicy( $policy ) {
509 $policy = trim( $policy );
510 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
511 $this->mFollowPolicy = $policy;
512 }
513 }
514
515 /**
516 * Set the new value of the "action text", this will be added to the
517 * "HTML title", separated from it with " - ".
518 *
519 * @param $text String: new value of the "action text"
520 */
521 public function setPageTitleActionText( $text ) {
522 $this->mPageTitleActionText = $text;
523 }
524
525 /**
526 * Get the value of the "action text"
527 *
528 * @return String
529 */
530 public function getPageTitleActionText() {
531 if ( isset( $this->mPageTitleActionText ) ) {
532 return $this->mPageTitleActionText;
533 }
534 }
535
536 /**
537 * "HTML title" means the contents of <title>.
538 * It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
539 */
540 public function setHTMLTitle( $name ) {
541 $this->mHTMLtitle = $name;
542 }
543
544 /**
545 * Return the "HTML title", i.e. the content of the <title> tag.
546 *
547 * @return String
548 */
549 public function getHTMLTitle() {
550 return $this->mHTMLtitle;
551 }
552
553 /**
554 * "Page title" means the contents of \<h1\>. It is stored as a valid HTML fragment.
555 * This function allows good tags like \<sup\> in the \<h1\> tag, but not bad tags like \<script\>.
556 * This function automatically sets \<title\> to the same content as \<h1\> but with all tags removed.
557 * Bad tags that were escaped in \<h1\> will still be escaped in \<title\>, and good tags like \<i\> will be dropped entirely.
558 */
559 public function setPageTitle( $name ) {
560 # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
561 # but leave "<i>foobar</i>" alone
562 $nameWithTags = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $name ) );
563 $this->mPagetitle = $nameWithTags;
564
565 $taction = $this->getPageTitleActionText();
566 if( !empty( $taction ) ) {
567 $name .= ' - '.$taction;
568 }
569
570 # change "<i>foo&amp;bar</i>" to "foo&bar"
571 $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer::stripAllTags( $nameWithTags ) ) );
572 }
573
574 /**
575 * Return the "page title", i.e. the content of the \<h1\> tag.
576 *
577 * @return String
578 */
579 public function getPageTitle() {
580 return $this->mPagetitle;
581 }
582
583 /**
584 * Set the Title object to use
585 *
586 * @param $t Title object
587 */
588 public function setTitle( $t ) {
589 $this->mTitle = $t;
590 }
591
592 /**
593 * Get the Title object used in this instance
594 *
595 * @return Title
596 */
597 public function getTitle() {
598 if ( $this->mTitle instanceof Title ) {
599 return $this->mTitle;
600 } else {
601 wfDebug( __METHOD__ . " called and \$mTitle is null. Return \$wgTitle for sanity\n" );
602 global $wgTitle;
603 return $wgTitle;
604 }
605 }
606
607 /**
608 * Replace the subtile with $str
609 *
610 * @param $str String: new value of the subtitle
611 */
612 public function setSubtitle( $str ) {
613 $this->mSubtitle = /*$this->parse(*/ $str /*)*/; // @bug 2514
614 }
615
616 /**
617 * Add $str to the subtitle
618 *
619 * @param $str String to add to the subtitle
620 */
621 public function appendSubtitle( $str ) {
622 $this->mSubtitle .= /*$this->parse(*/ $str /*)*/; // @bug 2514
623 }
624
625 /**
626 * Get the subtitle
627 *
628 * @return String
629 */
630 public function getSubtitle() {
631 return $this->mSubtitle;
632 }
633
634 /**
635 * Set the page as printable, i.e. it'll be displayed with with all
636 * print styles included
637 */
638 public function setPrintable() {
639 $this->mPrintable = true;
640 }
641
642 /**
643 * Return whether the page is "printable"
644 *
645 * @return Boolean
646 */
647 public function isPrintable() {
648 return $this->mPrintable;
649 }
650
651 /**
652 * Disable output completely, i.e. calling output() will have no effect
653 */
654 public function disable() {
655 $this->mDoNothing = true;
656 }
657
658 /**
659 * Return whether the output will be completely disabled
660 *
661 * @return Boolean
662 */
663 public function isDisabled() {
664 return $this->mDoNothing;
665 }
666
667 /**
668 * Show an "add new section" link?
669 *
670 * @return Boolean
671 */
672 public function showNewSectionLink() {
673 return $this->mNewSectionLink;
674 }
675
676 /**
677 * Forcibly hide the new section link?
678 *
679 * @return Boolean
680 */
681 public function forceHideNewSectionLink() {
682 return $this->mHideNewSectionLink;
683 }
684
685 /**
686 * Add or remove feed links in the page header
687 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
688 * for the new version
689 * @see addFeedLink()
690 *
691 * @param $show Boolean: true: add default feeds, false: remove all feeds
692 */
693 public function setSyndicated( $show = true ) {
694 if ( $show ) {
695 $this->setFeedAppendQuery( false );
696 } else {
697 $this->mFeedLinks = array();
698 }
699 }
700
701 /**
702 * Add default feeds to the page header
703 * This is mainly kept for backward compatibility, see OutputPage::addFeedLink()
704 * for the new version
705 * @see addFeedLink()
706 *
707 * @param $val String: query to append to feed links or false to output
708 * default links
709 */
710 public function setFeedAppendQuery( $val ) {
711 global $wgAdvertisedFeedTypes;
712
713 $this->mFeedLinks = array();
714
715 foreach ( $wgAdvertisedFeedTypes as $type ) {
716 $query = "feed=$type";
717 if ( is_string( $val ) ) {
718 $query .= '&' . $val;
719 }
720 $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
721 }
722 }
723
724 /**
725 * Add a feed link to the page header
726 *
727 * @param $format String: feed type, should be a key of $wgFeedClasses
728 * @param $href String: URL
729 */
730 public function addFeedLink( $format, $href ) {
731 global $wgAdvertisedFeedTypes;
732
733 if ( in_array( $format, $wgAdvertisedFeedTypes ) ) {
734 $this->mFeedLinks[$format] = $href;
735 }
736 }
737
738 /**
739 * Should we output feed links for this page?
740 * @return Boolean
741 */
742 public function isSyndicated() {
743 return count( $this->mFeedLinks ) > 0;
744 }
745
746 /**
747 * Return URLs for each supported syndication format for this page.
748 * @return array associating format keys with URLs
749 */
750 public function getSyndicationLinks() {
751 return $this->mFeedLinks;
752 }
753
754 /**
755 * Will currently always return null
756 *
757 * @return null
758 */
759 public function getFeedAppendQuery() {
760 return $this->mFeedLinksAppendQuery;
761 }
762
763 /**
764 * Set whether the displayed content is related to the source of the
765 * corresponding article on the wiki
766 * Setting true will cause the change "article related" toggle to true
767 *
768 * @param $v Boolean
769 */
770 public function setArticleFlag( $v ) {
771 $this->mIsarticle = $v;
772 if ( $v ) {
773 $this->mIsArticleRelated = $v;
774 }
775 }
776
777 /**
778 * Return whether the content displayed page is related to the source of
779 * the corresponding article on the wiki
780 *
781 * @return Boolean
782 */
783 public function isArticle() {
784 return $this->mIsarticle;
785 }
786
787 /**
788 * Set whether this page is related an article on the wiki
789 * Setting false will cause the change of "article flag" toggle to false
790 *
791 * @param $v Boolean
792 */
793 public function setArticleRelated( $v ) {
794 $this->mIsArticleRelated = $v;
795 if ( !$v ) {
796 $this->mIsarticle = false;
797 }
798 }
799
800 /**
801 * Return whether this page is related an article on the wiki
802 *
803 * @return Boolean
804 */
805 public function isArticleRelated() {
806 return $this->mIsArticleRelated;
807 }
808
809 /**
810 * Add new language links
811 *
812 * @param $newLinkArray Associative array mapping language code to the page
813 * name
814 */
815 public function addLanguageLinks( $newLinkArray ) {
816 $this->mLanguageLinks += $newLinkArray;
817 }
818
819 /**
820 * Reset the language links and add new language links
821 *
822 * @param $newLinkArray Associative array mapping language code to the page
823 * name
824 */
825 public function setLanguageLinks( $newLinkArray ) {
826 $this->mLanguageLinks = $newLinkArray;
827 }
828
829 /**
830 * Get the list of language links
831 *
832 * @return Associative array mapping language code to the page name
833 */
834 public function getLanguageLinks() {
835 return $this->mLanguageLinks;
836 }
837
838 /**
839 * Add an array of categories, with names in the keys
840 *
841 * @param $categories Associative array mapping category name to its sort key
842 */
843 public function addCategoryLinks( $categories ) {
844 global $wgUser, $wgContLang;
845
846 if ( !is_array( $categories ) || count( $categories ) == 0 ) {
847 return;
848 }
849
850 # Add the links to a LinkBatch
851 $arr = array( NS_CATEGORY => $categories );
852 $lb = new LinkBatch;
853 $lb->setArray( $arr );
854
855 # Fetch existence plus the hiddencat property
856 $dbr = wfGetDB( DB_SLAVE );
857 $pageTable = $dbr->tableName( 'page' );
858 $where = $lb->constructSet( 'page', $dbr );
859 $propsTable = $dbr->tableName( 'page_props' );
860 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest, pp_value
861 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
862 $res = $dbr->query( $sql, __METHOD__ );
863
864 # Add the results to the link cache
865 $lb->addResultToCache( LinkCache::singleton(), $res );
866
867 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
868 $categories = array_combine(
869 array_keys( $categories ),
870 array_fill( 0, count( $categories ), 'normal' )
871 );
872
873 # Mark hidden categories
874 foreach ( $res as $row ) {
875 if ( isset( $row->pp_value ) ) {
876 $categories[$row->page_title] = 'hidden';
877 }
878 }
879
880 # Add the remaining categories to the skin
881 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) {
882 $sk = $wgUser->getSkin();
883 foreach ( $categories as $category => $type ) {
884 $origcategory = $category;
885 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
886 $wgContLang->findVariantLink( $category, $title, true );
887 if ( $category != $origcategory ) {
888 if ( array_key_exists( $category, $categories ) ) {
889 continue;
890 }
891 }
892 $text = $wgContLang->convertHtml( $title->getText() );
893 $this->mCategories[] = $title->getText();
894 $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
895 }
896 }
897 }
898
899 /**
900 * Reset the category links (but not the category list) and add $categories
901 *
902 * @param $categories Associative array mapping category name to its sort key
903 */
904 public function setCategoryLinks( $categories ) {
905 $this->mCategoryLinks = array();
906 $this->addCategoryLinks( $categories );
907 }
908
909 /**
910 * Get the list of category links, in a 2-D array with the following format:
911 * $arr[$type][] = $link, where $type is either "normal" or "hidden" (for
912 * hidden categories) and $link a HTML fragment with a link to the category
913 * page
914 *
915 * @return Array
916 */
917 public function getCategoryLinks() {
918 return $this->mCategoryLinks;
919 }
920
921 /**
922 * Get the list of category names this page belongs to
923 *
924 * @return Array of strings
925 */
926 public function getCategories() {
927 return $this->mCategories;
928 }
929
930 /**
931 * Suppress the quickbar from the output, only for skin supporting
932 * the quickbar
933 */
934 public function suppressQuickbar() {
935 $this->mSuppressQuickbar = true;
936 }
937
938 /**
939 * Return whether the quickbar should be suppressed from the output
940 *
941 * @return Boolean
942 */
943 public function isQuickbarSuppressed() {
944 return $this->mSuppressQuickbar;
945 }
946
947 /**
948 * Remove user JavaScript from scripts to load
949 */
950 public function disallowUserJs() {
951 $this->mAllowUserJs = false;
952 }
953
954 /**
955 * Return whether user JavaScript is allowed for this page
956 *
957 * @return Boolean
958 */
959 public function isUserJsAllowed() {
960 return $this->mAllowUserJs;
961 }
962
963 /**
964 * Prepend $text to the body HTML
965 *
966 * @param $text String: HTML
967 */
968 public function prependHTML( $text ) {
969 $this->mBodytext = $text . $this->mBodytext;
970 }
971
972 /**
973 * Append $text to the body HTML
974 *
975 * @param $text String: HTML
976 */
977 public function addHTML( $text ) {
978 $this->mBodytext .= $text;
979 }
980
981 /**
982 * Clear the body HTML
983 */
984 public function clearHTML() {
985 $this->mBodytext = '';
986 }
987
988 /**
989 * Get the body HTML
990 *
991 * @return String: HTML
992 */
993 public function getHTML() {
994 return $this->mBodytext;
995 }
996
997 /**
998 * Add $text to the debug output
999 *
1000 * @param $text String: debug text
1001 */
1002 public function debug( $text ) {
1003 $this->mDebugtext .= $text;
1004 }
1005
1006 /**
1007 * @deprecated use parserOptions() instead
1008 */
1009 public function setParserOptions( $options ) {
1010 wfDeprecated( __METHOD__ );
1011 return $this->parserOptions( $options );
1012 }
1013
1014 /**
1015 * Get/set the ParserOptions object to use for wikitext parsing
1016 *
1017 * @param $options either the ParserOption to use or null to only get the
1018 * current ParserOption object
1019 * @return current ParserOption object
1020 */
1021 public function parserOptions( $options = null ) {
1022 if ( !$this->mParserOptions ) {
1023 $this->mParserOptions = new ParserOptions;
1024 }
1025 return wfSetVar( $this->mParserOptions, $options );
1026 }
1027
1028 /**
1029 * Set the revision ID which will be seen by the wiki text parser
1030 * for things such as embedded {{REVISIONID}} variable use.
1031 *
1032 * @param $revid Mixed: an positive integer, or null
1033 * @return Mixed: previous value
1034 */
1035 public function setRevisionId( $revid ) {
1036 $val = is_null( $revid ) ? null : intval( $revid );
1037 return wfSetVar( $this->mRevisionId, $val );
1038 }
1039
1040 /**
1041 * Get the current revision ID
1042 *
1043 * @return Integer
1044 */
1045 public function getRevisionId() {
1046 return $this->mRevisionId;
1047 }
1048
1049 /**
1050 * Convert wikitext to HTML and add it to the buffer
1051 * Default assumes that the current page title will be used.
1052 *
1053 * @param $text String
1054 * @param $linestart Boolean: is this the start of a line?
1055 */
1056 public function addWikiText( $text, $linestart = true ) {
1057 $title = $this->getTitle(); // Work arround E_STRICT
1058 $this->addWikiTextTitle( $text, $title, $linestart );
1059 }
1060
1061 /**
1062 * Add wikitext with a custom Title object
1063 *
1064 * @param $text String: wikitext
1065 * @param $title Title object
1066 * @param $linestart Boolean: is this the start of a line?
1067 */
1068 public function addWikiTextWithTitle( $text, &$title, $linestart = true ) {
1069 $this->addWikiTextTitle( $text, $title, $linestart );
1070 }
1071
1072 /**
1073 * Add wikitext with a custom Title object and
1074 *
1075 * @param $text String: wikitext
1076 * @param $title Title object
1077 * @param $linestart Boolean: is this the start of a line?
1078 */
1079 function addWikiTextTitleTidy( $text, &$title, $linestart = true ) {
1080 $this->addWikiTextTitle( $text, $title, $linestart, true );
1081 }
1082
1083 /**
1084 * Add wikitext with tidy enabled
1085 *
1086 * @param $text String: wikitext
1087 * @param $linestart Boolean: is this the start of a line?
1088 */
1089 public function addWikiTextTidy( $text, $linestart = true ) {
1090 $title = $this->getTitle();
1091 $this->addWikiTextTitleTidy( $text, $title, $linestart );
1092 }
1093
1094 /**
1095 * Add wikitext with a custom Title object
1096 *
1097 * @param $text String: wikitext
1098 * @param $title Title object
1099 * @param $linestart Boolean: is this the start of a line?
1100 * @param $tidy Boolean: whether to use tidy
1101 */
1102 public function addWikiTextTitle( $text, &$title, $linestart, $tidy = false ) {
1103 global $wgParser;
1104
1105 wfProfileIn( __METHOD__ );
1106
1107 wfIncrStats( 'pcache_not_possible' );
1108
1109 $popts = $this->parserOptions();
1110 $oldTidy = $popts->setTidy( $tidy );
1111
1112 $parserOutput = $wgParser->parse(
1113 $text, $title, $popts,
1114 $linestart, true, $this->mRevisionId
1115 );
1116
1117 $popts->setTidy( $oldTidy );
1118
1119 $this->addParserOutput( $parserOutput );
1120
1121 wfProfileOut( __METHOD__ );
1122 }
1123
1124 /**
1125 * Add wikitext to the buffer, assuming that this is the primary text for a page view
1126 * Saves the text into the parser cache if possible.
1127 *
1128 * @param $text String: wikitext
1129 * @param $article Article object
1130 * @param $cache Boolean
1131 * @deprecated Use Article::outputWikitext
1132 */
1133 public function addPrimaryWikiText( $text, $article, $cache = true ) {
1134 global $wgParser;
1135
1136 wfDeprecated( __METHOD__ );
1137
1138 $popts = $this->parserOptions();
1139 $popts->setTidy( true );
1140 $parserOutput = $wgParser->parse(
1141 $text, $article->mTitle,
1142 $popts, true, true, $this->mRevisionId
1143 );
1144 $popts->setTidy( false );
1145 if ( $cache && $article && $parserOutput->isCacheable() ) {
1146 $parserCache = ParserCache::singleton();
1147 $parserCache->save( $parserOutput, $article, $popts );
1148 }
1149
1150 $this->addParserOutput( $parserOutput );
1151 }
1152
1153 /**
1154 * @deprecated use addWikiTextTidy()
1155 */
1156 public function addSecondaryWikiText( $text, $linestart = true ) {
1157 wfDeprecated( __METHOD__ );
1158 $this->addWikiTextTitleTidy( $text, $this->getTitle(), $linestart );
1159 }
1160
1161 /**
1162 * Add a ParserOutput object, but without Html
1163 *
1164 * @param $parserOutput ParserOutput object
1165 */
1166 public function addParserOutputNoText( &$parserOutput ) {
1167 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
1168 $this->addCategoryLinks( $parserOutput->getCategories() );
1169 $this->mNewSectionLink = $parserOutput->getNewSection();
1170 $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
1171
1172 $this->mParseWarnings = $parserOutput->getWarnings();
1173 if ( !$parserOutput->isCacheable() ) {
1174 $this->enableClientCache( false );
1175 }
1176 $this->mNoGallery = $parserOutput->getNoGallery();
1177 $this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
1178 $this->addModules( $parserOutput->getModules() );
1179 // Versioning...
1180 foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
1181 if ( isset( $this->mTemplateIds[$ns] ) ) {
1182 $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
1183 } else {
1184 $this->mTemplateIds[$ns] = $dbks;
1185 }
1186 }
1187
1188 // Hooks registered in the object
1189 global $wgParserOutputHooks;
1190 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
1191 list( $hookName, $data ) = $hookInfo;
1192 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
1193 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
1194 }
1195 }
1196
1197 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
1198 }
1199
1200 /**
1201 * Add a ParserOutput object
1202 *
1203 * @param $parserOutput ParserOutput
1204 */
1205 function addParserOutput( &$parserOutput ) {
1206 $this->addParserOutputNoText( $parserOutput );
1207 $text = $parserOutput->getText();
1208 wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
1209 $this->addHTML( $text );
1210 }
1211
1212
1213 /**
1214 * Add the output of a QuickTemplate to the output buffer
1215 *
1216 * @param $template QuickTemplate
1217 */
1218 public function addTemplate( &$template ) {
1219 ob_start();
1220 $template->execute();
1221 $this->addHTML( ob_get_contents() );
1222 ob_end_clean();
1223 }
1224
1225 /**
1226 * Parse wikitext and return the HTML.
1227 *
1228 * @param $text String
1229 * @param $linestart Boolean: is this the start of a line?
1230 * @param $interface Boolean: use interface language ($wgLang instead of
1231 * $wgContLang) while parsing language sensitive magic
1232 * words like GRAMMAR and PLURAL
1233 * @return String: HTML
1234 */
1235 public function parse( $text, $linestart = true, $interface = false ) {
1236 global $wgParser;
1237 if( is_null( $this->getTitle() ) ) {
1238 throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
1239 }
1240 $popts = $this->parserOptions();
1241 if ( $interface ) {
1242 $popts->setInterfaceMessage( true );
1243 }
1244 $parserOutput = $wgParser->parse(
1245 $text, $this->getTitle(), $popts,
1246 $linestart, true, $this->mRevisionId
1247 );
1248 if ( $interface ) {
1249 $popts->setInterfaceMessage( false );
1250 }
1251 return $parserOutput->getText();
1252 }
1253
1254 /**
1255 * Parse wikitext, strip paragraphs, and return the HTML.
1256 *
1257 * @param $text String
1258 * @param $linestart Boolean: is this the start of a line?
1259 * @param $interface Boolean: use interface language ($wgLang instead of
1260 * $wgContLang) while parsing language sensitive magic
1261 * words like GRAMMAR and PLURAL
1262 * @return String: HTML
1263 */
1264 public function parseInline( $text, $linestart = true, $interface = false ) {
1265 $parsed = $this->parse( $text, $linestart, $interface );
1266
1267 $m = array();
1268 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
1269 $parsed = $m[1];
1270 }
1271
1272 return $parsed;
1273 }
1274
1275 /**
1276 * @deprecated
1277 *
1278 * @param $article Article
1279 * @return Boolean: true if successful, else false.
1280 */
1281 public function tryParserCache( &$article ) {
1282 wfDeprecated( __METHOD__ );
1283 $parserOutput = ParserCache::singleton()->get( $article, $article->getParserOptions() );
1284
1285 if ( $parserOutput !== false ) {
1286 $this->addParserOutput( $parserOutput );
1287 return true;
1288 } else {
1289 return false;
1290 }
1291 }
1292
1293 /**
1294 * Set the value of the "s-maxage" part of the "Cache-control" HTTP header
1295 *
1296 * @param $maxage Integer: maximum cache time on the Squid, in seconds.
1297 */
1298 public function setSquidMaxage( $maxage ) {
1299 $this->mSquidMaxage = $maxage;
1300 }
1301
1302 /**
1303 * Use enableClientCache(false) to force it to send nocache headers
1304 *
1305 * @param $state ??
1306 */
1307 public function enableClientCache( $state ) {
1308 return wfSetVar( $this->mEnableClientCache, $state );
1309 }
1310
1311 /**
1312 * Get the list of cookies that will influence on the cache
1313 *
1314 * @return Array
1315 */
1316 function getCacheVaryCookies() {
1317 global $wgCookiePrefix, $wgCacheVaryCookies;
1318 static $cookies;
1319 if ( $cookies === null ) {
1320 $cookies = array_merge(
1321 array(
1322 "{$wgCookiePrefix}Token",
1323 "{$wgCookiePrefix}LoggedOut",
1324 session_name()
1325 ),
1326 $wgCacheVaryCookies
1327 );
1328 wfRunHooks( 'GetCacheVaryCookies', array( $this, &$cookies ) );
1329 }
1330 return $cookies;
1331 }
1332
1333 /**
1334 * Return whether this page is not cacheable because "useskin" or "uselang"
1335 * URL parameters were passed.
1336 *
1337 * @return Boolean
1338 */
1339 function uncacheableBecauseRequestVars() {
1340 global $wgRequest;
1341 return $wgRequest->getText( 'useskin', false ) === false
1342 && $wgRequest->getText( 'uselang', false ) === false;
1343 }
1344
1345 /**
1346 * Check if the request has a cache-varying cookie header
1347 * If it does, it's very important that we don't allow public caching
1348 *
1349 * @return Boolean
1350 */
1351 function haveCacheVaryCookies() {
1352 global $wgRequest;
1353 $cookieHeader = $wgRequest->getHeader( 'cookie' );
1354 if ( $cookieHeader === false ) {
1355 return false;
1356 }
1357 $cvCookies = $this->getCacheVaryCookies();
1358 foreach ( $cvCookies as $cookieName ) {
1359 # Check for a simple string match, like the way squid does it
1360 if ( strpos( $cookieHeader, $cookieName ) !== false ) {
1361 wfDebug( __METHOD__ . ": found $cookieName\n" );
1362 return true;
1363 }
1364 }
1365 wfDebug( __METHOD__ . ": no cache-varying cookies found\n" );
1366 return false;
1367 }
1368
1369 /**
1370 * Add an HTTP header that will influence on the cache
1371 *
1372 * @param $header String: header name
1373 * @param $option either an Array or null
1374 */
1375 public function addVaryHeader( $header, $option = null ) {
1376 if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
1377 $this->mVaryHeader[$header] = $option;
1378 } elseif( is_array( $option ) ) {
1379 if( is_array( $this->mVaryHeader[$header] ) ) {
1380 $this->mVaryHeader[$header] = array_merge( $this->mVaryHeader[$header], $option );
1381 } else {
1382 $this->mVaryHeader[$header] = $option;
1383 }
1384 }
1385 $this->mVaryHeader[$header] = array_unique( $this->mVaryHeader[$header] );
1386 }
1387
1388 /**
1389 * Get a complete X-Vary-Options header
1390 *
1391 * @return String
1392 */
1393 public function getXVO() {
1394 $cvCookies = $this->getCacheVaryCookies();
1395
1396 $cookiesOption = array();
1397 foreach ( $cvCookies as $cookieName ) {
1398 $cookiesOption[] = 'string-contains=' . $cookieName;
1399 }
1400 $this->addVaryHeader( 'Cookie', $cookiesOption );
1401
1402 $headers = array();
1403 foreach( $this->mVaryHeader as $header => $option ) {
1404 $newheader = $header;
1405 if( is_array( $option ) ) {
1406 $newheader .= ';' . implode( ';', $option );
1407 }
1408 $headers[] = $newheader;
1409 }
1410 $xvo = 'X-Vary-Options: ' . implode( ',', $headers );
1411
1412 return $xvo;
1413 }
1414
1415 /**
1416 * bug 21672: Add Accept-Language to Vary and XVO headers
1417 * if there's no 'variant' parameter existed in GET.
1418 *
1419 * For example:
1420 * /w/index.php?title=Main_page should always be served; but
1421 * /w/index.php?title=Main_page&variant=zh-cn should never be served.
1422 */
1423 function addAcceptLanguage() {
1424 global $wgRequest, $wgContLang;
1425 if( !$wgRequest->getCheck( 'variant' ) && $wgContLang->hasVariants() ) {
1426 $variants = $wgContLang->getVariants();
1427 $aloption = array();
1428 foreach ( $variants as $variant ) {
1429 if( $variant === $wgContLang->getCode() ) {
1430 continue;
1431 } else {
1432 $aloption[] = "string-contains=$variant";
1433 }
1434 }
1435 $this->addVaryHeader( 'Accept-Language', $aloption );
1436 }
1437 }
1438
1439 /**
1440 * Send cache control HTTP headers
1441 */
1442 public function sendCacheControl() {
1443 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
1444
1445 $response = $wgRequest->response();
1446 if ( $wgUseETag && $this->mETag ) {
1447 $response->header( "ETag: $this->mETag" );
1448 }
1449
1450 $this->addAcceptLanguage();
1451
1452 # don't serve compressed data to clients who can't handle it
1453 # maintain different caches for logged-in users and non-logged in ones
1454 $response->header( 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ) );
1455
1456 if ( $wgUseXVO ) {
1457 # Add an X-Vary-Options header for Squid with Wikimedia patches
1458 $response->header( $this->getXVO() );
1459 }
1460
1461 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
1462 if(
1463 $wgUseSquid && session_id() == '' && !$this->isPrintable() &&
1464 $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies()
1465 )
1466 {
1467 if ( $wgUseESI ) {
1468 # We'll purge the proxy cache explicitly, but require end user agents
1469 # to revalidate against the proxy on each visit.
1470 # Surrogate-Control controls our Squid, Cache-Control downstream caches
1471 wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **\n", false );
1472 # start with a shorter timeout for initial testing
1473 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
1474 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
1475 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
1476 } else {
1477 # We'll purge the proxy cache for anons explicitly, but require end user agents
1478 # to revalidate against the proxy on each visit.
1479 # IMPORTANT! The Squid needs to replace the Cache-Control header with
1480 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
1481 wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **\n", false );
1482 # start with a shorter timeout for initial testing
1483 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
1484 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
1485 }
1486 } else {
1487 # We do want clients to cache if they can, but they *must* check for updates
1488 # on revisiting the page.
1489 wfDebug( __METHOD__ . ": private caching; {$this->mLastModified} **\n", false );
1490 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1491 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
1492 }
1493 if($this->mLastModified) {
1494 $response->header( "Last-Modified: {$this->mLastModified}" );
1495 }
1496 } else {
1497 wfDebug( __METHOD__ . ": no caching **\n", false );
1498
1499 # In general, the absence of a last modified header should be enough to prevent
1500 # the client from using its cache. We send a few other things just to make sure.
1501 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
1502 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
1503 $response->header( 'Pragma: no-cache' );
1504 }
1505 }
1506
1507 /**
1508 * Get the message associed with the HTTP response code $code
1509 *
1510 * @param $code Integer: status code
1511 * @return String or null: message or null if $code is not in the list of
1512 * messages
1513 */
1514 public static function getStatusMessage( $code ) {
1515 static $statusMessage = array(
1516 100 => 'Continue',
1517 101 => 'Switching Protocols',
1518 102 => 'Processing',
1519 200 => 'OK',
1520 201 => 'Created',
1521 202 => 'Accepted',
1522 203 => 'Non-Authoritative Information',
1523 204 => 'No Content',
1524 205 => 'Reset Content',
1525 206 => 'Partial Content',
1526 207 => 'Multi-Status',
1527 300 => 'Multiple Choices',
1528 301 => 'Moved Permanently',
1529 302 => 'Found',
1530 303 => 'See Other',
1531 304 => 'Not Modified',
1532 305 => 'Use Proxy',
1533 307 => 'Temporary Redirect',
1534 400 => 'Bad Request',
1535 401 => 'Unauthorized',
1536 402 => 'Payment Required',
1537 403 => 'Forbidden',
1538 404 => 'Not Found',
1539 405 => 'Method Not Allowed',
1540 406 => 'Not Acceptable',
1541 407 => 'Proxy Authentication Required',
1542 408 => 'Request Timeout',
1543 409 => 'Conflict',
1544 410 => 'Gone',
1545 411 => 'Length Required',
1546 412 => 'Precondition Failed',
1547 413 => 'Request Entity Too Large',
1548 414 => 'Request-URI Too Large',
1549 415 => 'Unsupported Media Type',
1550 416 => 'Request Range Not Satisfiable',
1551 417 => 'Expectation Failed',
1552 422 => 'Unprocessable Entity',
1553 423 => 'Locked',
1554 424 => 'Failed Dependency',
1555 500 => 'Internal Server Error',
1556 501 => 'Not Implemented',
1557 502 => 'Bad Gateway',
1558 503 => 'Service Unavailable',
1559 504 => 'Gateway Timeout',
1560 505 => 'HTTP Version Not Supported',
1561 507 => 'Insufficient Storage'
1562 );
1563 return isset( $statusMessage[$code] ) ? $statusMessage[$code] : null;
1564 }
1565
1566 /**
1567 * Finally, all the text has been munged and accumulated into
1568 * the object, let's actually output it:
1569 */
1570 public function output() {
1571 global $wgUser, $wgOutputEncoding, $wgRequest;
1572 global $wgLanguageCode, $wgDebugRedirects, $wgMimeType;
1573 global $wgUseAjax, $wgAjaxWatch;
1574 global $wgEnableMWSuggest, $wgUniversalEditButton;
1575 global $wgArticle;
1576
1577 if( $this->mDoNothing ) {
1578 return;
1579 }
1580 wfProfileIn( __METHOD__ );
1581 if ( $this->mRedirect != '' ) {
1582 # Standards require redirect URLs to be absolute
1583 $this->mRedirect = wfExpandUrl( $this->mRedirect );
1584 if( $this->mRedirectCode == '301' || $this->mRedirectCode == '303' ) {
1585 if( !$wgDebugRedirects ) {
1586 $message = self::getStatusMessage( $this->mRedirectCode );
1587 $wgRequest->response()->header( "HTTP/1.1 {$this->mRedirectCode} $message" );
1588 }
1589 $this->mLastModified = wfTimestamp( TS_RFC2822 );
1590 }
1591 $this->sendCacheControl();
1592
1593 $wgRequest->response()->header( "Content-Type: text/html; charset=utf-8" );
1594 if( $wgDebugRedirects ) {
1595 $url = htmlspecialchars( $this->mRedirect );
1596 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
1597 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
1598 print "</body>\n</html>\n";
1599 } else {
1600 $wgRequest->response()->header( 'Location: ' . $this->mRedirect );
1601 }
1602 wfProfileOut( __METHOD__ );
1603 return;
1604 } elseif ( $this->mStatusCode ) {
1605 $message = self::getStatusMessage( $this->mStatusCode );
1606 if ( $message ) {
1607 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $message );
1608 }
1609 }
1610
1611 $sk = $wgUser->getSkin();
1612
1613 // Add base resources
1614 $this->addModules( array( 'mediawiki.legacy.wikibits' ) );
1615
1616 // Add various resources if required
1617 if ( $wgUseAjax ) {
1618 $this->addModules( 'mediawiki.legacy.ajax' );
1619
1620 wfRunHooks( 'AjaxAddScript', array( &$this ) );
1621
1622 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
1623 $this->addModules( 'mediawiki.legacy.ajaxwatch' );
1624 }
1625
1626 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
1627 $this->addModules( 'mediawiki.legacy.mwsuggest' );
1628 }
1629 }
1630
1631 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
1632 $this->addModules( 'mediawiki.legacy.rightclickedit' );
1633 }
1634
1635 if( $wgUniversalEditButton ) {
1636 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
1637 && ( $this->getTitle()->exists() || $this->getTitle()->quickUserCan( 'create' ) ) ) {
1638 // Original UniversalEditButton
1639 $msg = wfMsg( 'edit' );
1640 $this->addLink( array(
1641 'rel' => 'alternate',
1642 'type' => 'application/x-wiki',
1643 'title' => $msg,
1644 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1645 ) );
1646 // Alternate edit link
1647 $this->addLink( array(
1648 'rel' => 'edit',
1649 'title' => $msg,
1650 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
1651 ) );
1652 }
1653 }
1654
1655
1656 # Buffer output; final headers may depend on later processing
1657 ob_start();
1658
1659 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1660 $wgRequest->response()->header( 'Content-language: ' . $wgLanguageCode );
1661
1662 if ( $this->mArticleBodyOnly ) {
1663 $this->out( $this->mBodytext );
1664 } else {
1665 // Hook that allows last minute changes to the output page, e.g.
1666 // adding of CSS or Javascript by extensions.
1667 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1668
1669 wfProfileIn( 'Output-skin' );
1670 $sk->outputPage( $this );
1671 wfProfileOut( 'Output-skin' );
1672 }
1673
1674 $this->sendCacheControl();
1675 ob_end_flush();
1676 wfProfileOut( __METHOD__ );
1677 }
1678
1679 /**
1680 * Actually output something with print(). Performs an iconv to the
1681 * output encoding, if needed.
1682 *
1683 * @param $ins String: the string to output
1684 */
1685 public function out( $ins ) {
1686 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1687 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1688 $outs = $ins;
1689 } else {
1690 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1691 if ( false === $outs ) {
1692 $outs = $ins;
1693 }
1694 }
1695 print $outs;
1696 }
1697
1698 /**
1699 * @todo document
1700 */
1701 public static function setEncodings() {
1702 global $wgInputEncoding, $wgOutputEncoding;
1703
1704 $wgInputEncoding = strtolower( $wgInputEncoding );
1705
1706 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1707 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1708 return;
1709 }
1710 $wgOutputEncoding = $wgInputEncoding;
1711 }
1712
1713 /**
1714 * @deprecated use wfReportTime() instead.
1715 *
1716 * @return String
1717 */
1718 public function reportTime() {
1719 wfDeprecated( __METHOD__ );
1720 $time = wfReportTime();
1721 return $time;
1722 }
1723
1724 /**
1725 * Produce a "user is blocked" page.
1726 *
1727 * @param $return Boolean: whether to have a "return to $wgTitle" message or not.
1728 * @return nothing
1729 */
1730 function blockedPage( $return = true ) {
1731 global $wgUser, $wgContLang, $wgLang;
1732
1733 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1734 $this->setRobotPolicy( 'noindex,nofollow' );
1735 $this->setArticleRelated( false );
1736
1737 $name = User::whoIs( $wgUser->blockedBy() );
1738 $reason = $wgUser->blockedFor();
1739 if( $reason == '' ) {
1740 $reason = wfMsg( 'blockednoreason' );
1741 }
1742 $blockTimestamp = $wgLang->timeanddate(
1743 wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true
1744 );
1745 $ip = wfGetIP();
1746
1747 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1748
1749 $blockid = $wgUser->mBlock->mId;
1750
1751 $blockExpiry = $wgUser->mBlock->mExpiry;
1752 if ( $blockExpiry == 'infinity' ) {
1753 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1754 // Search for localization in 'ipboptions'
1755 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1756 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1757 if ( strpos( $option, ':' ) === false ) {
1758 continue;
1759 }
1760 list( $show, $value ) = explode( ':', $option );
1761 if ( $value == 'infinite' || $value == 'indefinite' ) {
1762 $blockExpiry = $show;
1763 break;
1764 }
1765 }
1766 } else {
1767 $blockExpiry = $wgLang->timeanddate(
1768 wfTimestamp( TS_MW, $blockExpiry ),
1769 true
1770 );
1771 }
1772
1773 if ( $wgUser->mBlock->mAuto ) {
1774 $msg = 'autoblockedtext';
1775 } else {
1776 $msg = 'blockedtext';
1777 }
1778
1779 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1780 * This could be a username, an IP range, or a single IP. */
1781 $intended = $wgUser->mBlock->mAddress;
1782
1783 $this->addWikiMsg(
1784 $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry,
1785 $intended, $blockTimestamp
1786 );
1787
1788 # Don't auto-return to special pages
1789 if( $return ) {
1790 $return = $this->getTitle()->getNamespace() > -1 ? $this->getTitle() : null;
1791 $this->returnToMain( null, $return );
1792 }
1793 }
1794
1795 /**
1796 * Output a standard error page
1797 *
1798 * @param $title String: message key for page title
1799 * @param $msg String: message key for page text
1800 * @param $params Array: message parameters
1801 */
1802 public function showErrorPage( $title, $msg, $params = array() ) {
1803 if ( $this->getTitle() ) {
1804 $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1805 }
1806 $this->setPageTitle( wfMsg( $title ) );
1807 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1808 $this->setRobotPolicy( 'noindex,nofollow' );
1809 $this->setArticleRelated( false );
1810 $this->enableClientCache( false );
1811 $this->mRedirect = '';
1812 $this->mBodytext = '';
1813
1814 array_unshift( $params, 'parse' );
1815 array_unshift( $params, $msg );
1816 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1817
1818 $this->returnToMain();
1819 }
1820
1821 /**
1822 * Output a standard permission error page
1823 *
1824 * @param $errors Array: error message keys
1825 * @param $action String: action that was denied or null if unknown
1826 */
1827 public function showPermissionsErrorPage( $errors, $action = null ) {
1828 $this->mDebugtext .= 'Original title: ' .
1829 $this->getTitle()->getPrefixedText() . "\n";
1830 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1831 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1832 $this->setRobotPolicy( 'noindex,nofollow' );
1833 $this->setArticleRelated( false );
1834 $this->enableClientCache( false );
1835 $this->mRedirect = '';
1836 $this->mBodytext = '';
1837 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1838 }
1839
1840 /**
1841 * Display an error page indicating that a given version of MediaWiki is
1842 * required to use it
1843 *
1844 * @param $version Mixed: the version of MediaWiki needed to use the page
1845 */
1846 public function versionRequired( $version ) {
1847 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1848 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1849 $this->setRobotPolicy( 'noindex,nofollow' );
1850 $this->setArticleRelated( false );
1851 $this->mBodytext = '';
1852
1853 $this->addWikiMsg( 'versionrequiredtext', $version );
1854 $this->returnToMain();
1855 }
1856
1857 /**
1858 * Display an error page noting that a given permission bit is required.
1859 *
1860 * @param $permission String: key required
1861 */
1862 public function permissionRequired( $permission ) {
1863 global $wgLang;
1864
1865 $this->setPageTitle( wfMsg( 'badaccess' ) );
1866 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1867 $this->setRobotPolicy( 'noindex,nofollow' );
1868 $this->setArticleRelated( false );
1869 $this->mBodytext = '';
1870
1871 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1872 User::getGroupsWithPermission( $permission ) );
1873 if( $groups ) {
1874 $this->addWikiMsg(
1875 'badaccess-groups',
1876 $wgLang->commaList( $groups ),
1877 count( $groups )
1878 );
1879 } else {
1880 $this->addWikiMsg( 'badaccess-group0' );
1881 }
1882 $this->returnToMain();
1883 }
1884
1885 /**
1886 * Produce the stock "please login to use the wiki" page
1887 */
1888 public function loginToUse() {
1889 global $wgUser;
1890
1891 if( $wgUser->isLoggedIn() ) {
1892 $this->permissionRequired( 'read' );
1893 return;
1894 }
1895
1896 $skin = $wgUser->getSkin();
1897
1898 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1899 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1900 $this->setRobotPolicy( 'noindex,nofollow' );
1901 $this->setArticleFlag( false );
1902
1903 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1904 $loginLink = $skin->link(
1905 $loginTitle,
1906 wfMsgHtml( 'loginreqlink' ),
1907 array(),
1908 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1909 array( 'known', 'noclasses' )
1910 );
1911 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1912 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . '-->' );
1913
1914 # Don't return to the main page if the user can't read it
1915 # otherwise we'll end up in a pointless loop
1916 $mainPage = Title::newMainPage();
1917 if( $mainPage->userCanRead() ) {
1918 $this->returnToMain( null, $mainPage );
1919 }
1920 }
1921
1922 /**
1923 * Format a list of error messages
1924 *
1925 * @param $errors An array of arrays returned by Title::getUserPermissionsErrors
1926 * @param $action String: action that was denied or null if unknown
1927 * @return String: the wikitext error-messages, formatted into a list.
1928 */
1929 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1930 if ( $action == null ) {
1931 $text = wfMsgNoTrans( 'permissionserrorstext', count( $errors ) ) . "\n\n";
1932 } else {
1933 $action_desc = wfMsgNoTrans( "action-$action" );
1934 $text = wfMsgNoTrans(
1935 'permissionserrorstext-withaction',
1936 count( $errors ),
1937 $action_desc
1938 ) . "\n\n";
1939 }
1940
1941 if ( count( $errors ) > 1 ) {
1942 $text .= '<ul class="permissions-errors">' . "\n";
1943
1944 foreach( $errors as $error ) {
1945 $text .= '<li>';
1946 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1947 $text .= "</li>\n";
1948 }
1949 $text .= '</ul>';
1950 } else {
1951 $text .= "<div class=\"permissions-errors\">\n" .
1952 call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) .
1953 "\n</div>";
1954 }
1955
1956 return $text;
1957 }
1958
1959 /**
1960 * Display a page stating that the Wiki is in read-only mode,
1961 * and optionally show the source of the page that the user
1962 * was trying to edit. Should only be called (for this
1963 * purpose) after wfReadOnly() has returned true.
1964 *
1965 * For historical reasons, this function is _also_ used to
1966 * show the error message when a user tries to edit a page
1967 * they are not allowed to edit. (Unless it's because they're
1968 * blocked, then we show blockedPage() instead.) In this
1969 * case, the second parameter should be set to true and a list
1970 * of reasons supplied as the third parameter.
1971 *
1972 * @todo Needs to be split into multiple functions.
1973 *
1974 * @param $source String: source code to show (or null).
1975 * @param $protected Boolean: is this a permissions error?
1976 * @param $reasons Array: list of reasons for this error, as returned by Title::getUserPermissionsErrors().
1977 * @param $action String: action that was denied or null if unknown
1978 */
1979 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1980 global $wgUser;
1981 $skin = $wgUser->getSkin();
1982
1983 $this->setRobotPolicy( 'noindex,nofollow' );
1984 $this->setArticleRelated( false );
1985
1986 // If no reason is given, just supply a default "I can't let you do
1987 // that, Dave" message. Should only occur if called by legacy code.
1988 if ( $protected && empty( $reasons ) ) {
1989 $reasons[] = array( 'badaccess-group0' );
1990 }
1991
1992 if ( !empty( $reasons ) ) {
1993 // Permissions error
1994 if( $source ) {
1995 $title = $this->getTitle();
1996 $link = $skin->linkKnown( $title );
1997 $this->mPagetitle = wfMessage( 'viewsourceheader' )->rawParams( $link )->escaped();
1998 $this->mHTMLtitle = wfMessage( 'viewsourcetitle', $title->getPrefixedText() )->escaped();
1999 } else {
2000 $this->setPageTitle( wfMsg( 'badaccess' ) );
2001 }
2002 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
2003 } else {
2004 // Wiki is read only
2005 $this->setPageTitle( wfMsg( 'readonly' ) );
2006 $reason = wfReadOnlyReason();
2007 $this->wrapWikiMsg( "<div class='mw-readonly-error'>\n$1\n</div>", array( 'readonlytext', $reason ) );
2008 }
2009
2010 // Show source, if supplied
2011 if( is_string( $source ) ) {
2012 $this->addWikiMsg( 'viewsourcetext' );
2013
2014 $params = array(
2015 'id' => 'wpTextbox1',
2016 'name' => 'wpTextbox1',
2017 'cols' => $wgUser->getOption( 'cols' ),
2018 'rows' => $wgUser->getOption( 'rows' ),
2019 'readonly' => 'readonly'
2020 );
2021 $this->addHTML( Html::element( 'textarea', $params, $source ) );
2022
2023 // Show templates used by this article
2024 $skin = $wgUser->getSkin();
2025 $article = new Article( $this->getTitle() );
2026 $this->addHTML( "<div class='templatesUsed'>
2027 {$skin->formatTemplates( $article->getUsedTemplates() )}
2028 </div>
2029 " );
2030 }
2031
2032 # If the title doesn't exist, it's fairly pointless to print a return
2033 # link to it. After all, you just tried editing it and couldn't, so
2034 # what's there to do there?
2035 if( $this->getTitle()->exists() ) {
2036 $this->returnToMain( null, $this->getTitle() );
2037 }
2038 }
2039
2040 /**
2041 * Adds JS-based password security checker
2042 * @param $passwordId String ID of input box containing password
2043 * @param $retypeId String ID of input box containing retyped password
2044 * @return none
2045 */
2046 public function addPasswordSecurity( $passwordId, $retypeId ) {
2047 $this->includeJQuery();
2048 $data = array(
2049 'password' => '#' . $passwordId,
2050 'retype' => '#' . $retypeId,
2051 'messages' => array(),
2052 );
2053 foreach ( array( 'password-strength', 'password-strength-bad', 'password-strength-mediocre',
2054 'password-strength-acceptable', 'password-strength-good', 'password-retype', 'password-retype-mismatch'
2055 ) as $message ) {
2056 $data['messages'][$message] = wfMsg( $message );
2057 }
2058 $this->addScript( Html::inlineScript( 'var passwordSecurity=' . FormatJson::encode( $data ) ) );
2059 $this->addModules( 'mediawiki.legacy.password' );
2060 }
2061
2062 /** @deprecated */
2063 public function errorpage( $title, $msg ) {
2064 wfDeprecated( __METHOD__ );
2065 throw new ErrorPageError( $title, $msg );
2066 }
2067
2068 /** @deprecated */
2069 public function databaseError( $fname, $sql, $error, $errno ) {
2070 throw new MWException( "OutputPage::databaseError is obsolete\n" );
2071 }
2072
2073 /** @deprecated */
2074 public function fatalError( $message ) {
2075 wfDeprecated( __METHOD__ );
2076 throw new FatalError( $message );
2077 }
2078
2079 /** @deprecated */
2080 public function unexpectedValueError( $name, $val ) {
2081 wfDeprecated( __METHOD__ );
2082 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
2083 }
2084
2085 /** @deprecated */
2086 public function fileCopyError( $old, $new ) {
2087 wfDeprecated( __METHOD__ );
2088 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
2089 }
2090
2091 /** @deprecated */
2092 public function fileRenameError( $old, $new ) {
2093 wfDeprecated( __METHOD__ );
2094 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
2095 }
2096
2097 /** @deprecated */
2098 public function fileDeleteError( $name ) {
2099 wfDeprecated( __METHOD__ );
2100 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
2101 }
2102
2103 /** @deprecated */
2104 public function fileNotFoundError( $name ) {
2105 wfDeprecated( __METHOD__ );
2106 throw new FatalError( wfMsg( 'filenotfound', $name ) );
2107 }
2108
2109 public function showFatalError( $message ) {
2110 $this->setPageTitle( wfMsg( 'internalerror' ) );
2111 $this->setRobotPolicy( 'noindex,nofollow' );
2112 $this->setArticleRelated( false );
2113 $this->enableClientCache( false );
2114 $this->mRedirect = '';
2115 $this->mBodytext = $message;
2116 }
2117
2118 public function showUnexpectedValueError( $name, $val ) {
2119 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
2120 }
2121
2122 public function showFileCopyError( $old, $new ) {
2123 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
2124 }
2125
2126 public function showFileRenameError( $old, $new ) {
2127 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
2128 }
2129
2130 public function showFileDeleteError( $name ) {
2131 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
2132 }
2133
2134 public function showFileNotFoundError( $name ) {
2135 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
2136 }
2137
2138 /**
2139 * Add a "return to" link pointing to a specified title
2140 *
2141 * @param $title Title to link
2142 * @param $query String: query string
2143 * @param $text String text of the link (input is not escaped)
2144 */
2145 public function addReturnTo( $title, $query = array(), $text = null ) {
2146 global $wgUser;
2147 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL() ) );
2148 $link = wfMsgHtml(
2149 'returnto',
2150 $wgUser->getSkin()->link( $title, $text, array(), $query )
2151 );
2152 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
2153 }
2154
2155 /**
2156 * Add a "return to" link pointing to a specified title,
2157 * or the title indicated in the request, or else the main page
2158 *
2159 * @param $unused No longer used
2160 * @param $returnto Title or String to return to
2161 * @param $returntoquery String: query string for the return to link
2162 */
2163 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
2164 global $wgRequest;
2165
2166 if ( $returnto == null ) {
2167 $returnto = $wgRequest->getText( 'returnto' );
2168 }
2169
2170 if ( $returntoquery == null ) {
2171 $returntoquery = $wgRequest->getText( 'returntoquery' );
2172 }
2173
2174 if ( $returnto === '' ) {
2175 $returnto = Title::newMainPage();
2176 }
2177
2178 if ( is_object( $returnto ) ) {
2179 $titleObj = $returnto;
2180 } else {
2181 $titleObj = Title::newFromText( $returnto );
2182 }
2183 if ( !is_object( $titleObj ) ) {
2184 $titleObj = Title::newMainPage();
2185 }
2186
2187 $this->addReturnTo( $titleObj, $returntoquery );
2188 }
2189
2190 /**
2191 * @param $sk Skin The given Skin
2192 * @param $includeStyle Boolean: unused
2193 * @return String: The doctype, opening <html>, and head element.
2194 */
2195 public function headElement( Skin $sk, $includeStyle = true ) {
2196 global $wgOutputEncoding, $wgMimeType;
2197 global $wgUseTrackbacks, $wgHtml5;
2198 global $wgUser, $wgRequest, $wgLang;
2199
2200 if ( $sk->commonPrintStylesheet() ) {
2201 $this->addModuleStyles( 'mediawiki.legacy.wikiprintable' );
2202 }
2203 $sk->setupUserCss( $this );
2204
2205 $ret = Html::htmlHeader( array( 'lang' => wfUILang()->getCode() ) );
2206
2207 if ( $this->getHTMLTitle() == '' ) {
2208 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ) );
2209 }
2210
2211 $openHead = Html::openElement( 'head' );
2212 if ( $openHead ) {
2213 # Don't bother with the newline if $head == ''
2214 $ret .= "$openHead\n";
2215 }
2216
2217 if ( $wgHtml5 ) {
2218 # More succinct than <meta http-equiv=Content-Type>, has the
2219 # same effect
2220 $ret .= Html::element( 'meta', array( 'charset' => $wgOutputEncoding ) ) . "\n";
2221 } else {
2222 $this->addMeta( 'http:Content-Type', "$wgMimeType; charset=$wgOutputEncoding" );
2223 }
2224
2225 $ret .= Html::element( 'title', null, $this->getHTMLTitle() ) . "\n";
2226
2227 $ret .= implode( "\n", array(
2228 $this->getHeadLinks( $sk ),
2229 $this->buildCssLinks(),
2230 $this->getHeadItems(),
2231 ) );
2232 if ( $sk->usercss ) {
2233 $ret .= Html::inlineStyle( $sk->usercss );
2234 }
2235
2236 if ( $wgUseTrackbacks && $this->isArticleRelated() ) {
2237 $ret .= $this->getTitle()->trackbackRDF();
2238 }
2239
2240 $closeHead = Html::closeElement( 'head' );
2241 if ( $closeHead ) {
2242 $ret .= "$closeHead\n";
2243 }
2244
2245 $bodyAttrs = array();
2246
2247 # Crazy edit-on-double-click stuff
2248 $action = $wgRequest->getVal( 'action', 'view' );
2249
2250 if (
2251 $this->getTitle()->getNamespace() != NS_SPECIAL &&
2252 !in_array( $action, array( 'edit', 'submit' ) ) &&
2253 $wgUser->getOption( 'editondblclick' )
2254 )
2255 {
2256 $bodyAttrs['ondblclick'] = "document.location = '" . Xml::escapeJsString( $this->getTitle()->getEditURL() ) . "'";
2257 }
2258
2259 # Class bloat
2260 $dir = wfUILang()->getDir();
2261 $bodyAttrs['class'] = "mediawiki $dir";
2262
2263 if ( $wgLang->capitalizeAllNouns() ) {
2264 # A <body> class is probably not the best way to do this . . .
2265 $bodyAttrs['class'] .= ' capitalize-all-nouns';
2266 }
2267 $bodyAttrs['class'] .= ' ns-' . $this->getTitle()->getNamespace();
2268 if ( $this->getTitle()->getNamespace() == NS_SPECIAL ) {
2269 $bodyAttrs['class'] .= ' ns-special';
2270 } elseif ( $this->getTitle()->isTalkPage() ) {
2271 $bodyAttrs['class'] .= ' ns-talk';
2272 } else {
2273 $bodyAttrs['class'] .= ' ns-subject';
2274 }
2275 $bodyAttrs['class'] .= ' ' . Sanitizer::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
2276 $bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass( $wgUser->getSkin()->getSkinName() );
2277
2278 $ret .= Html::openElement( 'body', $bodyAttrs ) . "\n";
2279
2280 return $ret;
2281 }
2282
2283 // TODO: Document
2284 static function makeResourceLoaderLink( $skin, $modules, $only, $useESI = false ) {
2285 global $wgUser, $wgLang, $wgRequest, $wgLoadScript, $wgResourceLoaderDebug, $wgResourceLoaderUseESI,
2286 $wgResourceLoaderInlinePrivateModules;
2287 // TODO: Should this be a static function of ResourceLoader instead?
2288 // TODO: Divide off modules starting with "user", and add the user parameter to them
2289 $query = array(
2290 'lang' => $wgLang->getCode(),
2291 'debug' => $wgRequest->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ? 'true' : 'false',
2292 'skin' => $wgUser->getSkin()->getSkinName(),
2293 'only' => $only,
2294 );
2295 // Remove duplicate module requests
2296 $modules = array_unique( (array) $modules );
2297 // Sort module names so requests are more uniform
2298 sort( $modules );
2299 // Create keyed-by-group list of module objects from modules list
2300 $groups = array();
2301 foreach ( (array) $modules as $name ) {
2302 $module = ResourceLoader::getModule( $name );
2303 $group = $module->getGroup();
2304 if ( !isset( $groups[$group] ) ) {
2305 $groups[$group] = array();
2306 }
2307 $groups[$group][$name] = $module;
2308 }
2309 $links = '';
2310 foreach ( $groups as $group => $modules ) {
2311 $query['modules'] = implode( '|', array_keys( $modules ) );
2312 // Special handling for user-specific groups
2313 if ( ( $group === 'user' || $group === 'private' ) && $wgUser->isLoggedIn() ) {
2314 $query['user'] = $wgUser->getName();
2315 }
2316 // Support inlining of private modules if configured as such
2317 if ( $group === 'private' && $wgResourceLoaderInlinePrivateModules ) {
2318 $context = new ResourceLoaderContext( new FauxRequest( $query ) );
2319 if ( $only == 'styles' ) {
2320 $links .= Html::inlineStyle(
2321 ResourceLoader::makeLoaderConditionalScript(
2322 ResourceLoader::makeModuleResponse( $context, $modules )
2323 )
2324 );
2325 } else {
2326 $links .= Html::inlineScript(
2327 ResourceLoader::makeLoaderConditionalScript(
2328 ResourceLoader::makeModuleResponse( $context, $modules )
2329 )
2330 );
2331 }
2332 continue;
2333 }
2334 // Special handling for user and site groups; because users might change their stuff on-wiki like site or
2335 // user pages, or user preferences; we need to find the highest timestamp of these user-changable modules so
2336 // we can ensure cache misses on change
2337 if ( $group === 'user' || $group === 'site' ) {
2338 // Create a fake request based on the one we are about to make so modules return correct times
2339 $context = new ResourceLoaderContext( new FauxRequest( $query ) );
2340 // Get the maximum timestamp
2341 $timestamp = 0;
2342 foreach ( $modules as $module ) {
2343 $timestamp = max( $timestamp, $module->getModifiedTime( $context ) );
2344 }
2345 // Add a version parameter so cache will break when things change
2346 $query['version'] = wfTimestamp( TS_ISO_8601, round( $timestamp, -2 ) );
2347 }
2348 // Make queries uniform in order
2349 ksort( $query );
2350
2351 $url = wfAppendQuery( $wgLoadScript, $query );
2352 if ( $useESI && $wgResourceLoaderUseESI ) {
2353 $esi = Xml::element( 'esi:include', array( 'src' => $url ) );
2354 if ( $only == 'styles' ) {
2355 $links .= Html::inlineStyle( $esi );
2356 } else {
2357 $links .= Html::inlineScript( $esi );
2358 }
2359 } else {
2360 // Automatically select style/script elements
2361 if ( $only === 'styles' ) {
2362 $links .= Html::linkedStyle( wfAppendQuery( $wgLoadScript, $query ) ) . "\n";
2363 } else {
2364 $links .= Html::linkedScript( wfAppendQuery( $wgLoadScript, $query ) ) . "\n";
2365 }
2366 }
2367 }
2368 return $links;
2369 }
2370
2371 /**
2372 * Gets the global variables and mScripts; also adds userjs to the end if
2373 * enabled. Despite the name, these scripts are no longer put in the
2374 * <head> but at the bottom of the <body>
2375 *
2376 * @param $sk Skin object to use
2377 * @return String: HTML fragment
2378 */
2379 function getHeadScripts( Skin $sk ) {
2380 global $wgUser, $wgRequest, $wgUseSiteJs, $wgResourceLoaderDebug;
2381
2382 // Startup - this will immediately load jquery and mediawiki modules
2383 $scripts = self::makeResourceLoaderLink( $sk, 'startup', 'scripts', true );
2384
2385 // Configuration -- This could be merged together with the load and go, but makeGlobalVariablesScript returns a
2386 // whole script tag -- grumble grumble...
2387 $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
2388
2389 // Script and Messages "only"
2390 if ( $wgRequest->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ) {
2391 // Scripts
2392 foreach ( $this->getModuleScripts() as $name ) {
2393 $scripts .= self::makeResourceLoaderLink( $sk, $name, 'scripts' );
2394 }
2395 // Messages
2396 foreach ( $this->getModuleMessages() as $name ) {
2397 $scripts .= self::makeResourceLoaderLink( $sk, $name, 'messages' );
2398 }
2399 } else {
2400 // Scripts
2401 if ( count( $this->getModuleScripts() ) ) {
2402 $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' );
2403 }
2404 // Messages
2405 if ( count( $this->getModuleMessages() ) ) {
2406 $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' );
2407 }
2408 }
2409
2410 // Modules - let the client calculate dependencies and batch requests as it likes
2411 if ( $this->getModules() ) {
2412 $modules = FormatJson::encode( $this->getModules() );
2413 $scripts .= Html::inlineScript(
2414 "if ( window.mediaWiki ) { mediaWiki.loader.load( {$modules} ); mediaWiki.loader.go(); }"
2415 ) . "\n";
2416 }
2417
2418 // Add user JS if enabled - trying to load user.options as a bundle if possible
2419 $userOptionsAdded = false;
2420 if ( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
2421 $action = $wgRequest->getVal( 'action', 'view' );
2422 if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
2423 # XXX: additional security check/prompt?
2424 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
2425 } else {
2426 $scripts .= self::makeResourceLoaderLink( $sk, array( 'user', 'user.options' ), 'scripts' );
2427 $userOptionsAdded = true;
2428 }
2429 }
2430 if ( !$userOptionsAdded ) {
2431 $scripts .= self::makeResourceLoaderLink( $sk, 'user.options', 'scripts' );
2432 }
2433 $scripts .= "\n" . $this->mScripts;
2434
2435 // Add site JS if enabled
2436 if ( $wgUseSiteJs ) {
2437 $scripts .= self::makeResourceLoaderLink( $sk, 'site', 'scripts' );
2438 }
2439
2440 return $scripts;
2441 }
2442
2443 /**
2444 * Add default \<meta\> tags
2445 */
2446 protected function addDefaultMeta() {
2447 global $wgVersion, $wgHtml5;
2448
2449 static $called = false;
2450 if ( $called ) {
2451 # Don't run this twice
2452 return;
2453 }
2454 $called = true;
2455
2456 if ( !$wgHtml5 ) {
2457 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); // bug 15835
2458 }
2459 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
2460
2461 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
2462 if( $p !== 'index,follow' ) {
2463 // http://www.robotstxt.org/wc/meta-user.html
2464 // Only show if it's different from the default robots policy
2465 $this->addMeta( 'robots', $p );
2466 }
2467
2468 if ( count( $this->mKeywords ) > 0 ) {
2469 $strip = array(
2470 "/<.*?" . ">/" => '',
2471 "/_/" => ' '
2472 );
2473 $this->addMeta(
2474 'keywords',
2475 preg_replace(
2476 array_keys( $strip ),
2477 array_values( $strip ),
2478 implode( ',', $this->mKeywords )
2479 )
2480 );
2481 }
2482 }
2483
2484 /**
2485 * @return string HTML tag links to be put in the header.
2486 */
2487 public function getHeadLinks( $sk ) {
2488 global $wgFeed, $wgRequest, $wgResourceLoaderDebug;
2489
2490 // Ideally this should happen earlier, somewhere. :P
2491 $this->addDefaultMeta();
2492
2493 $tags = array();
2494
2495 foreach ( $this->mMetatags as $tag ) {
2496 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
2497 $a = 'http-equiv';
2498 $tag[0] = substr( $tag[0], 5 );
2499 } else {
2500 $a = 'name';
2501 }
2502 $tags[] = Html::element( 'meta',
2503 array(
2504 $a => $tag[0],
2505 'content' => $tag[1]
2506 )
2507 );
2508 }
2509 foreach ( $this->mLinktags as $tag ) {
2510 $tags[] = Html::element( 'link', $tag );
2511 }
2512
2513 if( $wgFeed ) {
2514 foreach( $this->getSyndicationLinks() as $format => $link ) {
2515 # Use the page name for the title (accessed through $wgTitle since
2516 # there's no other way). In principle, this could lead to issues
2517 # with having the same name for different feeds corresponding to
2518 # the same page, but we can't avoid that at this low a level.
2519
2520 $tags[] = $this->feedLink(
2521 $format,
2522 $link,
2523 # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
2524 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() )
2525 );
2526 }
2527
2528 # Recent changes feed should appear on every page (except recentchanges,
2529 # that would be redundant). Put it after the per-page feed to avoid
2530 # changing existing behavior. It's still available, probably via a
2531 # menu in your browser. Some sites might have a different feed they'd
2532 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
2533 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
2534 # If so, use it instead.
2535
2536 global $wgOverrideSiteFeed, $wgSitename, $wgAdvertisedFeedTypes;
2537 $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
2538
2539 if ( $wgOverrideSiteFeed ) {
2540 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
2541 $tags[] = $this->feedLink(
2542 $type,
2543 htmlspecialchars( $feedUrl ),
2544 wfMsg( "site-{$type}-feed", $wgSitename )
2545 );
2546 }
2547 } elseif ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
2548 foreach ( $wgAdvertisedFeedTypes as $format ) {
2549 $tags[] = $this->feedLink(
2550 $format,
2551 $rctitle->getLocalURL( "feed={$format}" ),
2552 wfMsg( "site-{$format}-feed", $wgSitename ) # For grep: 'site-rss-feed', 'site-atom-feed'.
2553 );
2554 }
2555 }
2556 }
2557
2558 // Support individual script requests in debug mode
2559 if ( $wgRequest->getFuzzyBool( 'debug', $wgResourceLoaderDebug ) ) {
2560 foreach ( $this->getModuleStyles() as $name ) {
2561 $tags[] = self::makeResourceLoaderLink( $sk, $name, 'styles' );
2562 }
2563 } else {
2564 if ( count( $this->getModuleStyles() ) ) {
2565 $tags[] = self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' );
2566 }
2567 }
2568
2569 return implode( "\n", $tags );
2570 }
2571
2572 /**
2573 * Generate a <link rel/> for a feed.
2574 *
2575 * @param $type String: feed type
2576 * @param $url String: URL to the feed
2577 * @param $text String: value of the "title" attribute
2578 * @return String: HTML fragment
2579 */
2580 private function feedLink( $type, $url, $text ) {
2581 return Html::element( 'link', array(
2582 'rel' => 'alternate',
2583 'type' => "application/$type+xml",
2584 'title' => $text,
2585 'href' => $url )
2586 );
2587 }
2588
2589 /**
2590 * Add a local or specified stylesheet, with the given media options.
2591 * Meant primarily for internal use...
2592 *
2593 * @param $style String: URL to the file
2594 * @param $media String: to specify a media type, 'screen', 'printable', 'handheld' or any.
2595 * @param $condition String: for IE conditional comments, specifying an IE version
2596 * @param $dir String: set to 'rtl' or 'ltr' for direction-specific sheets
2597 */
2598 public function addStyle( $style, $media = '', $condition = '', $dir = '' ) {
2599 $options = array();
2600 // Even though we expect the media type to be lowercase, but here we
2601 // force it to lowercase to be safe.
2602 if( $media ) {
2603 $options['media'] = $media;
2604 }
2605 if( $condition ) {
2606 $options['condition'] = $condition;
2607 }
2608 if( $dir ) {
2609 $options['dir'] = $dir;
2610 }
2611 $this->styles[$style] = $options;
2612 }
2613
2614 /**
2615 * Adds inline CSS styles
2616 * @param $style_css Mixed: inline CSS
2617 */
2618 public function addInlineStyle( $style_css ){
2619 $this->mScripts .= Html::inlineStyle( $style_css );
2620 }
2621
2622 /**
2623 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
2624 * These will be applied to various media & IE conditionals.
2625 */
2626 public function buildCssLinks() {
2627 return implode( "\n", $this->buildCssLinksArray() );
2628 }
2629
2630 public function buildCssLinksArray() {
2631 $links = array();
2632 foreach( $this->styles as $file => $options ) {
2633 $link = $this->styleLink( $file, $options );
2634 if( $link ) {
2635 $links[$file] = $link;
2636 }
2637 }
2638 return $links;
2639 }
2640
2641 /**
2642 * Generate \<link\> tags for stylesheets
2643 *
2644 * @param $style String: URL to the file
2645 * @param $options Array: option, can contain 'condition', 'dir', 'media'
2646 * keys
2647 * @return String: HTML fragment
2648 */
2649 protected function styleLink( $style, $options ) {
2650 if( isset( $options['dir'] ) ) {
2651 $siteDir = wfUILang()->getDir();
2652 if( $siteDir != $options['dir'] ) {
2653 return '';
2654 }
2655 }
2656
2657 if( isset( $options['media'] ) ) {
2658 $media = $this->transformCssMedia( $options['media'] );
2659 if( is_null( $media ) ) {
2660 return '';
2661 }
2662 } else {
2663 $media = 'all';
2664 }
2665
2666 if( substr( $style, 0, 1 ) == '/' ||
2667 substr( $style, 0, 5 ) == 'http:' ||
2668 substr( $style, 0, 6 ) == 'https:' ) {
2669 $url = $style;
2670 } else {
2671 global $wgStylePath, $wgStyleVersion;
2672 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
2673 }
2674
2675 $link = Html::linkedStyle( $url, $media );
2676
2677 if( isset( $options['condition'] ) ) {
2678 $condition = htmlspecialchars( $options['condition'] );
2679 $link = "<!--[if $condition]>$link<![endif]-->";
2680 }
2681 return $link;
2682 }
2683
2684 /**
2685 * Transform "media" attribute based on request parameters
2686 *
2687 * @param $media String: current value of the "media" attribute
2688 * @return String: modified value of the "media" attribute
2689 */
2690 function transformCssMedia( $media ) {
2691 global $wgRequest, $wgHandheldForIPhone;
2692
2693 // Switch in on-screen display for media testing
2694 $switches = array(
2695 'printable' => 'print',
2696 'handheld' => 'handheld',
2697 );
2698 foreach( $switches as $switch => $targetMedia ) {
2699 if( $wgRequest->getBool( $switch ) ) {
2700 if( $media == $targetMedia ) {
2701 $media = '';
2702 } elseif( $media == 'screen' ) {
2703 return null;
2704 }
2705 }
2706 }
2707
2708 // Expand longer media queries as iPhone doesn't grok 'handheld'
2709 if( $wgHandheldForIPhone ) {
2710 $mediaAliases = array(
2711 'screen' => 'screen and (min-device-width: 481px)',
2712 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
2713 );
2714
2715 if( isset( $mediaAliases[$media] ) ) {
2716 $media = $mediaAliases[$media];
2717 }
2718 }
2719
2720 return $media;
2721 }
2722
2723 /**
2724 * Turn off regular page output and return an error reponse
2725 * for when rate limiting has triggered.
2726 */
2727 public function rateLimited() {
2728 $this->setPageTitle( wfMsg( 'actionthrottled' ) );
2729 $this->setRobotPolicy( 'noindex,follow' );
2730 $this->setArticleRelated( false );
2731 $this->enableClientCache( false );
2732 $this->mRedirect = '';
2733 $this->clearHTML();
2734 $this->setStatusCode( 503 );
2735 $this->addWikiMsg( 'actionthrottledtext' );
2736
2737 $this->returnToMain( null, $this->getTitle() );
2738 }
2739
2740 /**
2741 * Show a warning about slave lag
2742 *
2743 * If the lag is higher than $wgSlaveLagCritical seconds,
2744 * then the warning is a bit more obvious. If the lag is
2745 * lower than $wgSlaveLagWarning, then no warning is shown.
2746 *
2747 * @param $lag Integer: slave lag
2748 */
2749 public function showLagWarning( $lag ) {
2750 global $wgSlaveLagWarning, $wgSlaveLagCritical, $wgLang;
2751 if( $lag >= $wgSlaveLagWarning ) {
2752 $message = $lag < $wgSlaveLagCritical
2753 ? 'lag-warn-normal'
2754 : 'lag-warn-high';
2755 $wrap = Html::rawElement( 'div', array( 'class' => "mw-{$message}" ), "\n$1\n" );
2756 $this->wrapWikiMsg( "$wrap\n", array( $message, $wgLang->formatNum( $lag ) ) );
2757 }
2758 }
2759
2760 /**
2761 * Add a wikitext-formatted message to the output.
2762 * This is equivalent to:
2763 *
2764 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
2765 */
2766 public function addWikiMsg( /*...*/ ) {
2767 $args = func_get_args();
2768 $name = array_shift( $args );
2769 $this->addWikiMsgArray( $name, $args );
2770 }
2771
2772 /**
2773 * Add a wikitext-formatted message to the output.
2774 * Like addWikiMsg() except the parameters are taken as an array
2775 * instead of a variable argument list.
2776 *
2777 * $options is passed through to wfMsgExt(), see that function for details.
2778 */
2779 public function addWikiMsgArray( $name, $args, $options = array() ) {
2780 $options[] = 'parse';
2781 $text = wfMsgExt( $name, $options, $args );
2782 $this->addHTML( $text );
2783 }
2784
2785 /**
2786 * This function takes a number of message/argument specifications, wraps them in
2787 * some overall structure, and then parses the result and adds it to the output.
2788 *
2789 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
2790 * on. The subsequent arguments may either be strings, in which case they are the
2791 * message names, or arrays, in which case the first element is the message name,
2792 * and subsequent elements are the parameters to that message.
2793 *
2794 * The special named parameter 'options' in a message specification array is passed
2795 * through to the $options parameter of wfMsgExt().
2796 *
2797 * Don't use this for messages that are not in users interface language.
2798 *
2799 * For example:
2800 *
2801 * $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>", 'some-error' );
2802 *
2803 * Is equivalent to:
2804 *
2805 * $wgOut->addWikiText( "<div class='error'>\n" . wfMsgNoTrans( 'some-error' ) . "\n</div>" );
2806 *
2807 * The newline after opening div is needed in some wikitext. See bug 19226.
2808 */
2809 public function wrapWikiMsg( $wrap /*, ...*/ ) {
2810 $msgSpecs = func_get_args();
2811 array_shift( $msgSpecs );
2812 $msgSpecs = array_values( $msgSpecs );
2813 $s = $wrap;
2814 foreach ( $msgSpecs as $n => $spec ) {
2815 $options = array();
2816 if ( is_array( $spec ) ) {
2817 $args = $spec;
2818 $name = array_shift( $args );
2819 if ( isset( $args['options'] ) ) {
2820 $options = $args['options'];
2821 unset( $args['options'] );
2822 }
2823 } else {
2824 $args = array();
2825 $name = $spec;
2826 }
2827 $s = str_replace( '$' . ( $n + 1 ), wfMsgExt( $name, $options, $args ), $s );
2828 }
2829 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
2830 }
2831
2832 /**
2833 * Include jQuery core. Use this to avoid loading it multiple times
2834 * before we get a usable script loader.
2835 *
2836 * @param $modules Array: list of jQuery modules which should be loaded
2837 * @return Array: the list of modules which were not loaded.
2838 * @since 1.16
2839 * @deprecated No longer needed as of 1.17
2840 */
2841 public function includeJQuery( $modules = array() ) {
2842 return array();
2843 }
2844
2845 }