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