Paladox has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/272918

Change subject: Fix resource path check when ResourceBasePath is an empty string
......................................................................

Fix resource path check when ResourceBasePath is an empty string

If you have MediaWiki installed in the root of the domain, then
$wgScriptPath and $wgResourceBasePath is an empty string. In HHVM and
PHP, passing an empty string as the second parameter of strpos() causes
a warning and returns false, which will cause the condition to fail, as
if the path were not within the base path.

So, normalize such paths. Using substr() instead of strpos() for a
"starts with" check would have worked except that RelPath also fails
when given an empty string.

Bug: T127652
Change-Id: If7e94ae638d6834f7cc0f31f67a5fe6a2f74771c
(cherry picked from commit a2530a9fb83a20f5520ba726873e2260a3b4fd26)
---
M includes/OutputPage.php
1 file changed, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/18/272918/1

diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 317c126..f0b4f23 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -3869,13 +3869,20 @@
         */
        public static function transformResourcePath( Config $config, $path ) {
                global $IP;
-               $remotePath = $config->get( 'ResourceBasePath' );
+               $remotePathPrefix = $config->get( 'ResourceBasePath' );
+               if ( $remotePathPrefix === '' ) {
+                       // The configured base path is required to be empty 
string for
+                       // wikis in the domain root
+                       $remotePath = '/';
+               } else {
+                       $remotePath = $remotePathPrefix;
+               }
                if ( strpos( $path, $remotePath ) !== 0 ) {
                        // Path is outside wgResourceBasePath, ignore.
                        return $path;
                }
                $path = RelPath\getRelativePath( $path, $remotePath );
-               return self::transformFilePath( $remotePath, $IP, $path );
+               return self::transformFilePath( $remotePathPrefix, $IP, $path );
        }
 
        /**
@@ -3884,18 +3891,18 @@
         * Caller is responsible for ensuring the file exists. Emits a PHP 
warning otherwise.
         *
         * @since 1.27
-        * @param string $remotePath URL path that points to $localPath
+        * @param string $remotePath URL path prefix that points to $localPath
         * @param string $localPath File directory exposed at $remotePath
         * @param string $file Path to target file relative to $localPath
         * @return string URL
         */
-       public static function transformFilePath( $remotePath, $localPath, 
$file ) {
+       public static function transformFilePath( $remotePathPrefix, 
$localPath, $file ) {
                $hash = md5_file( "$localPath/$file" );
                if ( $hash === false ) {
                        wfLogWarning( __METHOD__ . ": Failed to hash 
$localPath/$file" );
                        $hash = '';
                }
-               return "$remotePath/$file?" . substr( $hash, 0, 5 );
+               return "$remotePathPrefix/$file?" . substr( $hash, 0, 5 );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If7e94ae638d6834f7cc0f31f67a5fe6a2f74771c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.27.0-wmf.13
Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com>
Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org>

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

Reply via email to