X-Git-Url: https://projects.mako.cc/source/editimage_extension/blobdiff_plain/a551c8fbc9b821de4d8d397ac2fc96a3d64d9ff8..7e7ba742d1216e41693d52e7ff3cba9351669997:/EditImage_body.php diff --git a/EditImage_body.php b/EditImage_body.php index e08de0b..294a07d 100644 --- a/EditImage_body.php +++ b/EditImage_body.php @@ -18,14 +18,12 @@ function resizeImage ( $srcpath, $x1, $y1, $x2, $y2) { # specify white background color, will be used for transparent images # in internet explorer/windows instead of default black. $cmd = wfescapeshellarg($wgImageMagickConvertCommand) . - " -background white ". + " -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"; - global $wgOut; - $wgOut->addHTML($cmd); wfDebug( __METHOD__.": running ImageMagick: $cmd\n"); wfProfileIn( 'convert' ); $err = wfShellExec( $cmd, $retval ); @@ -43,10 +41,7 @@ function uploadNewFile ($old_file, $new_filename) { $form->mSessionKey = false; $form->mStashed = false; $form->mUploadClicked = true; - //$form->mReUpload = true; - // PHP won't auto-cleanup the file - $form->mRemoveTempFile = file_exists( $local_file); $form->execute(); } @@ -61,13 +56,9 @@ class EditImage extends SpecialPage { global $wgContLang; global $wgUser; - # add the javascript - global $wgJsMimeType, $wgScriptPath ; - $wgOut->addScript( "\n"); - $wgOut->addScript( "\n"); - $wgOut->addScript( "\n"); - $wgOut->addScript( "\n"); - + # 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 ); @@ -86,10 +77,21 @@ class EditImage extends SpecialPage { $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 { 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\" />
\n"); @@ -121,18 +123,15 @@ class EditImage extends SpecialPage { -

+

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