Mw_parse: Add more support for original files

pull/620/head
gnosygnu 8 years ago
parent e4e899f72a
commit ffc112a085

@ -20,6 +20,7 @@ public class Php_utl_ {
public static boolean Empty(byte[] v) {return v == null || v.length == 0;} public static boolean Empty(byte[] v) {return v == null || v.length == 0;}
public static boolean Empty(boolean v) {return v == false;} public static boolean Empty(boolean v) {return v == false;}
public static boolean Is_set(byte[] v) {return v != null;} public static boolean Is_set(byte[] v) {return v != null;}
public static boolean isset(int v) {return v != Int_.Max_value;}
public static boolean isnumeric(byte[] src) { public static boolean isnumeric(byte[] src) {
if (src == null) return false; if (src == null) return false;
int len = src.length; int len = src.length;

@ -123,8 +123,8 @@ public class Xomw_linker {
postfix = Gfh_tag_.Div_rhs; postfix = Gfh_tag_.Div_rhs;
frame_params.align = Align__frame__none; frame_params.align = Align__frame__none;
} }
if (file != null && handler_params.width == -1) { if (file != null && handler_params.width == Xomw_param_itm.Null_int) {
if (handler_params.height != -1 && file.isVectorized()) { if (handler_params.height != Xomw_param_itm.Null_int && file.isVectorized()) {
// If its a vector image, and user only specifies height // If its a vector image, and user only specifies height
// we don't want it to be limited by its "normal" width. // we don't want it to be limited by its "normal" width.
// global $wgSVGMaxSize; // global $wgSVGMaxSize;
@ -138,7 +138,7 @@ public class Xomw_linker {
|| frame_params.manual_thumb != null || frame_params.manual_thumb != null
|| frame_params.framed != null || frame_params.framed != null
|| frame_params.frameless != null || frame_params.frameless != null
|| handler_params.width == -1 || handler_params.width == Xomw_param_itm.Null_int
) { ) {
// global $wgThumbLimits, $wgThumbUpright; // global $wgThumbLimits, $wgThumbUpright;
@ -161,7 +161,7 @@ public class Xomw_linker {
// Use width which is smaller: real image width or user preference width // Use width which is smaller: real image width or user preference width
// Unless image is scalable vector. // Unless image is scalable vector.
if (handler_params.height == -1 && handler_params.width <= 0 || if (handler_params.height == Xomw_param_itm.Null_int && handler_params.width <= 0 ||
pref_width < handler_params.width || file.isVectorized()) { pref_width < handler_params.width || file.isVectorized()) {
handler_params.width = pref_width; handler_params.width = pref_width;
} }
@ -190,17 +190,15 @@ public class Xomw_linker {
// For "frameless" option: do not present an image bigger than the // For "frameless" option: do not present an image bigger than the
// source (for bitmap-style images). This is the same behavior as the // source (for bitmap-style images). This is the same behavior as the
// "thumb" option does it already. // "thumb" option does it already.
if (src_width != -1 && !file.mustRender() && handler_params.width > src_width) { if (src_width != Xomw_param_itm.Null_int && !file.mustRender() && handler_params.width > src_width) {
handler_params.width = src_width; handler_params.width = src_width;
} }
} }
Xomw_MediaTransformOutput thumb = null; Xomw_MediaTransformOutput thumb = null;
if (file != null && handler_params.width != -1) { if (file != null && handler_params.width != Xomw_param_itm.Null_int) {
// Create a resized image, without the additional thumbnail features // Create a resized image, without the additional thumbnail features
// $thumb = $file->transform(handler_params); thumb = file.transform(handler_params);
// file.getPath()
thumb = new Xomw_MediaTransformOutput(file, file.getUrl(), file.getUrl(), file.getWidth(), file.getHeight());
} }
else { else {
thumb = null; thumb = null;
@ -291,9 +289,9 @@ public class Xomw_linker {
frame_params.caption = Bry_.Empty; frame_params.caption = Bry_.Empty;
} }
if (handler_params.width == -1) { if (handler_params.width == Xomw_param_itm.Null_int) {
// Reduce width for upright images when parameter 'upright' is used // Reduce width for upright images when parameter 'upright' is used
handler_params.width = frame_params.upright != -1 ? 130 : 180; handler_params.width = frame_params.upright != Xomw_param_itm.Null_int ? 130 : 180;
} }
boolean no_scale = false; boolean no_scale = false;
boolean manual_thumb = false; boolean manual_thumb = false;
@ -327,7 +325,7 @@ public class Xomw_linker {
// Do not present an image bigger than the source, for bitmap-style images // Do not present an image bigger than the source, for bitmap-style images
// This is a hack to maintain compatibility with arbitrary pre-1.10 behavior // This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
int src_width = file.getWidth(page); int src_width = file.getWidth(page);
if (src_width != -1 && !file.mustRender() && handler_params.width > src_width) { if (src_width != Xomw_param_itm.Null_int && !file.mustRender() && handler_params.width > src_width) {
handler_params.width = src_width; handler_params.width = src_width;
} }
// thumb = $file->transform(handler_params); // thumb = $file->transform(handler_params);

@ -751,8 +751,8 @@ public class Xomw_File {
* @return boolean * @return boolean
*/ */
public boolean mustRender() { public boolean mustRender() {
return true; Xomw_MediaHandler handler = this.getHandler();
// return this.getHandler() && this.handler.mustRender(this); return handler.mustRender(this);
} }
/** /**
@ -1030,7 +1030,7 @@ public class Xomw_File {
* @param int flags A bitfield, may contain self::RENDER_NOW to force rendering * @param int flags A bitfield, may contain self::RENDER_NOW to force rendering
* @return ThumbnailImage|MediaTransformOutput|boolean False on failure * @return ThumbnailImage|MediaTransformOutput|boolean False on failure
*/ */
// XO.MW.DFLT:flags=0; public Xomw_MediaTransformOutput transform(Xomw_params_handler handlerParams) {return transform(handlerParams, 0);}
public Xomw_MediaTransformOutput transform(Xomw_params_handler handlerParams, int flags) { public Xomw_MediaTransformOutput transform(Xomw_params_handler handlerParams, int flags) {
// global wgThumbnailEpoch; // global wgThumbnailEpoch;
@ -1060,8 +1060,8 @@ public class Xomw_File {
// handler.normaliseParams(this, normalisedParams); // handler.normaliseParams(this, normalisedParams);
byte[] thumbName = this.thumbName(normalisedParams); byte[] thumbName = this.thumbName(normalisedParams);
byte[] thumbUrl = this.getThumbUrl(thumbName); // byte[] thumbUrl = this.getThumbUrl(thumbName);
byte[] thumbPath = this.getThumbPath(thumbName); // final thumb path // byte[] thumbPath = this.getThumbPath(thumbName); // final thumb path
if (this.repo != null) { if (this.repo != null) {
// // Defer rendering if a 404 handler is set up... // // Defer rendering if a 404 handler is set up...
@ -1081,9 +1081,9 @@ public class Xomw_File {
// // XXX: Pass in the storage path even though we are not rendering anything // // XXX: Pass in the storage path even though we are not rendering anything
// // and the path is supposed to be an FS path. This is due to getScalerType() // // and the path is supposed to be an FS path. This is due to getScalerType()
// // getting called on the path and clobbering thumb.getUrl() if it's false. // // getting called on the path and clobbering thumb.getUrl() if it's false.
thumb = handler.getTransform(this, thumbPath, thumbUrl, handlerParams); // thumb = handler.getTransform(this, thumbPath, thumbUrl, handlerParams);
// thumb.setStoragePath(thumbPath); // thumb.setStoragePath(thumbPath);
break; // break;
// } // }
} }
// elseif (flags & self::RENDER_FORCE) { // elseif (flags & self::RENDER_FORCE) {
@ -1097,13 +1097,14 @@ public class Xomw_File {
// break; // break;
// } // }
// } // }
// Object tmpFile = null; Object tmpFile = null;
// tmpFile = this.makeTransformTmpFile(thumbPath); // tmpFile = this.makeTransformTmpFile(thumbPath);
// //
// if (!tmpFile) { // if (!tmpFile) {
// thumb = this.transformErrorOutput(thumbPath, thumbUrl, paramsMap, flags); // thumb = this.transformErrorOutput(thumbPath, thumbUrl, paramsMap, flags);
// } else { // } else {
// thumb = this.generateAndSaveThumb(tmpFile, paramsMap, flags); thumb = this.generateAndSaveThumb(tmpFile, handlerParams, flags);
break;
// } // }
} while (thumb != null); } while (thumb != null);
@ -1117,22 +1118,23 @@ public class Xomw_File {
* @param int flags * @param int flags
* @return boolean|MediaTransformOutput * @return boolean|MediaTransformOutput
*/ */
public Object generateAndSaveThumb(Object tmpFile, Object transformParams, int flags) { public Xomw_MediaTransformOutput generateAndSaveThumb(Object tmpFile, Xomw_params_handler transformParams, int flags) {
// global wgIgnoreImageErrors; // global wgIgnoreImageErrors;
// //
// stats = RequestContext::getMain().getStats(); // stats = RequestContext::getMain().getStats();
//
// handler = this.getHandler(); Xomw_MediaHandler handler = this.getHandler();
//
// normalisedParams = transformParams; Xomw_params_handler normalisedParams = transformParams;
// handler.normaliseParams(this, normalisedParams); handler.normaliseParams(this, normalisedParams);
//
// thumbName = this.thumbName(normalisedParams); byte[] thumbName = this.thumbName(normalisedParams);
// thumbUrl = this.getThumbUrl(thumbName); byte[] thumbUrl = this.getThumbUrl(thumbName);
// thumbPath = this.getThumbPath(thumbName); // final thumb path // byte[] thumbPath = this.getThumbPath(thumbName); // final thumb path
//
// tmpThumbPath = tmpFile.getPath(); // tmpThumbPath = tmpFile.getPath();
// byte[] tmpThumbPath = Bry_.Empty;
// if (handler.supportsBucketing()) { // if (handler.supportsBucketing()) {
// this.generateBucketsIfNeeded(normalisedParams, flags); // this.generateBucketsIfNeeded(normalisedParams, flags);
// } // }
@ -1140,8 +1142,7 @@ public class Xomw_File {
// starttime = microtime(true); // starttime = microtime(true);
// //
// Actually render the thumbnail... // Actually render the thumbnail...
Object thumb = null; Xomw_MediaTransformOutput thumb = handler.doTransform(this, tmpThumbPath, thumbUrl, transformParams);
// thumb = handler.doTransform(this, tmpThumbPath, thumbUrl, transformParams);
// tmpFile.bind(thumb); // keep alive with thumb // tmpFile.bind(thumb); // keep alive with thumb
// //
// statTiming = microtime(true) - starttime; // statTiming = microtime(true) - starttime;

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.parsers.lnkis.*; import gplx.xowa.mws.filerepo.file.*; import gplx.xowa.mws.parsers.lnkis.*;
import gplx.langs.phps.utls.*;
// MEMORY:only one instance per wiki // MEMORY:only one instance per wiki
public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private final Xomw_param_map paramMap = new Xomw_param_map(); public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private final Xomw_param_map paramMap = new Xomw_param_map();
public Xomw_ImageHandler(byte[] key) {super(key); public Xomw_ImageHandler(byte[] key) {super(key);
@ -27,7 +28,7 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
* @return boolean * @return boolean
*/ */
@Override public boolean canRender(Xomw_File file) { @Override public boolean canRender(Xomw_File file) {
return (file.getWidth(1) != -1 && file.getHeight(1) != -1); return (file.getWidth(1) != Xomw_param_itm.Null_int && file.getHeight(1) != Xomw_param_itm.Null_int);
} }
@Override public Xomw_param_map getParamMap() { @Override public Xomw_param_map getParamMap() {
@ -50,10 +51,10 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
@Override public byte[] makeParamString(Xomw_params_handler handlerParams) { @Override public byte[] makeParamString(Xomw_params_handler handlerParams) {
int width = 0; int width = 0;
if (handlerParams.physicalWidth != -1) { if (handlerParams.physicalWidth != Xomw_param_itm.Null_int) {
width = handlerParams.physicalWidth; width = handlerParams.physicalWidth;
} }
else if (handlerParams.width != -1) { else if (handlerParams.width != Xomw_param_itm.Null_int) {
width = handlerParams.width; width = handlerParams.width;
} }
else { else {
@ -74,81 +75,82 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// } // }
// } // }
// //
// function getScriptParams(params) { // function getScriptParams(paramsVar) {
// return [ 'width' => params['width'] ]; // return [ 'width' => paramsVar['width'] ];
// } // }
//
// /** /**
// * @param File image * @param File image
// * @param array params * @param array paramsVar
// * @return boolean * @return boolean
// */ */
// function normaliseParams(image, &params) { @Override public boolean normaliseParams(Xomw_File image, Xomw_params_handler handlerParams) {
// mimeType = image.getMimeType(); // mimeType = image.getMimeType();
//
// if (!isset(params['width'])) { if (!Php_utl_.isset(handlerParams.width)) {
// return false; return false;
// } }
//
// if (!isset(params['page'])) { if (!Php_utl_.isset(handlerParams.page)) {
// params['page'] = 1; handlerParams.page = 1;
// } else { }
// params['page'] = intval(params['page']); else {
// if (params['page'] > image.pageCount()) { // handlerParams.page = intval(handlerParams.page);
// params['page'] = image.pageCount(); // if (handlerParams.page > image.pageCount()) {
// } // handlerParams.page = image.pageCount();
//
// if (params['page'] < 1) {
// params['page'] = 1;
// } // }
// }
//
// srcWidth = image.getWidth(params['page']);
// srcHeight = image.getHeight(params['page']);
// //
// if (isset(params['height']) && params['height'] != -1) { // if (handlerParams.page < 1) {
// # Height & width were both set // handlerParams.page = 1;
// if (params['width'] * srcHeight > params['height'] * srcWidth) {
// # Height is the relative smaller dimension, so scale width accordingly
// params['width'] = self::fitBoxWidth(srcWidth, srcHeight, params['height']);
//
// if (params['width'] == 0) {
// # Very small image, so we need to rely on client side scaling :(
// params['width'] = 1;
// }
//
// params['physicalWidth'] = params['width'];
// } else {
// # Height was crap, unset it so that it will be calculated later
// unset(params['height']);
// } // }
// } }
//
// if (!isset(params['physicalWidth'])) { int srcWidth = image.getWidth(handlerParams.page);
// # Passed all validations, so set the physicalWidth int srcHeight = image.getHeight(handlerParams.page);
// params['physicalWidth'] = params['width'];
// } if (Php_utl_.isset(handlerParams.height) && handlerParams.height != -1) {
// // Height & width were both set
// # Because thumbs are only referred to by width, the height always needs if (handlerParams.width * srcHeight > handlerParams.height * srcWidth) {
// # to be scaled by the width to keep the thumbnail sizes consistent, // Height is the relative smaller dimension, so scale width accordingly
// # even if it was set inside the if block above // handlerParams.width = self::fitBoxWidth(srcWidth, srcHeight, handlerParams.height);
// params['physicalHeight'] = File::scaleHeight(srcWidth, srcHeight,
// params['physicalWidth']); if (handlerParams.width == 0) {
// // Very small image, so we need to rely on client side scaling :(
// # Set the height if it was not validated in the if block higher up handlerParams.width = 1;
// if (!isset(params['height']) || params['height'] == -1) { }
// params['height'] = params['physicalHeight'];
// } handlerParams.physicalWidth = handlerParams.width;
// } else {
// if (!this.validateThumbParams(params['physicalWidth'], // Height was crap, unset it so that it will be calculated later
// params['physicalHeight'], srcWidth, srcHeight, mimeType) handlerParams.height = Xomw_param_itm.Null_int;
}
}
if (!Php_utl_.isset(handlerParams.physicalWidth)) {
// Passed all validations, so set the physicalWidth
handlerParams.physicalWidth = handlerParams.width;
}
// Because thumbs are only referred to by width, the height always needs
// to be scaled by the width to keep the thumbnail sizes consistent,
// even if it was set inside the if block above
// handlerParams.physicalHeight = File::scaleHeight(srcWidth, srcHeight,
// handlerParams.physicalWidth);
// Set the height if it was not validated in the if block higher up
if (!Php_utl_.isset(handlerParams.height) || handlerParams.height == -1) {
handlerParams.height = handlerParams.physicalHeight;
}
// if (!this.validateThumbParams(handlerParams.physicalWidth,
// handlerParams.physicalHeight, srcWidth, srcHeight, mimeType)
// ) { // ) {
// return false; // return false;
// } // }
//
// return true; return true;
// } }
//
// /** // /**
// * Validate thumbnail parameters and fill in the correct height // * Validate thumbnail parameters and fill in the correct height
// * // *
@ -186,17 +188,17 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// /** // /**
// * @param File image // * @param File image
// * @param String script // * @param String script
// * @param array params // * @param array paramsVar
// * @return boolean|MediaTransformOutput // * @return boolean|MediaTransformOutput
// */ // */
// function getScriptedTransform(image, script, params) { // function getScriptedTransform(image, script, paramsVar) {
// if (!this.normaliseParams(image, params)) { // if (!this.normaliseParams(image, paramsVar)) {
// return false; // return false;
// } // }
// url = wfAppendQuery(script, this.getScriptParams(params)); // url = wfAppendQuery(script, this.getScriptParams(paramsVar));
// //
// if (image.mustRender() || params['width'] < image.getWidth()) { // if (image.mustRender() || paramsVar['width'] < image.getWidth()) {
// return new ThumbnailImage(image, url, false, params); // return new ThumbnailImage(image, url, false, paramsVar);
// } // }
// } // }
// //
@ -244,11 +246,11 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// size = htmlspecialchars(wgLang.formatSize(file.getSize())); // size = htmlspecialchars(wgLang.formatSize(file.getSize()));
// if (pages === false || pages <= 1) { // if (pages === false || pages <= 1) {
// msg = wfMessage('file-info-size').numParams(file.getWidth(), // msg = wfMessage('file-info-size').numParams(file.getWidth(),
// file.getHeight()).params(size, // file.getHeight()).paramsVar(size,
// '<span class="mime-type">' . file.getMimeType() . '</span>').parse(); // '<span class="mime-type">' . file.getMimeType() . '</span>').parse();
// } else { // } else {
// msg = wfMessage('file-info-size-pages').numParams(file.getWidth(), // msg = wfMessage('file-info-size-pages').numParams(file.getWidth(),
// file.getHeight()).params(size, // file.getHeight()).paramsVar(size,
// '<span class="mime-type">' . file.getMimeType() . '</span>').numParams(pages).parse(); // '<span class="mime-type">' . file.getMimeType() . '</span>').numParams(pages).parse();
// } // }
// //
@ -270,19 +272,19 @@ public abstract class Xomw_ImageHandler extends Xomw_MediaHandler { private fina
// } // }
// } // }
// //
// public function sanitizeParamsForBucketing(params) { // public function sanitizeParamsForBucketing(paramsVar) {
// params = parent::sanitizeParamsForBucketing(params); // paramsVar = parent::sanitizeParamsForBucketing(paramsVar);
// //
// // We unset the height parameters in order to let normaliseParams recalculate them // // We unset the height parameters in order to let normaliseParams recalculate them
// // Otherwise there might be a height discrepancy // // Otherwise there might be a height discrepancy
// if (isset(params['height'])) { // if (isset(paramsVar['height'])) {
// unset(params['height']); // unset(paramsVar['height']);
// } // }
// //
// if (isset(params['physicalHeight'])) { // if (isset(paramsVar['physicalHeight'])) {
// unset(params['physicalHeight']); // unset(paramsVar['physicalHeight']);
// } // }
// //
// return params; // return paramsVar;
// } // }
} }

@ -75,16 +75,16 @@ public abstract class Xomw_MediaHandler {
// * @return array|boolean Array of parameters or false on failure. // * @return array|boolean Array of parameters or false on failure.
// */ // */
// abstract public function parseParamString($str); // abstract public function parseParamString($str);
//
// /** /**
// * Changes the parameter array as necessary, ready for transformation. * Changes the parameter array as necessary, ready for transformation.
// * Should be idempotent. * Should be idempotent.
// * Returns false if the parameters are unacceptable and the transform should fail * Returns false if the parameters are unacceptable and the transform should fail
// * @param File $image * @param File $image
// * @param array $paramsVar * @param array $paramsVar
// */ */
// abstract function normaliseParams($image, &$paramsVar); public abstract boolean normaliseParams(Xomw_File image, Xomw_params_handler handlerParams);
//
// /** // /**
// * Get an image size array like that returned by getimagesize(), or false if it // * Get an image size array like that returned by getimagesize(), or false if it
// * can't be determined. // * can't be determined.
@ -274,7 +274,7 @@ public abstract class Xomw_MediaHandler {
* @param int $flags A bitfield, may contain self::TRANSFORM_LATER * @param int $flags A bitfield, may contain self::TRANSFORM_LATER
* @return MediaTransformOutput * @return MediaTransformOutput
*/ */
// XO.MW:flags=0 public Xomw_MediaTransformOutput doTransform(Xomw_File image, byte[] dstPath, byte[] dstUrl, Xomw_params_handler handlerParams) {return doTransform(image, dstPath, dstUrl, handlerParams, 0);}
public abstract Xomw_MediaTransformOutput doTransform(Xomw_File image, byte[] dstPath, byte[] dstUrl, Xomw_params_handler handlerParams, int flags); public abstract Xomw_MediaTransformOutput doTransform(Xomw_File image, byte[] dstPath, byte[] dstUrl, Xomw_params_handler handlerParams, int flags);
// /** // /**
@ -320,18 +320,18 @@ public abstract class Xomw_MediaHandler {
@gplx.Virtual public boolean canRender(Xomw_File file) { @gplx.Virtual public boolean canRender(Xomw_File file) {
return true; return true;
} }
//
// /** /**
// * True if handled types cannot be displayed directly in a browser * True if handled types cannot be displayed directly in a browser
// * but can be rendered * but can be rendered
// * *
// * @param File $file * @param File $file
// * @return boolean * @return boolean
// */ */
// public function mustRender($file) { public boolean mustRender(Xomw_File file) {
// return false; return false;
// } }
//
// /** // /**
// * True if the type has multi-page capabilities // * True if the type has multi-page capabilities
// * // *

@ -21,37 +21,37 @@ import gplx.xowa.mws.parsers.lnkis.*;
public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { public Xomw_TransformationalImageHandler(byte[] key) {super(key); public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { public Xomw_TransformationalImageHandler(byte[] key) {super(key);
} }
// /** /**
// * @param File image * @param File image
// * @param array paramsVar Transform parameters. Entries with the keys 'width' * @param array paramsVar Transform parameters. Entries with the keys 'width'
// * and 'height' are the respective screen width and height, while the keys * and 'height' are the respective screen width and height, while the keys
// * 'physicalWidth' and 'physicalHeight' indicate the thumbnail dimensions. * 'physicalWidth' and 'physicalHeight' indicate the thumbnail dimensions.
// * @return boolean * @return boolean
// */ */
// function normaliseParams(image, &paramsVar) { @Override public boolean normaliseParams(Xomw_File image, Xomw_params_handler handlerParams) {
// if (!parent::normaliseParams(image, paramsVar)) { if (!super.normaliseParams(image, handlerParams)) {
// return false; return false;
// } }
//
// // Obtain the source, pre-rotation dimensions // Obtain the source, pre-rotation dimensions
// srcWidth = image.getWidth(paramsVar['page']); int srcWidth = image.getWidth(handlerParams.page);
// srcHeight = image.getHeight(paramsVar['page']); int srcHeight = image.getHeight(handlerParams.page);
//
// // Don't make an image bigger than the source // Don't make an image bigger than the source
// if (paramsVar['physicalWidth'] >= srcWidth) { if (handlerParams.physicalWidth >= srcWidth) {
// paramsVar['physicalWidth'] = srcWidth; handlerParams.physicalWidth = srcWidth;
// paramsVar['physicalHeight'] = srcHeight; handlerParams.physicalHeight = srcHeight;
//
// // Skip scaling limit checks if no scaling is required // Skip scaling limit checks if no scaling is required
// // due to requested size being bigger than source. // due to requested size being bigger than source.
// if (!image.mustRender()) { if (!image.mustRender()) {
// return true; return true;
// } }
// } }
//
// return true; return true;
// } }
//
// /** // /**
// * Extracts the width/height if the image will be scaled before rotating // * Extracts the width/height if the image will be scaled before rotating
// * // *
@ -96,37 +96,36 @@ public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { publi
// } // }
// //
// // Create a parameter array to pass to the scaler // // Create a parameter array to pass to the scaler
// scalerParams = [ Xomw_params_scalar scalerParams = new Xomw_params_scalar();
// // The size to which the image will be resized // // The size to which the image will be resized
// 'physicalWidth' => paramsVar['physicalWidth'], scalerParams.physicalWidth = handlerParams.physicalWidth;
// 'physicalHeight' => paramsVar['physicalHeight'], scalerParams.physicalHeight = handlerParams.physicalHeight;
// 'physicalDimensions' => "{paramsVar['physicalWidth']}x{paramsVar['physicalHeight']}", // 'physicalDimensions' => "{paramsVar['physicalWidth']}x{paramsVar['physicalHeight']}",
// // The size of the image on the page // The size of the image on the page
// 'clientWidth' => paramsVar['width'], scalerParams.clientWidth = handlerParams.width;
// 'clientHeight' => paramsVar['height'], scalerParams.clientHeight = handlerParams.height;
// // Comment as will be added to the Exif of the thumbnail // Comment as will be added to the Exif of the thumbnail
// 'comment' => isset(paramsVar['descriptionUrl']) // 'comment' => isset(paramsVar['descriptionUrl'])
// ? "File source: {paramsVar['descriptionUrl']}" // ? "File source: {paramsVar['descriptionUrl']}"
// : '', // : '',
// // Properties of the original image // Properties of the original image
// 'srcWidth' => image.getWidth(), scalerParams.srcWidth = image.getWidth();
// 'srcHeight' => image.getHeight(), scalerParams.srcHeight = image.getHeight();
// 'mimeType' => image.getMimeType(), scalerParams.mimeType = image.getMimeType();
// 'dstPath' => dstPath, scalerParams.dstPath = dstPath;
// 'dstUrl' => dstUrl, scalerParams.dstUrl = dstUrl;
// 'interlace' => isset(paramsVar['interlace']) ? paramsVar['interlace'] : false, // 'interlace' => isset(paramsVar['interlace']) ? paramsVar['interlace'] : false,
// ];
//
// if (isset(paramsVar['quality']) && paramsVar['quality'] === 'low') { // if (isset(paramsVar['quality']) && paramsVar['quality'] === 'low') {
// scalerParams['quality'] = 30; // scalerParams['quality'] = 30;
// } // }
//
// // For subclasses that might be paged. // For subclasses that might be paged.
// if (image.isMultipage() && isset(paramsVar['page'])) { // if (image.isMultipage() && isset(paramsVar['page'])) {
// scalerParams['page'] = intval(paramsVar['page']); // scalerParams['page'] = intval(paramsVar['page']);
// } // }
//
// // Determine scaler type // Determine scaler type
// scaler = this.getScalerType(dstPath); // scaler = this.getScalerType(dstPath);
// //
// if (is_array(scaler)) { // if (is_array(scaler)) {
@ -137,19 +136,19 @@ public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { publi
// //
// wfDebug(__METHOD__ . ": creating {scalerParams['physicalDimensions']} " . // wfDebug(__METHOD__ . ": creating {scalerParams['physicalDimensions']} " .
// "thumbnail at dstPath using scaler scalerName\n"); // "thumbnail at dstPath using scaler scalerName\n");
//
// if (!image.mustRender() && if (!image.mustRender() &&
// scalerParams['physicalWidth'] == scalerParams['srcWidth'] scalerParams.physicalWidth == scalerParams.srcWidth
// && scalerParams['physicalHeight'] == scalerParams['srcHeight'] && scalerParams.physicalHeight == scalerParams.srcHeight
// && !isset(scalerParams['quality']) // && !isset(scalerParams['quality'])
// ) { ) {
//
// // normaliseParams (or the user) wants us to return the unscaled image // normaliseParams (or the user) wants us to return the unscaled image
// wfDebug(__METHOD__ . ": returning unscaled image\n"); // wfDebug(__METHOD__ . ": returning unscaled image\n");
//
// return this.getClientScalingThumbnailImage(image, scalerParams); return this.getClientScalingThumbnailImage(image, scalerParams);
// } }
//
// if (scaler == 'client') { // if (scaler == 'client') {
// // Client-side image scaling, use the source URL // // Client-side image scaling, use the source URL
// // Using the destination URL in a TRANSFORM_LATER request would be incorrect // // Using the destination URL in a TRANSFORM_LATER request would be incorrect
@ -308,26 +307,25 @@ public class Xomw_TransformationalImageHandler extends Xomw_ImageHandler { publi
// * @return String|Callable One of client, im, custom, gd, imext, or a Callable array. // * @return String|Callable One of client, im, custom, gd, imext, or a Callable array.
// */ // */
// abstract protected function getScalerType(dstPath, checkDstPath = true); // abstract protected function getScalerType(dstPath, checkDstPath = true);
//
// /** /**
// * Get a ThumbnailImage that respresents an image that will be scaled * Get a ThumbnailImage that respresents an image that will be scaled
// * client side * client side
// * *
// * @param File image File associated with this thumbnail * @param File image File associated with this thumbnail
// * @param array scalerParams Array with scaler paramsVar * @param array scalerParams Array with scaler paramsVar
// * @return ThumbnailImage * @return ThumbnailImage
// * *
// * @todo FIXME: No rotation support * @todo FIXME: No rotation support
// */ */
// protected function getClientScalingThumbnailImage(image, scalerParams) { private Xomw_ThumbnailImage getClientScalingThumbnailImage(Xomw_File image, Xomw_params_scalar scalerParams) {
// paramsVar = [ Xomw_params_handler handler_params = new Xomw_params_handler();
// 'width' => scalerParams['clientWidth'], handler_params.width = scalerParams.clientWidth;
// 'height' => scalerParams['clientHeight'] handler_params.height = scalerParams.clientHeight;
// ];
// return new Xomw_ThumbnailImage(image, image.getUrl(), image.getPath(), handler_params);
// return new ThumbnailImage(image, image.getUrl(), null, paramsVar); }
// }
//
// /** // /**
// * Transform an image using ImageMagick // * Transform an image using ImageMagick
// * // *

@ -743,7 +743,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// Parsed a width param of imagelink like 300px or 200x300px // Parsed a width param of imagelink like 300px or 200x300px
// XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0 // XO.MW.NOTE: for MW, "" -> null, null while "AxB" -> 0x0
public void parseWidthParam(int[] img_size, byte[] src) { public void parseWidthParam(int[] img_size, byte[] src) {
img_size[0] = img_size[1] = -1; img_size[0] = img_size[1] = Xomw_param_itm.Null_int;
if (src == Bry_.Empty) { if (src == Bry_.Empty) {
return; return;
} }

@ -30,7 +30,7 @@ public class Xomw_lnki_wkr__file__tst {
fxt.Test__to_html("[[File:A.png|thumb]]", "<div class='thumb tright'><div class='thumbinner' style='width:222px;'><a><img alt='A.png' src='/thumb/7/70/A.png/220px-A.png' class='thumbimage' /></a> <div class='thumbcaption'><div class='magnify'><a href='' class='internal'></a></div></div></div></div>"); fxt.Test__to_html("[[File:A.png|thumb]]", "<div class='thumb tright'><div class='thumbinner' style='width:222px;'><a><img alt='A.png' src='/thumb/7/70/A.png/220px-A.png' class='thumbimage' /></a> <div class='thumbcaption'><div class='magnify'><a href='' class='internal'></a></div></div></div></div>");
} }
@Test public void Size() { @Test public void Size() {
fxt.Test__to_html("[[File:A.png|123x456px]]", "<img alt='A.png' src='/orig/7/70/A.png' />"); fxt.Test__to_html("[[File:A.png|123x456px]]", "<img alt='A.png' src='/thumb/7/70/A.png/123px-A.png' />");
} }
@Test public void Test__parseWidthParam() { @Test public void Test__parseWidthParam() {
int[] img_size = new int[2]; int[] img_size = new int[2];

@ -54,4 +54,6 @@ public class Xomw_param_itm {
public static final byte[] public static final byte[]
Name_bry__width = Bry_.new_a7("width") Name_bry__width = Bry_.new_a7("width")
; ;
public static final int Null_int = Int_.Max_value;
} }

@ -17,20 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*; package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
public class Xomw_params_handler { public class Xomw_params_handler {
public int width = -1; public int width;
public int height = -1; public int height;
public int page = -1; public int page;
public int physicalWidth = -1; public int physicalWidth;
public int physicalHeight;
public Xomw_params_handler Clear() { public Xomw_params_handler Clear() {
width = height = page = -1; width = height = page
physicalWidth = -1; = physicalWidth = physicalHeight = Xomw_param_itm.Null_int;
return this; return this;
} }
public void Copy_to(Xomw_params_handler src) { public void Copy_to(Xomw_params_handler src) {
this.width = src.width; this.width = src.width;
this.height = src.height; this.height = src.height;
this.page = src.page; this.page = src.page;
this.physicalWidth = -1; this.physicalWidth = src.physicalWidth;
this.physicalHeight = src.physicalHeight;
} }
public void Set(int uid, byte[] val_bry, int val_int) { public void Set(int uid, byte[] val_bry, int val_int) {
switch (uid) { switch (uid) {

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
public class Xomw_params_scalar {
public int physicalWidth;
public int physicalHeight;
public byte[] physicalDimensions;
public int clientWidth;
public int clientHeight;
public byte[] comment;
public int srcWidth;
public int srcHeight;
public byte[] mimeType;
public byte[] dstPath;
public byte[] dstUrl;
public byte[] interlace;
public Xomw_params_scalar() {
physicalWidth = physicalHeight = clientWidth = clientHeight = srcWidth = srcHeight = Xomw_param_itm.Null_int;
}
}
Loading…
Cancel
Save