jenkins-bot has submitted this change and it was merged.

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/deprecated/resources.php
M lib/resources/experts/resources.php
M lib/resources/jquery.wikibase-shared/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 repo/resources/Resources.php
M repo/resources/entityChangers/resources.php
M repo/resources/formatters/resources.php
M repo/resources/parsers/resources.php
M repo/resources/store/resources.php
M repo/resources/utilities/resources.php
16 files changed, 58 insertions(+), 112 deletions(-)

Approvals:
  Adrian Lang: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 5cbd1ba..508d905 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -507,14 +507,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 ab61b4f..57c15f1 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 178e718..e60c07f 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 2b81676..86ddd23 100644
--- a/lib/resources/api/resources.php
+++ b/lib/resources/api/resources.php
@@ -4,16 +4,12 @@
  * @author Adrian Lang <adrian.l...@wikimedia.de>
  */
 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/deprecated/resources.php 
b/lib/resources/deprecated/resources.php
index 1bb49ff..48f0d9d 100644
--- a/lib/resources/deprecated/resources.php
+++ b/lib/resources/deprecated/resources.php
@@ -4,15 +4,12 @@
  * @author Adrian Lang <adrian.l...@wikimedia.de>
  */
 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/experts/resources.php 
b/lib/resources/experts/resources.php
index 3b392b0..6987418 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/jquery.wikibase-shared/resources.php 
b/lib/resources/jquery.wikibase-shared/resources.php
index c63cbcd..3501eff 100644
--- a/lib/resources/jquery.wikibase-shared/resources.php
+++ b/lib/resources/jquery.wikibase-shared/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/resources.php 
b/lib/resources/jquery.wikibase/resources.php
index f156aa0..829d395 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 622f924..eca37f3 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 d69b0a7..c8ac950 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/repo/resources/Resources.php b/repo/resources/Resources.php
index 88054d6..dec76b3 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
        );
 
diff --git a/repo/resources/entityChangers/resources.php 
b/repo/resources/entityChangers/resources.php
index c0eb1ae..99b2e23 100644
--- a/repo/resources/entityChangers/resources.php
+++ b/repo/resources/entityChangers/resources.php
@@ -4,16 +4,12 @@
  * @author Adrian Lang <adrian.l...@wikimedia.de>
  */
 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/repo/resources/formatters/resources.php 
b/repo/resources/formatters/resources.php
index cf71378..d830bf2 100644
--- a/repo/resources/formatters/resources.php
+++ b/repo/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/repo/resources/parsers/resources.php 
b/repo/resources/parsers/resources.php
index 9717d3d..d9f6e6b 100644
--- a/repo/resources/parsers/resources.php
+++ b/repo/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/repo/resources/store/resources.php 
b/repo/resources/store/resources.php
index 02f4a36..26efe00 100644
--- a/repo/resources/store/resources.php
+++ b/repo/resources/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/repo/resources/utilities/resources.php 
b/repo/resources/utilities/resources.php
index 841939a..dc18625 100644
--- a/repo/resources/utilities/resources.php
+++ b/repo/resources/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(

-- 
To view, visit https://gerrit.wikimedia.org/r/172289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Icbcc490879779bd6de64856411fcd862454347d4
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Adrian Lang <adrian.l...@wikimedia.de>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: JanZerebecki <jan.wikime...@zerebecki.de>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to