X-Git-Url: https://projects.mako.cc/source/editimage_extension/blobdiff_plain/7750a6d88ec2890d3d4a936c2a8c0dc7f2f8c617..HEAD:/EditImage_body.php diff --git a/EditImage_body.php b/EditImage_body.php index 58b4794..e305d5d 100644 --- a/EditImage_body.php +++ b/EditImage_body.php @@ -1,9 +1,64 @@ + This file is part of the EditImage Mediawiki Extension. + + EditImage is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at + your option) any later version. + + Foobar 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 General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with Foobar. If not, see . */ + function efRunEditImage( $par ) { EditImage::run( $par ); } -function resizeImage ( $x1, $y1, $x2, $y2 ) { +function resizeImage ( $srcpath, $x1, $y1, $x2, $y2) { + global $wgUseImageMagick, $wgImageMagickConvertCommand; + global $wgCustomConvertCommand; + global $wgTmpDirectory; + + # generate width and height + $w = abs($x2 - $x1); + $h = abs($y2 - $y1); + + # create temporary destination file location + $dstpath = tempnam($wgTmpDirectory, "EditImage"); + + # specify white background color, will be used for transparent images + # in internet explorer/windows instead of default black. + $cmd = wfescapeshellarg($wgImageMagickConvertCommand) . + " -background white " . + wfescapeshellarg($srcpath) . + // coalesce is needed to scale animated gifs properly (bug 1017). + ' -coalesce ' . + " -crop {$w}x{$h}+$x1+$y1! " . + wfescapeshellarg($dstpath) . " 2>&1"; + wfDebug( __METHOD__.": running ImageMagick: $cmd\n"); + wfProfileIn( 'convert' ); + $err = wfShellExec( $cmd, $retval ); + wfProfileOut( 'convert' ); + return($dstpath); +} + +function uploadNewFile ($old_file, $new_filename) { + global $wgRequest; + $form = new UploadForm($wgRequest); + + $form->mTempPath = $new_filename; + $form->mSrcName = $old_file->getName(); + $form->mFileSize = filesize($new_filename); + $form->mSessionKey = false; + $form->mStashed = false; + $form->mUploadClicked = true; + + $form->execute(); } class EditImage extends SpecialPage { @@ -15,16 +70,15 @@ class EditImage extends SpecialPage { function run( $par ) { global $wgRequest, $wgOut; - # add the javascript - global $wgJsMimeType, $wgScriptPath ; - $wgOut->addScript( "\n"); - $wgOut->addScript( "\n"); - $wgOut->addScript( "\n"); - $wgOut->addScript( "\n"); - + global $wgContLang; + global $wgUser; + # globals for javascript + global $wgJsMimeType, $wgScriptPath; + # try to find the image that the user entered $image = $wgRequest->getText('image'); $title = Title::newFromText( $image, NS_IMAGE ); + $file = wfFindFile( $title ); if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) { $wgOut->addWikiText("Sorry, can't find that image!"); @@ -33,22 +87,43 @@ class EditImage extends SpecialPage { if ($wgRequest->wasPosted()) { $x1 = $wgRequest->getInt(x1); $x2 = $wgRequest->getInt(x2); - $y1 = $wgRequest->getInt(x1); + $y1 = $wgRequest->getInt(y1); $y2 = $wgRequest->getInt(y2); - resizeImage($x1, $y1, $x2, $y2); - $wgOut->addHTML("x1: $x1
x2: $x2
"); + $resized_fn = resizeImage($file->getFullPath(), $x1, $y1, $x2, $y2); + uploadNewFile($file, $resized_fn); + + # delete the file if it still exists + if (file_exists($resized_fn)) { unlink($resized_fn); } } else { - $file = wfFindFile( $title ); if ( $file && $file->exists() ) { - $wgOut->addHTML("

Use your mouse to select the new area on the image below. When you are done, press crop.

\n"); + # add the javascript + $wgOut->addScript( "\n"); + $wgOut->addScript( "\n"); + $wgOut->addScript( "\n"); + $wgOut->addScript( "\n"); + + $instructions = wfMsg('editimage-instructions'); + $crop_text = wfMsg('cropimage'); + $wgOut->addHTML("

{$instructions}

\n"); # add image - $wgOut->addHTML("
getUrl()}\" alt=\"source image\" id=\"sourceImage\" width=\"500\" height=\"333\" />
\n"); + $wgOut->addHTML("
getUrl()}\" alt=\"source image\" id=\"sourceImage\" />
\n"); # add bottom of the template + $encComment = htmlspecialchars($wgRequest->getText('wpUploadDescription')); + $align1 = $wgContLang->isRTL() ? 'left' : 'right'; + $align2 = $wgContLang->isRTL() ? 'right' : 'left'; + $cols = intval($wgUser->getOption('cols')); + if( $wgUser->getOption( 'editwidth' ) ) { + $width = " style=\"width:100%\""; + } else { + $width = ''; + } + $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' ); + $wgOut->addHTML("
@@ -57,18 +132,22 @@ class EditImage extends SpecialPage { -

+ + + +
+ +
+ +

"); } else { $wgOut->setStatusCode( 404 ); } } - } - } - } ?>