MtDu has uploaded a new change for review.

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

Change subject: [WIP] Convert VipsScaler to use new extension registration
......................................................................

[WIP] Convert VipsScaler to use new extension registration

Bug: T87991
Change-Id: Ie3c98c5f41c5ddfe98b8ff2af1e138fa062719d3
---
A VipsScaler.hooks.php
D VipsScaler.i18n.php
M VipsScaler.php
A extension.json
4 files changed, 119 insertions(+), 132 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VipsScaler 
refs/changes/28/263028/1

diff --git a/VipsScaler.hooks.php b/VipsScaler.hooks.php
new file mode 100644
index 0000000..812f3c8
--- /dev/null
+++ b/VipsScaler.hooks.php
@@ -0,0 +1,11 @@
+<?php
+class VipsScalerHooks {
+       /**
+       * @param $files array
+       * @return bool
+       */
+       public static function onWfVipsScalerTests ( &$files ) {
+               $files[] = __DIR__ . '/tests/VipsScalerTest.php';
+               return true;
+       }
+}
diff --git a/VipsScaler.i18n.php b/VipsScaler.i18n.php
deleted file mode 100644
index 422d1cb..0000000
--- a/VipsScaler.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShim516b4d3ef6cda813' ) ) {
-       function wfJsonI18nShim516b4d3ef6cda813( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
-               foreach ( $codeSequence as $csCode ) {
-                       $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
-                       if ( is_readable( $fileName ) ) {
-                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
-                               foreach ( array_keys( $data ) as $key ) {
-                                       if ( $key === '' || $key[0] === '@' ) {
-                                               unset( $data[$key] );
-                                       }
-                               }
-                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
-                       }
-
-                       $cachedData['deps'][] = new FileDependency( $fileName );
-               }
-               return true;
-       }
-
-       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShim516b4d3ef6cda813';
-}
diff --git a/VipsScaler.php b/VipsScaler.php
index 7d62ca5..6bf063d 100644
--- a/VipsScaler.php
+++ b/VipsScaler.php
@@ -20,101 +20,16 @@
  * @file
  */
 
