42 return mb_check_encoding( (
string)
$value,
'UTF-8' );
57 $subject, $nested =
false ) {
61 $encStart = preg_quote( $startDelim,
'!' );
62 $encEnd = preg_quote( $endDelim,
'!' );
63 $encSep = preg_quote( $separator,
'!' );
64 $len = strlen( $subject );
70 "!$encStart|$encEnd|$encSep!S", $subject, $m,
71 PREG_OFFSET_CAPTURE, $inputPos
76 $inputPos = $matchPos + strlen( $match );
77 if ( $match === $separator ) {
80 $subject, $lastPos, $matchPos - $lastPos
84 } elseif ( $match === $startDelim ) {
85 if ( $depth === 0 || $nested ) {
92 $exploded[] = substr( $subject, $lastPos );
95 return new ArrayIterator( $exploded );
116 $segments =
explode( $startDelim, $subject );
117 $output = array_shift( $segments );
118 foreach ( $segments
as $s ) {
119 $endDelimPos = strpos(
$s, $endDelim );
120 if ( $endDelimPos ===
false ) {
123 $output .= $replace . substr(
$s, $endDelimPos + strlen( $endDelim ) );
155 $subject, $flags =
''
162 $encStart = preg_quote( $startDelim,
'!' );
163 $encEnd = preg_quote( $endDelim,
'!' );
164 $strcmp = strpos( $flags,
'i' ) ===
false ?
'strcmp' :
'strcasecmp';
165 $endLength = strlen( $endDelim );
168 while ( $inputPos < strlen( $subject ) &&
169 preg_match(
"!($encStart)|($encEnd)!S$flags", $subject, $m, PREG_OFFSET_CAPTURE, $inputPos )
171 $tokenOffset = $m[0][1];
172 if ( $m[1][0] !=
'' ) {
174 $strcmp( $endDelim, substr( $subject, $tokenOffset, $endLength ) ) == 0
176 # An end match is present at the same location
178 $tokenLength = $endLength;
180 $tokenType =
'start';
181 $tokenLength = strlen( $m[0][0] );
183 } elseif ( $m[2][0] !=
'' ) {
185 $tokenLength = strlen( $m[0][0] );
187 throw new InvalidArgumentException(
'Invalid delimiter given to ' . __METHOD__ );
190 if ( $tokenType ==
'start' ) {
191 # Only move the start position if we haven't already found a start
192 # This means that START START END matches outer pair
193 if ( !$foundStart ) {
195 $inputPos = $tokenOffset + $tokenLength;
196 # Write out the non-matching section
197 $output .= substr( $subject, $outputPos, $tokenOffset - $outputPos );
198 $outputPos = $tokenOffset;
199 $contentPos = $inputPos;
202 # Move the input position past the *first character* of START,
203 # to protect against missing END when it overlaps with START
204 $inputPos = $tokenOffset + 1;
206 } elseif ( $tokenType ==
'end' ) {
210 substr( $subject, $outputPos, $tokenOffset + $tokenLength - $outputPos ),
211 substr( $subject, $contentPos, $tokenOffset - $contentPos )
215 # Non-matching end, write it out
216 $output .= substr( $subject, $inputPos, $tokenOffset + $tokenLength - $outputPos );
218 $inputPos = $outputPos = $tokenOffset + $tokenLength;
220 throw new InvalidArgumentException(
'Invalid delimiter given to ' . __METHOD__ );
223 if ( $outputPos < strlen( $subject ) ) {
224 $output .= substr( $subject, $outputPos );
245 static function delimiterReplace( $startDelim, $endDelim, $replace, $subject, $flags =
'' ) {
247 $startDelim, $endDelim,
263 $placeholder =
"\x00";
266 $text = str_replace( $placeholder,
'', $text );
272 return str_replace( $separator, $placeholder,
$matches[0] );
278 $items =
explode( $separator, $cleaned );
279 foreach ( $items
as $i => $str ) {
280 $items[$i] = str_replace( $placeholder, $separator, $str );
295 $placeholder =
"\x00";
298 $text = str_replace( $placeholder,
'', $text );
304 return str_replace( $search, $placeholder,
$matches[0] );
310 $cleaned = str_replace( $search, $replace, $cleaned );
311 $text = str_replace( $placeholder, $search, $cleaned );
324 $string = str_replace(
'\\',
'\\\\', $string );
325 $string = str_replace(
'$',
'\\$', $string );
336 static function explode( $separator, $subject ) {
337 if ( substr_count( $subject, $separator ) > 1000 ) {
340 return new ArrayIterator(
explode( $separator, $subject ) );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
An iterator which works exactly like:
A collection of static methods to play with strings.
static hungryDelimiterReplace( $startDelim, $endDelim, $replace, $subject)
Perform an operation equivalent to preg_replace()
static delimiterReplace( $startDelim, $endDelim, $replace, $subject, $flags='')
Perform an operation equivalent to preg_replace() with flags.
static explodeMarkup( $separator, $text)
More or less "markup-safe" explode() Ignores any instances of the separator inside <....
static delimiterReplaceCallback( $startDelim, $endDelim, $callback, $subject, $flags='')
Perform an operation equivalent to preg_replace_callback()
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
static isUtf8( $value)
Test whether a string is valid UTF-8.
static replaceMarkup( $search, $replace, $text)
More or less "markup-safe" str_replace() Ignores any instances of the separator inside <....
static explode( $separator, $subject)
Workalike for explode() with limited memory usage.
static delimiterExplode( $startDelim, $endDelim, $separator, $subject, $nested=false)
Explode a string, but ignore any instances of the separator inside the given start and end delimiters...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))