Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
GlobalFunctions.php
Go to the documentation of this file.
1<?php
23useMediaWiki\Debug\MWDebug;
24useMediaWiki\Exception\ProcOpenError;
25useMediaWiki\FileRepo\File\File;
26useMediaWiki\HookContainer\HookRunner;
27useMediaWiki\Logger\LoggerFactory;
28useMediaWiki\MediaWikiServices;
29useMediaWiki\Message\Message;
30useMediaWiki\Registration\ExtensionRegistry;
31useMediaWiki\Request\WebRequest;
32useMediaWiki\Shell\Shell;
33useMediaWiki\Title\Title;
34useMediaWiki\Utils\UrlUtils;
35use Wikimedia\AtEase\AtEase;
36useWikimedia\FileBackend\FileBackend;
37useWikimedia\FileBackend\FSFile\TempFSFile;
38useWikimedia\Http\HttpStatus;
39useWikimedia\Message\MessageParam;
40useWikimedia\Message\MessageSpecifier;
41useWikimedia\ParamValidator\TypeDef\ExpiryDef;
42use Wikimedia\RequestTimeout\RequestTimeout;
43use Wikimedia\Timestamp\ConvertibleTimestamp;
44
55functionwfLoadExtension( $ext,$path =null ) {
56if ( !$path ) {
57 global$wgExtensionDirectory;
58$path ="$wgExtensionDirectory/$ext/extension.json";
59 }
60 ExtensionRegistry::getInstance()->queue($path );
61}
62
76functionwfLoadExtensions( array $exts ) {
77 global$wgExtensionDirectory;
78 $registry = ExtensionRegistry::getInstance();
79foreach ( $exts as $ext ) {
80 $registry->queue("$wgExtensionDirectory/$ext/extension.json" );
81 }
82}
83
92functionwfLoadSkin( $skin,$path =null ) {
93if ( !$path ) {
94 global$wgStyleDirectory;
95$path ="$wgStyleDirectory/$skin/skin.json";
96 }
97 ExtensionRegistry::getInstance()->queue($path );
98}
99
107functionwfLoadSkins( array $skins ) {
108 global$wgStyleDirectory;
109 $registry = ExtensionRegistry::getInstance();
110foreach ( $skins as $skin ) {
111 $registry->queue("$wgStyleDirectory/$skin/skin.json" );
112 }
113}
114
122functionwfArrayDiff2( $arr1, $arr2 ) {
123wfDeprecated( __FUNCTION__,'1.43' );
128 $comparator =staticfunction ( $a, $b ):int {
129if ( is_string( $a ) && is_string( $b ) ) {
130return strcmp( $a, $b );
131 }
132if ( !is_array( $a ) && !is_array( $b ) ) {
133thrownew InvalidArgumentException(
134'This function assumes that array elements are all strings or all arrays'
135 );
136 }
137if ( count( $a ) !== count( $b ) ) {
138return count( $a ) <=> count( $b );
139 }else {
140 reset( $a );
141 reset( $b );
142while ( key( $a ) !==null && key( $b ) !==null ) {
143 $valueA = current( $a );
144 $valueB = current( $b );
145 $cmp = strcmp( $valueA, $valueB );
146if ( $cmp !== 0 ) {
147return $cmp;
148 }
149 next( $a );
150 next( $b );
151 }
152return 0;
153 }
154 };
155return array_udiff( $arr1, $arr2, $comparator );
156}
157
178functionwfMergeErrorArrays( ...$args ) {
179wfDeprecated( __FUNCTION__,'1.43' );
180 $out = [];
181foreach ( $args as $errors ) {
182foreach ( $errors as $params ) {
183 $originalParams = $params;
184if ( $params[0] instanceofMessageSpecifier ) {
185 $params = [ $params[0]->getKey(), ...$params[0]->getParams() ];
186 }
187 # @todo FIXME: Sometimes get nested arrays for $params,
188 # which leads to E_NOTICEs
189 $spec = implode("\t", $params );
190 $out[$spec] = $originalParams;
191 }
192 }
193return array_values( $out );
194}
195
205functionwfArrayInsertAfter( array $array, array $insert, $after ) {
206// Find the offset of the element to insert after.
207 $keys = array_keys( $array );
208 $offsetByKey = array_flip( $keys );
209
210if ( !\array_key_exists( $after, $offsetByKey ) ) {
211return $array;
212 }
213 $offset = $offsetByKey[$after];
214
215// Insert at the specified offset
216 $before = array_slice( $array, 0, $offset + 1,true );
217 $after = array_slice( $array, $offset + 1, count( $array ) - $offset,true );
218
219 $output = $before + $insert + $after;
220
221return $output;
222}
223
232functionwfObjectToArray( $objOrArray, $recursive =true ) {
233 $array = [];
234if ( is_object( $objOrArray ) ) {
235 $objOrArray = get_object_vars( $objOrArray );
236 }
237foreach ( $objOrArray as $key => $value ) {
238if ( $recursive && ( is_object( $value ) || is_array( $value ) ) ) {
239 $value =wfObjectToArray( $value );
240 }
241
242 $array[$key] = $value;
243 }
244
245return $array;
246}
247
258functionwfRandom() {
259// The maximum random value is "only" 2^31-1, so get two random
260// values to reduce the chance of dupes
261 $max = mt_getrandmax() + 1;
262 $rand = number_format( ( mt_rand() * $max + mt_rand() ) / $max / $max, 12,'.','' );
263return $rand;
264}
265
276functionwfRandomString( $length = 32 ) {
277 $str ='';
278for ( $n = 0; $n < $length; $n += 7 ) {
279 $str .= sprintf('%07x', mt_rand() & 0xfffffff );
280 }
281return substr( $str, 0, $length );
282}
283
311functionwfUrlencode( $s ) {
312static $needle;
313
314if ( $s ===null ) {
315// Reset $needle for testing.
316 $needle =null;
317return'';
318 }
319
320if ( $needle ===null ) {
321 $needle = ['%3B','%40','%24','%21','%2A','%28','%29','%2C','%2F','%7E' ];
322if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) ||
323 !str_contains( $_SERVER['SERVER_SOFTWARE'],'Microsoft-IIS/7' )
324 ) {
325 $needle[] ='%3A';
326 }
327 }
328
329 $s = urlencode( $s );
330 $s = str_ireplace(
331 $needle,
332 [';','@','$','!','*','(',')',',','/','~',':' ],
333 $s
334 );
335
336return $s;
337}
338
349functionwfArrayToCgi( $array1, $array2 =null, $prefix ='' ) {
350if ( $array2 !==null ) {
351 $array1 += $array2;
352 }
353
354 $cgi ='';
355foreach ( $array1 as $key => $value ) {
356if ( $value !==null && $value !==false ) {
357if ( $cgi !='' ) {
358 $cgi .='&';
359 }
360if ( $prefix !=='' ) {
361 $key = $prefix ."[$key]";
362 }
363if ( is_array( $value ) ) {
364 $firstTime =true;
365foreach ( $value as $k => $v ) {
366 $cgi .= $firstTime ?'' :'&';
367if ( is_array( $v ) ) {
368 $cgi .=wfArrayToCgi( $v,null, $key ."[$k]" );
369 }else {
370 $cgi .= urlencode( $key ."[$k]" ) .'=' . urlencode( $v );
371 }
372 $firstTime =false;
373 }
374 }else {
375if ( is_object( $value ) ) {
376 $value = $value->__toString();
377 }
378 $cgi .= urlencode( $key ) .'=' . urlencode( $value );
379 }
380 }
381 }
382return $cgi;
383}
384
394functionwfCgiToArray( $query ) {
395if ( isset( $query[0] ) && $query[0] =='?' ) {
396 $query = substr( $query, 1 );
397 }
398 $bits = explode('&', $query );
399 $ret = [];
400foreach ( $bits as $bit ) {
401if ( $bit ==='' ) {
402continue;
403 }
404if ( strpos( $bit,'=' ) ===false ) {
405// Pieces like &qwerty become 'qwerty' => '' (at least this is what php does)
406 $key = $bit;
407 $value ='';
408 }else {
409 [ $key, $value ] = explode('=', $bit );
410 }
411 $key = urldecode( $key );
412 $value = urldecode( $value );
413if ( strpos( $key,'[' ) !==false ) {
414 $keys = array_reverse( explode('[', $key ) );
415 $key = array_pop( $keys );
416 $temp = $value;
417foreach ( $keys as $k ) {
418 $k = substr( $k, 0, -1 );
419 $temp = [ $k => $temp ];
420 }
421if ( isset( $ret[$key] ) && is_array( $ret[$key] ) ) {
422 $ret[$key] = array_merge( $ret[$key], $temp );
423 }else {
424 $ret[$key] = $temp;
425 }
426 }else {
427 $ret[$key] = $value;
428 }
429 }
430return $ret;
431}
432
441functionwfAppendQuery($url, $query ) {
442if ( is_array( $query ) ) {
443 $query =wfArrayToCgi( $query );
444 }
445if ( $query !='' ) {
446// Remove the fragment, if there is one
447 $fragment =false;
448 $hashPos = strpos($url,'#' );
449if ( $hashPos !==false ) {
450 $fragment = substr($url, $hashPos );
451$url = substr($url, 0, $hashPos );
452 }
453
454// Add parameter
455if ( strpos($url,'?' ) ===false ) {
456$url .='?';
457 }else {
458$url .='&';
459 }
460$url .= $query;
461
462// Put the fragment back
463if ( $fragment !==false ) {
464$url .= $fragment;
465 }
466 }
467return$url;
468}
469
475functionwfGetUrlUtils():UrlUtils {
476 global$wgServer,$wgCanonicalServer,$wgInternalServer,$wgRequest,$wgHttpsPort,
477$wgUrlProtocols;
478
479if ( MediaWikiServices::hasInstance() ) {
480 $services = MediaWikiServices::getInstance();
481if ( $services->hasService('UrlUtils' ) ) {
482return $services->getUrlUtils();
483 }
484 }
485
486returnnewUrlUtils( [
487// UrlUtils throws if the relevant $wg(|Canonical|Internal) variable is null, but the old
488// implementations implicitly converted it to an empty string (presumably by mistake).
489// Preserve the old behavior for compatibility.
490 UrlUtils::SERVER =>$wgServer ??'',
491 UrlUtils::CANONICAL_SERVER =>$wgCanonicalServer ??'',
492 UrlUtils::INTERNAL_SERVER =>$wgInternalServer ??'',
493 UrlUtils::FALLBACK_PROTOCOL =>$wgRequest ?$wgRequest->getProtocol()
494 :WebRequest::detectProtocol(),
495UrlUtils::HTTPS_PORT =>$wgHttpsPort,
496UrlUtils::VALID_PROTOCOLS =>$wgUrlProtocols,
497 ] );
498}
499
527functionwfExpandUrl($url, $defaultProto =PROTO_CURRENT ) {
528returnwfGetUrlUtils()->expand( (string)$url, $defaultProto ) ??false;
529}
530
540functionwfGetServerUrl( $proto ) {
541wfDeprecated( __FUNCTION__,'1.39' );
542
543returnwfGetUrlUtils()->getServer( $proto ) ??'';
544}
545
558functionwfAssembleUrl( $urlParts ) {
559wfDeprecated( __FUNCTION__,'1.39' );
560
561return UrlUtils::assemble( (array)$urlParts );
562}
563
572functionwfUrlProtocols( $includeProtocolRelative =true ) {
573wfDeprecated( __FUNCTION__,'1.39' );
574
575return $includeProtocolRelative ?wfGetUrlUtils()->validProtocols() :
576wfGetUrlUtils()->validAbsoluteProtocols();
577}
578
586functionwfUrlProtocolsWithoutProtRel() {
587wfDeprecated( __FUNCTION__,'1.39' );
588
589returnwfGetUrlUtils()->validAbsoluteProtocols();
590}
591
618functionwfParseUrl($url ) {
619returnwfGetUrlUtils()->parse( (string)$url ) ??false;
620}
621
631functionwfExpandIRI($url ) {
632wfDeprecated( __FUNCTION__,'1.39' );
633
634returnwfGetUrlUtils()->expandIRI( (string)$url ) ??'';
635}
636
645functionwfMatchesDomainList($url, $domains ) {
646wfDeprecated( __FUNCTION__,'1.39' );
647
648returnwfGetUrlUtils()->matchesDomainList( (string)$url, (array)$domains );
649}
650
671functionwfDebug( $text, $dest ='all', array $context = [] ) {
672 global$wgDebugRawPage,$wgDebugLogPrefix;
673
674if ( !$wgDebugRawPage &&wfIsDebugRawPage() ) {
675return;
676 }
677
678 $text = trim( $text );
679
680if ($wgDebugLogPrefix !=='' ) {
681 $context['prefix'] =$wgDebugLogPrefix;
682 }
683 $context['private'] = ( $dest ===false || $dest ==='private' );
684
685 $logger = LoggerFactory::getInstance('wfDebug' );
686 $logger->debug( $text, $context );
687}
688
693functionwfIsDebugRawPage() {
694static $cache;
695if ( $cache !==null ) {
696return $cache;
697 }
698// Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
699// phpcs:ignore MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
700if ( ( isset( $_GET['action'] ) && $_GET['action'] =='raw' )
701 ||MW_ENTRY_POINT ==='load'
702 ) {
703 $cache =true;
704 }else {
705 $cache =false;
706 }
707return $cache;
708}
709
735functionwfDebugLog(
736 $logGroup, $text, $dest ='all', array $context = []
737) {
738 $text = trim( $text );
739
740 $logger = LoggerFactory::getInstance( $logGroup );
741 $context['private'] = ( $dest ===false || $dest ==='private' );
742 $logger->info( $text, $context );
743}
744
753functionwfLogDBError( $text, array $context = [] ) {
754 $logger = LoggerFactory::getInstance('wfLogDBError' );
755 $logger->error( trim( $text ), $context );
756}
757
774functionwfDeprecated( $function, $version =false, $component =false, $callerOffset = 2 ) {
775if ( !is_string( $version ) && $version !==false ) {
776thrownew InvalidArgumentException(
777"MediaWiki version must either be a string or false. " .
778"Example valid version: '1.33'"
779 );
780 }
781
782 MWDebug::deprecated( $function, $version, $component, $callerOffset + 1 );
783}
784
805functionwfDeprecatedMsg( $msg, $version =false, $component =false, $callerOffset = 2 ) {
806 MWDebug::deprecatedMsg( $msg, $version, $component,
807 $callerOffset ===false ?false : $callerOffset + 1 );
808}
809
820functionwfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
821 MWDebug::warning( $msg, $callerOffset + 1, $level,'auto' );
822}
823
833functionwfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) {
834 MWDebug::warning( $msg, $callerOffset + 1, $level,'production' );
835}
836
859functionwfMessage( $key, ...$params ) {
860if ( is_array( $key ) ) {
861// Fallback keys are not allowed in message specifiers
862 $message =wfMessageFallback( ...$key );
863 }else {
864 $message = Message::newFromSpecifier( $key );
865 }
866
867// We call Message::params() to reduce code duplication
868if ( $params ) {
869 $message->params( ...$params );
870 }
871
872return $message;
873}
874
887functionwfMessageFallback( ...$keys ) {
888return Message::newFallbackSequence( ...$keys );
889}
890
899functionwfMsgReplaceArgs( $message, $args ) {
900 # Fix windows line-endings
901 # Some messages are split with explode("\n", $msg)
902 $message = str_replace("\r",'', $message );
903
904// Replace arguments
905if ( is_array( $args ) && $args ) {
906if ( is_array( $args[0] ) ) {
907 $args = array_values( $args[0] );
908 }
909 $replacementKeys = [];
910foreach ( $args as $n => $param ) {
911 $replacementKeys['$' . ( $n + 1 )] = $param;
912 }
913 $message = strtr( $message, $replacementKeys );
914 }
915
916return $message;
917}
918
927functionwfHostname() {
928// Hostname overriding
929 global$wgOverrideHostname;
930if ($wgOverrideHostname !==false ) {
931return$wgOverrideHostname;
932 }
933
934return php_uname('n' ) ?:'unknown';
935}
936
947functionwfDebugBacktrace( $limit = 0 ) {
948static $disabled =null;
949
950if ( $disabled ===null ) {
951 $disabled = !function_exists('debug_backtrace' );
952if ( $disabled ) {
953wfDebug("debug_backtrace() is disabled" );
954 }
955 }
956if ( $disabled ) {
957return [];
958 }
959
960if ( $limit ) {
961return array_slice( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $limit + 1 ), 1 );
962 }else {
963return array_slice( debug_backtrace(), 1 );
964 }
965}
966
975functionwfBacktrace( $raw =null ) {
976 $raw ??=MW_ENTRY_POINT ==='cli';
977if ( $raw ) {
978 $frameFormat ="%s line %s calls %s()\n";
979 $traceFormat ="%s";
980 }else {
981 $frameFormat ="<li>%s line %s calls %s()</li>\n";
982 $traceFormat ="<ul>\n%s</ul>\n";
983 }
984
985 $frames = array_map(staticfunction ( $frame ) use ( $frameFormat ) {
986 $file = !empty( $frame['file'] ) ? basename( $frame['file'] ) :'-';
987 $line = $frame['line'] ??'-';
988 $call = $frame['function'];
989if ( !empty( $frame['class'] ) ) {
990 $call = $frame['class'] . $frame['type'] . $call;
991 }
992return sprintf( $frameFormat, $file, $line, $call );
993 },wfDebugBacktrace() );
994
995return sprintf( $traceFormat, implode('', $frames ) );
996}
997
1008functionwfGetCaller( $level = 2 ) {
1009 $backtrace =wfDebugBacktrace( $level + 1 );
1010if ( isset( $backtrace[$level] ) ) {
1011returnwfFormatStackFrame( $backtrace[$level] );
1012 }else {
1013return'unknown';
1014 }
1015}
1016
1024functionwfGetAllCallers( $limit = 3 ) {
1025 $trace = array_reverse(wfDebugBacktrace() );
1026if ( !$limit || $limit > count( $trace ) - 1 ) {
1027 $limit = count( $trace ) - 1;
1028 }
1029 $trace = array_slice( $trace, -$limit - 1, $limit );
1030return implode('/', array_map('wfFormatStackFrame', $trace ) );
1031}
1032
1045functionwfFormatStackFrame( $frame ) {
1046if ( !isset( $frame['function'] ) ) {
1047return'NO_FUNCTION_GIVEN';
1048 }
1049return isset( $frame['class'] ) && isset( $frame['type'] ) ?
1050 $frame['class'] . $frame['type'] . $frame['function'] :
1051 $frame['function'];
1052}
1053
1063functionwfClientAcceptsGzip( $force =false ) {
1064static $result =null;
1065if ( $result ===null || $force ) {
1066 $result =false;
1067if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
1068 # @todo FIXME: We may want to disallow some broken browsers
1069 $m = [];
1070if ( preg_match(
1071'/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
1072 $_SERVER['HTTP_ACCEPT_ENCODING'],
1073 $m
1074 )
1075 ) {
1076if ( isset( $m[2] ) && ( $m[1] =='q' ) && ( $m[2] == 0 ) ) {
1077return $result;
1078 }
1079wfDebug("wfClientAcceptsGzip: client accepts gzip." );
1080 $result =true;
1081 }
1082 }
1083 }
1084return $result;
1085}
1086
1097functionwfEscapeWikiText( $input ): string {
1098 global$wgEnableMagicLinks;
1099static $repl =null, $repl2 =null, $repl3 =null, $repl4 =null;
1100if ( $repl ===null || defined('MW_PHPUNIT_TEST' ) ) {
1101// Tests depend upon being able to change $wgEnableMagicLinks, so don't cache
1102// in those situations
1103 $repl = [
1104'"' =>'&#34;','&' =>'&#38;',"'" =>'&#39;','<' =>'&#60;',
1105'=' =>'&#61;','>' =>'&#62;','[' =>'&#91;',']' =>'&#93;',
1106'{' =>'&#123;','|' =>'&#124;','}' =>'&#125;',
1107';' =>'&#59;',// a token inside language converter brackets
1108'!!' =>'&#33;!',// a token inside table context
1109"\n!" =>"\n&#33;","\r!" =>"\r&#33;",// a token inside table context
1110"\n#" =>"\n&#35;","\r#" =>"\r&#35;",
1111"\n*" =>"\n&#42;","\r*" =>"\r&#42;",
1112"\n:" =>"\n&#58;","\r:" =>"\r&#58;",
1113"\n " =>"\n&#32;","\r " =>"\r&#32;",
1114"\n\n" =>"\n&#10;","\r\n" =>"&#13;\n",
1115"\n\r" =>"\n&#13;","\r\r" =>"\r&#13;",
1116"\n\t" =>"\n&#9;","\r\t" =>"\r&#9;",// "\n\t\n" is treated like "\n\n"
1117"\n----" =>"\n&#45;---","\r----" =>"\r&#45;---",
1118'__' =>'_&#95;','://' =>'&#58;//',
1119'~~~' =>'~~&#126;',// protect from PST, just to be safe(r)
1120 ];
1121
1122 $magicLinks = array_keys( array_filter($wgEnableMagicLinks ) );
1123// We have to catch everything "\s" matches in PCRE
1124foreach ( $magicLinks as $magic ) {
1125 $repl["$magic "] ="$magic&#32;";
1126 $repl["$magic\t"] ="$magic&#9;";
1127 $repl["$magic\r"] ="$magic&#13;";
1128 $repl["$magic\n"] ="$magic&#10;";
1129 $repl["$magic\f"] ="$magic&#12;";
1130 }
1131// Additionally escape the following characters at the beginning of the
1132// string, in case they merge to form tokens when spliced into a
1133// string. Tokens like -{ {{ [[ {| etc are already escaped because
1134// the second character is escaped above, but the following tokens
1135// are handled here: |+ |- __FOO__ ~~~
1136 $repl3 = [
1137'+' =>'&#43;','-' =>'&#45;','_' =>'&#95;','~' =>'&#126;',
1138 ];
1139// Similarly, protect the following characters at the end of the
1140// string, which could turn form the start of `__FOO__` or `~~~~`
1141// A trailing newline could also form the unintended start of a
1142// paragraph break if it is glued to a newline in the following
1143// context.
1144 $repl4 = [
1145'_' =>'&#95;','~' =>'&#126;',
1146"\n" =>"&#10;","\r" =>"&#13;",
1147"\t" =>"&#9;",// "\n\t\n" is treated like "\n\n"
1148 ];
1149
1150// And handle protocols that don't use "://"
1151 global$wgUrlProtocols;
1152 $repl2 = [];
1153foreach ($wgUrlProtocols as $prot ) {
1154if ( substr( $prot, -1 ) ===':' ) {
1155 $repl2[] = preg_quote( substr( $prot, 0, -1 ),'/' );
1156 }
1157 }
1158 $repl2 = $repl2 ?'/\b(' . implode('|', $repl2 ) .'):/i' :'/^(?!)/';
1159 }
1160// Tell phan that $repl2, $repl3 and $repl4 will also be non-null here
1161'@phan-var string $repl2';
1162'@phan-var string $repl3';
1163'@phan-var string $repl4';
1164// This will also stringify input in case it's not a string
1165 $text = substr( strtr("\n$input", $repl ), 1 );
1166if ( $text ==='' ) {
1167return $text;
1168 }
1169 $first = strtr( $text[0], $repl3 );// protect first character
1170if ( strlen( $text ) > 1 ) {
1171 $text = $first . substr( $text, 1, -1 ) .
1172 strtr( substr( $text, -1 ), $repl4 );// protect last character
1173 }else {
1174// special case for single-character strings
1175 $text = strtr( $first, $repl4 );// protect last character
1176 }
1177 $text = preg_replace( $repl2,'$1&#58;', $text );
1178return $text;
1179}
1180
1191functionwfSetVar( &$dest,$source, $force =false ) {
1192 $temp = $dest;
1193if ($source !==null || $force ) {
1194 $dest =$source;
1195 }
1196return $temp;
1197}
1198
1208functionwfSetBit( &$dest, $bit, $state =true ) {
1209 $temp = (bool)( $dest & $bit );
1210if ( $state !==null ) {
1211if ( $state ) {
1212 $dest |= $bit;
1213 }else {
1214 $dest &= ~$bit;
1215 }
1216 }
1217return $temp;
1218}
1219
1226functionwfVarDump( $var ) {
1227 global$wgOut;
1228 $s = str_replace("\n","<br />\n", var_export( $var,true ) ."\n" );
1229if ( headers_sent() ||$wgOut ===null || !is_object($wgOut ) ) {
1230 print $s;
1231 }else {
1232$wgOut->addHTML( $s );
1233 }
1234}
1235
1243functionwfHttpError( $code, $label, $desc ) {
1244 global$wgOut;
1245 HttpStatus::header( $code );
1246if ($wgOut ) {
1247$wgOut->disable();
1248$wgOut->sendCacheControl();
1249 }
1250
1251 \MediaWiki\Request\HeaderCallback::warnIfHeadersSent();
1252 header('Content-type: text/html; charset=utf-8' );
1253 ob_start();
1254 print'<!DOCTYPE html>' .
1255'<html><head><title>' .
1256 htmlspecialchars( $label ) .
1257'</title><meta name="color-scheme" content="light dark" /></head><body><h1>' .
1258 htmlspecialchars( $label ) .
1259'</h1><p>' .
1260 nl2br( htmlspecialchars( $desc ) ) .
1261"</p></body></html>\n";
1262 header('Content-Length: ' . ob_get_length() );
1263 ob_end_flush();
1264}
1265
1286functionwfResetOutputBuffers( $resetGzipEncoding =true ) {
1287// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
1288while ( $status = ob_get_status() ) {
1289if ( isset( $status['flags'] ) ) {
1290 $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
1291 $deleteable = ( $status['flags'] & $flags ) === $flags;
1292 } elseif ( isset( $status['del'] ) ) {
1293 $deleteable = $status['del'];
1294 }else {
1295// Guess that any PHP-internal setting can't be removed.
1296 $deleteable = $status['type'] !== 0;/* PHP_OUTPUT_HANDLER_INTERNAL */
1297 }
1298if ( !$deleteable ) {
1299// Give up, and hope the result doesn't break
1300// output behavior.
1301break;
1302 }
1303if ( $status['name'] ==='MediaWikiIntegrationTestCase::wfResetOutputBuffersBarrier' ) {
1304// Unit testing barrier to prevent this function from breaking PHPUnit.
1305break;
1306 }
1307if ( !ob_end_clean() ) {
1308// Could not remove output buffer handler; abort now
1309// to avoid getting in some kind of infinite loop.
1310break;
1311 }
1312if ( $resetGzipEncoding && $status['name'] =='ob_gzhandler' ) {
1313// Reset the 'Content-Encoding' field set by this handler
1314// so we can start fresh.
1315 header_remove('Content-Encoding' );
1316break;
1317 }
1318 }
1319}
1320
1331functionwfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
1332 $ret = ConvertibleTimestamp::convert( $outputtype, $ts );
1333if ( $ret ===false ) {
1334wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts" );
1335 }
1336return $ret;
1337}
1338
1347functionwfTimestampOrNull( $outputtype = TS_UNIX, $ts =null ) {
1348if ( $ts ===null ) {
1349returnnull;
1350 }else {
1351returnwfTimestamp( $outputtype, $ts );
1352 }
1353}
1354
1360functionwfTimestampNow() {
1361return ConvertibleTimestamp::now( TS_MW );
1362}
1363
1375functionwfTempDir() {
1376 global$wgTmpDirectory;
1377
1378if ($wgTmpDirectory !==false ) {
1379return$wgTmpDirectory;
1380 }
1381
1382return TempFSFile::getUsableTempDirectory();
1383}
1384
1393functionwfMkdirParents( $dir, $mode =null, $caller =null ) {
1394 global$wgDirectoryMode;
1395
1396if ( FileBackend::isStoragePath( $dir ) ) {
1397thrownew LogicException( __FUNCTION__ ." given storage path '$dir'." );
1398 }
1399if ( $caller !==null ) {
1400wfDebug("$caller: called wfMkdirParents($dir)" );
1401 }
1402if ( strval( $dir ) ==='' ) {
1403returntrue;
1404 }
1405
1406 $dir = str_replace( ['\\','/' ], DIRECTORY_SEPARATOR, $dir );
1407 $mode ??=$wgDirectoryMode;
1408
1409// Turn off the normal warning, we're doing our own below
1410// PHP doesn't include the path in its warning message, so we add our own to aid in diagnosis.
1411//
1412// Repeat existence check if creation failed so that we silently recover in case of
1413// a race condition where another request created it since the first check.
1414//
1415// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
1416 $ok = is_dir( $dir ) || @mkdir( $dir, $mode,true ) || is_dir( $dir );
1417if ( !$ok ) {
1418 trigger_error( sprintf("failed to mkdir \"%s\" mode 0%o", $dir, $mode ), E_USER_WARNING );
1419 }
1420
1421return $ok;
1422}
1423
1429functionwfRecursiveRemoveDir( $dir ) {
1430// taken from https://www.php.net/manual/en/function.rmdir.php#98622
1431if ( is_dir( $dir ) ) {
1432 $objects = scandir( $dir );
1433foreach ( $objects as $object ) {
1434if ( $object !="." && $object !=".." ) {
1435if ( filetype( $dir .'/' . $object ) =="dir" ) {
1436wfRecursiveRemoveDir( $dir .'/' . $object );
1437 }else {
1438 unlink( $dir .'/' . $object );
1439 }
1440 }
1441 }
1442 rmdir( $dir );
1443 }
1444}
1445
1452functionwfPercent( $nr,int $acc = 2,bool $round =true ) {
1453 $accForFormat = $acc >= 0 ? $acc : 0;
1454 $ret = sprintf("%.{$accForFormat}f", $nr );
1455return $round ? round( (float)$ret, $acc ) .'%' :"$ret%";
1456}
1457
1481functionwfIniGetBool( $setting ) {
1482returnwfStringToBool( ini_get( $setting ) );
1483}
1484
1497functionwfStringToBool( $val ) {
1498 $val = strtolower( $val );
1499// 'on' and 'true' can't have whitespace around them, but '1' can.
1500return $val =='on'
1501 || $val =='true'
1502 || $val =='yes'
1503 || preg_match("/^\s*[+-]?0*[1-9]/", $val );// approx C atoi() function
1504}
1505
1519functionwfEscapeShellArg( ...$args ) {
1520return Shell::escape( ...$args );
1521}
1522
1547functionwfShellExec( $cmd, &$retval =null, $environ = [],
1548 $limits = [], $options = []
1549) {
1550if ( Shell::isDisabled() ) {
1551 $retval = 1;
1552// Backwards compatibility be upon us...
1553return'Unable to run external programs, proc_open() is disabled.';
1554 }
1555
1556if ( is_array( $cmd ) ) {
1557 $cmd = Shell::escape( $cmd );
1558 }
1559
1560 $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr'];
1561 $profileMethod = $options['profileMethod'] ??wfGetCaller();
1562
1563try {
1564 $result = Shell::command( [] )
1565 ->unsafeParams( (array)$cmd )
1566 ->environment( $environ )
1567 ->limits( $limits )
1568 ->includeStderr( $includeStderr )
1569 ->profileMethod( $profileMethod )
1570// For b/c
1571 ->restrict( Shell::RESTRICT_NONE )
1572 ->execute();
1573 }catch (ProcOpenError ) {
1574 $retval = -1;
1575return'';
1576 }
1577
1578 $retval = $result->getExitCode();
1579
1580return $result->getStdout();
1581}
1582
1600functionwfShellExecWithStderr( $cmd, &$retval =null, $environ = [], $limits = [] ) {
1601returnwfShellExec( $cmd, $retval, $environ, $limits,
1602 ['duplicateStderr' =>true,'profileMethod' =>wfGetCaller() ] );
1603}
1604
1620functionwfShellWikiCmd( $script, array $parameters = [], array $options = [] ) {
1621 global$wgPhpCli;
1622// Give site config file a chance to run the script in a wrapper.
1623// The caller may likely want to call wfBasename() on $script.
1624 (newHookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
1625 ->onWfShellWikiCmd( $script, $parameters, $options );
1626 $cmd = [ $options['php'] ??$wgPhpCli ];
1627if ( isset( $options['wrapper'] ) ) {
1628 $cmd[] = $options['wrapper'];
1629 }
1630 $cmd[] = $script;
1631// Escape each parameter for shell
1632return Shell::escape( array_merge( $cmd, $parameters ) );
1633}
1634
1651functionwfMerge(
1652string $old,
1653string $mine,
1654string $yours,
1655 ?string &$simplisticMergeAttempt,
1656 ?string &$mergeLeftovers =null
1657): bool {
1658 global$wgDiff3;
1659
1660 # This check may also protect against code injection in
1661 # case of broken installations.
1662 AtEase::suppressWarnings();
1663 $haveDiff3 =$wgDiff3 && file_exists($wgDiff3 );
1664 AtEase::restoreWarnings();
1665
1666if ( !$haveDiff3 ) {
1667wfDebug("diff3 not found" );
1668returnfalse;
1669 }
1670
1671 # Make temporary files
1672 $td =wfTempDir();
1673 $oldtextFile = fopen( $oldtextName = tempnam( $td,'merge-old-' ),'w' );
1674 $mytextFile = fopen( $mytextName = tempnam( $td,'merge-mine-' ),'w' );
1675 $yourtextFile = fopen( $yourtextName = tempnam( $td,'merge-your-' ),'w' );
1676
1677 # NOTE: diff3 issues a warning to stderr if any of the files does not end with
1678 # a newline character. To avoid this, we normalize the trailing whitespace before
1679 # creating the diff.
1680
1681 fwrite( $oldtextFile, rtrim( $old ) ."\n" );
1682 fclose( $oldtextFile );
1683 fwrite( $mytextFile, rtrim( $mine ) ."\n" );
1684 fclose( $mytextFile );
1685 fwrite( $yourtextFile, rtrim( $yours ) ."\n" );
1686 fclose( $yourtextFile );
1687
1688 # Check for a conflict
1689 $cmd = Shell::escape($wgDiff3,'--text','--overlap-only', $mytextName,
1690 $oldtextName, $yourtextName );
1691 $handle = popen( $cmd,'r' );
1692
1693 $mergeLeftovers ='';
1694do {
1695 $data = fread( $handle, 8192 );
1696if ( $data ===false || $data ==='' ) {
1697break;
1698 }
1699 $mergeLeftovers .= $data;
1700 }while (true );
1701 pclose( $handle );
1702
1703 $conflict = $mergeLeftovers !=='';
1704
1705 # Merge differences automatically where possible, preferring "my" text for conflicts.
1706 $cmd = Shell::escape($wgDiff3,'--text','--ed','--merge', $mytextName,
1707 $oldtextName, $yourtextName );
1708 $handle = popen( $cmd,'r' );
1709 $simplisticMergeAttempt ='';
1710do {
1711 $data = fread( $handle, 8192 );
1712if ( $data ===false || $data ==='' ) {
1713break;
1714 }
1715 $simplisticMergeAttempt .= $data;
1716 }while (true );
1717 pclose( $handle );
1718 unlink( $mytextName );
1719 unlink( $oldtextName );
1720 unlink( $yourtextName );
1721
1722if ( $simplisticMergeAttempt ==='' && $old !=='' && !$conflict ) {
1723wfDebug("Unexpected null result from diff3. Command: $cmd" );
1724 $conflict =true;
1725 }
1726return !$conflict;
1727}
1728
1741functionwfBaseName($path, $suffix ='' ) {
1742if ( $suffix =='' ) {
1743 $encSuffix ='';
1744 }else {
1745 $encSuffix ='(?:' . preg_quote( $suffix,'#' ) .')?';
1746 }
1747
1748$matches = [];
1749if ( preg_match("#([^/\\\\]*?){$encSuffix}[/\\\\]*$#",$path,$matches ) ) {
1750return$matches[1];
1751 }else {
1752return'';
1753 }
1754}
1755
1765functionwfRelativePath($path, $from ) {
1766// Normalize mixed input on Windows...
1767$path = str_replace('/', DIRECTORY_SEPARATOR,$path );
1768 $from = str_replace('/', DIRECTORY_SEPARATOR, $from );
1769
1770// Trim trailing slashes -- fix for drive root
1771$path = rtrim($path, DIRECTORY_SEPARATOR );
1772 $from = rtrim( $from, DIRECTORY_SEPARATOR );
1773
1774 $pieces = explode( DIRECTORY_SEPARATOR, dirname($path ) );
1775 $against = explode( DIRECTORY_SEPARATOR, $from );
1776
1777if ( $pieces[0] !== $against[0] ) {
1778// Non-matching Windows drive letters?
1779// Return a full path.
1780return$path;
1781 }
1782
1783// Trim off common prefix
1784while ( count( $pieces ) && count( $against )
1785 && $pieces[0] == $against[0] ) {
1786 array_shift( $pieces );
1787 array_shift( $against );
1788 }
1789
1790// relative dots to bump us to the parent
1791while ( count( $against ) ) {
1792 array_unshift( $pieces,'..' );
1793 array_shift( $against );
1794 }
1795
1796 $pieces[] =wfBaseName($path );
1797
1798return implode( DIRECTORY_SEPARATOR, $pieces );
1799}
1800
1810functionwfScript( $script ='index' ) {
1811 global$wgScriptPath,$wgScript,$wgLoadScript;
1812if ( $script ==='index' ) {
1813return$wgScript;
1814 } elseif ( $script ==='load' ) {
1815return$wgLoadScript;
1816 }else {
1817return"{$wgScriptPath}/{$script}.php";
1818 }
1819}
1820
1828functionwfBoolToStr( $value ) {
1829return $value ?'true' :'false';
1830}
1831
1837functionwfGetNull() {
1838returnwfIsWindows() ?'NUL' :'/dev/null';
1839}
1840
1849functionwfStripIllegalFilenameChars( $name ) {
1850 global$wgIllegalFileChars;
1851 $illegalFileChars =$wgIllegalFileChars ?"|[" .$wgIllegalFileChars ."]" :'';
1852 $name = preg_replace(
1853"/[^" . Title::legalChars() ."]" . $illegalFileChars ."/",
1854'-',
1855 $name
1856 );
1857// $wgIllegalFileChars may not include '/' and '\', so we still need to do this
1858 $name =wfBaseName( $name );
1859return $name;
1860}
1861
1868functionwfMemoryLimit( $newLimit ) {
1869 $oldLimit =wfShorthandToInteger( ini_get('memory_limit' ) );
1870// If the INI config is already unlimited, there is nothing larger
1871if ( $oldLimit != -1 ) {
1872 $newLimit =wfShorthandToInteger( (string)$newLimit );
1873if ( $newLimit == -1 ) {
1874wfDebug("Removing PHP's memory limit" );
1875 AtEase::suppressWarnings();
1876 ini_set('memory_limit', $newLimit );
1877 AtEase::restoreWarnings();
1878 } elseif ( $newLimit > $oldLimit ) {
1879wfDebug("Raising PHP's memory limit to $newLimit bytes" );
1880 AtEase::suppressWarnings();
1881 ini_set('memory_limit', $newLimit );
1882 AtEase::restoreWarnings();
1883 }
1884 }
1885}
1886
1893functionwfTransactionalTimeLimit() {
1894 global$wgTransactionalTimeLimit;
1895
1896 $timeout = RequestTimeout::singleton();
1897 $timeLimit = $timeout->getWallTimeLimit();
1898if ( $timeLimit !== INF ) {
1899// RequestTimeout library is active
1900if ($wgTransactionalTimeLimit > $timeLimit ) {
1901 $timeout->setWallTimeLimit($wgTransactionalTimeLimit );
1902 }
1903 }else {
1904// Fallback case, likely $wgRequestTimeLimit === null
1905 $timeLimit = (int)ini_get('max_execution_time' );
1906// Note that CLI scripts use 0
1907if ( $timeLimit > 0 &&$wgTransactionalTimeLimit > $timeLimit ) {
1908 $timeout->setWallTimeLimit($wgTransactionalTimeLimit );
1909 }
1910 }
1911 ignore_user_abort(true );// ignore client disconnects
1912
1913return $timeLimit;
1914}
1915
1923functionwfShorthandToInteger( ?string $string ='',int $default = -1 ): int {
1924 $string = trim( $string ??'' );
1925if ( $string ==='' ) {
1926return $default;
1927 }
1928 $last = $string[strlen( $string ) - 1];
1929 $val = intval( $string );
1930switch ( $last ) {
1931case'g':
1932case'G':
1933 $val *= 1024;
1934// break intentionally missing
1935case'm':
1936case'M':
1937 $val *= 1024;
1938// break intentionally missing
1939case'k':
1940case'K':
1941 $val *= 1024;
1942 }
1943
1944return $val;
1945}
1946
1954functionwfIsInfinity( $str ) {
1955// The INFINITY_VALS are hardcoded elsewhere in MediaWiki (e.g. mediawiki.special.block.js).
1956return in_array( $str, ExpiryDef::INFINITY_VALS );
1957}
1958
1973functionwfThumbIsStandard(File $file, array $params ) {
1974 global$wgThumbLimits,$wgImageLimits,$wgResponsiveImages;
1975
1976 $multipliers = [ 1 ];
1977if ($wgResponsiveImages ) {
1978// These available sizes are hardcoded currently elsewhere in MediaWiki.
1979// @see Linker::processResponsiveImages
1980 $multipliers[] = 1.5;
1981 $multipliers[] = 2;
1982 }
1983
1984 $handler = $file->getHandler();
1985if ( !$handler || !isset( $params['width'] ) ) {
1986returnfalse;
1987 }
1988
1989 $basicParams = [];
1990if ( isset( $params['page'] ) ) {
1991 $basicParams['page'] = $params['page'];
1992 }
1993
1994 $thumbLimits = [];
1995 $imageLimits = [];
1996// Expand limits to account for multipliers
1997foreach ( $multipliers as $multiplier ) {
1998 $thumbLimits = array_merge( $thumbLimits, array_map(
1999staticfunction ( $width ) use ( $multiplier ) {
2000return round( $width * $multiplier );
2001 },$wgThumbLimits )
2002 );
2003 $imageLimits = array_merge( $imageLimits, array_map(
2004staticfunction ( $pair ) use ( $multiplier ) {
2005return [
2006 round( $pair[0] * $multiplier ),
2007 round( $pair[1] * $multiplier ),
2008 ];
2009 },$wgImageLimits )
2010 );
2011 }
2012
2013// Check if the width matches one of $wgThumbLimits
2014if ( in_array( $params['width'], $thumbLimits ) ) {
2015 $normalParams = $basicParams + ['width' => $params['width'] ];
2016// Append any default values to the map (e.g. "lossy", "lossless", ...)
2017 $handler->normaliseParams( $file, $normalParams );
2018 }else {
2019// If not, then check if the width matches one of $wgImageLimits
2020 $match =false;
2021foreach ( $imageLimits as $pair ) {
2022 $normalParams = $basicParams + ['width' => $pair[0],'height' => $pair[1] ];
2023// Decide whether the thumbnail should be scaled on width or height.
2024// Also append any default values to the map (e.g. "lossy", "lossless", ...)
2025 $handler->normaliseParams( $file, $normalParams );
2026// Check if this standard thumbnail size maps to the given width
2027if ( $normalParams['width'] == $params['width'] ) {
2028 $match =true;
2029break;
2030 }
2031 }
2032if ( !$match ) {
2033returnfalse;// not standard for description pages
2034 }
2035 }
2036
2037// Check that the given values for non-page, non-width, params are just defaults
2038foreach ( $params as $key => $value ) {
2039if ( !isset( $normalParams[$key] ) || $normalParams[$key] != $value ) {
2040returnfalse;
2041 }
2042 }
2043
2044returntrue;
2045}
2046
2059functionwfArrayPlus2d( array $baseArray, array $newValues ) {
2060// First merge items that are in both arrays
2061foreach ( $baseArray as $name => &$groupVal ) {
2062if ( isset( $newValues[$name] ) ) {
2063 $groupVal += $newValues[$name];
2064 }
2065 }
2066// Now add items that didn't exist yet
2067 $baseArray += $newValues;
2068
2069return $baseArray;
2070}
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
DefinitionBootstrapHelperFunctions.php:83
PROTO_CURRENT
const PROTO_CURRENT
DefinitionDefines.php:236
wfThumbIsStandard
wfThumbIsStandard(File $file, array $params)
Returns true if these thumbnail parameters match one that MediaWiki requests from file description pa...
DefinitionGlobalFunctions.php:1973
wfVarDump
wfVarDump( $var)
A wrapper around the PHP function var_export().
DefinitionGlobalFunctions.php:1226
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
DefinitionGlobalFunctions.php:671
wfRandom
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
DefinitionGlobalFunctions.php:258
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
DefinitionGlobalFunctions.php:311
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
DefinitionGlobalFunctions.php:618
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
DefinitionGlobalFunctions.php:1375
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
DefinitionGlobalFunctions.php:820
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
DefinitionGlobalFunctions.php:276
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
DefinitionGlobalFunctions.php:1347
wfBaseName
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
DefinitionGlobalFunctions.php:1741
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
DefinitionGlobalFunctions.php:1360
wfClientAcceptsGzip
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
DefinitionGlobalFunctions.php:1063
wfEscapeShellArg
wfEscapeShellArg(... $args)
Locale-independent version of escapeshellarg()
DefinitionGlobalFunctions.php:1519
wfLogDBError
wfLogDBError( $text, array $context=[])
Log for database errors.
DefinitionGlobalFunctions.php:753
wfLoadSkins
wfLoadSkins(array $skins)
Load multiple skins at once.
DefinitionGlobalFunctions.php:107
wfEscapeWikiText
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
DefinitionGlobalFunctions.php:1097
wfUrlProtocolsWithoutProtRel
wfUrlProtocolsWithoutProtRel()
Like wfUrlProtocols(), but excludes '//' from the protocol list.
DefinitionGlobalFunctions.php:586
wfRecursiveRemoveDir
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
DefinitionGlobalFunctions.php:1429
wfLoadExtension
wfLoadExtension( $ext, $path=null)
Load an extension.
DefinitionGlobalFunctions.php:55
wfMemoryLimit
wfMemoryLimit( $newLimit)
Raise PHP's memory limit (if needed).
DefinitionGlobalFunctions.php:1868
wfSetBit
wfSetBit(&$dest, $bit, $state=true)
As for wfSetVar except setting a bit.
DefinitionGlobalFunctions.php:1208
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
DefinitionGlobalFunctions.php:1481
wfShorthandToInteger
wfShorthandToInteger(?string $string='', int $default=-1)
Converts shorthand byte notation to integer form.
DefinitionGlobalFunctions.php:1923
wfBacktrace
wfBacktrace( $raw=null)
Get a debug backtrace as a string.
DefinitionGlobalFunctions.php:975
wfArrayDiff2
wfArrayDiff2( $arr1, $arr2)
Like array_diff( $arr1, $arr2 ) except that it works with two-dimensional arrays.
DefinitionGlobalFunctions.php:122
wfGetCaller
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
DefinitionGlobalFunctions.php:1008
wfExpandIRI
wfExpandIRI( $url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
DefinitionGlobalFunctions.php:631
wfMergeErrorArrays
wfMergeErrorArrays(... $args)
Merge arrays in the style of PermissionManager::getPermissionErrors, with duplicate removal e....
DefinitionGlobalFunctions.php:178
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
DefinitionGlobalFunctions.php:805
wfGetUrlUtils
wfGetUrlUtils()
DefinitionGlobalFunctions.php:475
wfShellExec
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
DefinitionGlobalFunctions.php:1547
wfIsDebugRawPage
wfIsDebugRawPage()
Returns true if debug logging should be suppressed if $wgDebugRawPage = false.
DefinitionGlobalFunctions.php:693
wfHostname
wfHostname()
Get host name of the current machine, for use in error reporting.
DefinitionGlobalFunctions.php:927
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
DefinitionGlobalFunctions.php:527
wfShellWikiCmd
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
DefinitionGlobalFunctions.php:1620
wfPercent
wfPercent( $nr, int $acc=2, bool $round=true)
DefinitionGlobalFunctions.php:1452
wfSetVar
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...
DefinitionGlobalFunctions.php:1191
wfShellExecWithStderr
wfShellExecWithStderr( $cmd, &$retval=null, $environ=[], $limits=[])
Execute a shell command, returning both stdout and stderr.
DefinitionGlobalFunctions.php:1600
wfGetNull
wfGetNull()
Get a platform-independent path to the null file, e.g.
DefinitionGlobalFunctions.php:1837
wfRelativePath
wfRelativePath( $path, $from)
Generate a relative path name to the given file.
DefinitionGlobalFunctions.php:1765
wfHttpError
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
DefinitionGlobalFunctions.php:1243
wfUrlProtocols
wfUrlProtocols( $includeProtocolRelative=true)
Returns a partial regular expression of recognized URL protocols, e.g.
DefinitionGlobalFunctions.php:572
wfMessageFallback
wfMessageFallback(... $keys)
This function accepts multiple message keys and returns a message instance for the first message whic...
DefinitionGlobalFunctions.php:887
wfMerge
wfMerge(string $old, string $mine, string $yours, ?string &$simplisticMergeAttempt, ?string &$mergeLeftovers=null)
wfMerge attempts to merge differences between three texts.
DefinitionGlobalFunctions.php:1651
wfGetAllCallers
wfGetAllCallers( $limit=3)
Return a string consisting of callers in the stack.
DefinitionGlobalFunctions.php:1024
wfArrayPlus2d
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
DefinitionGlobalFunctions.php:2059
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
DefinitionGlobalFunctions.php:833
wfTransactionalTimeLimit
wfTransactionalTimeLimit()
Raise the request time limit to $wgTransactionalTimeLimit.
DefinitionGlobalFunctions.php:1893
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
DefinitionGlobalFunctions.php:735
wfObjectToArray
wfObjectToArray( $objOrArray, $recursive=true)
Recursively converts the parameter (an object) to an array with the same data.
DefinitionGlobalFunctions.php:232
wfLoadSkin
wfLoadSkin( $skin, $path=null)
Load a skin.
DefinitionGlobalFunctions.php:92
wfMsgReplaceArgs
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
DefinitionGlobalFunctions.php:899
wfGetServerUrl
wfGetServerUrl( $proto)
Get the wiki's "server", i.e.
DefinitionGlobalFunctions.php:540
wfStringToBool
wfStringToBool( $val)
Convert string value to boolean, when the following are interpreted as true:
DefinitionGlobalFunctions.php:1497
wfDebugBacktrace
wfDebugBacktrace( $limit=0)
Safety wrapper for debug_backtrace().
DefinitionGlobalFunctions.php:947
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
DefinitionGlobalFunctions.php:441
wfStripIllegalFilenameChars
wfStripIllegalFilenameChars( $name)
Replace all invalid characters with '-'.
DefinitionGlobalFunctions.php:1849
wfFormatStackFrame
wfFormatStackFrame( $frame)
Return a string representation of frame.
DefinitionGlobalFunctions.php:1045
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
DefinitionGlobalFunctions.php:349
wfScript
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
DefinitionGlobalFunctions.php:1810
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
DefinitionGlobalFunctions.php:394
wfMatchesDomainList
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
DefinitionGlobalFunctions.php:645
wfIsInfinity
wfIsInfinity( $str)
Determine input string is represents as infinity.
DefinitionGlobalFunctions.php:1954
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
DefinitionGlobalFunctions.php:1393
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
DefinitionGlobalFunctions.php:1331
wfLoadExtensions
wfLoadExtensions(array $exts)
Load multiple extensions at once.
DefinitionGlobalFunctions.php:76
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
DefinitionGlobalFunctions.php:1828
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
DefinitionGlobalFunctions.php:859
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
DefinitionGlobalFunctions.php:774
wfArrayInsertAfter
wfArrayInsertAfter(array $array, array $insert, $after)
Insert an array into another array after the specified key.
DefinitionGlobalFunctions.php:205
wfAssembleUrl
wfAssembleUrl( $urlParts)
This function will reassemble a URL parsed with wfParseURL.
DefinitionGlobalFunctions.php:558
wfResetOutputBuffers
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
DefinitionGlobalFunctions.php:1286
$path
$path
DefinitionNoLocalSettings.php:28
$matches
$matches
DefinitionNoLocalSettings.php:27
$wgRequest
global $wgRequest
DefinitionSetup.php:438
$wgOut
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
DefinitionSetup.php:559
MW_ENTRY_POINT
const MW_ENTRY_POINT
Definitionapi.php:35
MediaWiki\Debug\MWDebug
Debug toolbar.
DefinitionMWDebug.php:49
MediaWiki\Exception\ProcOpenError
DefinitionProcOpenError.php:28
MediaWiki\FileRepo\File\File
Implements some public methods and some protected utility functions which are required by multiple ch...
DefinitionFile.php:93
MediaWiki\FileRepo\File\File\getHandler
getHandler()
Get a MediaHandler instance for this file.
DefinitionFile.php:1629
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
DefinitionHookRunner.php:592
MediaWiki\Logger\LoggerFactory
Create PSR-3 logger objects.
DefinitionLoggerFactory.php:46
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
DefinitionMediaWikiServices.php:250
MediaWiki\Message\Message
The Message class deals with fetching and processing of interface message into a variety of formats.
DefinitionMessage.php:157
MediaWiki\Registration\ExtensionRegistry
Load JSON files, and uses a Processor to extract information.
DefinitionExtensionRegistry.php:35
MediaWiki\Request\WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form,...
DefinitionWebRequest.php:53
MediaWiki\Shell\Shell
Executes shell commands.
DefinitionShell.php:46
MediaWiki\Title\Title
Represents a title within MediaWiki.
DefinitionTitle.php:78
MediaWiki\Utils\UrlUtils
A service to expand, parse, and otherwise manipulate URLs.
DefinitionUrlUtils.php:16
MediaWiki\Utils\UrlUtils\expand
expand(string $url, $defaultProto=PROTO_FALLBACK)
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
DefinitionUrlUtils.php:124
Wikimedia\FileBackend\FSFile\TempFSFile
This class is used to hold the location and do limited manipulation of files stored temporarily (this...
DefinitionTempFSFile.php:37
Wikimedia\FileBackend\FileBackend
Base class for all file backend classes (including multi-write backends).
DefinitionFileBackend.php:112
Wikimedia\Http\HttpStatus
DefinitionHttpStatus.php:30
Wikimedia\Message\MessageParam
Value object representing a message parameter that consists of a list of values.
DefinitionMessageParam.php:12
Wikimedia\ParamValidator\TypeDef\ExpiryDef
Type definition for expiry timestamps.
DefinitionExpiryDef.php:17
$wgScript
$wgScript
Config variable stub for the Script setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:73
$wgInternalServer
$wgInternalServer
Config variable stub for the InternalServer setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:1695
$wgThumbLimits
$wgThumbLimits
Config variable stub for the ThumbLimits setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:765
$wgDebugLogPrefix
$wgDebugLogPrefix
Config variable stub for the DebugLogPrefix setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3202
$wgPhpCli
$wgPhpCli
Config variable stub for the PhpCli setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:4267
$wgOverrideHostname
$wgOverrideHostname
Config variable stub for the OverrideHostname setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3286
$wgImageLimits
$wgImageLimits
Config variable stub for the ImageLimits setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:759
$wgTmpDirectory
$wgTmpDirectory
Config variable stub for the TmpDirectory setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:187
$wgStyleDirectory
$wgStyleDirectory
Config variable stub for the StyleDirectory setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:115
$wgTransactionalTimeLimit
$wgTransactionalTimeLimit
Config variable stub for the TransactionalTimeLimit setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:1335
$wgIllegalFileChars
$wgIllegalFileChars
Config variable stub for the IllegalFileChars setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:249
$wgDirectoryMode
$wgDirectoryMode
Config variable stub for the DirectoryMode setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:843
$wgDiff3
$wgDiff3
Config variable stub for the Diff3 setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3472
$wgUrlProtocols
$wgUrlProtocols
Config variable stub for the UrlProtocols setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:2314
$wgResponsiveImages
$wgResponsiveImages
Config variable stub for the ResponsiveImages setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:849
$wgDebugRawPage
$wgDebugRawPage
Config variable stub for the DebugRawPage setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3214
$wgEnableMagicLinks
$wgEnableMagicLinks
Config variable stub for the EnableMagicLinks setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:2440
$wgScriptPath
$wgScriptPath
Config variable stub for the ScriptPath setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:61
$wgExtensionDirectory
$wgExtensionDirectory
Config variable stub for the ExtensionDirectory setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:109
$wgLoadScript
$wgLoadScript
Config variable stub for the LoadScript setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:79
$wgCanonicalServer
$wgCanonicalServer
Config variable stub for the CanonicalServer setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:31
$wgServer
$wgServer
Config variable stub for the Server setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:25
$wgHttpsPort
$wgHttpsPort
Config variable stub for the HttpsPort setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:49
Wikimedia\Message\MessageSpecifier
DefinitionMessageSpecifier.php:26
$source
$source
Definitionmwdoc-filter.php:36
$url
$url
Definitionopensearch_desc.php:37

[8]ページ先頭

©2009-2025 Movatter.jp