MediaWiki  1.23.15
OutputHandler.php
Go to the documentation of this file.
1 <?php
30 function wfOutputHandler( $s ) {
31  global $wgDisableOutputCompression, $wgValidateAllHtml, $wgMangleFlashPolicy;
32  if ( $wgMangleFlashPolicy ) {
34  }
35  if ( $wgValidateAllHtml ) {
36  $headers = headers_list();
37  $isHTML = false;
38  foreach ( $headers as $header ) {
39  $parts = explode( ':', $header, 2 );
40  if ( count( $parts ) !== 2 ) {
41  continue;
42  }
43  $name = strtolower( trim( $parts[0] ) );
44  $value = trim( $parts[1] );
45  if ( $name == 'content-type' && ( strpos( $value, 'text/html' ) === 0
46  || strpos( $value, 'application/xhtml+xml' ) === 0 )
47  ) {
48  $isHTML = true;
49  break;
50  }
51  }
52  if ( $isHTML ) {
54  }
55  }
56  if ( !$wgDisableOutputCompression && !ini_get( 'zlib.output_compression' ) ) {
57  if ( !defined( 'MW_NO_OUTPUT_COMPRESSION' ) ) {
58  $s = wfGzipHandler( $s );
59  }
60  if ( !ini_get( 'output_handler' ) ) {
61  wfDoContentLength( strlen( $s ) );
62  }
63  }
64  return $s;
65 }
66 
75 function wfRequestExtension() {
77  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
78  // Strip the query string...
79  list( $path ) = explode( '?', $_SERVER['REQUEST_URI'], 2 );
80  } elseif ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
81  // Probably IIS. QUERY_STRING appears separately.
82  $path = $_SERVER['SCRIPT_NAME'];
83  } else {
84  // Can't get the path from the server? :(
85  return '';
86  }
87 
88  $period = strrpos( $path, '.' );
89  if ( $period !== false ) {
90  return strtolower( substr( $path, $period ) );
91  }
92  return '';
93 }
94 
103 function wfGzipHandler( $s ) {
104  if ( !function_exists( 'gzencode' ) ) {
105  wfDebug( __FUNCTION__ . "() skipping compression (gzencode unavailable)\n" );
106  return $s;
107  }
108  if ( headers_sent() ) {
109  wfDebug( __FUNCTION__ . "() skipping compression (headers already sent)\n" );
110  return $s;
111  }
112 
114  if ( $ext == '.gz' || $ext == '.tgz' ) {
115  // Don't do gzip compression if the URL path ends in .gz or .tgz
116  // This confuses Safari and triggers a download of the page,
117  // even though it's pretty clearly labeled as viewable HTML.
118  // Bad Safari! Bad!
119  return $s;
120  }
121 
122  if ( wfClientAcceptsGzip() ) {
123  wfDebug( __FUNCTION__ . "() is compressing output\n" );
124  header( 'Content-Encoding: gzip' );
125  $s = gzencode( $s, 6 );
126  }
127 
128  // Set vary header if it hasn't been set already
129  $headers = headers_list();
130  $foundVary = false;
131  foreach ( $headers as $header ) {
132  if ( substr( $header, 0, 5 ) == 'Vary:' ) {
133  $foundVary = true;
134  break;
135  }
136  }
137  if ( !$foundVary ) {
138  header( 'Vary: Accept-Encoding' );
139  global $wgUseXVO;
140  if ( $wgUseXVO ) {
141  header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip' );
142  }
143  }
144  return $s;
145 }
146 
154 function wfMangleFlashPolicy( $s ) {
155  # Avoid weird excessive memory usage in PCRE on big articles
156  if ( preg_match( '/<\s*cross-domain-policy(?=\s|>)/i', $s ) ) {
157  return preg_replace( '/<(\s*)(cross-domain-policy(?=\s|>))/i', '<$1NOT-$2', $s );
158  } else {
159  return $s;
160  }
161 }
162 
168 function wfDoContentLength( $length ) {
169  if ( !headers_sent() && isset( $_SERVER['SERVER_PROTOCOL'] ) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) {
170  header( "Content-Length: $length" );
171  }
172 }
173 
182 
183  $errors = '';
184  if ( MWTidy::checkErrors( $s, $errors ) ) {
185  return $s;
186  }
187 
188  header( 'Cache-Control: no-cache' );
189 
190  $out = Html::element( 'h1', null, 'HTML validation error' );
191  $out .= Html::openElement( 'ul' );
192 
193  $error = strtok( $errors, "\n" );
194  $badLines = array();
195  while ( $error !== false ) {
196  if ( preg_match( '/^line (\d+)/', $error, $m ) ) {
197  $lineNum = intval( $m[1] );
198  $badLines[$lineNum] = true;
199  $out .= Html::rawElement( 'li', null,
200  Html::element( 'a', array( 'href' => "#line-{$lineNum}" ), $error ) ) . "\n";
201  }
202  $error = strtok( "\n" );
203  }
204 
205  $out .= Html::closeElement( 'ul' );
206  $out .= Html::element( 'pre', null, $errors );
207  $out .= Html::openElement( 'ol' ) . "\n";
208  $line = strtok( $s, "\n" );
209  $i = 1;
210  while ( $line !== false ) {
211  $attrs = array();
212  if ( isset( $badLines[$i] ) ) {
213  $attrs['class'] = 'highlight';
214  $attrs['id'] = "line-$i";
215  }
216  $out .= Html::element( 'li', $attrs, $line ) . "\n";
217  $line = strtok( "\n" );
218  $i++;
219  }
220  $out .= Html::closeElement( 'ol' );
221 
222  $style = <<<CSS
223 .highlight { background-color: #ffc }
224 li { white-space: pre }
225 CSS;
226 
227  $out = Html::htmlHeader( array( 'lang' => 'en', 'dir' => 'ltr' ) ) .
228  Html::rawElement( 'head', null,
229  Html::element( 'title', null, 'HTML validation error' ) .
230  Html::inlineStyle( $style ) ) .
231  Html::rawElement( 'body', null, $out ) .
232  Html::closeElement( 'html' );
233 
234  return $out;
235 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Html\htmlHeader
static htmlHeader( $attribs=array())
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:746
wfMangleFlashPolicy
wfMangleFlashPolicy( $s)
Mangle flash policy tags which open up the site to XSS attacks.
Definition: OutputHandler.php:154
$s
$s
Definition: mergeMessageFileList.php:156
pre
</p > ! end ! test Empty pre
Definition: parserTests.txt:1588
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:218
Html\openElement
static openElement( $element, $attribs=array())
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:159
$out
$out
Definition: UtfNormalGenerate.php:167
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:141
wfHtmlValidationHandler
wfHtmlValidationHandler( $s)
Replace the output with an error if the HTML is not valid.
Definition: OutputHandler.php:181
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$line
$line
Definition: cdb.php:57
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
wfClientAcceptsGzip
wfClientAcceptsGzip( $force=false)
Definition: GlobalFunctions.php:2076
Html\inlineStyle
static inlineStyle( $contents, $media='all')
Output a "<style>" tag with the given contents for the given media type (if any).
Definition: Html.php:540
wfGzipHandler
wfGzipHandler( $s)
Handler that compresses data with gzip if allowed by the Accept header.
Definition: OutputHandler.php:103
wfOutputHandler
wfOutputHandler( $s)
Standard output handler for use with ob_start.
Definition: OutputHandler.php:30
$ext
$ext
Definition: NoLocalSettings.php:34
color
in the sidebar</td >< td > font color
Definition: All_system_messages.txt:425
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
wfDoContentLength
wfDoContentLength( $length)
Add a Content-Length header if possible.
Definition: OutputHandler.php:168
MWTidy\checkErrors
static checkErrors( $text, &$errorStr=null)
Check HTML for errors, used if $wgValidateAllHtml = true.
Definition: Tidy.php:159
$error
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
Definition: hooks.txt:2584
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:121
wfRequestExtension
wfRequestExtension()
Get the "file extension" that some client apps will estimate from the currently-requested URL.
Definition: OutputHandler.php:75