* at the same time.
*
* Copyright © 2004, 2010 Brion Vibber <brion@pobox.com>
- * http://www.mediawiki.org/
+ * https://www.mediawiki.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
foreach ( $filenames as $filename ) {
$contents = file_get_contents( $filename );
- preg_match_all( '/!!\s*input\n(.*?)\n!!\s*result/s', $contents, $matches );
+ preg_match_all( '/!!\s*(input|wikitext)\n(.*?)\n!!\s*(result|html|html\/\*|html\/php)/s', $contents, $matches );
foreach ( $matches[1] as $match ) {
$dict .= $match . "\n";
// foo="bar baz"
// foo=[[bar baz]]
// foo=bar,"baz quux"
- $regex = '/\b
- ([\w-]+) # Key
- \b
- (?:\s*
- = # First sub-value
- \s*
- (
- "
- [^"]* # Quoted val
- "
+ // foo={...json...}
+ $defs = '(?(DEFINE)
+ (?<qstr> # Quoted string
+ "
+ (?:[^\\\\"] | \\\\.)*
+ "
+ )
+ (?<json>
+ \{ # Open bracket
+ (?:
+ [^"{}] | # Not a quoted string or object, or
+ (?&qstr) | # A quoted string, or
+ (?&json) # A json object (recursively)
+ )*
+ \} # Close bracket
+ )
+ (?<value>
+ (?:
+ (?&qstr) # Quoted val
|
\[\[
[^]]* # Link target
\]\]
|
[\w-]+ # Plain word
+ |
+ (?&json) # JSON object
+ )
+ )
+ )';
+ $regex = '/' . $defs . '\b
+ (?<k>[\w-]+) # Key
+ \b
+ (?:\s*
+ = # First sub-value
+ \s*
+ (?<v>
+ (?&value)
+ (?:\s*
+ , # Sub-vals 1..N
+ \s*
+ (?&value)
+ )*
)
- (?:\s*
- , # Sub-vals 1..N
- \s*
- (
- "[^"]*" # Quoted val
- |
- \[\[[^]]*\]\] # Link target
- |
- [\w-]+ # Plain word
- )
- )*
)?
/x';
+ $valueregex = '/' . $defs . '(?&value)/x';
if ( preg_match_all( $regex, $instring, $matches, PREG_SET_ORDER ) ) {
foreach ( $matches as $bits ) {
- array_shift( $bits );
- $key = strtolower( array_shift( $bits ) );
- if ( count( $bits ) == 0 ) {
+ $key = strtolower( $bits[ 'k' ] );
+ if ( !isset( $bits[ 'v' ] ) ) {
$opts[$key] = true;
- } elseif ( count( $bits ) == 1 ) {
- $opts[$key] = $this->cleanupOption( array_shift( $bits ) );
} else {
- // Array!
- $opts[$key] = array_map( array( $this, 'cleanupOption' ), $bits );
+ preg_match_all( $valueregex, $bits[ 'v' ], $vmatches );
+ $opts[$key] = array_map( array( $this, 'cleanupOption' ), $vmatches[0] );
+ if ( count( $opts[$key] ) == 1 ) {
+ $opts[$key] = $opts[$key][0];
+ }
}
}
}
private function cleanupOption( $opt ) {
if ( substr( $opt, 0, 1 ) == '"' ) {
- return substr( $opt, 1, -1 );
+ return stripcslashes( substr( $opt, 1, -1 ) );
}
if ( substr( $opt, 0, 2 ) == '[[' ) {
return substr( $opt, 2, -2 );
}
+
+ if ( substr( $opt, 0, 1 ) == '{' ) {
+ return FormatJson::decode( $opt, true );
+ }
return $opt;
}
'wgSVGConverters' => array( 'null' => 'echo "1">$output' ),
'wgLocaltimezone' => 'UTC',
'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
+ 'wgThumbLimits' => array( self::getOptionValue( 'thumbsize', $opts, 180 ) ),
'wgUseTidy' => false,
'wgDefaultLanguageVariant' => $variant,
'wgVariantArticlePath' => false,
$context = new RequestContext();
$GLOBALS['wgLang'] = $context->getLanguage();
$GLOBALS['wgOut'] = $context->getOutput();
+ $GLOBALS['wgUser'] = $context->getUser();
- $GLOBALS['wgUser'] = new User();
+ // We (re)set $wgThumbLimits to a single-element array above.
+ $context->getUser()->setOption( 'thumbsize', 0 );
global $wgHooks;
wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
wfMkdirParents( $dir . '/f/ff', null, __METHOD__ );
- copy( "$IP/skins/monobook/headbg.jpg", "$dir/f/ff/Foobar.svg" );
file_put_contents( "$dir/f/ff/Foobar.svg",
'<?xml version="1.0" encoding="utf-8"?>' .
- '<svg xmlns="http://www.w3.org/2000/svg" />' );
+ '<svg xmlns="http://www.w3.org/2000/svg"' .
+ ' version="1.1" width="240" height="180"/>' );
return $dir;
}