35use Wikimedia\AtEase\AtEase;
41use Wikimedia\RequestTimeout\RequestTimeout;
42use Wikimedia\Timestamp\ConvertibleTimestamp;
57 $path =
"$wgExtensionDirectory/$ext/extension.json";
59 ExtensionRegistry::getInstance()->queue(
$path );
77 $registry = ExtensionRegistry::getInstance();
78 foreach ( $exts as $ext ) {
79 $registry->queue(
"$wgExtensionDirectory/$ext/extension.json" );
94 $path =
"$wgStyleDirectory/$skin/skin.json";
96 ExtensionRegistry::getInstance()->queue(
$path );
108 $registry = ExtensionRegistry::getInstance();
109 foreach ( $skins as $skin ) {
110 $registry->queue(
"$wgStyleDirectory/$skin/skin.json" );
127 $comparator =
static function ( $a, $b ):
int {
128 if ( is_string( $a ) && is_string( $b ) ) {
129 return strcmp( $a, $b );
131 if ( !is_array( $a ) && !is_array( $b ) ) {
132 throw new InvalidArgumentException(
133 'This function assumes that array elements are all strings or all arrays'
136 if ( count( $a ) !== count( $b ) ) {
137 return count( $a ) <=> count( $b );
141 while ( key( $a ) !==
null && key( $b ) !==
null ) {
142 $valueA = current( $a );
143 $valueB = current( $b );
144 $cmp = strcmp( $valueA, $valueB );
154 return array_udiff( $arr1, $arr2, $comparator );
180 foreach ( $args as $errors ) {
181 foreach ( $errors as $params ) {
182 $originalParams = $params;
184 $params = [ $params[0]->getKey(), ...$params[0]->getParams() ];
186 # @todo FIXME: Sometimes get nested arrays for $params,
187 # which leads to E_NOTICEs
188 $spec = implode(
"\t", $params );
189 $out[$spec] = $originalParams;
192 return array_values( $out );
206 $keys = array_keys( $array );
207 $offsetByKey = array_flip( $keys );
209 if ( !\array_key_exists( $after, $offsetByKey ) ) {
212 $offset = $offsetByKey[$after];
215 $before = array_slice( $array, 0, $offset + 1,
true );
216 $after = array_slice( $array, $offset + 1, count( $array ) - $offset,
true );
218 $output = $before + $insert + $after;
233 if ( is_object( $objOrArray ) ) {
234 $objOrArray = get_object_vars( $objOrArray );
236 foreach ( $objOrArray as $key => $value ) {
237 if ( $recursive && ( is_object( $value ) || is_array( $value ) ) ) {
241 $array[$key] = $value;
260 $max = mt_getrandmax() + 1;
261 $rand = number_format( ( mt_rand() * $max + mt_rand() ) / $max / $max, 12,
'.',
'' );
277 for ( $n = 0; $n < $length; $n += 7 ) {
278 $str .= sprintf(
'%07x', mt_rand() & 0xfffffff );
280 return substr( $str, 0, $length );
319 if ( $needle ===
null ) {
320 $needle = [
'%3B',
'%40',
'%24',
'%21',
'%2A',
'%28',
'%29',
'%2C',
'%2F',
'%7E' ];
321 if ( !isset( $_SERVER[
'SERVER_SOFTWARE'] ) ||
322 !str_contains( $_SERVER[
'SERVER_SOFTWARE'],
'Microsoft-IIS/7' )
328 $s = urlencode( $s );
331 [
';',
'@',
'$',
'!',
'*',
'(',
')',
',',
'/',
'~',
':' ],
349 if ( $array2 !==
null ) {
354 foreach ( $array1 as $key => $value ) {
355 if ( $value !==
null && $value !==
false ) {
359 if ( $prefix !==
'' ) {
360 $key = $prefix .
"[$key]";
362 if ( is_array( $value ) ) {
364 foreach ( $value as $k => $v ) {
365 $cgi .= $firstTime ?
'' :
'&';
366 if ( is_array( $v ) ) {
369 $cgi .= urlencode( $key .
"[$k]" ) .
'=' . urlencode( $v );
374 if ( is_object( $value ) ) {
375 $value = $value->__toString();
377 $cgi .= urlencode( $key ) .
'=' . urlencode( $value );
394 if ( isset( $query[0] ) && $query[0] ==
'?' ) {
395 $query = substr( $query, 1 );
397 $bits = explode(
'&', $query );
399 foreach ( $bits as $bit ) {
403 if ( strpos( $bit,
'=' ) ===
false ) {
408 [ $key, $value ] = explode(
'=', $bit );
410 $key = urldecode( $key );
411 $value = urldecode( $value );
412 if ( strpos( $key,
'[' ) !==
false ) {
413 $keys = array_reverse( explode(
'[', $key ) );
414 $key = array_pop( $keys );
416 foreach ( $keys as $k ) {
417 $k = substr( $k, 0, -1 );
418 $temp = [ $k => $temp ];
420 if ( isset( $ret[$key] ) && is_array( $ret[$key] ) ) {
421 $ret[$key] = array_merge( $ret[$key], $temp );
441 if ( is_array( $query ) ) {
444 if ( $query !=
'' ) {
447 $hashPos = strpos(
$url,
'#' );
448 if ( $hashPos !==
false ) {
449 $fragment = substr(
$url, $hashPos );
454 if ( strpos(
$url,
'?' ) ===
false ) {
462 if ( $fragment !==
false ) {
478 if ( MediaWikiServices::hasInstance() ) {
479 $services = MediaWikiServices::getInstance();
480 if ( $services->hasService(
'UrlUtils' ) ) {
481 return $services->getUrlUtils();
560 return UrlUtils::assemble( (array)$urlParts );
574 return $includeProtocolRelative ?
wfGetUrlUtils()->validProtocols() :
670function wfDebug( $text, $dest =
'all', array $context = [] ) {
677 $text = trim( $text );
682 $context[
'private'] = ( $dest ===
false || $dest ===
'private' );
684 $logger = LoggerFactory::getInstance(
'wfDebug' );
685 $logger->debug( $text, $context );
694 if ( $cache !==
null ) {
699 if ( ( isset( $_GET[
'action'] ) && $_GET[
'action'] ==
'raw' )
735 $logGroup, $text, $dest =
'all', array $context = []
737 $text = trim( $text );
739 $logger = LoggerFactory::getInstance( $logGroup );
740 $context[
'private'] = ( $dest ===
false || $dest ===
'private' );
741 $logger->info( $text, $context );
753 $logger = LoggerFactory::getInstance(
'wfLogDBError' );
754 $logger->error( trim( $text ), $context );
773function wfDeprecated( $function, $version =
false, $component =
false, $callerOffset = 2 ) {
774 if ( !is_string( $version ) && $version !==
false ) {
775 throw new InvalidArgumentException(
776 "MediaWiki version must either be a string or false. " .
777 "Example valid version: '1.33'"
781 MWDebug::deprecated( $function, $version, $component, $callerOffset + 1 );
804function wfDeprecatedMsg( $msg, $version =
false, $component =
false, $callerOffset = 2 ) {
805 MWDebug::deprecatedMsg( $msg, $version, $component,
806 $callerOffset ===
false ?
false : $callerOffset + 1 );
819function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
820 MWDebug::warning( $msg, $callerOffset + 1, $level,
'auto' );
832function wfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) {
833 MWDebug::warning( $msg, $callerOffset + 1, $level,
'production' );
859 if ( is_array( $key ) ) {
863 $message = Message::newFromSpecifier( $key );
868 $message->params( ...$params );
887 return Message::newFallbackSequence( ...$keys );
899 # Fix windows line-endings
900 # Some messages are split with explode("\n", $msg)
901 $message = str_replace(
"\r",
'', $message );
904 if ( is_array( $args ) && $args ) {
905 if ( is_array( $args[0] ) ) {
906 $args = array_values( $args[0] );
908 $replacementKeys = [];
909 foreach ( $args as $n => $param ) {
910 $replacementKeys[
'$' . ( $n + 1 )] = $param;
912 $message = strtr( $message, $replacementKeys );
933 return php_uname(
'n' ) ?:
'unknown';
947 static $disabled =
null;
949 if ( $disabled ===
null ) {
950 $disabled = !function_exists(
'debug_backtrace' );
952 wfDebug(
"debug_backtrace() is disabled" );
960 return array_slice( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $limit + 1 ), 1 );
962 return array_slice( debug_backtrace(), 1 );
977 $frameFormat =
"%s line %s calls %s()\n";
980 $frameFormat =
"<li>%s line %s calls %s()</li>\n";
981 $traceFormat =
"<ul>\n%s</ul>\n";
984 $frames = array_map(
static function ( $frame ) use ( $frameFormat ) {
985 $file = !empty( $frame[
'file'] ) ? basename( $frame[
'file'] ) :
'-';
986 $line = $frame[
'line'] ??
'-';
987 $call = $frame[
'function'];
988 if ( !empty( $frame[
'class'] ) ) {
989 $call = $frame[
'class'] . $frame[
'type'] . $call;
991 return sprintf( $frameFormat, $file, $line, $call );
994 return sprintf( $traceFormat, implode(
'', $frames ) );
1009 if ( isset( $backtrace[$level] ) ) {
1025 if ( !$limit || $limit > count( $trace ) - 1 ) {
1026 $limit = count( $trace ) - 1;
1028 $trace = array_slice( $trace, -$limit - 1, $limit );
1029 return implode(
'/', array_map(
'wfFormatStackFrame', $trace ) );
1045 if ( !isset( $frame[
'function'] ) ) {
1046 return 'NO_FUNCTION_GIVEN';
1048 return isset( $frame[
'class'] ) && isset( $frame[
'type'] ) ?
1049 $frame[
'class'] . $frame[
'type'] . $frame[
'function'] :
1063 static $result =
null;
1064 if ( $result ===
null || $force ) {
1066 if ( isset( $_SERVER[
'HTTP_ACCEPT_ENCODING'] ) ) {
1067 # @todo FIXME: We may want to disallow some broken browsers
1070 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
1071 $_SERVER[
'HTTP_ACCEPT_ENCODING'],
1075 if ( isset( $m[2] ) && ( $m[1] ==
'q' ) && ( $m[2] == 0 ) ) {
1078 wfDebug(
"wfClientAcceptsGzip: client accepts gzip." );
1098 static $repl =
null, $repl2 =
null, $repl3 =
null, $repl4 =
null;
1099 if ( $repl ===
null || defined(
'MW_PARSER_TEST' ) || defined(
'MW_PHPUNIT_TEST' ) ) {
1103 '"' =>
'"',
'&' =>
'&',
"'" =>
''',
'<' =>
'<',
1104 '=' =>
'=',
'>' =>
'>',
'[' =>
'[',
']' =>
']',
1105 '{' =>
'{',
'|' =>
'|',
'}' =>
'}',
1108 "\n!" =>
"\n!",
"\r!" =>
"\r!",
1109 "\n#" =>
"\n#",
"\r#" =>
"\r#",
1110 "\n*" =>
"\n*",
"\r*" =>
"\r*",
1111 "\n:" =>
"\n:",
"\r:" =>
"\r:",
1112 "\n " =>
"\n ",
"\r " =>
"\r ",
1113 "\n\n" =>
"\n ",
"\r\n" =>
" \n",
1114 "\n\r" =>
"\n ",
"\r\r" =>
"\r ",
1115 "\n\t" =>
"\n	",
"\r\t" =>
"\r	",
1116 "\n----" =>
"\n----",
"\r----" =>
"\r----",
1117 '__' =>
'__',
'://' =>
'://',
1118 '~~~' =>
'~~~',
1123 foreach ( $magicLinks as $magic ) {
1124 $repl[
"$magic "] =
"$magic ";
1125 $repl[
"$magic\t"] =
"$magic	";
1126 $repl[
"$magic\r"] =
"$magic ";
1127 $repl[
"$magic\n"] =
"$magic ";
1128 $repl[
"$magic\f"] =
"$magic";
1136 '+' =>
'+',
'-' =>
'-',
'_' =>
'_',
'~' =>
'~',
1144 '_' =>
'_',
'~' =>
'~',
1145 "\n" =>
" ",
"\r" =>
" ",
1153 if ( substr( $prot, -1 ) ===
':' ) {
1154 $repl2[] = preg_quote( substr( $prot, 0, -1 ),
'/' );
1157 $repl2 = $repl2 ?
'/\b(' . implode(
'|', $repl2 ) .
'):/i' :
'/^(?!)/';
1160 '@phan-var string $repl2';
1161 '@phan-var string $repl3';
1162 '@phan-var string $repl4';
1164 $text = substr( strtr(
"\n$input", $repl ), 1 );
1165 if ( $text ===
'' ) {
1168 $first = strtr( $text[0], $repl3 );
1169 if ( strlen( $text ) > 1 ) {
1170 $text = $first . substr( $text, 1, -1 ) .
1171 strtr( substr( $text, -1 ), $repl4 );
1174 $text = strtr( $first, $repl4 );
1176 $text = preg_replace( $repl2,
'$1:', $text );
1192 if (
$source !==
null || $force ) {
1208 $temp = (bool)( $dest & $bit );
1209 if ( $state !==
null ) {
1227 $s = str_replace(
"\n",
"<br />\n", var_export( $var,
true ) .
"\n" );
1228 if ( headers_sent() ||
$wgOut ===
null || !is_object(
$wgOut ) ) {
1244 HttpStatus::header( $code );
1247 $wgOut->sendCacheControl();
1250 \MediaWiki\Request\HeaderCallback::warnIfHeadersSent();
1251 header(
'Content-type: text/html; charset=utf-8' );
1253 print
'<!DOCTYPE html>' .
1254 '<html><head><title>' .
1255 htmlspecialchars( $label ) .
1256 '</title><meta name="color-scheme" content="light dark" /></head><body><h1>' .
1257 htmlspecialchars( $label ) .
1259 nl2br( htmlspecialchars( $desc ) ) .
1260 "</p></body></html>\n";
1261 header(
'Content-Length: ' . ob_get_length() );
1287 while ( $status = ob_get_status() ) {
1288 if ( isset( $status[
'flags'] ) ) {
1289 $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
1290 $deleteable = ( $status[
'flags'] & $flags ) === $flags;
1291 } elseif ( isset( $status[
'del'] ) ) {
1292 $deleteable = $status[
'del'];
1295 $deleteable = $status[
'type'] !== 0;
1297 if ( !$deleteable ) {
1302 if ( $status[
'name'] ===
'MediaWikiIntegrationTestCase::wfResetOutputBuffersBarrier' ) {
1306 if ( !ob_end_clean() ) {
1311 if ( $resetGzipEncoding && $status[
'name'] ==
'ob_gzhandler' ) {
1314 header_remove(
'Content-Encoding' );
1331 $ret = ConvertibleTimestamp::convert( $outputtype, $ts );
1332 if ( $ret ===
false ) {
1333 wfDebug(
"wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts" );
1347 if ( $ts ===
null ) {
1360 return ConvertibleTimestamp::now( TS_MW );
1381 return TempFSFile::getUsableTempDirectory();
1395 if ( FileBackend::isStoragePath( $dir ) ) {
1396 throw new LogicException( __FUNCTION__ .
" given storage path '$dir'." );
1398 if ( $caller !==
null ) {
1399 wfDebug(
"$caller: called wfMkdirParents($dir)" );
1401 if ( strval( $dir ) ===
'' ) {
1405 $dir = str_replace( [
'\\',
'/' ], DIRECTORY_SEPARATOR, $dir );
1415 $ok = is_dir( $dir ) || @mkdir( $dir, $mode,
true ) || is_dir( $dir );
1417 trigger_error( sprintf(
"failed to mkdir \"%s\" mode 0%o", $dir, $mode ), E_USER_WARNING );
1430 if ( is_dir( $dir ) ) {
1431 $objects = scandir( $dir );
1432 foreach ( $objects as $object ) {
1433 if ( $object !=
"." && $object !=
".." ) {
1434 if ( filetype( $dir .
'/' . $object ) ==
"dir" ) {
1437 unlink( $dir .
'/' . $object );
1451function wfPercent( $nr,
int $acc = 2,
bool $round =
true ) {
1452 $accForFormat = $acc >= 0 ? $acc : 0;
1453 $ret = sprintf(
"%.{$accForFormat}f", $nr );
1454 return $round ? round( (
float)$ret, $acc ) .
'%' :
"$ret%";
1497 $val = strtolower( $val );
1502 || preg_match(
"/^\s*[+-]?0*[1-9]/", $val );
1519 return Shell::escape( ...$args );
1547 $limits = [], $options = []
1549 if ( Shell::isDisabled() ) {
1552 return 'Unable to run external programs, proc_open() is disabled.';
1555 if ( is_array( $cmd ) ) {
1556 $cmd = Shell::escape( $cmd );
1559 $includeStderr = isset( $options[
'duplicateStderr'] ) && $options[
'duplicateStderr'];
1560 $profileMethod = $options[
'profileMethod'] ??
wfGetCaller();
1563 $result = Shell::command( [] )
1564 ->unsafeParams( (array)$cmd )
1565 ->environment( $environ )
1567 ->includeStderr( $includeStderr )
1568 ->profileMethod( $profileMethod )
1570 ->restrict( Shell::RESTRICT_NONE )
1577 $retval = $result->getExitCode();
1579 return $result->getStdout();
1600 return wfShellExec( $cmd, $retval, $environ, $limits,
1601 [
'duplicateStderr' =>
true,
'profileMethod' =>
wfGetCaller() ] );
1623 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
1624 ->onWfShellWikiCmd( $script, $parameters, $options );
1625 $cmd = [ $options[
'php'] ??
$wgPhpCli ];
1626 if ( isset( $options[
'wrapper'] ) ) {
1627 $cmd[] = $options[
'wrapper'];
1631 return Shell::escape( array_merge( $cmd, $parameters ) );
1654 ?
string &$simplisticMergeAttempt,
1655 ?
string &$mergeLeftovers =
null
1659 # This check may also protect against code injection in
1660 # case of broken installations.
1661 AtEase::suppressWarnings();
1663 AtEase::restoreWarnings();
1665 if ( !$haveDiff3 ) {
1670 # Make temporary files
1672 $oldtextFile = fopen( $oldtextName = tempnam( $td,
'merge-old-' ),
'w' );
1673 $mytextFile = fopen( $mytextName = tempnam( $td,
'merge-mine-' ),
'w' );
1674 $yourtextFile = fopen( $yourtextName = tempnam( $td,
'merge-your-' ),
'w' );
1676 # NOTE: diff3 issues a warning to stderr if any of the files does not end with
1677 # a newline character. To avoid this, we normalize the trailing whitespace before
1678 # creating the diff.
1680 fwrite( $oldtextFile, rtrim( $old ) .
"\n" );
1681 fclose( $oldtextFile );
1682 fwrite( $mytextFile, rtrim( $mine ) .
"\n" );
1683 fclose( $mytextFile );
1684 fwrite( $yourtextFile, rtrim( $yours ) .
"\n" );
1685 fclose( $yourtextFile );
1687 # Check for a conflict
1688 $cmd = Shell::escape(
$wgDiff3,
'--text',
'--overlap-only', $mytextName,
1689 $oldtextName, $yourtextName );
1690 $handle = popen( $cmd,
'r' );
1692 $mergeLeftovers =
'';
1694 $data = fread( $handle, 8192 );
1695 if ( $data ===
false || $data ===
'' ) {
1698 $mergeLeftovers .= $data;
1702 $conflict = $mergeLeftovers !==
'';
1704 # Merge differences automatically where possible, preferring "my" text for conflicts.
1705 $cmd = Shell::escape(
$wgDiff3,
'--text',
'--ed',
'--merge', $mytextName,
1706 $oldtextName, $yourtextName );
1707 $handle = popen( $cmd,
'r' );
1708 $simplisticMergeAttempt =
'';
1710 $data = fread( $handle, 8192 );
1711 if ( $data ===
false || $data ===
'' ) {
1714 $simplisticMergeAttempt .= $data;
1717 unlink( $mytextName );
1718 unlink( $oldtextName );
1719 unlink( $yourtextName );
1721 if ( $simplisticMergeAttempt ===
'' && $old !==
'' && !$conflict ) {
1722 wfDebug(
"Unexpected null result from diff3. Command: $cmd" );
1741 if ( $suffix ==
'' ) {
1744 $encSuffix =
'(?:' . preg_quote( $suffix,
'#' ) .
')?';
1748 if ( preg_match(
"#([^/\\\\]*?){$encSuffix}[/\\\\]*$#",
$path,
$matches ) ) {
1766 $path = str_replace(
'/', DIRECTORY_SEPARATOR,
$path );
1767 $from = str_replace(
'/', DIRECTORY_SEPARATOR, $from );
1771 $from = rtrim( $from, DIRECTORY_SEPARATOR );
1773 $pieces = explode( DIRECTORY_SEPARATOR, dirname(
$path ) );
1774 $against = explode( DIRECTORY_SEPARATOR, $from );
1776 if ( $pieces[0] !== $against[0] ) {
1783 while ( count( $pieces ) && count( $against )
1784 && $pieces[0] == $against[0] ) {
1785 array_shift( $pieces );
1786 array_shift( $against );
1790 while ( count( $against ) ) {
1791 array_unshift( $pieces,
'..' );
1792 array_shift( $against );
1797 return implode( DIRECTORY_SEPARATOR, $pieces );
1811 if ( $script ===
'index' ) {
1813 } elseif ( $script ===
'load' ) {
1816 return "{$wgScriptPath}/{$script}.php";
1828 return $value ?
'true' :
'false';
1851 $name = preg_replace(
1852 "/[^" . Title::legalChars() .
"]" . $illegalFileChars .
"/",
1870 if ( $oldLimit != -1 ) {
1872 if ( $newLimit == -1 ) {
1873 wfDebug(
"Removing PHP's memory limit" );
1874 AtEase::suppressWarnings();
1875 ini_set(
'memory_limit', $newLimit );
1876 AtEase::restoreWarnings();
1877 } elseif ( $newLimit > $oldLimit ) {
1878 wfDebug(
"Raising PHP's memory limit to $newLimit bytes" );
1879 AtEase::suppressWarnings();
1880 ini_set(
'memory_limit', $newLimit );
1881 AtEase::restoreWarnings();
1895 $timeout = RequestTimeout::singleton();
1896 $timeLimit = $timeout->getWallTimeLimit();
1897 if ( $timeLimit !== INF ) {
1904 $timeLimit = (int)ini_get(
'max_execution_time' );
1910 ignore_user_abort(
true );
1923 $string = trim( $string ??
'' );
1924 if ( $string ===
'' ) {
1927 $last = $string[strlen( $string ) - 1];
1928 $val = intval( $string );
1955 return in_array( $str, ExpiryDef::INFINITY_VALS );
1975 $multipliers = [ 1 ];
1979 $multipliers[] = 1.5;
1984 if ( !$handler || !isset( $params[
'width'] ) ) {
1989 if ( isset( $params[
'page'] ) ) {
1990 $basicParams[
'page'] = $params[
'page'];
1996 foreach ( $multipliers as $multiplier ) {
1997 $thumbLimits = array_merge( $thumbLimits, array_map(
1998 static function ( $width ) use ( $multiplier ) {
1999 return round( $width * $multiplier );
2002 $imageLimits = array_merge( $imageLimits, array_map(
2003 static function ( $pair ) use ( $multiplier ) {
2005 round( $pair[0] * $multiplier ),
2006 round( $pair[1] * $multiplier ),
2013 if ( in_array( $params[
'width'], $thumbLimits ) ) {
2014 $normalParams = $basicParams + [
'width' => $params[
'width'] ];
2016 $handler->normaliseParams( $file, $normalParams );
2020 foreach ( $imageLimits as $pair ) {
2021 $normalParams = $basicParams + [
'width' => $pair[0],
'height' => $pair[1] ];
2024 $handler->normaliseParams( $file, $normalParams );
2026 if ( $normalParams[
'width'] == $params[
'width'] ) {
2037 foreach ( $params as $key => $value ) {
2038 if ( !isset( $normalParams[$key] ) || $normalParams[$key] != $value ) {
2060 foreach ( $baseArray as $name => &$groupVal ) {
2061 if ( isset( $newValues[$name] ) ) {
2062 $groupVal += $newValues[$name];
2066 $baseArray += $newValues;
wfIsWindows()
Check if the operating system is Windows.
wfThumbIsStandard(File $file, array $params)
Returns true if these thumbnail parameters match one that MediaWiki requests from file description pa...
wfVarDump( $var)
A wrapper around the PHP function var_export().
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfTempDir()
Tries to get the system directory for temporary files.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
wfEscapeShellArg(... $args)
Locale-independent version of escapeshellarg()
wfLogDBError( $text, array $context=[])
Log for database errors.
wfLoadSkins(array $skins)
Load multiple skins at once.
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfUrlProtocolsWithoutProtRel()
Like wfUrlProtocols(), but excludes '//' from the protocol list.
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
wfLoadExtension( $ext, $path=null)
Load an extension.
wfMemoryLimit( $newLimit)
Raise PHP's memory limit (if needed).
wfSetBit(&$dest, $bit, $state=true)
As for wfSetVar except setting a bit.
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfShorthandToInteger(?string $string='', int $default=-1)
Converts shorthand byte notation to integer form.
wfBacktrace( $raw=null)
Get a debug backtrace as a string.
wfArrayDiff2( $arr1, $arr2)
Like array_diff( $arr1, $arr2 ) except that it works with two-dimensional arrays.
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
wfExpandIRI( $url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
wfMergeErrorArrays(... $args)
Merge arrays in the style of PermissionManager::getPermissionErrors, with duplicate removal e....
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
wfIsDebugRawPage()
Returns true if debug logging should be suppressed if $wgDebugRawPage = false.
wfHostname()
Get host name of the current machine, for use in error reporting.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
wfPercent( $nr, int $acc=2, bool $round=true)
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
wfShellExecWithStderr( $cmd, &$retval=null, $environ=[], $limits=[])
Execute a shell command, returning both stdout and stderr.
wfGetNull()
Get a platform-independent path to the null file, e.g.
wfRelativePath( $path, $from)
Generate a relative path name to the given file.
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
wfUrlProtocols( $includeProtocolRelative=true)
Returns a partial regular expression of recognized URL protocols, e.g.
wfMessageFallback(... $keys)
This function accepts multiple message keys and returns a message instance for the first message whic...
wfMerge(string $old, string $mine, string $yours, ?string &$simplisticMergeAttempt, ?string &$mergeLeftovers=null)
wfMerge attempts to merge differences between three texts.
wfGetAllCallers( $limit=3)
Return a string consisting of callers in the stack.
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfTransactionalTimeLimit()
Raise the request time limit to $wgTransactionalTimeLimit.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfObjectToArray( $objOrArray, $recursive=true)
Recursively converts the parameter (an object) to an array with the same data.
wfLoadSkin( $skin, $path=null)
Load a skin.
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
wfGetServerUrl( $proto)
Get the wiki's "server", i.e.
wfStringToBool( $val)
Convert string value to boolean, when the following are interpreted as true:
wfDebugBacktrace( $limit=0)
Safety wrapper for debug_backtrace().
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfStripIllegalFilenameChars( $name)
Replace all invalid characters with '-'.
wfFormatStackFrame( $frame)
Return a string representation of frame.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
wfIsInfinity( $str)
Determine input string is represents as infinity.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfLoadExtensions(array $exts)
Load multiple extensions at once.
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
wfArrayInsertAfter(array $array, array $insert, $after)
Insert an array into another array after the specified key.
wfAssembleUrl( $urlParts)
This function will reassemble a URL parsed with wfParseURL.
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
$wgScript
Config variable stub for the Script setting, for use by phpdoc and IDEs.
$wgInternalServer
Config variable stub for the InternalServer setting, for use by phpdoc and IDEs.
$wgThumbLimits
Config variable stub for the ThumbLimits setting, for use by phpdoc and IDEs.
$wgDebugLogPrefix
Config variable stub for the DebugLogPrefix setting, for use by phpdoc and IDEs.
$wgPhpCli
Config variable stub for the PhpCli setting, for use by phpdoc and IDEs.
$wgOverrideHostname
Config variable stub for the OverrideHostname setting, for use by phpdoc and IDEs.
$wgImageLimits
Config variable stub for the ImageLimits setting, for use by phpdoc and IDEs.
$wgTmpDirectory
Config variable stub for the TmpDirectory setting, for use by phpdoc and IDEs.
$wgStyleDirectory
Config variable stub for the StyleDirectory setting, for use by phpdoc and IDEs.
$wgTransactionalTimeLimit
Config variable stub for the TransactionalTimeLimit setting, for use by phpdoc and IDEs.
$wgIllegalFileChars
Config variable stub for the IllegalFileChars setting, for use by phpdoc and IDEs.
$wgDirectoryMode
Config variable stub for the DirectoryMode setting, for use by phpdoc and IDEs.
$wgDiff3
Config variable stub for the Diff3 setting, for use by phpdoc and IDEs.
$wgUrlProtocols
Config variable stub for the UrlProtocols setting, for use by phpdoc and IDEs.
$wgResponsiveImages
Config variable stub for the ResponsiveImages setting, for use by phpdoc and IDEs.
$wgDebugRawPage
Config variable stub for the DebugRawPage setting, for use by phpdoc and IDEs.
$wgEnableMagicLinks
Config variable stub for the EnableMagicLinks setting, for use by phpdoc and IDEs.
$wgScriptPath
Config variable stub for the ScriptPath setting, for use by phpdoc and IDEs.
$wgExtensionDirectory
Config variable stub for the ExtensionDirectory setting, for use by phpdoc and IDEs.
$wgLoadScript
Config variable stub for the LoadScript setting, for use by phpdoc and IDEs.
$wgCanonicalServer
Config variable stub for the CanonicalServer setting, for use by phpdoc and IDEs.
$wgServer
Config variable stub for the Server setting, for use by phpdoc and IDEs.
$wgHttpsPort
Config variable stub for the HttpsPort setting, for use by phpdoc and IDEs.