[MediaWiki-commits] [Gerrit] Simplify remoteExtPath regex - change (mediawiki...Wikibase)

2014-11-19 Thread jenkins-bot (Code Review)
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( 

[MediaWiki-commits] [Gerrit] Simplify remoteExtPath regex - change (mediawiki...Wikibase)

2014-11-10 Thread WMDE
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 adrian.l...@wikimedia.de
  */
 return call_user_func( function() {
+   preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) . 
'(?:vendor|extensions)'
+