2 function efRunEditImage( $par ) {
3 EditImage::run( $par );
6 function resizeImage ( $srcpath, $x1, $y1, $x2, $y2) {
7 global $wgUseImageMagick, $wgImageMagickConvertCommand;
8 global $wgCustomConvertCommand;
9 global $wgTmpDirectory;
11 # generate width and height
15 # create temporary destination file location
16 $dstpath = tempnam($wgTmpDirectory, "EditImage");
18 # specify white background color, will be used for transparent images
19 # in internet explorer/windows instead of default black.
20 $cmd = wfescapeshellarg($wgImageMagickConvertCommand) .
21 " -background white ".
22 wfescapeshellarg($srcpath) .
23 // coalesce is needed to scale animated gifs properly (bug 1017).
25 " -crop {$w}x{$h}+$x1+$y1! " .
26 wfescapeshellarg($dstpath) . " 2>&1";
27 wfDebug( __METHOD__.": running ImageMagick: $cmd\n");
28 wfProfileIn( 'convert' );
29 $err = wfShellExec( $cmd, $retval );
30 wfProfileOut( 'convert' );
34 function uploadNewFile ($old_file, $new_filename) {
36 $form = new UploadForm($wgRequest);
38 $form->mTempPath = $new_filename;
39 $form->mSrcName = $old_file->getName();
40 $form->mFileSize = filesize($new_filename);
41 $form->mSessionKey = false;
42 $form->mStashed = false;
43 $form->mUploadClicked = true;
44 //$form->mReUpload = true;
46 // PHP won't auto-cleanup the file
47 $form->mRemoveTempFile = file_exists( $local_file);
51 class EditImage extends SpecialPage {
52 function EditImage() {
53 SpecialPage::SpecialPage("EditImage", '', true, 'efRunEditImage');
54 wfLoadExtensionMessages('EditImage');
57 function run( $par ) {
58 global $wgRequest, $wgOut;
63 global $wgJsMimeType, $wgScriptPath ;
64 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
65 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/scriptaculous.js\"></script>\n");
66 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/cropper.js\"></script>\n");
67 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/EditImage.js\"></script>\n");
69 # try to find the image that the user entered
70 $image = $wgRequest->getText('image');
71 $title = Title::newFromText( $image, NS_IMAGE );
72 $file = wfFindFile( $title );
74 if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) {
75 $wgOut->addWikiText("Sorry, can't find that image!");
77 # see if we're passed editing information
78 if ($wgRequest->wasPosted()) {
79 $x1 = $wgRequest->getInt(x1);
80 $x2 = $wgRequest->getInt(x2);
81 $y1 = $wgRequest->getInt(y1);
82 $y2 = $wgRequest->getInt(y2);
84 $resized_fn = resizeImage($file->getFullPath(), $x1, $y1, $x2, $y2);
85 uploadNewFile($file, $resized_fn);
89 if ( $file && $file->exists() ) {
90 $wgOut->addHTML("<p>Use your mouse to select the new area on the image below. When you are done, press crop.</p>\n");
93 $wgOut->addHTML("<div><img src=\"{$file->getUrl()}\" alt=\"source image\" id=\"sourceImage\" /></div>\n");
95 # add bottom of the template
96 $encComment = htmlspecialchars($wgRequest->getText('wpUploadDescription'));
97 $align1 = $wgContLang->isRTL() ? 'left' : 'right';
98 $align2 = $wgContLang->isRTL() ? 'right' : 'left';
99 $cols = intval($wgUser->getOption('cols'));
100 if( $wgUser->getOption( 'editwidth' ) ) {
101 $width = " style=\"width:100%\"";
105 $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
107 $wgOut->addHTML("<form action=\"\" method=\"POST\">
108 <input type=\"hidden\" name=\"image\" value=\"{$image}\" />
109 <input type=\"hidden\" name=\"x1\" id=\"x1\" />
110 <input type=\"hidden\" name=\"y1\" id=\"y1\" />
111 <input type=\"hidden\" name=\"x2\" id=\"x2\" />
112 <input type=\"hidden\" name=\"y2\" id=\"y2\" />
113 <input type=\"hidden\" name=\"width\" id=\"width\" />
114 <input type=\"hidden\" name=\"height\" id=\"height\" />
115 <table border='0'><tr>
116 <td align='$align1'><label for='wpUploadDescription'>{$summary}</label></td>
118 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$width}>$encComment</textarea>
122 <p><input type=\"submit\" value=\"Crop Image\" /></p>
126 $wgOut->setStatusCode( 404 );