got functionality up and working
author<mako@atdot.cc> <>
Mon, 11 Aug 2008 19:12:00 +0000 (15:12 -0400)
committer<mako@atdot.cc> <>
Mon, 11 Aug 2008 19:12:00 +0000 (15:12 -0400)
EditImage.i18n.php
EditImage.php
EditImage_body.php

index 91f3da836db8895c23bd05b549e5dd0516b66383..f19659c7ee8f5ed7baaf10e58babe39d95cd617b 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 $messages = array();
 $messages['en'] = array( 
 <?php
 $messages = array();
 $messages['en'] = array( 
-    'editimage' => 'Edit Image'
+    'editimage' => 'Edit Image',
+    'cropimage' => 'Crop Image'
 );
 ?>
 );
 ?>
index e945b7f487c0de0884acdebc9a93b7e0ac3ac943..af64e8dde84a7a5ade15577bbc579833c82ae67e 100644 (file)
@@ -15,6 +15,8 @@ $wgAutoloadClasses['EditImage'] = $dir . 'EditImage_body.php';
 $wgExtensionMessagesFiles['EditImage'] = $dir . 'EditImage.i18n.php';
 $wgSpecialPages['EditImage'] = 'EditImage'; 
 # $wgHooks['LanguageGetSpecialPageAliases'][] = 'EditImageLocalizedPageName';
 $wgExtensionMessagesFiles['EditImage'] = $dir . 'EditImage.i18n.php';
 $wgSpecialPages['EditImage'] = 'EditImage'; 
 # $wgHooks['LanguageGetSpecialPageAliases'][] = 'EditImageLocalizedPageName';
+$wgHooks['SkinTemplateContentActions'][] = 'wfAddactionContentHook';
+#$wgHooks['UnknownAction'][] = 'wfAddactActionHook';
 
 function myExtensionLocalizedPageName(&$specialPageArray, $code) {
   # The localized title of the special page is among the messages of the extension:
 
 function myExtensionLocalizedPageName(&$specialPageArray, $code) {
   # The localized title of the special page is among the messages of the extension:
@@ -38,4 +40,23 @@ $wgExtensionCredits['specialpage'][] = array(
 
 
 
 
 
 
+function wfAddActionContentHook( &$content_actions ) {
+    global $wgRequest, $wgRequest, $wgTitle;
+    
+    $action = $wgRequest->getText( 'action' ); 
+    if ( $wgTitle->getNamespace() == NS_IMAGE ) {
+
+        $editimage_page = SpecialPage::getTitleFor( 'EditImage');;
+
+        $content_actions['editimage'] = array(
+            'class' => $action == 'editimage' ? 'selected' : false,
+            'text' => "Crop Image", // the wfMsg was not working...
+            'href' => $editimage_page->getLocalURL("image={$wgTitle->getPrefixedURL()}")
+            );
+    }
+
+    return true;
+}
+
+
 ?>
 ?>
index 58b4794a8dfe6bc9204e660fadf0a6e3cc6b4e94..e08de0b51f466b8c99be0bb451ff68c0694fffbb 100644 (file)
@@ -3,7 +3,51 @@ function efRunEditImage( $par ) {
     EditImage::run( $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";
+    global $wgOut;
+    $wgOut->addHTML($cmd);
+    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->mReUpload       = true;
+
+    // PHP won't auto-cleanup the file
+    $form->mRemoveTempFile = file_exists( $local_file);
+    $form->execute();
 }
  
 class EditImage extends SpecialPage {
 }
  
 class EditImage extends SpecialPage {
@@ -15,6 +59,8 @@ class EditImage extends SpecialPage {
     function run( $par ) {
         global $wgRequest, $wgOut;
 
     function run( $par ) {
         global $wgRequest, $wgOut;
 
+        global $wgContLang;
+        global $wgUser;
         # add the javascript
         global $wgJsMimeType, $wgScriptPath ;
         $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
         # add the javascript
         global $wgJsMimeType, $wgScriptPath ;
         $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
@@ -25,6 +71,7 @@ class EditImage extends SpecialPage {
         # try to find the image that the user entered
         $image = $wgRequest->getText('image');
         $title = Title::newFromText( $image, NS_IMAGE );
         # 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!");
 
         if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) {
             $wgOut->addWikiText("Sorry, can't find that image!");
@@ -33,22 +80,32 @@ class EditImage extends SpecialPage {
             if ($wgRequest->wasPosted()) {
                 $x1 = $wgRequest->getInt(x1);
                 $x2 = $wgRequest->getInt(x2);
             if ($wgRequest->wasPosted()) {
                 $x1 = $wgRequest->getInt(x1);
                 $x2 = $wgRequest->getInt(x2);
-                $y1 = $wgRequest->getInt(x1);
+                $y1 = $wgRequest->getInt(y1);
                 $y2 = $wgRequest->getInt(y2);
 
                 $y2 = $wgRequest->getInt(y2);
 
-                resizeImage($x1, $y1, $x2, $y2);
-                $wgOut->addHTML("x1: $x1<br />x2: $x2<br />");
+                $resized_fn = resizeImage($file->getFullPath(), $x1, $y1, $x2, $y2);
+                uploadNewFile($file, $resized_fn);
 
             } else {
 
 
             } else {
 
-                $file = wfFindFile( $title );
                 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 image
                 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 image
-                    $wgOut->addHTML("<div><img src=\"{$file->getUrl()}\" alt=\"source image\" id=\"sourceImage\" width=\"500\" height=\"333\" /></div>\n");
+                    $wgOut->addHTML("<div><img src=\"{$file->getUrl()}\" alt=\"source image\" id=\"sourceImage\" /></div>\n");
 
                     # add bottom of the template
 
                     # 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("<form action=\"\" method=\"POST\">
                                      <input type=\"hidden\" name=\"image\" value=\"{$image}\" />
                                      <input type=\"hidden\" name=\"x1\" id=\"x1\" />
                     $wgOut->addHTML("<form action=\"\" method=\"POST\">
                                      <input type=\"hidden\" name=\"image\" value=\"{$image}\" />
                                      <input type=\"hidden\" name=\"x1\" id=\"x1\" />
@@ -57,7 +114,14 @@ class EditImage extends SpecialPage {
                                      <input type=\"hidden\" name=\"y2\" id=\"y2\" />
                                      <input type=\"hidden\" name=\"width\" id=\"width\" />
                                      <input type=\"hidden\" name=\"height\" id=\"height\" />
                                      <input type=\"hidden\" name=\"y2\" id=\"y2\" />
                                      <input type=\"hidden\" name=\"width\" id=\"width\" />
                                      <input type=\"hidden\" name=\"height\" id=\"height\" />
-                                     <p><input type=\"submit\" value=\"Save\" /></p>
+                                     <table border='0'><tr>
+                                       <td align='$align1'><label for='wpUploadDescription'>{$summary}</label></td>
+                                       <td align='$align2'>
+                                         <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$width}>$encComment</textarea>
+                                       </td>
+                                     </tr><table>
+
+                                     <p><input type=\"submit\" value=\"Crop Image\" /></p>
                                      </form>");
 
                 } else {
                                      </form>");
 
                 } else {

Benjamin Mako Hill || Want to submit a patch?