Add returntoquery= parameter to Special:Userlogin which adds a query string to the...
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 /**
6 * @todo document
7 */
8 class OutputPage {
9 var $mMetatags = array(), $mKeywords = array(), $mLinktags = array();
10 var $mExtStyles = array();
11 var $mPagetitle = '', $mBodytext = '', $mDebugtext = '';
12 var $mHTMLtitle = '', $mIsarticle = true, $mPrintable = false;
13 var $mSubtitle = '', $mRedirect = '', $mStatusCode;
14 var $mLastModified = '', $mETag = false;
15 var $mCategoryLinks = array(), $mLanguageLinks = array();
16 var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
17 var $mTemplateIds = array();
18
19 var $mAllowUserJs;
20 var $mSuppressQuickbar = false;
21 var $mOnloadHandler = '';
22 var $mDoNothing = false;
23 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
24 var $mIsArticleRelated = true;
25 protected $mParserOptions = null; // lazy initialised, use parserOptions()
26 var $mShowFeedLinks = false;
27 var $mFeedLinksAppendQuery = false;
28 var $mEnableClientCache = true;
29 var $mArticleBodyOnly = false;
30
31 var $mNewSectionLink = false;
32 var $mHideNewSectionLink = false;
33 var $mNoGallery = false;
34 var $mPageTitleActionText = '';
35 var $mParseWarnings = array();
36 var $mSquidMaxage = 0;
37 var $mRevisionId = null;
38 protected $mTitle = null;
39
40 /**
41 * An array of stylesheet filenames (relative from skins path), with options
42 * for CSS media, IE conditions, and RTL/LTR direction.
43 * For internal use; add settings in the skin via $this->addStyle()
44 */
45 var $styles = array();
46
47 private $mIndexPolicy = 'index';
48 private $mFollowPolicy = 'follow';
49
50 /**
51 * Constructor
52 * Initialise private variables
53 */
54 function __construct() {
55 global $wgAllowUserJs;
56 $this->mAllowUserJs = $wgAllowUserJs;
57 }
58
59 public function redirect( $url, $responsecode = '302' ) {
60 # Strip newlines as a paranoia check for header injection in PHP<5.1.2
61 $this->mRedirect = str_replace( "\n", '', $url );
62 $this->mRedirectCode = $responsecode;
63 }
64
65 public function getRedirect() {
66 return $this->mRedirect;
67 }
68
69 /**
70 * Set the HTTP status code to send with the output.
71 *
72 * @param int $statusCode
73 * @return nothing
74 */
75 function setStatusCode( $statusCode ) { $this->mStatusCode = $statusCode; }
76
77 /**
78 * Add a new <meta> tag
79 * To add an http-equiv meta tag, precede the name with "http:"
80 *
81 * @param $name tag name
82 * @param $val tag value
83 */
84 function addMeta( $name, $val ) {
85 array_push( $this->mMetatags, array( $name, $val ) );
86 }
87
88 function addKeyword( $text ) {
89 if( is_array( $text )) {
90 $this->mKeywords = array_merge( $this->mKeywords, $text );
91 }
92 else {
93 array_push( $this->mKeywords, $text );
94 }
95 }
96 function addScript( $script ) { $this->mScripts .= "\t" . $script . "\n"; }
97
98 function addExtensionStyle( $url ) {
99 $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
100 array_push( $this->mExtStyles, $linkarr );
101 }
102
103 /**
104 * Add a JavaScript file out of skins/common, or a given relative path.
105 * @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
106 */
107 function addScriptFile( $file ) {
108 global $wgStylePath, $wgStyleVersion, $wgJsMimeType;
109 if( substr( $file, 0, 1 ) == '/' ) {
110 $path = $file;
111 } else {
112 $path = "{$wgStylePath}/common/{$file}";
113 }
114 $this->addScript(
115 Xml::element( 'script',
116 array(
117 'type' => $wgJsMimeType,
118 'src' => "$path?$wgStyleVersion",
119 ),
120 '', false
121 )
122 );
123 }
124
125 /**
126 * Add a self-contained script tag with the given contents
127 * @param string $script JavaScript text, no <script> tags
128 */
129 function addInlineScript( $script ) {
130 global $wgJsMimeType;
131 $this->mScripts .= "\t\t<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
132 }
133
134 function getScript() {
135 return $this->mScripts . $this->getHeadItems();
136 }
137
138 function getHeadItems() {
139 $s = '';
140 foreach ( $this->mHeadItems as $item ) {
141 $s .= $item;
142 }
143 return $s;
144 }
145
146 function addHeadItem( $name, $value ) {
147 $this->mHeadItems[$name] = $value;
148 }
149
150 function hasHeadItem( $name ) {
151 return isset( $this->mHeadItems[$name] );
152 }
153
154 function setETag($tag) { $this->mETag = $tag; }
155 function setArticleBodyOnly($only) { $this->mArticleBodyOnly = $only; }
156 function getArticleBodyOnly($only) { return $this->mArticleBodyOnly; }
157
158 function addLink( $linkarr ) {
159 # $linkarr should be an associative array of attributes. We'll escape on output.
160 array_push( $this->mLinktags, $linkarr );
161 }
162
163 # Get all links added by extensions
164 function getExtStyle() {
165 return $this->mExtStyles;
166 }
167
168 function addMetadataLink( $linkarr ) {
169 # note: buggy CC software only reads first "meta" link
170 static $haveMeta = false;
171 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
172 $this->addLink( $linkarr );
173 $haveMeta = true;
174 }
175
176 /**
177 * checkLastModified tells the client to use the client-cached page if
178 * possible. If sucessful, the OutputPage is disabled so that
179 * any future call to OutputPage->output() have no effect.
180 *
181 * Side effect: sets mLastModified for Last-Modified header
182 *
183 * @return bool True iff cache-ok headers was sent.
184 */
185 function checkLastModified( $timestamp ) {
186 global $wgCachePages, $wgCacheEpoch, $wgUser, $wgRequest;
187
188 if ( !$timestamp || $timestamp == '19700101000000' ) {
189 wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
190 return false;
191 }
192 if( !$wgCachePages ) {
193 wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
194 return false;
195 }
196 if( $wgUser->getOption( 'nocache' ) ) {
197 wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
198 return false;
199 }
200
201 $timestamp = wfTimestamp( TS_MW, $timestamp );
202 $modifiedTimes = array(
203 'page' => $timestamp,
204 'user' => $wgUser->getTouched(),
205 'epoch' => $wgCacheEpoch
206 );
207 wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
208
209 $maxModified = max( $modifiedTimes );
210 $this->mLastModified = wfTimestamp( TS_RFC2822, $maxModified );
211
212 if( empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
213 wfDebug( __METHOD__ . ": client did not send If-Modified-Since header\n", false );
214 return false;
215 }
216
217 # Make debug info
218 $info = '';
219 foreach ( $modifiedTimes as $name => $value ) {
220 if ( $info !== '' ) {
221 $info .= ', ';
222 }
223 $info .= "$name=" . wfTimestamp( TS_ISO_8601, $value );
224 }
225
226 # IE sends sizes after the date like this:
227 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
228 # this breaks strtotime().
229 $clientHeader = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
230
231 wfSuppressWarnings(); // E_STRICT system time bitching
232 $clientHeaderTime = strtotime( $clientHeader );
233 wfRestoreWarnings();
234 if ( !$clientHeaderTime ) {
235 wfDebug( __METHOD__ . ": unable to parse the client's If-Modified-Since header: $clientHeader\n" );
236 return false;
237 }
238 $clientHeaderTime = wfTimestamp( TS_MW, $clientHeaderTime );
239
240 wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
241 wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n", false );
242 wfDebug( __METHOD__ . ": effective Last-Modified: " .
243 wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", false );
244 if( $clientHeaderTime < $maxModified ) {
245 wfDebug( __METHOD__ . ": STALE, $info\n", false );
246 return false;
247 }
248
249 # Not modified
250 # Give a 304 response code and disable body output
251 wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", false );
252 ini_set('zlib.output_compression', 0);
253 $wgRequest->response()->header( "HTTP/1.1 304 Not Modified" );
254 $this->sendCacheControl();
255 $this->disable();
256
257 // Don't output a compressed blob when using ob_gzhandler;
258 // it's technically against HTTP spec and seems to confuse
259 // Firefox when the response gets split over two packets.
260 wfClearOutputBuffers();
261
262 return true;
263 }
264
265 function setPageTitleActionText( $text ) {
266 $this->mPageTitleActionText = $text;
267 }
268
269 function getPageTitleActionText () {
270 if ( isset( $this->mPageTitleActionText ) ) {
271 return $this->mPageTitleActionText;
272 }
273 }
274
275 /**
276 * Set the robot policy for the page: <http://www.robotstxt.org/meta.html>
277 *
278 * @param $policy string The literal string to output as the contents of
279 * the meta tag. Will be parsed according to the spec and output in
280 * standardized form.
281 * @return null
282 */
283 public function setRobotPolicy( $policy ) {
284 $policy = explode( ',', $policy );
285 $policy = array_map( 'trim', $policy );
286
287 # The default policy is follow, so if nothing is said explicitly, we
288 # do that.
289 if( in_array( 'nofollow', $policy ) ) {
290 $this->mFollowPolicy = 'nofollow';
291 } else {
292 $this->mFollowPolicy = 'follow';
293 }
294
295 if( in_array( 'noindex', $policy ) ) {
296 $this->mIndexPolicy = 'noindex';
297 } else {
298 $this->mIndexPolicy = 'index';
299 }
300 }
301
302 /**
303 * Set the index policy for the page, but leave the follow policy un-
304 * touched.
305 *
306 * @param $policy string Either 'index' or 'noindex'.
307 * @return null
308 */
309 public function setIndexPolicy( $policy ) {
310 $policy = trim( $policy );
311 if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
312 $this->mIndexPolicy = $policy;
313 }
314 }
315
316 /**
317 * Set the follow policy for the page, but leave the index policy un-
318 * touched.
319 *
320 * @param $policy string Either 'follow' or 'nofollow'.
321 * @return null
322 */
323 public function setFollowPolicy( $policy ) {
324 $policy = trim( $policy );
325 if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
326 $this->mFollowPolicy = $policy;
327 }
328 }
329
330 /**
331 * "HTML title" means the contents of <title>. It is stored as plain, unescaped text and will be run through htmlspecialchars in the skin file.
332 */
333 public function setHTMLTitle( $name ) {
334 $this->mHTMLtitle = $name;
335 }
336
337 /**
338 * "Page title" means the contents of <h1>. It is stored as a valid HTML fragment.
339 * This function allows good tags like <sup> in the <h1> tag, but not bad tags like <script>.
340 * This function automatically sets <title> to the same content as <h1> but with all tags removed.
341 * Bad tags that were escaped in <h1> will still be escaped in <title>, and good tags like <i> will be dropped entirely.
342 */
343 public function setPageTitle( $name ) {
344 global $wgContLang;
345 $name = $wgContLang->convert( $name, true );
346 # change "<script>foo&bar</script>" to "&lt;script&gt;foo&amp;bar&lt;/script&gt;"
347 # but leave "<i>foobar</i>" alone
348 $nameWithTags = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $name ) );
349 $this->mPagetitle = $nameWithTags;
350
351 $taction = $this->getPageTitleActionText();
352 if( !empty( $taction ) ) {
353 $name .= ' - '.$taction;
354 }
355
356 # change "<i>foo&amp;bar</i>" to "foo&bar"
357 $this->setHTMLTitle( wfMsg( 'pagetitle', Sanitizer::stripAllTags( $nameWithTags ) ) );
358 }
359
360 public function setTitle( $t ) {
361 $this->mTitle = $t;
362 }
363
364 public function getTitle() {
365 if ( $this->mTitle instanceof Title ) {
366 return $this->mTitle;
367 }
368 else {
369 wfDebug( __METHOD__ . ' called and $mTitle is null. Return $wgTitle for sanity' );
370 global $wgTitle;
371 return $wgTitle;
372 }
373 }
374
375 public function getHTMLTitle() { return $this->mHTMLtitle; }
376 public function getPageTitle() { return $this->mPagetitle; }
377 public function setSubtitle( $str ) { $this->mSubtitle = /*$this->parse(*/$str/*)*/; } // @bug 2514
378 public function appendSubtitle( $str ) { $this->mSubtitle .= /*$this->parse(*/$str/*)*/; } // @bug 2514
379 public function getSubtitle() { return $this->mSubtitle; }
380 public function isArticle() { return $this->mIsarticle; }
381 public function setPrintable() { $this->mPrintable = true; }
382 public function isPrintable() { return $this->mPrintable; }
383 public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
384 public function isSyndicated() { return $this->mShowFeedLinks; }
385 public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery = $val; }
386 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery; }
387 public function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
388 public function getOnloadHandler() { return $this->mOnloadHandler; }
389 public function disable() { $this->mDoNothing = true; }
390 public function isDisabled() { return $this->mDoNothing; }
391
392 public function setArticleRelated( $v ) {
393 $this->mIsArticleRelated = $v;
394 if ( !$v ) {
395 $this->mIsarticle = false;
396 }
397 }
398 public function setArticleFlag( $v ) {
399 $this->mIsarticle = $v;
400 if ( $v ) {
401 $this->mIsArticleRelated = $v;
402 }
403 }
404
405 public function isArticleRelated() { return $this->mIsArticleRelated; }
406
407 public function getLanguageLinks() { return $this->mLanguageLinks; }
408 public function addLanguageLinks($newLinkArray) {
409 $this->mLanguageLinks += $newLinkArray;
410 }
411 public function setLanguageLinks($newLinkArray) {
412 $this->mLanguageLinks = $newLinkArray;
413 }
414
415 public function getCategoryLinks() {
416 return $this->mCategoryLinks;
417 }
418
419 /**
420 * Add an array of categories, with names in the keys
421 */
422 public function addCategoryLinks( $categories ) {
423 global $wgUser, $wgContLang;
424
425 if ( !is_array( $categories ) || count( $categories ) == 0 ) {
426 return;
427 }
428
429 # Add the links to a LinkBatch
430 $arr = array( NS_CATEGORY => $categories );
431 $lb = new LinkBatch;
432 $lb->setArray( $arr );
433
434 # Fetch existence plus the hiddencat property
435 $dbr = wfGetDB( DB_SLAVE );
436 $pageTable = $dbr->tableName( 'page' );
437 $where = $lb->constructSet( 'page', $dbr );
438 $propsTable = $dbr->tableName( 'page_props' );
439 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value
440 FROM $pageTable LEFT JOIN $propsTable ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
441 $res = $dbr->query( $sql, __METHOD__ );
442
443 # Add the results to the link cache
444 $lb->addResultToCache( LinkCache::singleton(), $res );
445
446 # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
447 $categories = array_combine( array_keys( $categories ),
448 array_fill( 0, count( $categories ), 'normal' ) );
449
450 # Mark hidden categories
451 foreach ( $res as $row ) {
452 if ( isset( $row->pp_value ) ) {
453 $categories[$row->page_title] = 'hidden';
454 }
455 }
456
457 # Add the remaining categories to the skin
458 if ( wfRunHooks( 'OutputPageMakeCategoryLinks', array( &$this, $categories, &$this->mCategoryLinks ) ) ) {
459 $sk = $wgUser->getSkin();
460 foreach ( $categories as $category => $type ) {
461 $origcategory = $category;
462 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
463 $wgContLang->findVariantLink( $category, $title, true );
464 if ( $category != $origcategory )
465 if ( array_key_exists( $category, $categories ) )
466 continue;
467 $text = $wgContLang->convertHtml( $title->getText() );
468 $this->mCategoryLinks[$type][] = $sk->link( $title, $text );
469 }
470 }
471 }
472
473 public function setCategoryLinks($categories) {
474 $this->mCategoryLinks = array();
475 $this->addCategoryLinks($categories);
476 }
477
478 public function suppressQuickbar() { $this->mSuppressQuickbar = true; }
479 public function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
480
481 public function disallowUserJs() { $this->mAllowUserJs = false; }
482 public function isUserJsAllowed() { return $this->mAllowUserJs; }
483
484 public function prependHTML( $text ) { $this->mBodytext = $text . $this->mBodytext; }
485 public function addHTML( $text ) { $this->mBodytext .= $text; }
486 public function clearHTML() { $this->mBodytext = ''; }
487 public function getHTML() { return $this->mBodytext; }
488 public function debug( $text ) { $this->mDebugtext .= $text; }
489
490 /* @deprecated */
491 public function setParserOptions( $options ) {
492 wfDeprecated( __METHOD__ );
493 return $this->parserOptions( $options );
494 }
495
496 public function parserOptions( $options = null ) {
497 if ( !$this->mParserOptions ) {
498 $this->mParserOptions = new ParserOptions;
499 }
500 return wfSetVar( $this->mParserOptions, $options );
501 }
502
503 /**
504 * Set the revision ID which will be seen by the wiki text parser
505 * for things such as embedded {{REVISIONID}} variable use.
506 * @param mixed $revid an integer, or NULL
507 * @return mixed previous value
508 */
509 public function setRevisionId( $revid ) {
510 $val = is_null( $revid ) ? null : intval( $revid );
511 return wfSetVar( $this->mRevisionId, $val );
512 }
513
514 public function getRevisionId() {
515 return $this->mRevisionId;
516 }
517
518 /**
519 * Convert wikitext to HTML and add it to the buffer
520 * Default assumes that the current page title will
521 * be used.
522 *
523 * @param string $text
524 * @param bool $linestart
525 */
526 public function addWikiText( $text, $linestart = true ) {
527 $title = $this->getTitle(); // Work arround E_STRICT
528 $this->addWikiTextTitle( $text, $title, $linestart );
529 }
530
531 public function addWikiTextWithTitle($text, &$title, $linestart = true) {
532 $this->addWikiTextTitle($text, $title, $linestart);
533 }
534
535 function addWikiTextTitleTidy($text, &$title, $linestart = true) {
536 $this->addWikiTextTitle( $text, $title, $linestart, true );
537 }
538
539 public function addWikiTextTitle($text, &$title, $linestart, $tidy = false) {
540 global $wgParser;
541
542 wfProfileIn( __METHOD__ );
543
544 wfIncrStats( 'pcache_not_possible' );
545
546 $popts = $this->parserOptions();
547 $oldTidy = $popts->setTidy( $tidy );
548
549 $parserOutput = $wgParser->parse( $text, $title, $popts,
550 $linestart, true, $this->mRevisionId );
551
552 $popts->setTidy( $oldTidy );
553
554 $this->addParserOutput( $parserOutput );
555
556 wfProfileOut( __METHOD__ );
557 }
558
559 /**
560 * @todo document
561 * @param ParserOutput object &$parserOutput
562 */
563 public function addParserOutputNoText( &$parserOutput ) {
564 global $wgExemptFromUserRobotsControl, $wgContentNamespaces;
565
566 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
567 $this->addCategoryLinks( $parserOutput->getCategories() );
568 $this->mNewSectionLink = $parserOutput->getNewSection();
569 $this->mHideNewSectionLink = $parserOutput->getHideNewSection();
570
571 if( is_null( $wgExemptFromUserRobotsControl ) ) {
572 $bannedNamespaces = $wgContentNamespaces;
573 } else {
574 $bannedNamespaces = $wgExemptFromUserRobotsControl;
575 }
576 if( !in_array( $this->getTitle()->getNamespace(), $bannedNamespaces ) ) {
577 # FIXME (bug 14900): This overrides $wgArticleRobotPolicies, and it
578 # shouldn't
579 $this->setIndexPolicy( $parserOutput->getIndexPolicy() );
580 }
581
582 $this->addKeywords( $parserOutput );
583 $this->mParseWarnings = $parserOutput->getWarnings();
584 if ( $parserOutput->getCacheTime() == -1 ) {
585 $this->enableClientCache( false );
586 }
587 $this->mNoGallery = $parserOutput->getNoGallery();
588 $this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
589 // Versioning...
590 foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
591 if ( isset( $this->mTemplateIds[$ns] ) ) {
592 $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
593 } else {
594 $this->mTemplateIds[$ns] = $dbks;
595 }
596 }
597 // Page title
598 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
599 $this->setPageTitle( $dt );
600 else if ( ( $title = $parserOutput->getTitleText() ) != '' )
601 $this->setPageTitle( $title );
602
603 // Hooks registered in the object
604 global $wgParserOutputHooks;
605 foreach ( $parserOutput->getOutputHooks() as $hookInfo ) {
606 list( $hookName, $data ) = $hookInfo;
607 if ( isset( $wgParserOutputHooks[$hookName] ) ) {
608 call_user_func( $wgParserOutputHooks[$hookName], $this, $parserOutput, $data );
609 }
610 }
611
612 wfRunHooks( 'OutputPageParserOutput', array( &$this, $parserOutput ) );
613 }
614
615 /**
616 * @todo document
617 * @param ParserOutput &$parserOutput
618 */
619 function addParserOutput( &$parserOutput ) {
620 $this->addParserOutputNoText( $parserOutput );
621 $text = $parserOutput->getText();
622 wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
623 $this->addHTML( $text );
624 }
625
626 /**
627 * Add wikitext to the buffer, assuming that this is the primary text for a page view
628 * Saves the text into the parser cache if possible.
629 *
630 * @param string $text
631 * @param Article $article
632 * @param bool $cache
633 * @deprecated Use Article::outputWikitext
634 */
635 public function addPrimaryWikiText( $text, $article, $cache = true ) {
636 global $wgParser;
637
638 wfDeprecated( __METHOD__ );
639
640 $popts = $this->parserOptions();
641 $popts->setTidy(true);
642 $parserOutput = $wgParser->parse( $text, $article->mTitle,
643 $popts, true, true, $this->mRevisionId );
644 $popts->setTidy(false);
645 if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) {
646 $parserCache = ParserCache::singleton();
647 $parserCache->save( $parserOutput, $article, $popts);
648 }
649
650 $this->addParserOutput( $parserOutput );
651 }
652
653 /**
654 * @deprecated use addWikiTextTidy()
655 */
656 public function addSecondaryWikiText( $text, $linestart = true ) {
657 wfDeprecated( __METHOD__ );
658 $this->addWikiTextTitleTidy($text, $this->getTitle(), $linestart);
659 }
660
661 /**
662 * Add wikitext with tidy enabled
663 */
664 public function addWikiTextTidy( $text, $linestart = true ) {
665 $title = $this->getTitle();
666 $this->addWikiTextTitleTidy($text, $title, $linestart);
667 }
668
669
670 /**
671 * Add the output of a QuickTemplate to the output buffer
672 *
673 * @param QuickTemplate $template
674 */
675 public function addTemplate( &$template ) {
676 ob_start();
677 $template->execute();
678 $this->addHTML( ob_get_contents() );
679 ob_end_clean();
680 }
681
682 /**
683 * Parse wikitext and return the HTML.
684 *
685 * @param string $text
686 * @param bool $linestart Is this the start of a line?
687 * @param bool $interface ??
688 */
689 public function parse( $text, $linestart = true, $interface = false ) {
690 global $wgParser;
691 if( is_null( $this->getTitle() ) ) {
692 throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
693 }
694 $popts = $this->parserOptions();
695 if ( $interface) { $popts->setInterfaceMessage(true); }
696 $parserOutput = $wgParser->parse( $text, $this->getTitle(), $popts,
697 $linestart, true, $this->mRevisionId );
698 if ( $interface) { $popts->setInterfaceMessage(false); }
699 return $parserOutput->getText();
700 }
701
702 /** Parse wikitext, strip paragraphs, and return the HTML. */
703 public function parseInline( $text, $linestart = true, $interface = false ) {
704 $parsed = $this->parse( $text, $linestart, $interface );
705
706 $m = array();
707 if ( preg_match( '/^<p>(.*)\n?<\/p>\n?/sU', $parsed, $m ) ) {
708 $parsed = $m[1];
709 }
710
711 return $parsed;
712 }
713
714 /**
715 * @param Article $article
716 * @param User $user
717 *
718 * @deprecated
719 *
720 * @return bool True if successful, else false.
721 */
722 public function tryParserCache( &$article ) {
723 wfDeprecated( __METHOD__ );
724 $parserOutput = ParserCache::singleton()->get( $article, $article->getParserOptions() );
725
726 if ($parserOutput !== false) {
727 $this->addParserOutput( $parserOutput );
728 return true;
729 } else {
730 return false;
731 }
732 }
733
734 /**
735 * @param int $maxage Maximum cache time on the Squid, in seconds.
736 */
737 public function setSquidMaxage( $maxage ) {
738 $this->mSquidMaxage = $maxage;
739 }
740
741 /**
742 * Use enableClientCache(false) to force it to send nocache headers
743 * @param $state ??
744 */
745 public function enableClientCache( $state ) {
746 return wfSetVar( $this->mEnableClientCache, $state );
747 }
748
749 function getCacheVaryCookies() {
750 global $wgCookiePrefix, $wgCacheVaryCookies;
751 static $cookies;
752 if ( $cookies === null ) {
753 $cookies = array_merge(
754 array(
755 "{$wgCookiePrefix}Token",
756 "{$wgCookiePrefix}LoggedOut",
757 session_name()
758 ),
759 $wgCacheVaryCookies
760 );
761 wfRunHooks('GetCacheVaryCookies', array( $this, &$cookies ) );
762 }
763 return $cookies;
764 }
765
766 function uncacheableBecauseRequestVars() {
767 global $wgRequest;
768 return $wgRequest->getText('useskin', false) === false
769 && $wgRequest->getText('uselang', false) === false;
770 }
771
772 /**
773 * Check if the request has a cache-varying cookie header
774 * If it does, it's very important that we don't allow public caching
775 */
776 function haveCacheVaryCookies() {
777 global $wgRequest;
778 $cookieHeader = $wgRequest->getHeader( 'cookie' );
779 if ( $cookieHeader === false ) {
780 return false;
781 }
782 $cvCookies = $this->getCacheVaryCookies();
783 foreach ( $cvCookies as $cookieName ) {
784 # Check for a simple string match, like the way squid does it
785 if ( strpos( $cookieHeader, $cookieName ) ) {
786 wfDebug( __METHOD__.": found $cookieName\n" );
787 return true;
788 }
789 }
790 wfDebug( __METHOD__.": no cache-varying cookies found\n" );
791 return false;
792 }
793
794 /** Get a complete X-Vary-Options header */
795 public function getXVO() {
796 $cvCookies = $this->getCacheVaryCookies();
797 $xvo = 'X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;';
798 $first = true;
799 foreach ( $cvCookies as $cookieName ) {
800 if ( $first ) {
801 $first = false;
802 } else {
803 $xvo .= ';';
804 }
805 $xvo .= 'string-contains=' . $cookieName;
806 }
807 return $xvo;
808 }
809
810 public function sendCacheControl() {
811 global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
812
813 $response = $wgRequest->response();
814 if ($wgUseETag && $this->mETag)
815 $response->header("ETag: $this->mETag");
816
817 # don't serve compressed data to clients who can't handle it
818 # maintain different caches for logged-in users and non-logged in ones
819 $response->header( 'Vary: Accept-Encoding, Cookie' );
820
821 # Add an X-Vary-Options header for Squid with Wikimedia patches
822 $response->header( $this->getXVO() );
823
824 if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
825 if( $wgUseSquid && session_id() == '' &&
826 ! $this->isPrintable() && $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies() )
827 {
828 if ( $wgUseESI ) {
829 # We'll purge the proxy cache explicitly, but require end user agents
830 # to revalidate against the proxy on each visit.
831 # Surrogate-Control controls our Squid, Cache-Control downstream caches
832 wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **\n", false );
833 # start with a shorter timeout for initial testing
834 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
835 $response->header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
836 $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
837 } else {
838 # We'll purge the proxy cache for anons explicitly, but require end user agents
839 # to revalidate against the proxy on each visit.
840 # IMPORTANT! The Squid needs to replace the Cache-Control header with
841 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
842 wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **\n", false );
843 # start with a shorter timeout for initial testing
844 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
845 $response->header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
846 }
847 } else {
848 # We do want clients to cache if they can, but they *must* check for updates
849 # on revisiting the page.
850 wfDebug( __METHOD__ . ": private caching; {$this->mLastModified} **\n", false );
851 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
852 $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
853 }
854 if($this->mLastModified) {
855 $response->header( "Last-Modified: {$this->mLastModified}" );
856 }
857 } else {
858 wfDebug( __METHOD__ . ": no caching **\n", false );
859
860 # In general, the absence of a last modified header should be enough to prevent
861 # the client from using its cache. We send a few other things just to make sure.
862 $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
863 $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
864 $response->header( 'Pragma: no-cache' );
865 }
866 }
867
868 /**
869 * Finally, all the text has been munged and accumulated into
870 * the object, let's actually output it:
871 */
872 public function output() {
873 global $wgUser, $wgOutputEncoding, $wgRequest;
874 global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
875 global $wgJsMimeType, $wgUseAjax, $wgAjaxWatch;
876 global $wgEnableMWSuggest, $wgUniversalEditButton;
877 global $wgArticle;
878
879 if( $this->mDoNothing ){
880 return;
881 }
882
883 wfProfileIn( __METHOD__ );
884
885 if ( '' != $this->mRedirect ) {
886 # Standards require redirect URLs to be absolute
887 $this->mRedirect = wfExpandUrl( $this->mRedirect );
888 if( $this->mRedirectCode == '301') {
889 if( !$wgDebugRedirects ) {
890 $wgRequest->response()->header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
891 }
892 $this->mLastModified = wfTimestamp( TS_RFC2822 );
893 }
894
895 $this->sendCacheControl();
896
897 $wgRequest->response()->header("Content-Type: text/html; charset=utf-8");
898 if( $wgDebugRedirects ) {
899 $url = htmlspecialchars( $this->mRedirect );
900 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
901 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
902 print "</body>\n</html>\n";
903 } else {
904 $wgRequest->response()->header( 'Location: '.$this->mRedirect );
905 }
906 wfProfileOut( __METHOD__ );
907 return;
908 }
909 elseif ( $this->mStatusCode )
910 {
911 $statusMessage = array(
912 100 => 'Continue',
913 101 => 'Switching Protocols',
914 102 => 'Processing',
915 200 => 'OK',
916 201 => 'Created',
917 202 => 'Accepted',
918 203 => 'Non-Authoritative Information',
919 204 => 'No Content',
920 205 => 'Reset Content',
921 206 => 'Partial Content',
922 207 => 'Multi-Status',
923 300 => 'Multiple Choices',
924 301 => 'Moved Permanently',
925 302 => 'Found',
926 303 => 'See Other',
927 304 => 'Not Modified',
928 305 => 'Use Proxy',
929 307 => 'Temporary Redirect',
930 400 => 'Bad Request',
931 401 => 'Unauthorized',
932 402 => 'Payment Required',
933 403 => 'Forbidden',
934 404 => 'Not Found',
935 405 => 'Method Not Allowed',
936 406 => 'Not Acceptable',
937 407 => 'Proxy Authentication Required',
938 408 => 'Request Timeout',
939 409 => 'Conflict',
940 410 => 'Gone',
941 411 => 'Length Required',
942 412 => 'Precondition Failed',
943 413 => 'Request Entity Too Large',
944 414 => 'Request-URI Too Large',
945 415 => 'Unsupported Media Type',
946 416 => 'Request Range Not Satisfiable',
947 417 => 'Expectation Failed',
948 422 => 'Unprocessable Entity',
949 423 => 'Locked',
950 424 => 'Failed Dependency',
951 500 => 'Internal Server Error',
952 501 => 'Not Implemented',
953 502 => 'Bad Gateway',
954 503 => 'Service Unavailable',
955 504 => 'Gateway Timeout',
956 505 => 'HTTP Version Not Supported',
957 507 => 'Insufficient Storage'
958 );
959
960 if ( $statusMessage[$this->mStatusCode] )
961 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
962 }
963
964 $sk = $wgUser->getSkin();
965
966 if ( $wgUseAjax ) {
967 $this->addScriptFile( 'ajax.js' );
968
969 wfRunHooks( 'AjaxAddScript', array( &$this ) );
970
971 if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
972 $this->addScriptFile( 'ajaxwatch.js' );
973 }
974
975 if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
976 $this->addScriptFile( 'mwsuggest.js' );
977 }
978 }
979
980 if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
981 $this->addScriptFile( 'rightclickedit.js' );
982 }
983
984 if( $wgUniversalEditButton ) {
985 if( isset( $wgArticle ) && $this->getTitle() && $this->getTitle()->quickUserCan( 'edit' )
986 && ( $this->getTitle()->exists() || $this->getTitle()->quickUserCan( 'create' ) ) ) {
987 // Original UniversalEditButton
988 $this->addLink( array(
989 'rel' => 'alternate',
990 'type' => 'application/x-wiki',
991 'title' => wfMsg( 'edit' ),
992 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
993 ) );
994 // Alternate edit link
995 $this->addLink( array(
996 'rel' => 'edit',
997 'title' => wfMsg( 'edit' ),
998 'href' => $this->getTitle()->getLocalURL( 'action=edit' )
999 ) );
1000 }
1001 }
1002
1003 # Buffer output; final headers may depend on later processing
1004 ob_start();
1005
1006 $wgRequest->response()->header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
1007 $wgRequest->response()->header( 'Content-language: '.$wgContLanguageCode );
1008
1009 if ($this->mArticleBodyOnly) {
1010 $this->out($this->mBodytext);
1011 } else {
1012 // Hook that allows last minute changes to the output page, e.g.
1013 // adding of CSS or Javascript by extensions.
1014 wfRunHooks( 'BeforePageDisplay', array( &$this, &$sk ) );
1015
1016 wfProfileIn( 'Output-skin' );
1017 $sk->outputPage( $this );
1018 wfProfileOut( 'Output-skin' );
1019 }
1020
1021 $this->sendCacheControl();
1022 ob_end_flush();
1023 wfProfileOut( __METHOD__ );
1024 }
1025
1026 /**
1027 * Actually output something with print(). Performs an iconv to the
1028 * output encoding, if needed.
1029 * @param string $ins The string to output
1030 */
1031 public function out( $ins ) {
1032 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
1033 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
1034 $outs = $ins;
1035 } else {
1036 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
1037 if ( false === $outs ) { $outs = $ins; }
1038 }
1039 print $outs;
1040 }
1041
1042 /**
1043 * @todo document
1044 */
1045 public static function setEncodings() {
1046 global $wgInputEncoding, $wgOutputEncoding;
1047 global $wgContLang;
1048
1049 $wgInputEncoding = strtolower( $wgInputEncoding );
1050
1051 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
1052 $wgOutputEncoding = strtolower( $wgOutputEncoding );
1053 return;
1054 }
1055 $wgOutputEncoding = $wgInputEncoding;
1056 }
1057
1058 /**
1059 * Deprecated, use wfReportTime() instead.
1060 * @return string
1061 * @deprecated
1062 */
1063 public function reportTime() {
1064 wfDeprecated( __METHOD__ );
1065 $time = wfReportTime();
1066 return $time;
1067 }
1068
1069 /**
1070 * Produce a "user is blocked" page.
1071 *
1072 * @param bool $return Whether to have a "return to $wgTitle" message or not.
1073 * @return nothing
1074 */
1075 function blockedPage( $return = true ) {
1076 global $wgUser, $wgContLang, $wgLang;
1077
1078 $this->setPageTitle( wfMsg( 'blockedtitle' ) );
1079 $this->setRobotPolicy( 'noindex,nofollow' );
1080 $this->setArticleRelated( false );
1081
1082 $name = User::whoIs( $wgUser->blockedBy() );
1083 $reason = $wgUser->blockedFor();
1084 if( $reason == '' ) {
1085 $reason = wfMsg( 'blockednoreason' );
1086 }
1087 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $wgUser->mBlock->mTimestamp ), true );
1088 $ip = wfGetIP();
1089
1090 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1091
1092 $blockid = $wgUser->mBlock->mId;
1093
1094 $blockExpiry = $wgUser->mBlock->mExpiry;
1095 if ( $blockExpiry == 'infinity' ) {
1096 // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
1097 // Search for localization in 'ipboptions'
1098 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1099 foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
1100 if ( strpos( $option, ":" ) === false )
1101 continue;
1102 list( $show, $value ) = explode( ":", $option );
1103 if ( $value == 'infinite' || $value == 'indefinite' ) {
1104 $blockExpiry = $show;
1105 break;
1106 }
1107 }
1108 } else {
1109 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
1110 }
1111
1112 if ( $wgUser->mBlock->mAuto ) {
1113 $msg = 'autoblockedtext';
1114 } else {
1115 $msg = 'blockedtext';
1116 }
1117
1118 /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
1119 * This could be a username, an ip range, or a single ip. */
1120 $intended = $wgUser->mBlock->mAddress;
1121
1122 $this->addWikiMsg( $msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp );
1123
1124 # Don't auto-return to special pages
1125 if( $return ) {
1126 $return = $this->getTitle()->getNamespace() > -1 ? $this->getTitle() : null;
1127 $this->returnToMain( null, $return );
1128 }
1129 }
1130
1131 /**
1132 * Output a standard error page
1133 *
1134 * @param string $title Message key for page title
1135 * @param string $msg Message key for page text
1136 * @param array $params Message parameters
1137 */
1138 public function showErrorPage( $title, $msg, $params = array() ) {
1139 if ( $this->getTitle() ) {
1140 $this->mDebugtext .= 'Original title: ' . $this->getTitle()->getPrefixedText() . "\n";
1141 }
1142 $this->setPageTitle( wfMsg( $title ) );
1143 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1144 $this->setRobotPolicy( 'noindex,nofollow' );
1145 $this->setArticleRelated( false );
1146 $this->enableClientCache( false );
1147 $this->mRedirect = '';
1148 $this->mBodytext = '';
1149
1150 array_unshift( $params, 'parse' );
1151 array_unshift( $params, $msg );
1152 $this->addHTML( call_user_func_array( 'wfMsgExt', $params ) );
1153
1154 $this->returnToMain();
1155 }
1156
1157 /**
1158 * Output a standard permission error page
1159 *
1160 * @param array $errors Error message keys
1161 */
1162 public function showPermissionsErrorPage( $errors, $action = null )
1163 {
1164 $this->mDebugtext .= 'Original title: ' .
1165 $this->getTitle()->getPrefixedText() . "\n";
1166 $this->setPageTitle( wfMsg( 'permissionserrors' ) );
1167 $this->setHTMLTitle( wfMsg( 'permissionserrors' ) );
1168 $this->setRobotPolicy( 'noindex,nofollow' );
1169 $this->setArticleRelated( false );
1170 $this->enableClientCache( false );
1171 $this->mRedirect = '';
1172 $this->mBodytext = '';
1173 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
1174 }
1175
1176 /** @deprecated */
1177 public function errorpage( $title, $msg ) {
1178 wfDeprecated( __METHOD__ );
1179 throw new ErrorPageError( $title, $msg );
1180 }
1181
1182 /**
1183 * Display an error page indicating that a given version of MediaWiki is
1184 * required to use it
1185 *
1186 * @param mixed $version The version of MediaWiki needed to use the page
1187 */
1188 public function versionRequired( $version ) {
1189 $this->setPageTitle( wfMsg( 'versionrequired', $version ) );
1190 $this->setHTMLTitle( wfMsg( 'versionrequired', $version ) );
1191 $this->setRobotPolicy( 'noindex,nofollow' );
1192 $this->setArticleRelated( false );
1193 $this->mBodytext = '';
1194
1195 $this->addWikiMsg( 'versionrequiredtext', $version );
1196 $this->returnToMain();
1197 }
1198
1199 /**
1200 * Display an error page noting that a given permission bit is required.
1201 *
1202 * @param string $permission key required
1203 */
1204 public function permissionRequired( $permission ) {
1205 global $wgLang;
1206
1207 $this->setPageTitle( wfMsg( 'badaccess' ) );
1208 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
1209 $this->setRobotPolicy( 'noindex,nofollow' );
1210 $this->setArticleRelated( false );
1211 $this->mBodytext = '';
1212
1213 $groups = array_map( array( 'User', 'makeGroupLinkWiki' ),
1214 User::getGroupsWithPermission( $permission ) );
1215 if( $groups ) {
1216 $this->addWikiMsg( 'badaccess-groups',
1217 $wgLang->commaList( $groups ),
1218 count( $groups) );
1219 } else {
1220 $this->addWikiMsg( 'badaccess-group0' );
1221 }
1222 $this->returnToMain();
1223 }
1224
1225 /**
1226 * Use permissionRequired.
1227 * @deprecated
1228 */
1229 public function sysopRequired() {
1230 throw new MWException( "Call to deprecated OutputPage::sysopRequired() method\n" );
1231 }
1232
1233 /**
1234 * Use permissionRequired.
1235 * @deprecated
1236 */
1237 public function developerRequired() {
1238 throw new MWException( "Call to deprecated OutputPage::developerRequired() method\n" );
1239 }
1240
1241 /**
1242 * Produce the stock "please login to use the wiki" page
1243 */
1244 public function loginToUse() {
1245 global $wgUser, $wgContLang;
1246
1247 if( $wgUser->isLoggedIn() ) {
1248 $this->permissionRequired( 'read' );
1249 return;
1250 }
1251
1252 $skin = $wgUser->getSkin();
1253
1254 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
1255 $this->setHtmlTitle( wfMsg( 'errorpagetitle' ) );
1256 $this->setRobotPolicy( 'noindex,nofollow' );
1257 $this->setArticleFlag( false );
1258
1259 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1260 $loginLink = $skin->link(
1261 $loginTitle,
1262 wfMsgHtml( 'loginreqlink' ),
1263 array(),
1264 array( 'returnto' => $this->getTitle()->getPrefixedText() ),
1265 array( 'known', 'noclasses' )
1266 );
1267 $this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
1268 $this->addHTML( "\n<!--" . $this->getTitle()->getPrefixedUrl() . "-->" );
1269
1270 # Don't return to the main page if the user can't read it
1271 # otherwise we'll end up in a pointless loop
1272 $mainPage = Title::newMainPage();
1273 if( $mainPage->userCanRead() )
1274 $this->returnToMain( null, $mainPage );
1275 }
1276
1277 /** @deprecated */
1278 public function databaseError( $fname, $sql, $error, $errno ) {
1279 throw new MWException( "OutputPage::databaseError is obsolete\n" );
1280 }
1281
1282 /**
1283 * @param array $errors An array of arrays returned by Title::getUserPermissionsErrors
1284 * @return string The wikitext error-messages, formatted into a list.
1285 */
1286 public function formatPermissionsErrorMessage( $errors, $action = null ) {
1287 if ($action == null) {
1288 $text = wfMsgNoTrans( 'permissionserrorstext', count($errors)). "\n\n";
1289 } else {
1290 global $wgLang;
1291 $action_desc = wfMsgNoTrans( "action-$action" );
1292 $text = wfMsgNoTrans( 'permissionserrorstext-withaction', count($errors), $action_desc ) . "\n\n";
1293 }
1294
1295 if (count( $errors ) > 1) {
1296 $text .= '<ul class="permissions-errors">' . "\n";
1297
1298 foreach( $errors as $error )
1299 {
1300 $text .= '<li>';
1301 $text .= call_user_func_array( 'wfMsgNoTrans', $error );
1302 $text .= "</li>\n";
1303 }
1304 $text .= '</ul>';
1305 } else {
1306 $text .= "<div class=\"permissions-errors\">\n" . call_user_func_array( 'wfMsgNoTrans', reset( $errors ) ) . "\n</div>";
1307 }
1308
1309 return $text;
1310 }
1311
1312 /**
1313 * Display a page stating that the Wiki is in read-only mode,
1314 * and optionally show the source of the page that the user
1315 * was trying to edit. Should only be called (for this
1316 * purpose) after wfReadOnly() has returned true.
1317 *
1318 * For historical reasons, this function is _also_ used to
1319 * show the error message when a user tries to edit a page
1320 * they are not allowed to edit. (Unless it's because they're
1321 * blocked, then we show blockedPage() instead.) In this
1322 * case, the second parameter should be set to true and a list
1323 * of reasons supplied as the third parameter.
1324 *
1325 * @todo Needs to be split into multiple functions.
1326 *
1327 * @param string $source Source code to show (or null).
1328 * @param bool $protected Is this a permissions error?
1329 * @param array $reasons List of reasons for this error, as returned by Title::getUserPermissionsErrors().
1330 */
1331 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1332 global $wgUser;
1333 $skin = $wgUser->getSkin();
1334
1335 $this->setRobotPolicy( 'noindex,nofollow' );
1336 $this->setArticleRelated( false );
1337
1338 // If no reason is given, just supply a default "I can't let you do
1339 // that, Dave" message. Should only occur if called by legacy code.
1340 if ( $protected && empty($reasons) ) {
1341 $reasons[] = array( 'badaccess-group0' );
1342 }
1343
1344 if ( !empty($reasons) ) {
1345 // Permissions error
1346 if( $source ) {
1347 $this->setPageTitle( wfMsg( 'viewsource' ) );
1348 $this->setSubtitle(
1349 wfMsg(
1350 'viewsourcefor',
1351 $skin->link(
1352 $this->getTitle(),
1353 null,
1354 array(),
1355 array(),
1356 array( 'known', 'noclasses' )
1357 )
1358 )
1359 );
1360 } else {
1361 $this->setPageTitle( wfMsg( 'badaccess' ) );
1362 }
1363 $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons, $action ) );
1364 } else {
1365 // Wiki is read only
1366 $this->setPageTitle( wfMsg( 'readonly' ) );
1367 $reason = wfReadOnlyReason();
1368 $this->wrapWikiMsg( '<div class="mw-readonly-error">$1</div>', array( 'readonlytext', $reason ) );
1369 }
1370
1371 // Show source, if supplied
1372 if( is_string( $source ) ) {
1373 $this->addWikiMsg( 'viewsourcetext' );
1374 $text = Xml::openElement( 'textarea',
1375 array( 'id' => 'wpTextbox1',
1376 'name' => 'wpTextbox1',
1377 'cols' => $wgUser->getOption( 'cols' ),
1378 'rows' => $wgUser->getOption( 'rows' ),
1379 'readonly' => 'readonly' ) );
1380 $text .= htmlspecialchars( $source );
1381 $text .= Xml::closeElement( 'textarea' );
1382 $this->addHTML( $text );
1383
1384 // Show templates used by this article
1385 $skin = $wgUser->getSkin();
1386 $article = new Article( $this->getTitle() );
1387 $this->addHTML( "<div class='templatesUsed'>
1388 {$skin->formatTemplates( $article->getUsedTemplates() )}
1389 </div>
1390 " );
1391 }
1392
1393 # If the title doesn't exist, it's fairly pointless to print a return
1394 # link to it. After all, you just tried editing it and couldn't, so
1395 # what's there to do there?
1396 if( $this->getTitle()->exists() ) {
1397 $this->returnToMain( null, $this->getTitle() );
1398 }
1399 }
1400
1401 /** @deprecated */
1402 public function fatalError( $message ) {
1403 wfDeprecated( __METHOD__ );
1404 throw new FatalError( $message );
1405 }
1406
1407 /** @deprecated */
1408 public function unexpectedValueError( $name, $val ) {
1409 wfDeprecated( __METHOD__ );
1410 throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
1411 }
1412
1413 /** @deprecated */
1414 public function fileCopyError( $old, $new ) {
1415 wfDeprecated( __METHOD__ );
1416 throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
1417 }
1418
1419 /** @deprecated */
1420 public function fileRenameError( $old, $new ) {
1421 wfDeprecated( __METHOD__ );
1422 throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
1423 }
1424
1425 /** @deprecated */
1426 public function fileDeleteError( $name ) {
1427 wfDeprecated( __METHOD__ );
1428 throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
1429 }
1430
1431 /** @deprecated */
1432 public function fileNotFoundError( $name ) {
1433 wfDeprecated( __METHOD__ );
1434 throw new FatalError( wfMsg( 'filenotfound', $name ) );
1435 }
1436
1437 public function showFatalError( $message ) {
1438 $this->setPageTitle( wfMsg( "internalerror" ) );
1439 $this->setRobotPolicy( "noindex,nofollow" );
1440 $this->setArticleRelated( false );
1441 $this->enableClientCache( false );
1442 $this->mRedirect = '';
1443 $this->mBodytext = $message;
1444 }
1445
1446 public function showUnexpectedValueError( $name, $val ) {
1447 $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
1448 }
1449
1450 public function showFileCopyError( $old, $new ) {
1451 $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
1452 }
1453
1454 public function showFileRenameError( $old, $new ) {
1455 $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
1456 }
1457
1458 public function showFileDeleteError( $name ) {
1459 $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
1460 }
1461
1462 public function showFileNotFoundError( $name ) {
1463 $this->showFatalError( wfMsg( 'filenotfound', $name ) );
1464 }
1465
1466 /**
1467 * Add a "return to" link pointing to a specified title
1468 *
1469 * @param Title $title Title to link
1470 * @param string $query Query string
1471 */
1472 public function addReturnTo( $title, $query ) {
1473 global $wgUser;
1474 $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
1475 $link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
1476 $title, null, array(), $query ) );
1477 $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
1478 }
1479
1480 /**
1481 * Add a "return to" link pointing to a specified title,
1482 * or the title indicated in the request, or else the main page
1483 *
1484 * @param null $unused No longer used
1485 * @param Title $returnto Title to return to
1486 */
1487 public function returnToMain( $unused = null, $returnto = null, $returntoquery = null ) {
1488 global $wgRequest;
1489
1490 if ( $returnto == null ) {
1491 $returnto = $wgRequest->getText( 'returnto' );
1492 }
1493
1494 if ( $returntoquery == null ) {
1495 $returntoquery = $wgRequest->getText( 'returntoquery' );
1496 }
1497
1498 if ( '' === $returnto ) {
1499 $returnto = Title::newMainPage();
1500 }
1501
1502 if ( is_object( $returnto ) ) {
1503 $titleObj = $returnto;
1504 } else {
1505 $titleObj = Title::newFromText( $returnto );
1506 }
1507 if ( !is_object( $titleObj ) ) {
1508 $titleObj = Title::newMainPage();
1509 }
1510
1511 $this->addReturnTo( $titleObj, $returntoquery );
1512 }
1513
1514 /**
1515 * This function takes the title (first item of mGoodLinks), categories,
1516 * existing and broken links for the page
1517 * and uses the first 10 of them for META keywords
1518 *
1519 * @param ParserOutput &$parserOutput
1520 */
1521 private function addKeywords( &$parserOutput ) {
1522 global $wgContLang;
1523 // Get an array of keywords if there are more than one
1524 // variant of the site language
1525 $text = $wgContLang->autoConvertToAllVariants( $this->getTitle()->getPrefixedText());
1526 // array_values: We needn't to merge variant's code name
1527 // into $this->mKeywords;
1528 // array_unique: We should insert a keyword just for once
1529 if( is_array( $text ))
1530 $text = array_unique( array_values( $text ));
1531 $this->addKeyword( $text );
1532 $count = 1;
1533 $links2d =& $parserOutput->getLinks();
1534 if ( !is_array( $links2d ) ) {
1535 return;
1536 }
1537 foreach ( $links2d as $dbkeys ) {
1538 foreach( $dbkeys as $dbkey => $unused ) {
1539 $dbkey = $wgContLang->autoConvertToAllVariants( $dbkey );
1540 if( is_array( $dbkey ))
1541 $dbkey = array_unique( array_values( $dbkey ));
1542 $this->addKeyword( $dbkey );
1543 if ( ++$count > 10 ) {
1544 break 2;
1545 }
1546 }
1547 }
1548 }
1549
1550 /**
1551 * @return string The doctype, opening <html>, and head element.
1552 */
1553 public function headElement( Skin $sk ) {
1554 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
1555 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
1556 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5;
1557
1558 $this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
1559 if ( $sk->commonPrintStylesheet() ) {
1560 $this->addStyle( 'common/wikiprintable.css', 'print' );
1561 }
1562 $sk->setupUserCss( $this );
1563
1564 $ret = '';
1565
1566 if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
1567 $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
1568 }
1569
1570 if ( $wgHtml5 ) {
1571 $ret .= "<!doctype html>\n";
1572 } else {
1573 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
1574 }
1575
1576 if ( '' == $this->getHTMLTitle() ) {
1577 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
1578 }
1579
1580 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
1581 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
1582 foreach($wgXhtmlNamespaces as $tag => $ns) {
1583 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
1584 }
1585 $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
1586 $ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
1587 $ret .= implode( "\n", array(
1588 $this->getHeadLinks(),
1589 $this->buildCssLinks(),
1590 $sk->getHeadScripts( $this->mAllowUserJs, $this->mScripts ),
1591 $this->getHeadItems(),
1592 ));
1593 if( $sk->usercss ){
1594 $ret .= "<style type='text/css'>{$sk->usercss}</style>";
1595 }
1596
1597 if ($wgUseTrackbacks && $this->isArticleRelated())
1598 $ret .= $this->getTitle()->trackbackRDF();
1599
1600 $ret .= "</head>\n";
1601 return $ret;
1602 }
1603
1604 protected function addDefaultMeta() {
1605 global $wgVersion, $wgHtml5;
1606
1607 static $called = false;
1608 if ( $called ) {
1609 # Don't run this twice
1610 return;
1611 }
1612 $called = true;
1613
1614 if ( !$wgHtml5 ) {
1615 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
1616 }
1617 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
1618
1619 $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
1620 if( $p !== 'index,follow' ) {
1621 // http://www.robotstxt.org/wc/meta-user.html
1622 // Only show if it's different from the default robots policy
1623 $this->addMeta( 'robots', $p );
1624 }
1625
1626 if ( count( $this->mKeywords ) > 0 ) {
1627 $strip = array(
1628 "/<.*?" . ">/" => '',
1629 "/_/" => ' '
1630 );
1631 $this->addMeta( 'keywords', preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ) ) );
1632 }
1633 }
1634
1635 /**
1636 * @return string HTML tag links to be put in the header.
1637 */
1638 public function getHeadLinks() {
1639 global $wgRequest, $wgFeed;
1640
1641 // Ideally this should happen earlier, somewhere. :P
1642 $this->addDefaultMeta();
1643
1644 $tags = array();
1645
1646 foreach ( $this->mMetatags as $tag ) {
1647 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
1648 $a = 'http-equiv';
1649 $tag[0] = substr( $tag[0], 5 );
1650 } else {
1651 $a = 'name';
1652 }
1653 $tags[] = Xml::element( 'meta',
1654 array(
1655 $a => $tag[0],
1656 'content' => $tag[1] ) );
1657 }
1658 foreach ( $this->mLinktags as $tag ) {
1659 $tags[] = Xml::element( 'link', $tag );
1660 }
1661
1662 if( $wgFeed ) {
1663 foreach( $this->getSyndicationLinks() as $format => $link ) {
1664 # Use the page name for the title (accessed through $wgTitle since
1665 # there's no other way). In principle, this could lead to issues
1666 # with having the same name for different feeds corresponding to
1667 # the same page, but we can't avoid that at this low a level.
1668
1669 $tags[] = $this->feedLink(
1670 $format,
1671 $link,
1672 wfMsg( "page-{$format}-feed", $this->getTitle()->getPrefixedText() ) ); # Used messages: 'page-rss-feed' and 'page-atom-feed' (for an easier grep)
1673 }
1674
1675 # Recent changes feed should appear on every page (except recentchanges,
1676 # that would be redundant). Put it after the per-page feed to avoid
1677 # changing existing behavior. It's still available, probably via a
1678 # menu in your browser. Some sites might have a different feed they'd
1679 # like to promote instead of the RC feed (maybe like a "Recent New Articles"
1680 # or "Breaking news" one). For this, we see if $wgOverrideSiteFeed is defined.
1681 # If so, use it instead.
1682
1683 global $wgOverrideSiteFeed, $wgSitename, $wgFeedClasses;
1684 $rctitle = SpecialPage::getTitleFor( 'Recentchanges' );
1685
1686 if ( $wgOverrideSiteFeed ) {
1687 foreach ( $wgOverrideSiteFeed as $type => $feedUrl ) {
1688 $tags[] = $this->feedLink (
1689 $type,
1690 htmlspecialchars( $feedUrl ),
1691 wfMsg( "site-{$type}-feed", $wgSitename ) );
1692 }
1693 }
1694 else if ( $this->getTitle()->getPrefixedText() != $rctitle->getPrefixedText() ) {
1695 foreach( $wgFeedClasses as $format => $class ) {
1696 $tags[] = $this->feedLink(
1697 $format,
1698 $rctitle->getLocalURL( "feed={$format}" ),
1699 wfMsg( "site-{$format}-feed", $wgSitename ) ); # For grep: 'site-rss-feed', 'site-atom-feed'.
1700 }
1701 }
1702 }
1703
1704 return implode( "\n\t", $tags ) . "\n";
1705 }
1706
1707 /**
1708 * Return URLs for each supported syndication format for this page.
1709 * @return array associating format keys with URLs
1710 */
1711 public function getSyndicationLinks() {
1712 global $wgFeedClasses;
1713 $links = array();
1714
1715 if( $this->isSyndicated() ) {
1716 if( is_string( $this->getFeedAppendQuery() ) ) {
1717 $appendQuery = "&" . $this->getFeedAppendQuery();
1718 } else {
1719 $appendQuery = "";
1720 }
1721
1722 foreach( $wgFeedClasses as $format => $class ) {
1723 $links[$format] = $this->getTitle()->getLocalUrl( "feed=$format{$appendQuery}" );
1724 }
1725 }
1726 return $links;
1727 }
1728
1729 /**
1730 * Generate a <link rel/> for an RSS feed.
1731 */
1732 private function feedLink( $type, $url, $text ) {
1733 return Xml::element( 'link', array(
1734 'rel' => 'alternate',
1735 'type' => "application/$type+xml",
1736 'title' => $text,
1737 'href' => $url ) );
1738 }
1739
1740 /**
1741 * Add a local or specified stylesheet, with the given media options.
1742 * Meant primarily for internal use...
1743 *
1744 * @param $media -- to specify a media type, 'screen', 'printable', 'handheld' or any.
1745 * @param $conditional -- for IE conditional comments, specifying an IE version
1746 * @param $dir -- set to 'rtl' or 'ltr' for direction-specific sheets
1747 */
1748 public function addStyle( $style, $media='', $condition='', $dir='' ) {
1749 $options = array();
1750 if( $media )
1751 $options['media'] = $media;
1752 if( $condition )
1753 $options['condition'] = $condition;
1754 if( $dir )
1755 $options['dir'] = $dir;
1756 $this->styles[$style] = $options;
1757 }
1758
1759 /**
1760 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
1761 * These will be applied to various media & IE conditionals.
1762 */
1763 public function buildCssLinks() {
1764 $links = array();
1765 foreach( $this->styles as $file => $options ) {
1766 $link = $this->styleLink( $file, $options );
1767 if( $link )
1768 $links[] = $link;
1769 }
1770
1771 return "\t" . implode( "\n\t", $links );
1772 }
1773
1774 protected function styleLink( $style, $options ) {
1775 global $wgRequest;
1776
1777 if( isset( $options['dir'] ) ) {
1778 global $wgContLang;
1779 $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
1780 if( $siteDir != $options['dir'] )
1781 return '';
1782 }
1783
1784 if( isset( $options['media'] ) ) {
1785 $media = $this->transformCssMedia( $options['media'] );
1786 if( is_null( $media ) ) {
1787 return '';
1788 }
1789 } else {
1790 $media = '';
1791 }
1792
1793 if( substr( $style, 0, 1 ) == '/' ||
1794 substr( $style, 0, 5 ) == 'http:' ||
1795 substr( $style, 0, 6 ) == 'https:' ) {
1796 $url = $style;
1797 } else {
1798 global $wgStylePath, $wgStyleVersion;
1799 $url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
1800 }
1801
1802 $attribs = array(
1803 'rel' => 'stylesheet',
1804 'href' => $url,
1805 'type' => 'text/css' );
1806 if( $media ) {
1807 $attribs['media'] = $media;
1808 }
1809
1810 $link = Xml::element( 'link', $attribs );
1811
1812 if( isset( $options['condition'] ) ) {
1813 $condition = htmlspecialchars( $options['condition'] );
1814 $link = "<!--[if $condition]>$link<![endif]-->";
1815 }
1816 return $link;
1817 }
1818
1819 function transformCssMedia( $media ) {
1820 global $wgRequest, $wgHandheldForIPhone;
1821
1822 // Switch in on-screen display for media testing
1823 $switches = array(
1824 'printable' => 'print',
1825 'handheld' => 'handheld',
1826 );
1827 foreach( $switches as $switch => $targetMedia ) {
1828 if( $wgRequest->getBool( $switch ) ) {
1829 if( $media == $targetMedia ) {
1830 $media = '';
1831 } elseif( $media == 'screen' ) {
1832 return null;
1833 }
1834 }
1835 }
1836
1837 // Expand longer media queries as iPhone doesn't grok 'handheld'
1838 if( $wgHandheldForIPhone ) {
1839 $mediaAliases = array(
1840 'screen' => 'screen and (min-device-width: 481px)',
1841 'handheld' => 'handheld, only screen and (max-device-width: 480px)',
1842 );
1843
1844 if( isset( $mediaAliases[$media] ) ) {
1845 $media = $mediaAliases[$media];
1846 }
1847 }
1848
1849 return $media;
1850 }
1851
1852 /**
1853 * Turn off regular page output and return an error reponse
1854 * for when rate limiting has triggered.
1855 */
1856 public function rateLimited() {
1857
1858 $this->setPageTitle(wfMsg('actionthrottled'));
1859 $this->setRobotPolicy( 'noindex,follow' );
1860 $this->setArticleRelated( false );
1861 $this->enableClientCache( false );
1862 $this->mRedirect = '';
1863 $this->clearHTML();
1864 $this->setStatusCode(503);
1865 $this->addWikiMsg( 'actionthrottledtext' );
1866
1867 $this->returnToMain( null, $this->getTitle() );
1868 }
1869
1870 /**
1871 * Show an "add new section" link?
1872 *
1873 * @return bool
1874 */
1875 public function showNewSectionLink() {
1876 return $this->mNewSectionLink;
1877 }
1878
1879 /**
1880 * Forcibly hide the new section link?
1881 *
1882 * @return bool
1883 */
1884 public function forceHideNewSectionLink() {
1885 return $this->mHideNewSectionLink;
1886 }
1887
1888 /**
1889 * Show a warning about slave lag
1890 *
1891 * If the lag is higher than $wgSlaveLagCritical seconds,
1892 * then the warning is a bit more obvious. If the lag is
1893 * lower than $wgSlaveLagWarning, then no warning is shown.
1894 *
1895 * @param int $lag Slave lag
1896 */
1897 public function showLagWarning( $lag ) {
1898 global $wgSlaveLagWarning, $wgSlaveLagCritical;
1899 if( $lag >= $wgSlaveLagWarning ) {
1900 $message = $lag < $wgSlaveLagCritical
1901 ? 'lag-warn-normal'
1902 : 'lag-warn-high';
1903 $warning = wfMsgExt( $message, 'parse', $lag );
1904 $this->addHTML( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
1905 }
1906 }
1907
1908 /**
1909 * Add a wikitext-formatted message to the output.
1910 * This is equivalent to:
1911 *
1912 * $wgOut->addWikiText( wfMsgNoTrans( ... ) )
1913 */
1914 public function addWikiMsg( /*...*/ ) {
1915 $args = func_get_args();
1916 $name = array_shift( $args );
1917 $this->addWikiMsgArray( $name, $args );
1918 }
1919
1920 /**
1921 * Add a wikitext-formatted message to the output.
1922 * Like addWikiMsg() except the parameters are taken as an array
1923 * instead of a variable argument list.
1924 *
1925 * $options is passed through to wfMsgExt(), see that function for details.
1926 */
1927 public function addWikiMsgArray( $name, $args, $options = array() ) {
1928 $options[] = 'parse';
1929 $text = wfMsgExt( $name, $options, $args );
1930 $this->addHTML( $text );
1931 }
1932
1933 /**
1934 * This function takes a number of message/argument specifications, wraps them in
1935 * some overall structure, and then parses the result and adds it to the output.
1936 *
1937 * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
1938 * on. The subsequent arguments may either be strings, in which case they are the
1939 * message names, or arrays, in which case the first element is the message name,
1940 * and subsequent elements are the parameters to that message.
1941 *
1942 * The special named parameter 'options' in a message specification array is passed
1943 * through to the $options parameter of wfMsgExt().
1944 *
1945 * Don't use this for messages that are not in users interface language.
1946 *
1947 * For example:
1948 *
1949 * $wgOut->wrapWikiMsg( '<div class="error">$1</div>', 'some-error' );
1950 *
1951 * Is equivalent to:
1952 *
1953 * $wgOut->addWikiText( '<div class="error">' . wfMsgNoTrans( 'some-error' ) . '</div>' );
1954 */
1955 public function wrapWikiMsg( $wrap /*, ...*/ ) {
1956 $msgSpecs = func_get_args();
1957 array_shift( $msgSpecs );
1958 $msgSpecs = array_values( $msgSpecs );
1959 $s = $wrap;
1960 foreach ( $msgSpecs as $n => $spec ) {
1961 $options = array();
1962 if ( is_array( $spec ) ) {
1963 $args = $spec;
1964 $name = array_shift( $args );
1965 if ( isset( $args['options'] ) ) {
1966 $options = $args['options'];
1967 unset( $args['options'] );
1968 }
1969 } else {
1970 $args = array();
1971 $name = $spec;
1972 }
1973 $s = str_replace( '$' . ( $n + 1 ), wfMsgExt( $name, $options, $args ), $s );
1974 }
1975 $this->addHTML( $this->parse( $s, /*linestart*/true, /*uilang*/true ) );
1976 }
1977 }