92 if ( $path[0] !==
'/' ) {
98 if ( strpos( $path,
'$1' ) ===
false ) {
99 if ( substr( $path, -1 ) !==
'/' ) {
108 if ( !isset(
$params[
'title'] ) && strpos( $path,
'$1' ) !==
false ) {
118 foreach (
$params as $paramName => $paramData ) {
119 if ( is_string( $paramData ) ) {
120 if ( preg_match(
'/\$(\d+|key)/u', $paramData ) ) {
121 $paramArrKey =
'pattern';
125 $paramArrKey =
'value';
128 $paramArrKey => $paramData
135 foreach (
$options as $optionName => $optionData ) {
136 if ( preg_match(
'/^\$\d+$/u', $optionName ) ) {
137 if ( !is_array( $optionData ) ) {
138 $options[$optionName] = [ $optionData ];
150 $this->patterns[] = $pattern;
161 if ( is_array( $path ) ) {
162 foreach ( $path as $key => $onePath ) {
188 foreach ( $this->patterns as $key => $pattern ) {
189 $weights[$key] = $pattern->weight;
191 array_multisort( $weights, SORT_DESC, SORT_NUMERIC, $this->patterns );
199 # Start with a weight of 0
203 $path = explode(
'/', $pattern->path );
205 # For each level of the path
206 foreach ( $path as $piece ) {
207 if ( preg_match(
'/^\$(\d+|key)$/u', $piece ) ) {
208 # For a piece that is only a $1 variable add 1 points of weight
210 } elseif ( preg_match(
'/\$(\d+|key)/u', $piece ) ) {
211 # For a piece that simply contains a $1 variable add 2 points of weight
214 # For a solid piece add a full 3 points of weight
219 foreach ( $pattern->options as $key => $option ) {
220 if ( preg_match(
'/^\$\d+$/u', $key ) ) {
221 # Add 0.5 for restrictions to values
222 # This way given two separate "/$2/$1" patterns the
223 # one with a limited set of $2 values will dominate
224 # the one that'll match more loosely
247 $path = preg_replace(
'#/+#',
'/', $path );
267 foreach ( $this->patterns as $pattern ) {
283 $regexp = preg_quote( $pattern->path,
'#' );
285 $regexp = preg_replace(
'#\\\\\$1#u',
'(?P<par1>.*)', $regexp );
287 $regexp = preg_replace(
'#\\\\\$(\d+)#u',
'(?P<par$1>.+?)', $regexp );
288 $regexp =
"#^{$regexp}$#";
294 if ( preg_match( $regexp, $path, $m ) ) {
297 foreach ( $pattern->options as $key => $option ) {
298 if ( preg_match(
'/^\$\d+$/u', $key ) ) {
299 $n = intval( substr( $key, 1 ) );
300 $value = rawurldecode( $m[
"par{$n}"] );
301 if ( !in_array(
$value, $option ) ) {
310 foreach ( $m as $matchKey => $matchValue ) {
311 if ( preg_match(
'/^par\d+$/u', $matchKey ) ) {
312 $n = intval( substr( $matchKey, 3 ) );
313 $data[
'$' . $n] = rawurldecode( $matchValue );
317 if ( isset( $pattern->key ) ) {
318 $data[
'$key'] = $pattern->key;
322 foreach ( $pattern->params as $paramName => $paramData ) {
326 if ( preg_match(
'/^data:/u', $paramName ) ) {
328 $key = substr( $paramName, 5 );
334 if ( isset( $paramData[
'value'] ) ) {
336 $value = $paramData[
'value'];
337 } elseif ( isset( $paramData[
'pattern'] ) ) {
340 $paramData[
'pattern'] );
356 if ( isset( $pattern->options[
'callback'] ) ) {
357 call_user_func_array( $pattern->options[
'callback'], [ &
$matches, $data ] );
378 $replacer =
function ( $m ) use ( $pathMatches, $key, &$error ) {
379 if ( $m[1] ==
"key" ) {
380 if ( is_null( $key ) ) {
389 if ( !isset( $pathMatches[
"par$d"] ) ) {
395 return rawurldecode( $pathMatches[
"par$d"] );
399 $value = preg_replace_callback(
'/\$(\d+|key)/u', $replacer,
$value );
wfRemoveDotSegments( $urlPath)
Remove all dot-segments in the provided URL path.
sortByWeight()
Protected helper to re-sort our patterns so that the most specific (most heavily weighted) patterns a...
static extractTitle( $path, $pattern)
add( $path, $params=[], $options=[])
Add a new path pattern to the path router.
static expandParamValue( $pathMatches, $key, $value)
Replace $key etc.
addStrict( $path, $params=[], $options=[])
Add a new path pattern to the path router with the strict option on.
static makeWeight( $pattern)
parse( $path)
Parse a path and return the query matches for the path.
doAdd( $path, $params, $options, $key=null)
Protected helper to do the actual bulk work of adding a single pattern.
internalParse( $path)
Match a path against each defined pattern.
An extension or a local will often add custom code to the function with or without a global variable For someone wanting email notification when an article is shown may add
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
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))