MediaWiki  1.23.2
OutputHandler.php
Go to the documentation of this file.
1 <?php
30 function wfOutputHandler( $s ) {
31  global $wgDisableOutputCompression, $wgValidateAllHtml;
33  if ( $wgValidateAllHtml ) {
34  $headers = headers_list();
35  $isHTML = false;
36  foreach ( $headers as $header ) {
37  $parts = explode( ':', $header, 2 );
38  if ( count( $parts ) !== 2 ) {
39  continue;
40  }
41  $name = strtolower( trim( $parts[0] ) );
42  $value = trim( $parts[1] );
43  if ( $name == 'content-type' && ( strpos( $value, 'text/html' ) === 0
44  || strpos( $value, 'application/xhtml+xml' ) === 0 )
45  ) {
46  $isHTML = true;
47  break;
48  }
49  }
50  if ( $isHTML ) {
52  }
53  }
54  if ( !$wgDisableOutputCompression && !ini_get( 'zlib.output_compression' ) ) {
55  if ( !defined( 'MW_NO_OUTPUT_COMPRESSION' ) ) {
56  $s = wfGzipHandler( $s );
57  }
58  if ( !ini_get( 'output_handler' ) ) {
59  wfDoContentLength( strlen( $s ) );
60  }
61  }
62  return $s;
63 }
64 
73 function wfRequestExtension() {
75  if ( isset( $_SERVER['REQUEST_URI'] ) ) {
76  // Strip the query string...
77  list( $path ) = explode( '?', $_SERVER['REQUEST_URI'], 2 );
78  } elseif ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
79  // Probably IIS. QUERY_STRING appears separately.
80  $path = $_SERVER['SCRIPT_NAME'];
81  } else {
82  // Can't get the path from the server? :(
83  return '';
84  }
85 
86  $period = strrpos( $path, '.' );
87  if ( $period !== false ) {
88  return strtolower( substr( $path, $period ) );
89  }
90  return '';
91 }
92 
101 function wfGzipHandler( $s ) {
102  if ( !function_exists( 'gzencode' ) ) {
103  wfDebug( __FUNCTION__ . "() skipping compression (gzencode unavailable)\n" );
104  return $s;
105  }
106  if ( headers_sent() ) {
107  wfDebug( __FUNCTION__ . "() skipping compression (headers already sent)\n" );
108  return $s;
109  }
110 
112  if ( $ext == '.gz' || $ext == '.tgz' ) {
113  // Don't do gzip compression if the URL path ends in .gz or .tgz
114  // This confuses Safari and triggers a download of the page,
115  // even though it's pretty clearly labeled as viewable HTML.
116  // Bad Safari! Bad!
117  return $s;
118  }
119 
120  if ( wfClientAcceptsGzip() ) {
121  wfDebug( __FUNCTION__ . "() is compressing output\n" );
122  header( 'Content-Encoding: gzip' );
123  $s = gzencode( $s, 6 );
124  }
125 
126  // Set vary header if it hasn't been set already
127  $headers = headers_list();
128  $foundVary = false;
129  foreach ( $headers as $header ) {
130  if ( substr( $header, 0, 5 ) == 'Vary:' ) {
131  $foundVary = true;
132  break;
133  }
134  }
135  if ( !$foundVary ) {
136  header( 'Vary: Accept-Encoding' );
137  global $wgUseXVO;
138  if ( $wgUseXVO ) {
139  header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip' );
140  }
141  }
142  return $s;
143 }
144 
152 function wfMangleFlashPolicy( $s ) {
153  # Avoid weird excessive memory usage in PCRE on big articles
154  if ( preg_match( '/<\s*cross-domain-policy\s*>/i', $s ) ) {
155  return preg_replace( '/<\s*cross-domain-policy\s*>/i', '<NOT-cross-domain-policy>', $s );
156  } else {
157  return $s;
158  }
159 }
160 
166 function wfDoContentLength( $length ) {
167  if ( !headers_sent() && isset( $_SERVER['SERVER_PROTOCOL'] ) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0' ) {
168  header( "Content-Length: $length" );
169  }
170 }
171 
180 
181  $errors = '';
182  if ( MWTidy::checkErrors( $s, $errors ) ) {
183  return $s;
184  }
185 
186  header( 'Cache-Control: no-cache' );
187 
188  $out = Html::element( 'h1', null, 'HTML validation error' );
189  $out .= Html::openElement( 'ul' );
190 
191  $error = strtok( $errors, "\n" );
192  $badLines = array();
193  while ( $error !== false ) {
194  if ( preg_match( '/^line (\d+)/', $error, $m ) ) {
195  $lineNum = intval( $m[1] );
196  $badLines[$lineNum] = true;
197  $out .= Html::rawElement( 'li', null,
198  Html::element( 'a', array( 'href' => "#line-{$lineNum}" ), $error ) ) . "\n";
199  }
200  $error = strtok( "\n" );
201  }
202 
203  $out .= Html::closeElement( 'ul' );
204  $out .= Html::element( 'pre', null, $errors );
205  $out .= Html::openElement( 'ol' ) . "\n";
206  $line = strtok( $s, "\n" );
207  $i = 1;
208  while ( $line !== false ) {
209  $attrs = array();
210  if ( isset( $badLines[$i] ) ) {
211  $attrs['class'] = 'highlight';
212  $attrs['id'] = "line-$i";
213  }
214  $out .= Html::element( 'li', $attrs, $line ) . "\n";
215  $line = strtok( "\n" );
216  $i++;
217  }
218  $out .= Html::closeElement( 'ol' );
219 
220  $style = <<<CSS
221 .highlight { background-color: #ffc }
222 li { white-space: pre }
223 CSS;
224 
225  $out = Html::htmlHeader( array( 'lang' => 'en', 'dir' => 'ltr' ) ) .
226  Html::rawElement( 'head', null,
227  Html::element( 'title', null, 'HTML validation error' ) .
228  Html::inlineStyle( $style ) ) .
229  Html::rawElement( 'body', null, $out ) .
230  Html::closeElement( 'html' );
231 
232  return $out;
233 }
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:801
wfMangleFlashPolicy
wfMangleFlashPolicy( $s)
Mangle flash policy tags which open up the site to XSS attacks.
Definition: OutputHandler.php:152
$s
$s
Definition: mergeMessageFileList.php:156
pre
</p > ! end ! test Empty pre
Definition: parserTests.txt:1579
Html\closeElement
static closeElement( $element)
Returns "</$element>", except if $wgWellFormedXml is off, in which case it returns the empty string w...
Definition: Html.php:235
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:166
$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:148
wfHtmlValidationHandler
wfHtmlValidationHandler( $s)
Replace the output with an error if the HTML is not valid.
Definition: OutputHandler.php:179
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:933
$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:2029
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:604
wfGzipHandler
wfGzipHandler( $s)
Handler that compresses data with gzip if allowed by the Accept header.
Definition: OutputHandler.php:101
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:166
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:2573
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
wfRequestExtension
wfRequestExtension()
Get the "file extension" that some client apps will estimate from the currently-requested URL.
Definition: OutputHandler.php:73