/**
  * Make file paths relative to MediaWiki directory.
  *
  * This is used to make file paths safe for storing in a database without the paths
  * becoming stale or incorrect when MediaWiki is moved or upgraded (T111481).
  *
  * @since 1.26
  * @param array $filePaths
  * @return array
  */
 protected static function getRelativePaths(array $filePaths)
 {
     global $IP;
     return array_map(function ($path) use($IP) {
         return RelPath\getRelativePath($path, $IP);
     }, $filePaths);
 }
Example #2
0
 /**
  * Transform path to web-accessible static resource.
  *
  * This is used to add a validation hash as query string.
  * This aids various behaviors:
  *
  * - Put long Cache-Control max-age headers on responses for improved
  *   cache performance.
  * - Get the correct version of a file as expected by the current page.
  * - Instantly get the updated version of a file after deployment.
  *
  * Avoid using this for urls included in HTML as otherwise clients may get different
  * versions of a resource when navigating the site depending on when the page was cached.
  * If changes to the url propagate, this is not a problem (e.g. if the url is in
  * an external stylesheet).
  *
  * @since 1.27
  * @param Config $config
  * @param string $path Path-absolute URL to file (from document root, must start with "/")
  * @return string URL
  */
 public static function transformResourcePath(Config $config, $path)
 {
     global $IP;
     $remotePath = $config->get('ResourceBasePath');
     if (strpos($path, $remotePath) !== 0) {
         // Path is outside wgResourceBasePath, ignore.
         return $path;
     }
     $path = RelPath\getRelativePath($path, $remotePath);
     return self::transformFilePath($remotePath, $IP, $path);
 }
Example #3
0
 /**
  * Transform path to web-accessible static resource.
  *
  * This is used to add a validation hash as query string.
  * This aids various behaviors:
  *
  * - Put long Cache-Control max-age headers on responses for improved
  *   cache performance.
  * - Get the correct version of a file as expected by the current page.
  * - Instantly get the updated version of a file after deployment.
  *
  * Avoid using this for urls included in HTML as otherwise clients may get different
  * versions of a resource when navigating the site depending on when the page was cached.
  * If changes to the url propagate, this is not a problem (e.g. if the url is in
  * an external stylesheet).
  *
  * @since 1.27
  * @param Config $config
  * @param string $path Path-absolute URL to file (from document root, must start with "/")
  * @return string URL
  */
 public static function transformResourcePath(Config $config, $path)
 {
     global $IP;
     $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($remotePathPrefix, $IP, $path);
 }