use Liuggio\StatsdClient\Sender\SocketSender;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Session\SessionManager;
+use Wikimedia\ScopedCallback;
// Hide compatibility functions from Doxygen
/// @cond
}
/**
- * @todo document
- * @todo FIXME: We may want to blacklist some broken browsers
+ * Whether the client accept gzip encoding
*
- * @param bool $force
- * @return bool Whereas client accept gzip compression
+ * Uses the Accept-Encoding header to check if the client supports gzip encoding.
+ * Use this when considering to send a gzip-encoded response to the client.
+ *
+ * @param bool $force Forces another check even if we already have a cached result.
+ * @return bool
*/
function wfClientAcceptsGzip( $force = false ) {
static $result = null;
}
/**
- * @deprecated since 1.28, use Parser::escapeWikitext() directly
- *
* Escapes the given text so that it may be output using addWikiText()
* without any linking, formatting, etc. making its way through. This
* is achieved by substituting certain characters with HTML entities.
* @return string
*/
function wfEscapeWikiText( $text ) {
- global $wgParser;
- return $wgParser->escapeWikitext( $text );
+ global $wgEnableMagicLinks;
+ static $repl = null, $repl2 = null;
+ if ( $repl === null || defined( 'MW_PARSER_TEST' ) || defined( 'MW_PHPUNIT_TEST' ) ) {
+ // Tests depend upon being able to change $wgEnableMagicLinks, so don't cache
+ // in those situations
+ $repl = [
+ '"' => '"', '&' => '&', "'" => ''', '<' => '<',
+ '=' => '=', '>' => '>', '[' => '[', ']' => ']',
+ '{' => '{', '|' => '|', '}' => '}', ';' => ';',
+ "\n#" => "\n#", "\r#" => "\r#",
+ "\n*" => "\n*", "\r*" => "\r*",
+ "\n:" => "\n:", "\r:" => "\r:",
+ "\n " => "\n ", "\r " => "\r ",
+ "\n\n" => "\n ", "\r\n" => " \n",
+ "\n\r" => "\n ", "\r\r" => "\r ",
+ "\n\t" => "\n	", "\r\t" => "\r	", // "\n\t\n" is treated like "\n\n"
+ "\n----" => "\n----", "\r----" => "\r----",
+ '__' => '__', '://' => '://',
+ ];
+
+ $magicLinks = array_keys( array_filter( $wgEnableMagicLinks ) );
+ // We have to catch everything "\s" matches in PCRE
+ foreach ( $magicLinks 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 = [];
+ foreach ( $wgUrlProtocols as $prot ) {
+ if ( substr( $prot, -1 ) === ':' ) {
+ $repl2[] = preg_quote( substr( $prot, 0, -1 ), '/' );
+ }
+ }
+ $repl2 = $repl2 ? '/\b(' . implode( '|', $repl2 ) . '):/i' : '/^(?!)/';
+ }
+ $text = substr( strtr( "\n$text", $repl ), 1 );
+ $text = preg_replace( $repl2, '$1:', $text );
+ return $text;
}
/**
}
/**
- * Windows-compatible version of escapeshellarg()
- * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
- * function puts single quotes in regardless of OS.
+ * Version of escapeshellarg() that works better on Windows.
*
- * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to
- * earlier distro releases of PHP)
+ * Originally, this fixed the incorrect use of single quotes on Windows
+ * (https://bugs.php.net/bug.php?id=26285) and the locale problems on Linux in
+ * PHP 5.2.6+ (bug backported to earlier distro releases of PHP).
*
* @param string ... strings to escape and glue together, or a single array of strings parameter
* @return string
* @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection()
* on an injected instance of LoadBalancer.
*
- * @return DatabaseBase
+ * @return Database
*/
function wfGetDB( $db, $groups = [], $wiki = false ) {
return wfGetLB( $wiki )->getConnection( $db, $groups, $wiki );