46 $fname, $headers = [], $sendErrors =
true, $optHeaders = [],
$flags = 0
51 throw new MWException( __FUNCTION__ .
" given storage path '$fname'." );
55 if ( ( (
$flags & self::STREAM_HEADLESS ) == 0 || $headers ) && headers_sent() ) {
56 echo
"Headers already sent, terminating.\n";
60 $headerFunc = (
$flags & self::STREAM_HEADLESS )
61 ?
function ( $header ) {
64 :
function ( $header ) {
68 MediaWiki\suppressWarnings();
70 MediaWiki\restoreWarnings();
72 if ( !is_array( $info ) ) {
82 if ( (
$flags & self::STREAM_ALLOW_OB ) == 0 ) {
89 $headerFunc(
"Content-type: $type" );
95 $headerFunc(
'Content-type: application/x-wiki' );
99 if ( isset( $optHeaders[
'if-modified-since'] ) ) {
100 $modsince = preg_replace(
'/;.*$/',
'', $optHeaders[
'if-modified-since'] );
102 ini_set(
'zlib.output_compression', 0 );
109 foreach ( $headers
as $header ) {
113 if ( isset( $optHeaders[
'range'] ) ) {
114 $range = self::parseRange( $optHeaders[
'range'], $info[
'size'] );
115 if ( is_array( $range ) ) {
117 $headerFunc(
'Content-Length: ' . $range[2] );
118 $headerFunc(
"Content-Range: bytes {$range[0]}-{$range[1]}/{$info['size']}" );
119 } elseif ( $range ===
'invalid' ) {
122 $headerFunc(
'Cache-Control: no-cache' );
123 $headerFunc(
'Content-Type: text/html; charset=utf-8' );
124 $headerFunc(
'Content-Range: bytes */' . $info[
'size'] );
129 $headerFunc(
'Content-Length: ' . $info[
'size'] );
133 $headerFunc(
'Content-Length: ' . $info[
'size'] );
136 if ( is_array( $range ) ) {
137 $handle = fopen(
$fname,
'rb' );
140 fseek( $handle, $range[0] );
141 $remaining = $range[2];
142 while ( $remaining > 0 && $ok ) {
143 $bytes = min( $remaining, 8 * 1024 );
144 $data = fread( $handle, $bytes );
145 $remaining -= $bytes;
146 $ok = ( $data !==
false );
153 return readfile(
$fname ) !==
false;
167 if ( (
$flags & self::STREAM_HEADLESS ) == 0 ) {
169 header(
'Cache-Control: no-cache' );
170 header(
'Content-Type: text/html; charset=utf-8' );
172 $encFile = htmlspecialchars(
$fname );
173 $encScript = htmlspecialchars( $_SERVER[
'SCRIPT_NAME'] );
174 echo
"<!DOCTYPE html><html><body>
175 <h1>File not found</h1>
176 <p>Although this PHP script ($encScript) exists, the file requested for output
177 ($encFile) does not.</p>
192 if ( preg_match(
'#^bytes=(\d*)-(\d*)$#', $range, $m ) ) {
193 list( , $start, $end ) = $m;
194 if ( $start ===
'' && $end ===
'' ) {
195 $absRange = [ 0, $size - 1 ];
196 } elseif ( $start ===
'' ) {
197 $absRange = [ $size - $end, $size - 1 ];
198 } elseif ( $end ===
'' ) {
199 $absRange = [ $start, $size - 1 ];
201 $absRange = [ $start, $end ];
203 if ( $absRange[0] >= 0 && $absRange[1] >= $absRange[0] ) {
204 if ( $absRange[0] < $size ) {
205 $absRange[1] = min( $absRange[1], $size - 1 );
206 $absRange[2] = $absRange[1] - $absRange[0] + 1;
208 } elseif ( $absRange[0] == 0 && $size == 0 ) {
209 return 'unrecognized';
214 return 'unrecognized';
227 $ext = strrchr( $filename,
'.' );
228 $ext =
$ext ===
false ?
'' : strtolower( substr(
$ext, 1 ) );
230 # trivial detection by file extension,
231 # used for thumbnails (thumb.php)
232 if ( $wgTrivialMimeDetection ) {
244 return 'unknown/unknown';
251 $type = $magic->guessTypesForExtension(
$ext );
262 return 'unknown/unknown';
264 if ( $wgCheckFileExtensions && $wgStrictFileExtensions
267 return 'unknown/unknown';
269 if ( $wgVerifyMimeType && in_array( strtolower(
$type ), $wgMimeTypeBlacklist ) ) {
270 return 'unknown/unknown';
$wgStrictFileExtensions
If this is turned off, users may override the warning for files not covered by $wgFileExtensions.
const TS_RFC2822
RFC 2822 format, for E-mail and HTTP headers.
static checkFileExtensionList($ext, $list)
Perform case-insensitive match against a list of file extensions.
Functions related to the output of file content.
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
processing should stop and the error should be shown to the user * false
static singleton()
Get an instance of this class.
static header($code)
Output an HTTP status code header.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
static send404Message($fname, $flags=0)
Send out a standard 404 message for a file.
when a variable name is used in a it is silently declared as a new local masking the global
$wgCheckFileExtensions
This is a flag to determine whether or not to check file extensions on upload.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfResetOutputBuffers($resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
static isStoragePath($path)
Check if a given path is a "mwstore://" path.
static splitExtensions($filename)
Split a file into a base name and all dot-delimited 'extensions' on the end.
static parseRange($range, $size)
Convert a Range header value to an absolute (start, end) range tuple.
Class for handling function-scope profiling.
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
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
static stream($fname, $headers=[], $sendErrors=true, $optHeaders=[], $flags=0)
Stream a file to the browser, adding all the headings and fun stuff.
$wgFileExtensions
This is the list of preferred extensions for uploading files.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static contentTypeFromPath($filename, $safe=true)
Determine the file type of a file based on the path.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
$wgTrivialMimeDetection
Switch for trivial MIME detection.
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
$wgMimeTypeBlacklist
Files with these MIME types will never be allowed as uploads if $wgVerifyMimeType is enabled...
$wgVerifyMimeType
Determines if the MIME type of uploaded files should be checked.
$wgFileBlacklist
Files with these extensions will never be allowed as uploads.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type