Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172289
Change subject: Simplify remoteExtPath regex
......................................................................
Simplify remoteExtPath regex
The complexity of this regular expression is just not needed. Just
search for the first occurrence of `/vendor/` or `/extensions/`
and match everything from there, that's it.
Using a regex character (`+`) as delimiter does have the advantage
that it must not be repeated when calling `preg_quote`, it's always
quoted.
Change-Id: Icbcc490879779bd6de64856411fcd862454347d4
---
M client/WikibaseClient.hooks.php
M client/resources/Resources.php
M lib/resources/Resources.php
M lib/resources/api/resources.php
M lib/resources/entityChangers/resources.php
M lib/resources/experts/resources.php
M lib/resources/formatters/resources.php
M lib/resources/jquery.wikibase/resources.php
M lib/resources/jquery.wikibase/snakview/resources.php
M lib/resources/jquery.wikibase/toolbar/resources.php
M lib/resources/parsers/resources.php
M lib/resources/wikibase.RepoApi/resources.php
M lib/resources/wikibase.store/resources.php
M lib/resources/wikibase.utilities/resources.php
M repo/resources/Resources.php
15 files changed, 54 insertions(+), 105 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/89/172289/1
diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 8f6b491..c3752ba 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -501,14 +501,10 @@
public static function onGetBetaFeaturePreferences( User $user, array
&$betaPreferences ) {
global $wgExtensionAssetsPath;
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
- $assetsPath = $wgExtensionAssetsPath . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR . $remoteExtPathParts[1];
+ $assetsPath = $wgExtensionAssetsPath . DIRECTORY_SEPARATOR .
'..' . $remoteExtPath[0];
$settings = WikibaseClient::getDefaultInstance()->getSettings();
if ( !$settings->getSetting( 'otherProjectsLinksBeta' ) ||
$settings->getSetting( 'otherProjectsLinksByDefault' ) ) {
diff --git a/client/resources/Resources.php b/client/resources/Resources.php
index 2c90075..7cbf1b0 100644
--- a/client/resources/Resources.php
+++ b/client/resources/Resources.php
@@ -1,15 +1,12 @@
<?php
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
return array(
diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index bd7ce2a..31dcb2e 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -11,15 +11,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/lib/resources/api/resources.php b/lib/resources/api/resources.php
index 1b0236a..f0e901c 100644
--- a/lib/resources/api/resources.php
+++ b/lib/resources/api/resources.php
@@ -4,16 +4,12 @@
* @author Adrian Lang <[email protected]>
*/
return call_user_func( function() {
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
return array(
diff --git a/lib/resources/entityChangers/resources.php
b/lib/resources/entityChangers/resources.php
index 2c1cb28..6f933f6 100644
--- a/lib/resources/entityChangers/resources.php
+++ b/lib/resources/entityChangers/resources.php
@@ -4,16 +4,12 @@
* @author Adrian Lang <[email protected]>
*/
return call_user_func( function() {
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
return array(
diff --git a/lib/resources/experts/resources.php
b/lib/resources/experts/resources.php
index 5da1565..40f4385 100644
--- a/lib/resources/experts/resources.php
+++ b/lib/resources/experts/resources.php
@@ -6,16 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
return array(
diff --git a/lib/resources/formatters/resources.php
b/lib/resources/formatters/resources.php
index d202543..9079b30 100644
--- a/lib/resources/formatters/resources.php
+++ b/lib/resources/formatters/resources.php
@@ -6,16 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
return array(
diff --git a/lib/resources/jquery.wikibase/resources.php
b/lib/resources/jquery.wikibase/resources.php
index 4759082..6700b3b 100644
--- a/lib/resources/jquery.wikibase/resources.php
+++ b/lib/resources/jquery.wikibase/resources.php
@@ -6,15 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/lib/resources/jquery.wikibase/snakview/resources.php
b/lib/resources/jquery.wikibase/snakview/resources.php
index 6a77b5f..36c681b 100644
--- a/lib/resources/jquery.wikibase/snakview/resources.php
+++ b/lib/resources/jquery.wikibase/snakview/resources.php
@@ -6,15 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/lib/resources/jquery.wikibase/toolbar/resources.php
b/lib/resources/jquery.wikibase/toolbar/resources.php
index 4dec8cd..273a5d9 100644
--- a/lib/resources/jquery.wikibase/toolbar/resources.php
+++ b/lib/resources/jquery.wikibase/toolbar/resources.php
@@ -6,15 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/lib/resources/parsers/resources.php
b/lib/resources/parsers/resources.php
index 9717d3d..d9f6e6b 100644
--- a/lib/resources/parsers/resources.php
+++ b/lib/resources/parsers/resources.php
@@ -6,16 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
return array(
diff --git a/lib/resources/wikibase.RepoApi/resources.php
b/lib/resources/wikibase.RepoApi/resources.php
index 4cc66c8..e2d813b 100644
--- a/lib/resources/wikibase.RepoApi/resources.php
+++ b/lib/resources/wikibase.RepoApi/resources.php
@@ -6,15 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/lib/resources/wikibase.store/resources.php
b/lib/resources/wikibase.store/resources.php
index 02f4a36..26efe00 100644
--- a/lib/resources/wikibase.store/resources.php
+++ b/lib/resources/wikibase.store/resources.php
@@ -6,15 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/lib/resources/wikibase.utilities/resources.php
b/lib/resources/wikibase.utilities/resources.php
index 841939a..dc18625 100644
--- a/lib/resources/wikibase.utilities/resources.php
+++ b/lib/resources/wikibase.utilities/resources.php
@@ -6,15 +6,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
);
$modules = array(
diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index 1f4a6cc..56bed57 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -11,15 +11,12 @@
* @codeCoverageIgnoreStart
*/
return call_user_func( function() {
- preg_match(
- '+' . preg_quote( DIRECTORY_SEPARATOR, '+' ) .
'((?:vendor|extensions)' .
- preg_quote( DIRECTORY_SEPARATOR, '+' ) . '.*)$+',
- __DIR__,
- $remoteExtPathParts
- );
+ preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) .
'(?:vendor|extensions)'
+ . preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__,
$remoteExtPath );
+
$moduleTemplate = array(
'localBasePath' => __DIR__,
- 'remoteExtPath' => '..' . DIRECTORY_SEPARATOR .
$remoteExtPathParts[1],
+ 'remoteExtPath' => '..' . $remoteExtPath[0],
'position' => 'top' // reducing the time between DOM
construction and JS initialisation
);
--
To view, visit https://gerrit.wikimedia.org/r/172289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbcc490879779bd6de64856411fcd862454347d4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits