From: Timo Tijhof Date: Sat, 25 Aug 2018 04:43:43 +0000 (+0100) Subject: maintenance: Implement 'file' type and use for jquery and qunitjs X-Git-Tag: 1.34.0-rc.0~4271^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/Boston?a=commitdiff_plain;h=81e5d5e24e2507a8506a202983d9b76e9a02866a;p=lhc%2Fweb%2Fwiklou.git maintenance: Implement 'file' type and use for jquery and qunitjs Change-Id: I05243e5a73664353d2b27ffca14ef0b6a3c86eaf --- diff --git a/maintenance/resources/foreign-resources.yaml b/maintenance/resources/foreign-resources.yaml index 8a21d40d1d..6a02eea298 100644 --- a/maintenance/resources/foreign-resources.yaml +++ b/maintenance/resources/foreign-resources.yaml @@ -1,10 +1,12 @@ ### Format of this file # # The top-level keys are module names (as registered in Resources.php). -# Each top-level key holds a resource descriptor that must have -# the following `type` value: +# Each top-level key holds a resource descriptor that must have one of +# the following `type` values: # # - `tar`: For tarball archive (may be gzip-compressed). +# - `file: For a plain file. +# - `multi-file`: For multiple plain files. # ### Type tar # @@ -15,6 +17,21 @@ # * `dest`: An object mapping paths to files or directory from the remote resource to a destination # in the module directory. The value of key in dest may be omitted, which will extract the key # directly to the module directory. +# +### Type file +# +# The `src` and `integrity` keys are quired. +# +# * `src`: Full URL to thes remote resource. +# * `integrity`: Cryptographic hash (integrity metadata format per ). +# * `dest`: The name of the file in the module directory. Default: Basename of URL. +# +### Type mult-file +# +# The `files` key is required. +# +# * `files`: An object mapping destination paths to an object containing `src` and `integrity` +# keys. oojs: type: tar src: https://registry.npmjs.org/oojs/-/oojs-2.2.2.tgz @@ -54,3 +71,18 @@ oojs-ui: package/dist/History.md: package/dist/LICENSE-MIT: package/dist/README.md: +jquery: + type: file + src: https://code.jquery.com/jquery-3.2.1.js + # From https://code.jquery.com/jquery/ + integrity: sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE= + dest: jquery.js +qunitjs: + type: multi-file + files: + qunit.js: + src: https://code.jquery.com/qunit/qunit-2.6.0.js + integrity: sha384-5O3bKbJBbAbxsqV+w/I1fcXgWJgbqM+hmYAPOE9aELSYpcTEsv48X8H+Hnq66V/9 + qunit.css: + src: https://code.jquery.com/qunit/qunit-2.6.0.css + integrity: sha384-8vDvsmsuiD7tCQyC+pW2LOwDDgsluGsIPeCqr3rHsDSF2k4WpmfvKKxcgSV5zPai diff --git a/maintenance/resources/manageForeignResources.php b/maintenance/resources/manageForeignResources.php index 6065401f24..41e579ba39 100644 --- a/maintenance/resources/manageForeignResources.php +++ b/maintenance/resources/manageForeignResources.php @@ -99,6 +99,12 @@ TEXT case 'tar': $this->handleTypeTar( $moduleName, $destDir, $info ); break; + case 'file': + $this->handleTypeFile( $moduleName, $destDir, $info ); + break; + case 'multi-file': + $this->handleTypeMultiFile( $moduleName, $destDir, $info ); + break; default: $this->fatalError( "Unknown type '{$info['type']}' for '$moduleName'" ); } @@ -134,6 +140,40 @@ TEXT return $data; } + private function handleTypeFile( $moduleName, $destDir, array $info ) { + if ( !isset( $info['src'] ) ) { + $this->fatalError( "Module '$moduleName' must have a 'src' key." ); + } + $data = $this->fetch( $info['src'], $info['integrity'] ?? null ); + $dest = $info['dest'] ?? basename( $info['src'] ); + $path = "$destDir/$dest"; + if ( $this->action === 'verify' && sha1_file( $path ) !== sha1( $data ) ) { + $this->fatalError( "File for '$moduleName' is different." ); + } elseif ( $this->action === 'update' ) { + wfMkdirParents( $destDir ); + file_put_contents( "$destDir/$dest", $data ); + } + } + + private function handleTypeMultiFile( $moduleName, $destDir, array $info ) { + if ( !isset( $info['files'] ) ) { + $this->fatalError( "Module '$moduleName' must have a 'files' key." ); + } + foreach ( $info['files'] as $dest => $file ) { + if ( !isset( $file['src'] ) ) { + $this->fatalError( "Module '$moduleName' file '$dest' must have a 'src' key." ); + } + $data = $this->fetch( $file['src'], $file['integrity'] ?? null ); + $path = "$destDir/$dest"; + if ( $this->action === 'verify' && sha1_file( $path ) !== sha1( $data ) ) { + $this->fatalError( "File '$dest' for '$moduleName' is different." ); + } elseif ( $this->action === 'update' ) { + wfMkdirParents( $destDir ); + file_put_contents( "$destDir/$dest", $data ); + } + } + } + private function handleTypeTar( $moduleName, $destDir, array $info ) { $info += [ 'src' => null, 'integrity' => null, 'dest' => null ]; if ( $info['src'] === null ) {