[MediaWiki-commits] [Gerrit] mediawiki/core[master]: OutputPage: Support UploadPath in testTransformResourcePath()

2017-02-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/336941 )

Change subject: OutputPage: Support UploadPath in testTransformResourcePath()
..


OutputPage: Support UploadPath in testTransformResourcePath()

Updated tests to reflect this use case. Currently we assume all web-accessible
paths within ResourceBasePath (e.g "/w") to exist on disk at the same path
in $IP (e.g. "/var/www/mw").

While in theory any number of web server rewrites or aliases could exist,
there is one case in particular that we should support since the information
is available in the configuration: UploadDir and UploadPath. This path may
be rewritten in a way that varies by wiki in multi-wiki installs that share
the same source code. E.g. a server may rewrite "/w/images" to somewhere
else, which means it will not match the directory on disk that is shared
between wikis.

Bug: T155146
Change-Id: I320478c9c262cc012f08b585b48d290594ec2420
---
M includes/OutputPage.php
M tests/phpunit/includes/OutputPageTest.php
2 files changed, 79 insertions(+), 13 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 91fc75c..af82436 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -3697,6 +3697,8 @@
 */
public static function transformResourcePath( Config $config, $path ) {
global $IP;
+
+   $localDir = $IP;
$remotePathPrefix = $config->get( 'ResourceBasePath' );
if ( $remotePathPrefix === '' ) {
// The configured base path is required to be empty 
string for
@@ -3710,8 +3712,18 @@
// - Path is protocol-relative. Fixes T155310. Not 
supported by RelPath lib.
return $path;
}
+   // For files in resources, extensions/ or skins/, 
ResourceBasePath is preferred here.
+   // For other misc files in $IP, we'll fallback to that as well. 
There is, however, a fourth
+   // supported dir/path pair in the configuration 
(wgUploadDirectory, wgUploadPath)
+   // which is not expected to be in wgResourceBasePath on CDNs. 
(T155146)
+   $uploadPath = $config->get( 'UploadPath' );
+   if ( strpos( $path, $uploadPath ) === 0 ) {
+   $localDir = $config->get( 'UploadDirectory' );
+   $remotePathPrefix = $remotePath = $uploadPath;
+   }
+
$path = RelPath\getRelativePath( $path, $remotePath );
-   return self::transformFilePath( $remotePathPrefix, $IP, $path );
+   return self::transformFilePath( $remotePathPrefix, $localDir, 
$path );
}
 
/**
diff --git a/tests/phpunit/includes/OutputPageTest.php 
b/tests/phpunit/includes/OutputPageTest.php
index d2494da..50f851c 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -181,22 +181,63 @@
$baseDir = dirname( __DIR__ ) . '/data/media';
return [
// File that matches basePath, and exists. Hash found 
and appended.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'/w/test.jpg', '/w/test.jpg?edcf2' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '/w/test.jpg',
+   '/w/test.jpg?edcf2'
+   ],
// File that matches basePath, but not found on disk. 
Empty query.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'/w/unknown.png', '/w/unknown.png?' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '/w/unknown.png',
+   '/w/unknown.png?'
+   ],
// File not matching basePath. Ignored.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'/files/test.jpg' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '/files/test.jpg'
+   ],
// Empty string. Ignored.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', '', '' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '',
+   ''
+   ],
// Similar path, but with domain component. Ignored.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'//example.org/w/test.jpg' ],
-   [ 'baseDir' => $baseDir, 'basePath' => 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: OutputPage: Support UploadPath in testTransformResourcePath()

2017-02-09 Thread Krinkle (Code Review)
Krinkle has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336941 )

Change subject: OutputPage: Support UploadPath in testTransformResourcePath()
..

OutputPage: Support UploadPath in testTransformResourcePath()

Updated tests to reflect this use case. Currently we assume all web-accessible
paths within ResourceBasePath (e.g "/w") to exist on disk at the same path
in $IP (e.g. "/var/www/mw").

While in theory any number of web server rewrites or aliases could exist,
there is one case in particular that we should support since the information
is available in the configuration: UploadDir and UploadPath. This path may
be rewritten in a way that varies by wiki in multi-wiki installs that share
the same source code. E.g. a server may rewrite "/w/images" to somewhere
else, which means it will not match the directory on disk that is shared
between wikis.

Bug: T155146
Change-Id: I320478c9c262cc012f08b585b48d290594ec2420
---
M includes/OutputPage.php
M tests/phpunit/includes/OutputPageTest.php
2 files changed, 76 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/41/336941/1

diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 91fc75c..4d7104e 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -3697,6 +3697,7 @@
 */
public static function transformResourcePath( Config $config, $path ) {
global $IP;
+   $localDir = $IP;
$remotePathPrefix = $config->get( 'ResourceBasePath' );
if ( $remotePathPrefix === '' ) {
// The configured base path is required to be empty 
string for
@@ -3710,8 +3711,18 @@
// - Path is protocol-relative. Fixes T155310. Not 
supported by RelPath lib.
return $path;
}
+   // For files in resources, extensions/ or skins/, 
ResourceBasePath is preferred here.
+   // For other misc files in $IP, we'll fallback to that as well. 
There is, however, a fourth
+   // supported dir/path pair in the configuration 
(wgUploadDirectory, wgUploadPath).
+   // Which is not expected to be in wgResourceBasePath on CDNs. 
(T155146)
+   $uploadPath = $config->get( 'UploadPath' );
+   if ( strpos( $path, $uploadPath ) === 0 ) {
+   $localDir = $config->get( 'UploadDirectory' );
+   $remotePathPrefix = $remotePath = $uploadPath;
+   }
+
$path = RelPath\getRelativePath( $path, $remotePath );
-   return self::transformFilePath( $remotePathPrefix, $IP, $path );
+   return self::transformFilePath( $remotePathPrefix, $localDir, 
$path );
}
 
/**
diff --git a/tests/phpunit/includes/OutputPageTest.php 
b/tests/phpunit/includes/OutputPageTest.php
index d2494da..c34b58b 100644
--- a/tests/phpunit/includes/OutputPageTest.php
+++ b/tests/phpunit/includes/OutputPageTest.php
@@ -181,22 +181,63 @@
$baseDir = dirname( __DIR__ ) . '/data/media';
return [
// File that matches basePath, and exists. Hash found 
and appended.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'/w/test.jpg', '/w/test.jpg?edcf2' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '/w/test.jpg',
+   '/w/test.jpg?edcf2'
+   ],
// File that matches basePath, but not found on disk. 
Empty query.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'/w/unknown.png', '/w/unknown.png?' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '/w/unknown.png',
+   '/w/unknown.png?'
+   ],
// File not matching basePath. Ignored.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'/files/test.jpg' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '/files/test.jpg'
+   ],
// Empty string. Ignored.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', '', '' ],
+   [
+   'baseDir' => $baseDir, 'basePath' => '/w',
+   '',
+   ''
+   ],
// Similar path, but with domain component. Ignored.
-   [ 'baseDir' => $baseDir, 'basePath' => '/w', 
'//example.org/w/test.jpg' ],
-   [ 'baseDir' => $baseDir, 'basePath' => '/w',