-$wgExtensionCredits['media'][] = array(
-       'path' => __FILE__,
-       'name' => 'VipsScaler',
-       'author' => array( 'Bryan Tong Minh' ),
-       'descriptionmsg' => 'vipsscaler-desc',
-       'url' => '//www.mediawiki.org/wiki/Extension:VipsScaler',
-       'license-name' => 'GPL-2.0+',
-);
-
-$dir = __DIR__;
-
-$wgAutoloadClasses['VipsScaler']      = "$dir/VipsScaler_body.php";
-$wgAutoloadClasses['VipsCommand']     = "$dir/VipsScaler_body.php";
-$wgAutoloadClasses['VipsConvolution'] = "$dir/VipsScaler_body.php";
-
-$wgMessagesDirs['VipsScaler'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['VipsScaler'] = "$dir/VipsScaler.i18n.php";
-
-$wgHooks['BitmapHandlerTransform'][] = 'VipsScaler::onTransform';
-$wgHooks['BitmapHandlerCheckImageArea'][] = 
'VipsScaler::onBitmapHandlerCheckImageArea';
-
-# Download vips from http://www.vips.ecs.soton.ac.uk/
-$wgVipsCommand = 'vips';
-
-/**
- * Options and conditions for images to be scaled with this scaler.
- * Set to an array of arrays. The inner array contains a condition array, which
- * contains a list of conditions that the image should pass for it to be scaled
- * with vips. Conditions are mimeType, minArea, maxArea, minShrinkFactor,
- * maxShrinkFactor. The other items in the array are options. Options available
- * are:
- * - sharpen: Set to an array with keys 'radius' and 'sigma', which are
- *   parameters to gaussian sharpen matrix.
- * - preconvert: Convert the file to a .v file first, which costs some space,
- *   but saves memory on the actual downsize
- * - bilinear: Use im_resize_linear instead of im_shrink
- * - convolution: Apply specified convolution matrix
- * - setcomment: Add an exif comment specifying the source of the file.
- *   Requires $wgExiv2Command to be set properly.
- */
-$wgVipsOptions = array(
-       # Sharpen jpeg files which are shrunk more than 1.2
-       array(
-               'conditions' => array(
-                       'mimeType' => 'image/jpeg',
-                       'minShrinkFactor' => 1.2,
-               ),
-               'sharpen' => array( 'radius' => 0, 'sigma' => 0.8 ),
-       ),
-       # Other jpeg files
-       array(
-               'conditions' => array(
-                       'mimeType' => 'image/jpeg',
-               ),
-               'sharpen' => false,
-               'bilinear' => true,
-       ),
-       # Do a simple shrink for PNGs
-       array(
-               'conditions' => array(
-                       'mimeType' => 'image/png',
-               ),
-       ),
-);
-
-# Package vipsScaler material in a resource loader module:
-$wgResourceModules['ext.vipsscaler'] = array(
-       'scripts' => array( 'ext.vipsScaler.js', ),
-       'styles' => array( 'ext.vipsScaler.css' ),
-       'messages' => array( 'vipsscaler-show-both', 'vipsscaler-show-default', 
'vipsscaler-show-vips' ),
-       'dependencies' => array(
-               'jquery.ucompare',
-       ),
-
-       'localBasePath' => __DIR__ . '/modules/ext.vipsScaler',
-       'remoteExtPath' => 'VipsScaler/modules/ext.vipsScaler',
-);
-
-# Also package upstream jquery.ucompare
-$wgResourceModules['jquery.ucompare'] = array(
-       'scripts' => array( 'js/jquery.ucompare.js', ),
-       'styles' => array( 'css/jquery.ucompare.css' ),
-
-       'localBasePath' => __DIR__ . '/modules/jquery.ucompare',
-       'remoteExtPath' => 'VipsScaler/modules/jquery.ucompare'
-);
-
-$wgHooks['UnitTestsList'][] = 'wfVipsScalerTests';
-
-/**
- * @param $files array
- * @return bool
- */
-function wfVipsScalerTests( &$files ) {
-       $files[] = __DIR__ . '/tests/VipsScalerTest.php';
-       return true;
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'VipsScaler' );
+       // Keep i18n globals so mergeMessageFileList.php doesn't break
+       $wgMessagesDirs['VipsScaler'] = __DIR__ . '/i18n';
+       $wgExtensionMessagesFiles['VipsScalerAlias'] = __DIR__ . 
'/VipsScaler.alias.php';
+       /*wfWarn(
+               'Deprecated PHP entry point used for VipsScaler extension. 
Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );*/
+       return;
+} else {
+       die( 'This version of the VipsScaler extension requires MediaWiki 
1.25+' );
 }
-
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..7eef35b
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,96 @@
+{
+       "name": "VipsScaler",
+       "author": [
+               "Bryan Tong Minh"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:VipsScaler";,
+       "descriptionmsg": "vipsscaler-desc",
+       "license-name": "GPL-2.0+",
+       "type": "media",
+       "AutoloadClasses": {
+               "VipsScaler": "VipsScaler_body.php",
+               "VipsCommand": "VipsScaler_body.php",
+               "VipsConvolution": "VipsScaler_body.php"
+       },
+       "MessageDirs": {
+               "VipsScaler": [
+                       "i18n"
+               ]
+       },
+       "ExtensionMessageFiles": {
+               "VipsScalerAlias": "VipsScaler.alias.php"
+       },
+       "Hooks": {
+               "BitmapHandlerTransform": [
+                       "VipsScaler::onTransform"
+               ],
+               "BitmapHandlerCheckImageArea": [
+                       "VipsScaler::onBitmapHandlerCheckImageArea"
+               ],
+               "UnitTestsList": [
+                       "VipsScalerHooks::onWfVipsScalerTests"
+               ]
+       },
+       "VipsCommand": "vips",
+       "VipsOptions": [
+               {
+                       "conditions": {
+                               "mimeType": "image/jpeg",
+                               "minShrinkFactor": 1.2
+                       },
+                       "sharpen": {
+                               "radius": 0,
+                               "sigma": 0.8
+                       }
+               },
+               {
+                       "conditions": {
+                               "mimeType": "image/jpeg"
+                       },
+                       "sharpen": false,
+                       "bilinear": true
+               },
+               {
+                       "conditions": {
+                               "mimeType": "image/png"
+                       }
+               }
+       ],
+       "ResourceFileModulePaths": {
+               "ext.vipsScaler": {
+                       "localBasePath": "modules/ext.vipsScaler",
+                       "remoteExtPath": "VipsScaler/modules/ext.vipsScaler"
+               },
+               "jquery.ucompare": {
+                       "localBasePath": "modules/jquery.ucompare",
+                       "remoteExtPath": "VipsScaler/modules/jquery.ucompare"
+               }
+       },
+       "ResourceModules": {
+               "ext.vipsscaler": {
+                       "scripts": [
+                               "ext.vipsScaler.js"
+                       ],
+                       "styles": [
+                               "ext.vipsScaler.css"
+                       ],
+                       "messages": [
+                               "vipsscaler-show-both",
+                               "vipsscaler-show-default",
+                               "vipsscaler-show-vips"
+                       ],
+                       "dependencies": [
+                               "jquery.ucompare"
+                       ]
+               },
+               "jquery.ucompare": {
+                       "scripts": [
+                               "js/jquery.ucompare.js"
+                       ],
+                       "styles": [
+                               "css/jquery.ucompare.css"
+                       ]
+               }
+       },
+       "manifest_version": 1
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3c98c5f41c5ddfe98b8ff2af1e138fa062719d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VipsScaler
Gerrit-Branch: master
Gerrit-Owner: MtDu <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to