noted the new URL for git repository
[editimage_extension] / EditImage_body.php
index e08de0b51f466b8c99be0bb451ff68c0694fffbb..e305d5d5fc5357791901784f82c4b20cf7508679 100644 (file)
@@ -1,4 +1,20 @@
 <?php
+/* Copyright (c) 2008 Benjamin Mako Hill <mako@atdot.cc>
+   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 <http://www.gnu.org/licenses/>.  */
+
 function efRunEditImage( $par ) {
     EditImage::run( $par );
 }
@@ -18,14 +34,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 +57,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 +72,9 @@ class EditImage extends SpecialPage {
 
         global $wgContLang;
         global $wgUser;
-        # add the javascript
-        global $wgJsMimeType, $wgScriptPath ;
-        $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
-        $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/scriptaculous.js\"></script>\n");
-        $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/cropper.js\"></script>\n");
-        $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/EditImage.js\"></script>\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 +93,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("<p>Use your mouse to select the new area on the image below. When you are done, press crop.</p>\n");
+                    # add the javascript
+                    $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
+                    $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/scriptaculous.js\"></script>\n");
+                    $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/cropper.js\"></script>\n");
+                    $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/EditImage.js\"></script>\n");
+
+                    $instructions = wfMsg('editimage-instructions');
+                    $crop_text = wfMsg('cropimage');
+                    $wgOut->addHTML("<p>{$instructions}</p>\n");
 
                     # add image
                     $wgOut->addHTML("<div><img src=\"{$file->getUrl()}\" alt=\"source image\" id=\"sourceImage\" /></div>\n");
@@ -119,20 +137,17 @@ class EditImage extends SpecialPage {
                                        <td align='$align2'>
                                          <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$width}>$encComment</textarea>
                                        </td>
-                                     </tr><table>
+                                     </tr></table>
 
-                                     <p><input type=\"submit\" value=\"Crop Image\" /></p>
+                                     <p><input type=\"submit\" value=\"{$crop_text}\" /></p>
                                      </form>");
 
                 } else {
                     $wgOut->setStatusCode( 404 );
                 }
             }
-
         }
-
     }
-
 }
 
 ?>

Benjamin Mako Hill || Want to submit a patch?