* @return String
*/
function wfEscapeWikiText( $text ) {
- $text = strtr( "\n$text", array(
- '"' => '"', '&' => '&', "'" => ''', '<' => '<',
- '=' => '=', '>' => '>', '[' => '[', ']' => ']',
- '{' => '{', '|' => '|', '}' => '}',
- "\n#" => "\n#", "\n*" => "\n*",
- "\n:" => "\n:", "\n;" => "\n;",
- '://' => '://', 'ISBN ' => 'ISBN ', 'RFC ' => 'RFC ',
- ) );
- return substr( $text, 1 );
+ static $repl = null, $repl2 = null;
+ if ( $repl === null ) {
+ $repl = array(
+ '"' => '"', '&' => '&', "'" => ''', '<' => '<',
+ '=' => '=', '>' => '>', '[' => '[', ']' => ']',
+ '{' => '{', '|' => '|', '}' => '}',
+ "\n#" => "\n#", "\r#" => "\r#",
+ "\n*" => "\n*", "\r*" => "\r*",
+ "\n:" => "\n:", "\r:" => "\r:",
+ "\n;" => "\n;", "\r;" => "\r;",
+ "\n " => "\n ", "\r " => "\r ",
+ '__' => '__', '://' => '://',
+ );
+
+ // We have to catch everything "\s" matches in PCRE
+ foreach ( array( 'ISBN', 'RFC', 'PMID' ) as $magic ) {
+ $repl["$magic "] = "$magic ";
+ $repl["$magic\t"] = "$magic	";
+ $repl["$magic\r"] = "$magic ";
+ $repl["$magic\n"] = "$magic ";
+ $repl["$magic\f"] = "$magic";
+ }
+
+ // And handle protocols that don't use "://"
+ global $wgUrlProtocols;
+ $repl2 = array();
+ foreach ( $wgUrlProtocols as $prot ) {
+ if ( substr( $prot, -1 ) === ':' ) {
+ $repl2[] = preg_quote( substr( $prot, 0, -1 ), '/' );
+ }
+ }
+ $repl2 = $repl2 ? '/\b(' . join( '|', $repl2 ) . '):/i' : '/^(?!)/';
+ }
+ $text = substr( strtr( "\n$text", $repl ), 1 );
+ $text = preg_replace( $repl2, '$1:', $text );
+ return $text;
}
/**
$sourceBase > 36 ||
$destBase < 2 ||
$destBase > 36 ||
- $sourceBase != (int) $sourceBase ||
- $destBase != (int) $destBase ||
- $pad != (int) $pad ||
+ $sourceBase != (int)$sourceBase ||
+ $destBase != (int)$destBase ||
+ $pad != (int)$pad ||
!preg_match( "/^[" . substr( '0123456789abcdefghijklmnopqrstuvwxyz', 0, $sourceBase ) . "]+$/i", $input )
) {
return false;
$work += $digit;
if ( $workDigits || $work >= $destBase ) {
- $workDigits[] = (int) ( $work / $destBase );
+ $workDigits[] = (int)( $work / $destBase );
}
$work %= $destBase;
}
$popts = $this->parserOptions();
$oldTidy = $popts->setTidy( $tidy );
- $popts->setInterfaceMessage( (bool) $interface );
+ $popts->setInterfaceMessage( (bool)$interface );
$parserOutput = $wgParser->parse(
$text, $title, $popts,
* @param $options Options array to pass to Linker
*/
public function addReturnTo( $title, $query = array(), $text = null, $options = array() ) {
- if ( in_array( 'http', $options ) ) {
- $proto = PROTO_HTTP;
- } elseif ( in_array( 'https', $options ) ) {
- $proto = PROTO_HTTPS;
- } else {
- $proto = PROTO_RELATIVE;
- }
-
$link = $this->msg( 'returnto' )->rawParams(
Linker::link( $title, $text, array(), $query, $options ) )->escaped();
$this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
protected function makeResourceLoaderLink( $modules, $only, $useESI = false, array $extraQuery = array(), $loadCall = false ) {
global $wgResourceLoaderUseESI;
- $modules = (array) $modules;
+ $modules = (array)$modules;
if ( !count( $modules ) ) {
return '';
}
}
- $this->namespaceAliases = $aliases;
+ # Also add converted namespace names as aliases, to avoid confusion.
+ $convertedNames = array();
+ foreach ( $this->getVariants() as $variant ) {
+ if ( $variant === $this->mCode ) {
+ continue;
+ }
+ foreach ( $this->getNamespaces() as $ns => $_ ) {
+ $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
+ }
+ }
+
+ $this->namespaceAliases = $aliases + $convertedNames;
}
return $this->namespaceAliases;
}
$segments = array();
foreach ( $intervals as $intervalName => $intervalValue ) {
- // Messages: duration-centuries, duration-decades, duration-years, duration-days,
- // duration-hours, duration-minutes, duration-seconds
+ // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
+ // duration-years, duration-decades, duration-centuries, duration-millennia
$message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
$segments[] = $message->inLanguage( $this )->escaped();
}
foreach ( $forms as $index => $form ) {
if ( preg_match( '/^\d+=/i', $form ) ) {
$pos = strpos( $form, '=' );
- if ( substr( $form, 0, $pos ) === (string) $count ) {
+ if ( substr( $form, 0, $pos ) === (string)$count ) {
return substr( $form, $pos + 1 );
}
unset( $forms[$index] );