Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
GlobalFunctions.php
Go to the documentation of this file.
1<?php
9useMediaWiki\Debug\MWDebug;
10useMediaWiki\Exception\ProcOpenError;
11useMediaWiki\FileRepo\File\File;
12useMediaWiki\HookContainer\HookRunner;
13useMediaWiki\Logger\LoggerFactory;
14useMediaWiki\MediaWikiServices;
15useMediaWiki\Message\Message;
16useMediaWiki\Registration\ExtensionRegistry;
17useMediaWiki\Request\ContentSecurityPolicy;
18useMediaWiki\Request\WebRequest;
19useMediaWiki\Shell\Shell;
20useMediaWiki\Title\Title;
21useMediaWiki\Utils\UrlUtils;
22use Wikimedia\AtEase\AtEase;
23useWikimedia\FileBackend\FileBackend;
24useWikimedia\FileBackend\FSFile\TempFSFile;
25useWikimedia\Http\HttpStatus;
26useWikimedia\Message\MessageParam;
27useWikimedia\Message\MessageSpecifier;
28useWikimedia\ParamValidator\TypeDef\ExpiryDef;
29use Wikimedia\RequestTimeout\RequestTimeout;
30use Wikimedia\Timestamp\ConvertibleTimestamp;
31
42functionwfLoadExtension( $ext,$path =null ) {
43if ( !$path ) {
44 global$wgExtensionDirectory;
45$path ="$wgExtensionDirectory/$ext/extension.json";
46 }
47 ExtensionRegistry::getInstance()->queue($path );
48}
49
63functionwfLoadExtensions( array $exts ) {
64 global$wgExtensionDirectory;
65 $registry = ExtensionRegistry::getInstance();
66foreach ( $exts as $ext ) {
67 $registry->queue("$wgExtensionDirectory/$ext/extension.json" );
68 }
69}
70
79functionwfLoadSkin( $skin,$path =null ) {
80if ( !$path ) {
81 global$wgStyleDirectory;
82$path ="$wgStyleDirectory/$skin/skin.json";
83 }
84 ExtensionRegistry::getInstance()->queue($path );
85}
86
94functionwfLoadSkins( array $skins ) {
95 global$wgStyleDirectory;
96 $registry = ExtensionRegistry::getInstance();
97foreach ( $skins as $skin ) {
98 $registry->queue("$wgStyleDirectory/$skin/skin.json" );
99 }
100}
101
109functionwfArrayDiff2( $arr1, $arr2 ) {
110wfDeprecated( __FUNCTION__,'1.43' );
115 $comparator =staticfunction ( $a, $b ):int {
116if ( is_string( $a ) && is_string( $b ) ) {
117return strcmp( $a, $b );
118 }
119if ( !is_array( $a ) && !is_array( $b ) ) {
120thrownew InvalidArgumentException(
121'This function assumes that array elements are all strings or all arrays'
122 );
123 }
124if ( count( $a ) !== count( $b ) ) {
125return count( $a ) <=> count( $b );
126 }else {
127 reset( $a );
128 reset( $b );
129while ( key( $a ) !==null && key( $b ) !==null ) {
130 $valueA = current( $a );
131 $valueB = current( $b );
132 $cmp = strcmp( $valueA, $valueB );
133if ( $cmp !== 0 ) {
134return $cmp;
135 }
136 next( $a );
137 next( $b );
138 }
139return 0;
140 }
141 };
142return array_udiff( $arr1, $arr2, $comparator );
143}
144
165functionwfMergeErrorArrays( ...$args ) {
166wfDeprecated( __FUNCTION__,'1.43' );
167 $out = [];
168foreach ( $args as $errors ) {
169foreach ( $errors as $params ) {
170 $originalParams = $params;
171if ( $params[0] instanceofMessageSpecifier ) {
172 $params = [ $params[0]->getKey(), ...$params[0]->getParams() ];
173 }
174 # @todo FIXME: Sometimes get nested arrays for $params,
175 # which leads to E_NOTICEs
176 $spec = implode("\t", $params );
177 $out[$spec] = $originalParams;
178 }
179 }
180return array_values( $out );
181}
182
192functionwfArrayInsertAfter( array $array, array $insert, $after ) {
193// Find the offset of the element to insert after.
194 $keys = array_keys( $array );
195 $offsetByKey = array_flip( $keys );
196
197if ( !\array_key_exists( $after, $offsetByKey ) ) {
198return $array;
199 }
200 $offset = $offsetByKey[$after];
201
202// Insert at the specified offset
203 $before = array_slice( $array, 0, $offset + 1,true );
204 $after = array_slice( $array, $offset + 1, count( $array ) - $offset,true );
205
206 $output = $before + $insert + $after;
207
208return $output;
209}
210
219functionwfObjectToArray( $objOrArray, $recursive =true ) {
220 $array = [];
221if ( is_object( $objOrArray ) ) {
222 $objOrArray = get_object_vars( $objOrArray );
223 }
224foreach ( $objOrArray as $key => $value ) {
225if ( $recursive && ( is_object( $value ) || is_array( $value ) ) ) {
226 $value =wfObjectToArray( $value );
227 }
228
229 $array[$key] = $value;
230 }
231
232return $array;
233}
234
245functionwfRandom() {
246// The maximum random value is "only" 2^31-1, so get two random
247// values to reduce the chance of dupes
248 $max = mt_getrandmax() + 1;
249 $rand = number_format( ( mt_rand() * $max + mt_rand() ) / $max / $max, 12,'.','' );
250return $rand;
251}
252
263functionwfRandomString( $length = 32 ) {
264 $str ='';
265for ( $n = 0; $n < $length; $n += 7 ) {
266 $str .= sprintf('%07x', mt_rand() & 0xfffffff );
267 }
268return substr( $str, 0, $length );
269}
270
298functionwfUrlencode( $s ) {
299static $needle;
300
301if ( $s ===null ) {
302// Reset $needle for testing.
303 $needle =null;
304return'';
305 }
306
307if ( $needle ===null ) {
308 $needle = ['%3B','%40','%24','%21','%2A','%28','%29','%2C','%2F','%7E' ];
309if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) ||
310 !str_contains( $_SERVER['SERVER_SOFTWARE'],'Microsoft-IIS/7' )
311 ) {
312 $needle[] ='%3A';
313 }
314 }
315
316 $s = urlencode( $s );
317 $s = str_ireplace(
318 $needle,
319 [';','@','$','!','*','(',')',',','/','~',':' ],
320 $s
321 );
322
323return $s;
324}
325
336functionwfArrayToCgi( $array1, $array2 =null, $prefix ='' ) {
337if ( $array2 !==null ) {
338 $array1 += $array2;
339 }
340
341 $cgi ='';
342foreach ( $array1 as $key => $value ) {
343if ( $value !==null && $value !==false ) {
344if ( $cgi !='' ) {
345 $cgi .='&';
346 }
347if ( $prefix !=='' ) {
348 $key = $prefix ."[$key]";
349 }
350if ( is_array( $value ) ) {
351 $firstTime =true;
352foreach ( $value as $k => $v ) {
353 $cgi .= $firstTime ?'' :'&';
354if ( is_array( $v ) ) {
355 $cgi .=wfArrayToCgi( $v,null, $key ."[$k]" );
356 }else {
357 $cgi .= urlencode( $key ."[$k]" ) .'=' . urlencode( $v );
358 }
359 $firstTime =false;
360 }
361 }else {
362if ( is_object( $value ) ) {
363 $value = $value->__toString();
364 }
365 $cgi .= urlencode( $key ) .'=' . urlencode( $value );
366 }
367 }
368 }
369return $cgi;
370}
371
381functionwfCgiToArray( $query ) {
382if ( isset( $query[0] ) && $query[0] =='?' ) {
383 $query = substr( $query, 1 );
384 }
385 $bits = explode('&', $query );
386 $ret = [];
387foreach ( $bits as $bit ) {
388if ( $bit ==='' ) {
389continue;
390 }
391if ( !str_contains( $bit,'=' ) ) {
392// Pieces like &qwerty become 'qwerty' => '' (at least this is what php does)
393 $key = $bit;
394 $value ='';
395 }else {
396 [ $key, $value ] = explode('=', $bit );
397 }
398 $key = urldecode( $key );
399 $value = urldecode( $value );
400if ( str_contains( $key,'[' ) ) {
401 $keys = array_reverse( explode('[', $key ) );
402 $key = array_pop( $keys );
403 $temp = $value;
404foreach ( $keys as $k ) {
405 $k = substr( $k, 0, -1 );
406 $temp = [ $k => $temp ];
407 }
408if ( isset( $ret[$key] ) && is_array( $ret[$key] ) ) {
409 $ret[$key] = array_merge( $ret[$key], $temp );
410 }else {
411 $ret[$key] = $temp;
412 }
413 }else {
414 $ret[$key] = $value;
415 }
416 }
417return $ret;
418}
419
428functionwfAppendQuery($url, $query ) {
429if ( is_array( $query ) ) {
430 $query =wfArrayToCgi( $query );
431 }
432if ( $query !='' ) {
433// Remove the fragment, if there is one
434 $fragment =false;
435 $hashPos = strpos($url,'#' );
436if ( $hashPos !==false ) {
437 $fragment = substr($url, $hashPos );
438$url = substr($url, 0, $hashPos );
439 }
440
441// Add parameter
442if ( !str_contains($url,'?' ) ) {
443$url .='?';
444 }else {
445$url .='&';
446 }
447$url .= $query;
448
449// Put the fragment back
450if ( $fragment !==false ) {
451$url .= $fragment;
452 }
453 }
454return$url;
455}
456
462functionwfGetUrlUtils():UrlUtils {
463 global$wgServer,$wgCanonicalServer,$wgInternalServer,$wgRequest,$wgHttpsPort,
464$wgUrlProtocols;
465
466if ( MediaWikiServices::hasInstance() ) {
467 $services = MediaWikiServices::getInstance();
468if ( $services->hasService('UrlUtils' ) ) {
469return $services->getUrlUtils();
470 }
471 }
472
473returnnewUrlUtils( [
474// UrlUtils throws if the relevant $wg(|Canonical|Internal) variable is null, but the old
475// implementations implicitly converted it to an empty string (presumably by mistake).
476// Preserve the old behavior for compatibility.
477 UrlUtils::SERVER =>$wgServer ??'',
478 UrlUtils::CANONICAL_SERVER =>$wgCanonicalServer ??'',
479 UrlUtils::INTERNAL_SERVER =>$wgInternalServer ??'',
480 UrlUtils::FALLBACK_PROTOCOL =>$wgRequest ?$wgRequest->getProtocol()
481 :WebRequest::detectProtocol(),
482UrlUtils::HTTPS_PORT =>$wgHttpsPort,
483UrlUtils::VALID_PROTOCOLS =>$wgUrlProtocols,
484 ] );
485}
486
514functionwfExpandUrl($url, $defaultProto =PROTO_CURRENT ) {
515wfDeprecated( __FUNCTION__,'1.39' );
516
517returnwfGetUrlUtils()->expand( (string)$url, $defaultProto ) ??false;
518}
519
532functionwfAssembleUrl( $urlParts ) {
533wfDeprecated( __FUNCTION__,'1.39' );
534
535return UrlUtils::assemble( (array)$urlParts );
536}
537
546functionwfUrlProtocols( $includeProtocolRelative =true ) {
547wfDeprecated( __FUNCTION__,'1.39' );
548
549return $includeProtocolRelative ?wfGetUrlUtils()->validProtocols() :
550wfGetUrlUtils()->validAbsoluteProtocols();
551}
552
560functionwfUrlProtocolsWithoutProtRel() {
561wfDeprecated( __FUNCTION__,'1.39' );
562
563returnwfGetUrlUtils()->validAbsoluteProtocols();
564}
565
592functionwfParseUrl($url ) {
593wfDeprecated( __FUNCTION__,'1.39' );
594
595returnwfGetUrlUtils()->parse( (string)$url ) ??false;
596}
597
606functionwfMatchesDomainList($url, $domains ) {
607wfDeprecated( __FUNCTION__,'1.39' );
608
609returnwfGetUrlUtils()->matchesDomainList( (string)$url, (array)$domains );
610}
611
632functionwfDebug( $text, $dest ='all', array $context = [] ) {
633 global$wgDebugRawPage,$wgDebugLogPrefix;
634
635if ( !$wgDebugRawPage &&wfIsDebugRawPage() ) {
636return;
637 }
638
639 $text = trim( $text );
640
641if ($wgDebugLogPrefix !=='' ) {
642 $context['prefix'] =$wgDebugLogPrefix;
643 }
644 $context['private'] = ( $dest ===false || $dest ==='private' );
645
646 $logger = LoggerFactory::getInstance('wfDebug' );
647 $logger->debug( $text, $context );
648}
649
654functionwfIsDebugRawPage() {
655static $cache;
656if ( $cache !==null ) {
657return $cache;
658 }
659// Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
660// phpcs:ignore MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
661if ( ( isset( $_GET['action'] ) && $_GET['action'] =='raw' )
662 ||MW_ENTRY_POINT ==='load'
663 ) {
664 $cache =true;
665 }else {
666 $cache =false;
667 }
668return $cache;
669}
670
696functionwfDebugLog(
697 $logGroup, $text, $dest ='all', array $context = []
698) {
699 $text = trim( $text );
700
701 $logger = LoggerFactory::getInstance( $logGroup );
702 $context['private'] = ( $dest ===false || $dest ==='private' );
703 $logger->info( $text, $context );
704}
705
714functionwfLogDBError( $text, array $context = [] ) {
715 $logger = LoggerFactory::getInstance('wfLogDBError' );
716 $logger->error( trim( $text ), $context );
717}
718
735functionwfDeprecated( $function, $version =false, $component =false, $callerOffset = 2 ) {
736if ( !is_string( $version ) && $version !==false ) {
737thrownew InvalidArgumentException(
738"MediaWiki version must either be a string or false. " .
739"Example valid version: '1.33'"
740 );
741 }
742
743 MWDebug::deprecated( $function, $version, $component, $callerOffset + 1 );
744}
745
766functionwfDeprecatedMsg( $msg, $version =false, $component =false, $callerOffset = 2 ) {
767 MWDebug::deprecatedMsg( $msg, $version, $component,
768 $callerOffset ===false ?false : $callerOffset + 1 );
769}
770
781functionwfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
782 MWDebug::warning( $msg, $callerOffset + 1, $level,'auto' );
783}
784
794functionwfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) {
795 MWDebug::warning( $msg, $callerOffset + 1, $level,'production' );
796}
797
820functionwfMessage( $key, ...$params ) {
821if ( is_array( $key ) ) {
822// Fallback keys are not allowed in message specifiers
823 $message =wfMessageFallback( ...$key );
824 }else {
825 $message = Message::newFromSpecifier( $key );
826 }
827
828// We call Message::params() to reduce code duplication
829if ( $params ) {
830 $message->params( ...$params );
831 }
832
833return $message;
834}
835
848functionwfMessageFallback( ...$keys ) {
849return Message::newFallbackSequence( ...$keys );
850}
851
860functionwfMsgReplaceArgs( $message, $args ) {
861 # Fix windows line-endings
862 # Some messages are split with explode("\n", $msg)
863 $message = str_replace("\r",'', $message );
864
865// Replace arguments
866if ( is_array( $args ) && $args ) {
867if ( is_array( $args[0] ) ) {
868 $args = array_values( $args[0] );
869 }
870 $replacementKeys = [];
871foreach ( $args as $n => $param ) {
872 $replacementKeys['$' . ( $n + 1 )] = $param;
873 }
874 $message = strtr( $message, $replacementKeys );
875 }
876
877return $message;
878}
879
888functionwfHostname() {
889// Hostname overriding
890 global$wgOverrideHostname;
891if ($wgOverrideHostname !==false ) {
892return$wgOverrideHostname;
893 }
894
895return php_uname('n' ) ?:'unknown';
896}
897
908functionwfDebugBacktrace( $limit = 0 ) {
909static $disabled =null;
910
911if ( $disabled ===null ) {
912 $disabled = !function_exists('debug_backtrace' );
913if ( $disabled ) {
914wfDebug("debug_backtrace() is disabled" );
915 }
916 }
917if ( $disabled ) {
918return [];
919 }
920
921if ( $limit ) {
922return array_slice( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, $limit + 1 ), 1 );
923 }else {
924return array_slice( debug_backtrace(), 1 );
925 }
926}
927
936functionwfBacktrace( $raw =null ) {
937 $raw ??=MW_ENTRY_POINT ==='cli';
938if ( $raw ) {
939 $frameFormat ="%s line %s calls %s()\n";
940 $traceFormat ="%s";
941 }else {
942 $frameFormat ="<li>%s line %s calls %s()</li>\n";
943 $traceFormat ="<ul>\n%s</ul>\n";
944 }
945
946 $frames = array_map(staticfunction ( $frame ) use ( $frameFormat ) {
947 $file = !empty( $frame['file'] ) ? basename( $frame['file'] ) :'-';
948 $line = $frame['line'] ??'-';
949 $call = $frame['function'];
950if ( !empty( $frame['class'] ) ) {
951 $call = $frame['class'] . $frame['type'] . $call;
952 }
953return sprintf( $frameFormat, $file, $line, $call );
954 },wfDebugBacktrace() );
955
956return sprintf( $traceFormat, implode('', $frames ) );
957}
958
969functionwfGetCaller( $level = 2 ) {
970 $backtrace =wfDebugBacktrace( $level + 1 );
971if ( isset( $backtrace[$level] ) ) {
972returnwfFormatStackFrame( $backtrace[$level] );
973 }else {
974return'unknown';
975 }
976}
977
985functionwfGetAllCallers( $limit = 3 ) {
986 $trace = array_reverse(wfDebugBacktrace() );
987if ( !$limit || $limit > count( $trace ) - 1 ) {
988 $limit = count( $trace ) - 1;
989 }
990 $trace = array_slice( $trace, -$limit - 1, $limit );
991// Do not use `wfFormatStackFrame( ... )` here for compatibility with PHP <8.1.4
992// https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1160800/comment/92e67687_ab221188/
993return implode('/', array_map('wfFormatStackFrame', $trace ) );
994}
995
1008functionwfFormatStackFrame( $frame ) {
1009if ( !isset( $frame['function'] ) ) {
1010return'NO_FUNCTION_GIVEN';
1011 }
1012return isset( $frame['class'] ) && isset( $frame['type'] ) ?
1013 $frame['class'] . $frame['type'] . $frame['function'] :
1014 $frame['function'];
1015}
1016
1026functionwfClientAcceptsGzip( $force =false ) {
1027static $result =null;
1028if ( $result ===null || $force ) {
1029 $result =false;
1030if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
1031 # @todo FIXME: We may want to disallow some broken browsers
1032 $m = [];
1033if ( preg_match(
1034'/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
1035 $_SERVER['HTTP_ACCEPT_ENCODING'],
1036 $m
1037 )
1038 ) {
1039if ( isset( $m[2] ) && ( $m[1] =='q' ) && ( $m[2] == 0 ) ) {
1040return $result;
1041 }
1042wfDebug("wfClientAcceptsGzip: client accepts gzip." );
1043 $result =true;
1044 }
1045 }
1046 }
1047return $result;
1048}
1049
1060functionwfEscapeWikiText( $input ): string {
1061 global$wgEnableMagicLinks;
1062static $repl =null, $repl2 =null, $repl3 =null, $repl4 =null;
1063if ( $repl ===null || defined('MW_PHPUNIT_TEST' ) ) {
1064// Tests depend upon being able to change $wgEnableMagicLinks, so don't cache
1065// in those situations
1066 $repl = [
1067'"' =>'&#34;','&' =>'&#38;',"'" =>'&#39;','<' =>'&#60;',
1068'=' =>'&#61;','>' =>'&#62;','[' =>'&#91;',']' =>'&#93;',
1069'{' =>'&#123;','|' =>'&#124;','}' =>'&#125;',
1070';' =>'&#59;',// a token inside language converter brackets
1071'!!' =>'&#33;!',// a token inside table context
1072"\n!" =>"\n&#33;","\r!" =>"\r&#33;",// a token inside table context
1073"\n#" =>"\n&#35;","\r#" =>"\r&#35;",
1074"\n*" =>"\n&#42;","\r*" =>"\r&#42;",
1075"\n:" =>"\n&#58;","\r:" =>"\r&#58;",
1076"\n " =>"\n&#32;","\r " =>"\r&#32;",
1077"\n\n" =>"\n&#10;","\r\n" =>"&#13;\n",
1078"\n\r" =>"\n&#13;","\r\r" =>"\r&#13;",
1079"\n\t" =>"\n&#9;","\r\t" =>"\r&#9;",// "\n\t\n" is treated like "\n\n"
1080"\n----" =>"\n&#45;---","\r----" =>"\r&#45;---",
1081'__' =>'_&#95;','://' =>'&#58;//',
1082// Japanese magic words start w/ wide underscore
1083'_' =>'&#xFF3F;',
1084'~~~' =>'~~&#126;',// protect from PST, just to be safe(r)
1085 ];
1086
1087 $magicLinks = array_keys( array_filter($wgEnableMagicLinks ) );
1088// We have to catch everything "\s" matches in PCRE
1089foreach ( $magicLinks as $magic ) {
1090 $repl["$magic "] ="$magic&#32;";
1091 $repl["$magic\t"] ="$magic&#9;";
1092 $repl["$magic\r"] ="$magic&#13;";
1093 $repl["$magic\n"] ="$magic&#10;";
1094 $repl["$magic\f"] ="$magic&#12;";
1095 }
1096// Additionally escape the following characters at the beginning of the
1097// string, in case they merge to form tokens when spliced into a
1098// string. Tokens like -{ {{ [[ {| etc are already escaped because
1099// the second character is escaped above, but the following tokens
1100// are handled here: |+ |- __FOO__ ~~~
1101// (Only single-byte characters can go here; multibyte characters
1102// like 'wide underscore' must go into $repl above.)
1103 $repl3 = [
1104'+' =>'&#43;','-' =>'&#45;','_' =>'&#95;','~' =>'&#126;',
1105 ];
1106// Similarly, protect the following characters at the end of the
1107// string, which could turn form the start of `__FOO__` or `~~~~`
1108// A trailing newline could also form the unintended start of a
1109// paragraph break if it is glued to a newline in the following
1110// context. Again, only single-byte characters can be protected
1111// here; 'wide underscore' is protected by $repl above.
1112 $repl4 = [
1113'_' =>'&#95;','~' =>'&#126;',
1114"\n" =>"&#10;","\r" =>"&#13;",
1115"\t" =>"&#9;",// "\n\t\n" is treated like "\n\n"
1116 ];
1117
1118// And handle protocols that don't use "://"
1119 global$wgUrlProtocols;
1120 $repl2 = [];
1121foreach ($wgUrlProtocols as $prot ) {
1122if ( substr( $prot, -1 ) ===':' ) {
1123 $repl2[] = preg_quote( substr( $prot, 0, -1 ),'/' );
1124 }
1125 }
1126 $repl2 = $repl2 ?'/\b(' . implode('|', $repl2 ) .'):/i' :'/^(?!)/';
1127 }
1128// Tell phan that $repl2, $repl3 and $repl4 will also be non-null here
1129'@phan-var string $repl2';
1130'@phan-var string $repl3';
1131'@phan-var string $repl4';
1132// This will also stringify input in case it's not a string
1133 $text = substr( strtr("\n$input", $repl ), 1 );
1134if ( $text ==='' ) {
1135return $text;
1136 }
1137 $first = strtr( $text[0], $repl3 );// protect first character
1138if ( strlen( $text ) > 1 ) {
1139 $text = $first . substr( $text, 1, -1 ) .
1140 strtr( substr( $text, -1 ), $repl4 );// protect last character
1141 }else {
1142// special case for single-character strings
1143 $text = strtr( $first, $repl4 );// protect last character
1144 }
1145 $text = preg_replace( $repl2,'$1&#58;', $text );
1146return $text;
1147}
1148
1159functionwfSetVar( &$dest,$source, $force =false ) {
1160 $temp = $dest;
1161if ($source !==null || $force ) {
1162 $dest =$source;
1163 }
1164return $temp;
1165}
1166
1176functionwfSetBit( &$dest, $bit, $state =true ) {
1177 $temp = (bool)( $dest & $bit );
1178if ( $state !==null ) {
1179if ( $state ) {
1180 $dest |= $bit;
1181 }else {
1182 $dest &= ~$bit;
1183 }
1184 }
1185return $temp;
1186}
1187
1194functionwfVarDump( $var ) {
1195 global$wgOut;
1196 $s = str_replace("\n","<br />\n", var_export( $var,true ) ."\n" );
1197if ( headers_sent() ||$wgOut ===null || !is_object($wgOut ) ) {
1198 print $s;
1199 }else {
1200$wgOut->addHTML( $s );
1201 }
1202}
1203
1211functionwfHttpError( $code, $label, $desc ) {
1212 global$wgOut;
1213 HttpStatus::header( $code );
1214if ($wgOut ) {
1215$wgOut->disable();
1216$wgOut->sendCacheControl();
1217 }
1218
1219 \MediaWiki\Request\HeaderCallback::warnIfHeadersSent();
1220 header('Content-type: text/html; charset=utf-8' );
1221 ContentSecurityPolicy::sendRestrictiveHeader();
1222 ob_start();
1223 print'<!DOCTYPE html>' .
1224'<html><head><title>' .
1225 htmlspecialchars( $label ) .
1226'</title><meta name="color-scheme" content="light dark" /></head><body><h1>' .
1227 htmlspecialchars( $label ) .
1228'</h1><p>' .
1229 nl2br( htmlspecialchars( $desc ) ) .
1230"</p></body></html>\n";
1231 header('Content-Length: ' . ob_get_length() );
1232 ob_end_flush();
1233}
1234
1255functionwfResetOutputBuffers( $resetGzipEncoding =true ) {
1256// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
1257while ( $status = ob_get_status() ) {
1258if ( isset( $status['flags'] ) ) {
1259 $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
1260 $deleteable = ( $status['flags'] & $flags ) === $flags;
1261 } elseif ( isset( $status['del'] ) ) {
1262 $deleteable = $status['del'];
1263 }else {
1264// Guess that any PHP-internal setting can't be removed.
1265 $deleteable = $status['type'] !== 0;/* PHP_OUTPUT_HANDLER_INTERNAL */
1266 }
1267if ( !$deleteable ) {
1268// Give up, and hope the result doesn't break
1269// output behavior.
1270break;
1271 }
1272if ( $status['name'] ==='MediaWikiIntegrationTestCase::wfResetOutputBuffersBarrier' ) {
1273// Unit testing barrier to prevent this function from breaking PHPUnit.
1274break;
1275 }
1276if ( !ob_end_clean() ) {
1277// Could not remove output buffer handler; abort now
1278// to avoid getting in some kind of infinite loop.
1279break;
1280 }
1281if ( $resetGzipEncoding && $status['name'] =='ob_gzhandler' ) {
1282// Reset the 'Content-Encoding' field set by this handler
1283// so we can start fresh.
1284 header_remove('Content-Encoding' );
1285break;
1286 }
1287 }
1288}
1289
1300functionwfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
1301 $ret = ConvertibleTimestamp::convert( $outputtype, $ts );
1302if ( $ret ===false ) {
1303wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts" );
1304 }
1305return $ret;
1306}
1307
1316functionwfTimestampOrNull( $outputtype = TS_UNIX, $ts =null ) {
1317if ( $ts ===null ) {
1318returnnull;
1319 }else {
1320returnwfTimestamp( $outputtype, $ts );
1321 }
1322}
1323
1329functionwfTimestampNow() {
1330return ConvertibleTimestamp::now( TS_MW );
1331}
1332
1344functionwfTempDir() {
1345 global$wgTmpDirectory;
1346
1347if ($wgTmpDirectory !==false ) {
1348return$wgTmpDirectory;
1349 }
1350
1351return TempFSFile::getUsableTempDirectory();
1352}
1353
1362functionwfMkdirParents( $dir, $mode =null, $caller =null ) {
1363 global$wgDirectoryMode;
1364
1365if ( FileBackend::isStoragePath( $dir ) ) {
1366thrownew LogicException( __FUNCTION__ ." given storage path '$dir'." );
1367 }
1368if ( $caller !==null ) {
1369wfDebug("$caller: called wfMkdirParents($dir)" );
1370 }
1371if ( strval( $dir ) ==='' ) {
1372returntrue;
1373 }
1374
1375 $dir = str_replace( ['\\','/' ], DIRECTORY_SEPARATOR, $dir );
1376 $mode ??=$wgDirectoryMode;
1377
1378// Turn off the normal warning, we're doing our own below
1379// PHP doesn't include the path in its warning message, so we add our own to aid in diagnosis.
1380//
1381// Repeat existence check if creation failed so that we silently recover in case of
1382// a race condition where another request created it since the first check.
1383//
1384// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
1385 $ok = is_dir( $dir ) || @mkdir( $dir, $mode,true ) || is_dir( $dir );
1386if ( !$ok ) {
1387 trigger_error( sprintf("failed to mkdir \"%s\" mode 0%o", $dir, $mode ), E_USER_WARNING );
1388 }
1389
1390return $ok;
1391}
1392
1398functionwfRecursiveRemoveDir( $dir ) {
1399// taken from https://www.php.net/manual/en/function.rmdir.php#98622
1400if ( is_dir( $dir ) ) {
1401 $objects = scandir( $dir );
1402foreach ( $objects as $object ) {
1403if ( $object !="." && $object !=".." ) {
1404if ( filetype( $dir .'/' . $object ) =="dir" ) {
1405wfRecursiveRemoveDir( $dir .'/' . $object );
1406 }else {
1407 unlink( $dir .'/' . $object );
1408 }
1409 }
1410 }
1411 rmdir( $dir );
1412 }
1413}
1414
1421functionwfPercent( $nr,int $acc = 2,bool $round =true ) {
1422 $accForFormat = $acc >= 0 ? $acc : 0;
1423 $ret = sprintf("%.{$accForFormat}f", $nr );
1424return $round ? round( (float)$ret, $acc ) .'%' :"$ret%";
1425}
1426
1450functionwfIniGetBool( $setting ) {
1451returnwfStringToBool( ini_get( $setting ) );
1452}
1453
1466functionwfStringToBool( $val ) {
1467 $val = strtolower( $val );
1468// 'on' and 'true' can't have whitespace around them, but '1' can.
1469return $val =='on'
1470 || $val =='true'
1471 || $val =='yes'
1472 || preg_match("/^\s*[+-]?0*[1-9]/", $val );// approx C atoi() function
1473}
1474
1488functionwfEscapeShellArg( ...$args ) {
1489return Shell::escape( ...$args );
1490}
1491
1516functionwfShellExec( $cmd, &$retval =null, $environ = [],
1517 $limits = [], $options = []
1518) {
1519if ( Shell::isDisabled() ) {
1520 $retval = 1;
1521// Backwards compatibility be upon us...
1522return'Unable to run external programs, proc_open() is disabled.';
1523 }
1524
1525if ( is_array( $cmd ) ) {
1526 $cmd = Shell::escape( $cmd );
1527 }
1528
1529 $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr'];
1530 $profileMethod = $options['profileMethod'] ??wfGetCaller();
1531
1532try {
1533 $result = Shell::command( [] )
1534 ->unsafeParams( (array)$cmd )
1535 ->environment( $environ )
1536 ->limits( $limits )
1537 ->includeStderr( $includeStderr )
1538 ->profileMethod( $profileMethod )
1539// For b/c
1540 ->restrict( Shell::RESTRICT_NONE )
1541 ->execute();
1542 }catch (ProcOpenError ) {
1543 $retval = -1;
1544return'';
1545 }
1546
1547 $retval = $result->getExitCode();
1548
1549return $result->getStdout();
1550}
1551
1569functionwfShellExecWithStderr( $cmd, &$retval =null, $environ = [], $limits = [] ) {
1570returnwfShellExec( $cmd, $retval, $environ, $limits,
1571 ['duplicateStderr' =>true,'profileMethod' =>wfGetCaller() ] );
1572}
1573
1589functionwfShellWikiCmd( $script, array $parameters = [], array $options = [] ) {
1590 global$wgPhpCli;
1591// Give site config file a chance to run the script in a wrapper.
1592// The caller may likely want to call wfBasename() on $script.
1593 (newHookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
1594 ->onWfShellWikiCmd( $script, $parameters, $options );
1595 $cmd = [ $options['php'] ??$wgPhpCli ];
1596if ( isset( $options['wrapper'] ) ) {
1597 $cmd[] = $options['wrapper'];
1598 }
1599 $cmd[] = $script;
1600// Escape each parameter for shell
1601return Shell::escape( array_merge( $cmd, $parameters ) );
1602}
1603
1620functionwfMerge(
1621string $old,
1622string $mine,
1623string $yours,
1624 ?string &$simplisticMergeAttempt,
1625 ?string &$mergeLeftovers =null
1626): bool {
1627 global$wgDiff3;
1628
1629 # This check may also protect against code injection in
1630 # case of broken installations.
1631 AtEase::suppressWarnings();
1632 $haveDiff3 =$wgDiff3 && file_exists($wgDiff3 );
1633 AtEase::restoreWarnings();
1634
1635if ( !$haveDiff3 ) {
1636wfDebug("diff3 not found" );
1637returnfalse;
1638 }
1639
1640 # Make temporary files
1641 $td =wfTempDir();
1642 $oldtextFile = fopen( $oldtextName = tempnam( $td,'merge-old-' ),'w' );
1643 $mytextFile = fopen( $mytextName = tempnam( $td,'merge-mine-' ),'w' );
1644 $yourtextFile = fopen( $yourtextName = tempnam( $td,'merge-your-' ),'w' );
1645
1646 # NOTE: diff3 issues a warning to stderr if any of the files does not end with
1647 # a newline character. To avoid this, we normalize the trailing whitespace before
1648 # creating the diff.
1649
1650 fwrite( $oldtextFile, rtrim( $old ) ."\n" );
1651 fclose( $oldtextFile );
1652 fwrite( $mytextFile, rtrim( $mine ) ."\n" );
1653 fclose( $mytextFile );
1654 fwrite( $yourtextFile, rtrim( $yours ) ."\n" );
1655 fclose( $yourtextFile );
1656
1657 # Check for a conflict
1658 $cmd = Shell::escape($wgDiff3,'--text','--overlap-only', $mytextName,
1659 $oldtextName, $yourtextName );
1660 $handle = popen( $cmd,'r' );
1661
1662 $mergeLeftovers ='';
1663do {
1664 $data = fread( $handle, 8192 );
1665if ( $data ===false || $data ==='' ) {
1666break;
1667 }
1668 $mergeLeftovers .= $data;
1669 }while (true );
1670 pclose( $handle );
1671
1672 $conflict = $mergeLeftovers !=='';
1673
1674 # Merge differences automatically where possible, preferring "my" text for conflicts.
1675 $cmd = Shell::escape($wgDiff3,'--text','--ed','--merge', $mytextName,
1676 $oldtextName, $yourtextName );
1677 $handle = popen( $cmd,'r' );
1678 $simplisticMergeAttempt ='';
1679do {
1680 $data = fread( $handle, 8192 );
1681if ( $data ===false || $data ==='' ) {
1682break;
1683 }
1684 $simplisticMergeAttempt .= $data;
1685 }while (true );
1686 pclose( $handle );
1687 unlink( $mytextName );
1688 unlink( $oldtextName );
1689 unlink( $yourtextName );
1690
1691if ( $simplisticMergeAttempt ==='' && $old !=='' && !$conflict ) {
1692wfDebug("Unexpected null result from diff3. Command: $cmd" );
1693 $conflict =true;
1694 }
1695return !$conflict;
1696}
1697
1710functionwfBaseName($path, $suffix ='' ) {
1711if ( $suffix =='' ) {
1712 $encSuffix ='';
1713 }else {
1714 $encSuffix ='(?:' . preg_quote( $suffix,'#' ) .')?';
1715 }
1716
1717$matches = [];
1718if ( preg_match("#([^/\\\\]*?){$encSuffix}[/\\\\]*$#",$path,$matches ) ) {
1719return$matches[1];
1720 }else {
1721return'';
1722 }
1723}
1724
1734functionwfRelativePath($path, $from ) {
1735// Normalize mixed input on Windows...
1736$path = str_replace('/', DIRECTORY_SEPARATOR,$path );
1737 $from = str_replace('/', DIRECTORY_SEPARATOR, $from );
1738
1739// Trim trailing slashes -- fix for drive root
1740$path = rtrim($path, DIRECTORY_SEPARATOR );
1741 $from = rtrim( $from, DIRECTORY_SEPARATOR );
1742
1743 $pieces = explode( DIRECTORY_SEPARATOR, dirname($path ) );
1744 $against = explode( DIRECTORY_SEPARATOR, $from );
1745
1746if ( $pieces[0] !== $against[0] ) {
1747// Non-matching Windows drive letters?
1748// Return a full path.
1749return$path;
1750 }
1751
1752// Trim off common prefix
1753while ( count( $pieces ) && count( $against )
1754 && $pieces[0] == $against[0] ) {
1755 array_shift( $pieces );
1756 array_shift( $against );
1757 }
1758
1759// relative dots to bump us to the parent
1760while ( count( $against ) ) {
1761 array_unshift( $pieces,'..' );
1762 array_shift( $against );
1763 }
1764
1765 $pieces[] =wfBaseName($path );
1766
1767return implode( DIRECTORY_SEPARATOR, $pieces );
1768}
1769
1779functionwfScript( $script ='index' ) {
1780 global$wgScriptPath,$wgScript,$wgLoadScript;
1781if ( $script ==='index' ) {
1782return$wgScript;
1783 } elseif ( $script ==='load' ) {
1784return$wgLoadScript;
1785 }else {
1786return"{$wgScriptPath}/{$script}.php";
1787 }
1788}
1789
1797functionwfBoolToStr( $value ) {
1798return $value ?'true' :'false';
1799}
1800
1806functionwfGetNull() {
1807returnwfIsWindows() ?'NUL' :'/dev/null';
1808}
1809
1818functionwfStripIllegalFilenameChars( $name ) {
1819 global$wgIllegalFileChars;
1820 $illegalFileChars =$wgIllegalFileChars ?"|[" .$wgIllegalFileChars ."]" :'';
1821 $name = preg_replace(
1822"/[^" . Title::legalChars() ."]" . $illegalFileChars ."/",
1823'-',
1824 $name
1825 );
1826// $wgIllegalFileChars may not include '/' and '\', so we still need to do this
1827 $name =wfBaseName( $name );
1828return $name;
1829}
1830
1837functionwfMemoryLimit( $newLimit ) {
1838 $oldLimit =wfShorthandToInteger( ini_get('memory_limit' ) );
1839// If the INI config is already unlimited, there is nothing larger
1840if ( $oldLimit != -1 ) {
1841 $newLimit =wfShorthandToInteger( (string)$newLimit );
1842if ( $newLimit == -1 ) {
1843wfDebug("Removing PHP's memory limit" );
1844 AtEase::suppressWarnings();
1845 ini_set('memory_limit', $newLimit );
1846 AtEase::restoreWarnings();
1847 } elseif ( $newLimit > $oldLimit ) {
1848wfDebug("Raising PHP's memory limit to $newLimit bytes" );
1849 AtEase::suppressWarnings();
1850 ini_set('memory_limit', $newLimit );
1851 AtEase::restoreWarnings();
1852 }
1853 }
1854}
1855
1862functionwfTransactionalTimeLimit() {
1863 global$wgTransactionalTimeLimit;
1864
1865 $timeout = RequestTimeout::singleton();
1866 $timeLimit = $timeout->getWallTimeLimit();
1867if ( $timeLimit !== INF ) {
1868// RequestTimeout library is active
1869if ($wgTransactionalTimeLimit > $timeLimit ) {
1870 $timeout->setWallTimeLimit($wgTransactionalTimeLimit );
1871 }
1872 }else {
1873// Fallback case, likely $wgRequestTimeLimit === null
1874 $timeLimit = (int)ini_get('max_execution_time' );
1875// Note that CLI scripts use 0
1876if ( $timeLimit > 0 &&$wgTransactionalTimeLimit > $timeLimit ) {
1877 $timeout->setWallTimeLimit($wgTransactionalTimeLimit );
1878 }
1879 }
1880 ignore_user_abort(true );// ignore client disconnects
1881
1882return $timeLimit;
1883}
1884
1892functionwfShorthandToInteger( ?string $string ='',int $default = -1 ): int {
1893 $string = trim( $string ??'' );
1894if ( $string ==='' ) {
1895return $default;
1896 }
1897 $last = substr( $string, -1 );
1898 $val = intval( $string );
1899switch ( $last ) {
1900case'g':
1901case'G':
1902 $val *= 1024;
1903// break intentionally missing
1904case'm':
1905case'M':
1906 $val *= 1024;
1907// break intentionally missing
1908case'k':
1909case'K':
1910 $val *= 1024;
1911 }
1912
1913return $val;
1914}
1915
1923functionwfIsInfinity( $str ) {
1924// The INFINITY_VALS are hardcoded elsewhere in MediaWiki (e.g. mediawiki.special.block.js).
1925return in_array( $str, ExpiryDef::INFINITY_VALS );
1926}
1927
1942functionwfThumbIsStandard(File $file, array $params ) {
1943 global$wgThumbLimits,$wgImageLimits,$wgResponsiveImages;
1944
1945 $multipliers = [ 1 ];
1946if ($wgResponsiveImages ) {
1947// These available sizes are hardcoded currently elsewhere in MediaWiki.
1948// @see Linker::processResponsiveImages
1949 $multipliers[] = 1.5;
1950 $multipliers[] = 2;
1951 }
1952
1953 $handler = $file->getHandler();
1954if ( !$handler || !isset( $params['width'] ) ) {
1955returnfalse;
1956 }
1957
1958 $basicParams = [];
1959if ( isset( $params['page'] ) ) {
1960 $basicParams['page'] = $params['page'];
1961 }
1962
1963 $thumbLimits = [];
1964 $imageLimits = [];
1965// Expand limits to account for multipliers
1966foreach ( $multipliers as $multiplier ) {
1967 $thumbLimits = array_merge( $thumbLimits, array_map(
1968staticfunction ( $width ) use ( $multiplier ) {
1969return round( $width * $multiplier );
1970 },$wgThumbLimits )
1971 );
1972 $imageLimits = array_merge( $imageLimits, array_map(
1973staticfunction ( $pair ) use ( $multiplier ) {
1974return [
1975 round( $pair[0] * $multiplier ),
1976 round( $pair[1] * $multiplier ),
1977 ];
1978 },$wgImageLimits )
1979 );
1980 }
1981
1982// Check if the width matches one of $wgThumbLimits
1983if ( in_array( $params['width'], $thumbLimits ) ) {
1984 $normalParams = $basicParams + ['width' => $params['width'] ];
1985// Append any default values to the map (e.g. "lossy", "lossless", ...)
1986 $handler->normaliseParams( $file, $normalParams );
1987 }else {
1988// If not, then check if the width matches one of $wgImageLimits
1989 $match =false;
1990foreach ( $imageLimits as $pair ) {
1991 $normalParams = $basicParams + ['width' => $pair[0],'height' => $pair[1] ];
1992// Decide whether the thumbnail should be scaled on width or height.
1993// Also append any default values to the map (e.g. "lossy", "lossless", ...)
1994 $handler->normaliseParams( $file, $normalParams );
1995// Check if this standard thumbnail size maps to the given width
1996if ( $normalParams['width'] == $params['width'] ) {
1997 $match =true;
1998break;
1999 }
2000 }
2001if ( !$match ) {
2002returnfalse;// not standard for description pages
2003 }
2004 }
2005
2006// Check that the given values for non-page, non-width, params are just defaults
2007foreach ( $params as $key => $value ) {
2008if ( !isset( $normalParams[$key] ) || $normalParams[$key] != $value ) {
2009returnfalse;
2010 }
2011 }
2012
2013returntrue;
2014}
2015
2028functionwfArrayPlus2d( array $baseArray, array $newValues ) {
2029// First merge items that are in both arrays
2030foreach ( $baseArray as $name => &$groupVal ) {
2031if ( isset( $newValues[$name] ) ) {
2032 $groupVal += $newValues[$name];
2033 }
2034 }
2035// Now add items that didn't exist yet
2036 $baseArray += $newValues;
2037
2038return $baseArray;
2039}
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
DefinitionBootstrapHelperFunctions.php:83
PROTO_CURRENT
const PROTO_CURRENT
DefinitionDefines.php:222
wfThumbIsStandard
wfThumbIsStandard(File $file, array $params)
Returns true if these thumbnail parameters match one that MediaWiki requests from file description pa...
DefinitionGlobalFunctions.php:1942
wfVarDump
wfVarDump( $var)
A wrapper around the PHP function var_export().
DefinitionGlobalFunctions.php:1194
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:632
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:245
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
DefinitionGlobalFunctions.php:298
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
DefinitionGlobalFunctions.php:592
wfTempDir
wfTempDir()
Tries to get the system directory for temporary files.
DefinitionGlobalFunctions.php:1344
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:781
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
DefinitionGlobalFunctions.php:263
wfTimestampOrNull
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
DefinitionGlobalFunctions.php:1316
wfBaseName
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
DefinitionGlobalFunctions.php:1710
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
DefinitionGlobalFunctions.php:1329
wfClientAcceptsGzip
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
DefinitionGlobalFunctions.php:1026
wfEscapeShellArg
wfEscapeShellArg(... $args)
Locale-independent version of escapeshellarg()
DefinitionGlobalFunctions.php:1488
wfLogDBError
wfLogDBError( $text, array $context=[])
Log for database errors.
DefinitionGlobalFunctions.php:714
wfLoadSkins
wfLoadSkins(array $skins)
Load multiple skins at once.
DefinitionGlobalFunctions.php:94
wfEscapeWikiText
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
DefinitionGlobalFunctions.php:1060
wfUrlProtocolsWithoutProtRel
wfUrlProtocolsWithoutProtRel()
Like wfUrlProtocols(), but excludes '//' from the protocol list.
DefinitionGlobalFunctions.php:560
wfRecursiveRemoveDir
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
DefinitionGlobalFunctions.php:1398
wfLoadExtension
wfLoadExtension( $ext, $path=null)
Load an extension.
DefinitionGlobalFunctions.php:42
wfMemoryLimit
wfMemoryLimit( $newLimit)
Raise PHP's memory limit (if needed).
DefinitionGlobalFunctions.php:1837
wfSetBit
wfSetBit(&$dest, $bit, $state=true)
As for wfSetVar except setting a bit.
DefinitionGlobalFunctions.php:1176
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
DefinitionGlobalFunctions.php:1450
wfShorthandToInteger
wfShorthandToInteger(?string $string='', int $default=-1)
Converts shorthand byte notation to integer form.
DefinitionGlobalFunctions.php:1892
wfBacktrace
wfBacktrace( $raw=null)
Get a debug backtrace as a string.
DefinitionGlobalFunctions.php:936
wfArrayDiff2
wfArrayDiff2( $arr1, $arr2)
Like array_diff( $arr1, $arr2 ) except that it works with two-dimensional arrays.
DefinitionGlobalFunctions.php:109
wfGetCaller
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
DefinitionGlobalFunctions.php:969
wfMergeErrorArrays
wfMergeErrorArrays(... $args)
Merge arrays in the style of PermissionManager::getPermissionErrors, with duplicate removal e....
DefinitionGlobalFunctions.php:165
wfDeprecatedMsg
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
DefinitionGlobalFunctions.php:766
wfGetUrlUtils
wfGetUrlUtils()
DefinitionGlobalFunctions.php:462
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:1516
wfIsDebugRawPage
wfIsDebugRawPage()
Returns true if debug logging should be suppressed if $wgDebugRawPage = false.
DefinitionGlobalFunctions.php:654
wfHostname
wfHostname()
Get host name of the current machine, for use in error reporting.
DefinitionGlobalFunctions.php:888
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:514
wfShellWikiCmd
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
DefinitionGlobalFunctions.php:1589
wfPercent
wfPercent( $nr, int $acc=2, bool $round=true)
DefinitionGlobalFunctions.php:1421
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:1159
wfShellExecWithStderr
wfShellExecWithStderr( $cmd, &$retval=null, $environ=[], $limits=[])
Execute a shell command, returning both stdout and stderr.
DefinitionGlobalFunctions.php:1569
wfGetNull
wfGetNull()
Get a platform-independent path to the null file, e.g.
DefinitionGlobalFunctions.php:1806
wfRelativePath
wfRelativePath( $path, $from)
Generate a relative path name to the given file.
DefinitionGlobalFunctions.php:1734
wfHttpError
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
DefinitionGlobalFunctions.php:1211
wfUrlProtocols
wfUrlProtocols( $includeProtocolRelative=true)
Returns a partial regular expression of recognized URL protocols, e.g.
DefinitionGlobalFunctions.php:546
wfMessageFallback
wfMessageFallback(... $keys)
This function accepts multiple message keys and returns a message instance for the first message whic...
DefinitionGlobalFunctions.php:848
wfMerge
wfMerge(string $old, string $mine, string $yours, ?string &$simplisticMergeAttempt, ?string &$mergeLeftovers=null)
wfMerge attempts to merge differences between three texts.
DefinitionGlobalFunctions.php:1620
wfGetAllCallers
wfGetAllCallers( $limit=3)
Return a string consisting of callers in the stack.
DefinitionGlobalFunctions.php:985
wfArrayPlus2d
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
DefinitionGlobalFunctions.php:2028
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
DefinitionGlobalFunctions.php:794
wfTransactionalTimeLimit
wfTransactionalTimeLimit()
Raise the request time limit to $wgTransactionalTimeLimit.
DefinitionGlobalFunctions.php:1862
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:696
wfObjectToArray
wfObjectToArray( $objOrArray, $recursive=true)
Recursively converts the parameter (an object) to an array with the same data.
DefinitionGlobalFunctions.php:219
wfLoadSkin
wfLoadSkin( $skin, $path=null)
Load a skin.
DefinitionGlobalFunctions.php:79
wfMsgReplaceArgs
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
DefinitionGlobalFunctions.php:860
wfStringToBool
wfStringToBool( $val)
Convert string value to boolean, when the following are interpreted as true:
DefinitionGlobalFunctions.php:1466
wfDebugBacktrace
wfDebugBacktrace( $limit=0)
Safety wrapper for debug_backtrace().
DefinitionGlobalFunctions.php:908
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:428
wfStripIllegalFilenameChars
wfStripIllegalFilenameChars( $name)
Replace all invalid characters with '-'.
DefinitionGlobalFunctions.php:1818
wfFormatStackFrame
wfFormatStackFrame( $frame)
Return a string representation of frame.
DefinitionGlobalFunctions.php:1008
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
DefinitionGlobalFunctions.php:336
wfScript
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
DefinitionGlobalFunctions.php:1779
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
DefinitionGlobalFunctions.php:381
wfMatchesDomainList
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
DefinitionGlobalFunctions.php:606
wfIsInfinity
wfIsInfinity( $str)
Determine input string is represents as infinity.
DefinitionGlobalFunctions.php:1923
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
DefinitionGlobalFunctions.php:1362
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
DefinitionGlobalFunctions.php:1300
wfLoadExtensions
wfLoadExtensions(array $exts)
Load multiple extensions at once.
DefinitionGlobalFunctions.php:63
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
DefinitionGlobalFunctions.php:1797
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
DefinitionGlobalFunctions.php:820
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
DefinitionGlobalFunctions.php:735
wfArrayInsertAfter
wfArrayInsertAfter(array $array, array $insert, $after)
Insert an array into another array after the specified key.
DefinitionGlobalFunctions.php:192
wfAssembleUrl
wfAssembleUrl( $urlParts)
This function will reassemble a URL parsed with wfParseURL.
DefinitionGlobalFunctions.php:532
wfResetOutputBuffers
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
DefinitionGlobalFunctions.php:1255
$path
$path
DefinitionNoLocalSettings.php:14
$matches
$matches
DefinitionNoLocalSettings.php:13
$wgRequest
global $wgRequest
DefinitionSetup.php:434
$wgOut
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
DefinitionSetup.php:551
MW_ENTRY_POINT
const MW_ENTRY_POINT
Definitionapi.php:21
MediaWiki\Debug\MWDebug
Debug toolbar.
DefinitionMWDebug.php:35
MediaWiki\Exception\ProcOpenError
DefinitionProcOpenError.php:14
MediaWiki\FileRepo\File\File
Implements some public methods and some protected utility functions which are required by multiple ch...
DefinitionFile.php:79
MediaWiki\FileRepo\File\File\getHandler
getHandler()
Get a MediaHandler instance for this file.
DefinitionFile.php:1619
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
DefinitionHookRunner.php:595
MediaWiki\Logger\LoggerFactory
Create PSR-3 logger objects.
DefinitionLoggerFactory.php:32
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
DefinitionMediaWikiServices.php:256
MediaWiki\Message\Message
The Message class deals with fetching and processing of interface message into a variety of formats.
DefinitionMessage.php:144
MediaWiki\Registration\ExtensionRegistry
Load JSON files, and uses a Processor to extract information.
DefinitionExtensionRegistry.php:35
MediaWiki\Request\ContentSecurityPolicy
Handle sending Content-Security-Policy headers.
DefinitionContentSecurityPolicy.php:23
MediaWiki\Request\WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form,...
DefinitionWebRequest.php:40
MediaWiki\Shell\Shell
Executes shell commands.
DefinitionShell.php:32
MediaWiki\Title\Title
Represents a title within MediaWiki.
DefinitionTitle.php:69
MediaWiki\Utils\UrlUtils
A service to expand, parse, and otherwise manipulate URLs.
DefinitionUrlUtils.php:16
Wikimedia\FileBackend\FSFile\TempFSFile
This class is used to hold the location and do limited manipulation of files stored temporarily (this...
DefinitionTempFSFile.php:23
Wikimedia\FileBackend\FileBackend
Base class for all file backend classes (including multi-write backends).
DefinitionFileBackend.php:98
Wikimedia\Http\HttpStatus
DefinitionHttpStatus.php:16
Wikimedia\Message\MessageParam
Value object representing a message parameter that consists of a list of values.
DefinitionMessageParam.php:14
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:1709
$wgThumbLimits
$wgThumbLimits
Config variable stub for the ThumbLimits setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:771
$wgDebugLogPrefix
$wgDebugLogPrefix
Config variable stub for the DebugLogPrefix setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3246
$wgPhpCli
$wgPhpCli
Config variable stub for the PhpCli setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:4323
$wgOverrideHostname
$wgOverrideHostname
Config variable stub for the OverrideHostname setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3330
$wgImageLimits
$wgImageLimits
Config variable stub for the ImageLimits setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:765
$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:849
$wgDiff3
$wgDiff3
Config variable stub for the Diff3 setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3517
$wgUrlProtocols
$wgUrlProtocols
Config variable stub for the UrlProtocols setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:2328
$wgResponsiveImages
$wgResponsiveImages
Config variable stub for the ResponsiveImages setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:855
$wgDebugRawPage
$wgDebugRawPage
Config variable stub for the DebugRawPage setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:3258
$wgEnableMagicLinks
$wgEnableMagicLinks
Config variable stub for the EnableMagicLinks setting, for use by phpdoc and IDEs.
Definitionconfig-vars.php:2454
$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:12
$source
$source
Definitionmwdoc-filter.php:36
$url
$url
Definitionopensearch_desc.php:23

[8]ページ先頭

©2009-2025 Movatter.jp