Hi,
Filipe Brandenburger wrote:
Would there be a way for me to "save" this
temporary file somewhere
inside the uploads directory, in a way that I could use it later in
doTransform?
I mean, in getImageSize() I would write the temporary file to somewhere
inside the upload directory (how could I automate the creation of a path
for that?) and not remove it after getting its size. Then, in
doTransform(), I would check if the requested dimensions match the ones
of the temporary file I created, if they do, I would just
copy/rename/hardlink the original file to the new one. Would that work?
How should I manage creating a path on the upload directory for that?
(I'm thinking something such as "math" or "graphviz" under the
root of
uploads.)
I found a way to do this, but I really did not like it at all!
It goes like this:
function getImageSize( $image, $path ) {
#...
$uploadData = array_values( $_SESSION['wsUploadData'] );
$imageName = $uploadData[0]['mSrcName'];
global $wgUploadDirectory;
$imageDir = $wgUploadDirectory . "/dia/" .
FileRepo::getHashPathForLevel($imageName, 2);
wfMkdirParents($imageDir);
$imagePath = $imageDir . $imageName . ".png";
#...
}
And then using $imagePath as a destination to save the generated PNG.
In "doTransform()", recalculate "$imagePath" for the temporary one,
then
use PHP's "getimagesize()" and compare with the requested dimensions. If
it matches, then use "link()" to copy the image, without the need to
call "dia" again.
The problem is, it depends on undocumented behaviour, and on getting
data from the session that was not meant to be seen by extensions.
I believe the "right" solution for that would be adding another method
to ImageHandler that would permit this kind of manipulation.
I was thinking of something along these lines:
* If "mustRender()" returns true, then the "doRender()" method will
be
called (before "getImageSize()" or "doTransform()"). It will be passed
a
$dstPath parameter with the file name of the PNG to be generated.
* If "doRender()" does indeed render the image, it should return the
"getimagesize()" output with the dimensions of the image. This will be
used by the calling method to know what is the image size.
* Optional: the calling method will be responsible for renaming XXX.png
into NNNpx-XXX.png. (Is this really necessary?)
* The default implementation of "doRender()" just returns false. In that
case, the calling method knows that it should use the other methods
("getImageSize()" and then "doTransform()") to create the PNG image.
How does all this sound to you? Is this a patch you would be willing to
accept and merge into MediaWiki?
Thanks,
Filipe