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