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