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";
28 $wgOut->addHTML($cmd);
29 wfDebug( __METHOD__.": running ImageMagick: $cmd\n");
30 wfProfileIn( 'convert' );
31 $err = wfShellExec( $cmd, $retval );
32 wfProfileOut( 'convert' );
36 function uploadNewFile ($old_file, $new_filename) {
38 $form = new UploadForm($wgRequest);
40 $form->mTempPath = $new_filename;
41 $form->mSrcName = $old_file->getName();
42 $form->mFileSize = filesize($new_filename);
43 $form->mSessionKey = false;
44 $form->mStashed = false;
45 $form->mUploadClicked = true;
46 //$form->mReUpload = true;
48 // PHP won't auto-cleanup the file
49 $form->mRemoveTempFile = file_exists( $local_file);
53 class EditImage extends SpecialPage {
54 function EditImage() {
55 SpecialPage::SpecialPage("EditImage", '', true, 'efRunEditImage');
56 wfLoadExtensionMessages('EditImage');
59 function run( $par ) {
60 global $wgRequest, $wgOut;
65 global $wgJsMimeType, $wgScriptPath ;
66 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
67 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/scriptaculous.js\"></script>\n");
68 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/cropper.js\"></script>\n");
69 $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/EditImage.js\"></script>\n");
71 # try to find the image that the user entered
72 $image = $wgRequest->getText('image');
73 $title = Title::newFromText( $image, NS_IMAGE );
74 $file = wfFindFile( $title );
76 if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) {
77 $wgOut->addWikiText("Sorry, can't find that image!");
79 # see if we're passed editing information
80 if ($wgRequest->wasPosted()) {
81 $x1 = $wgRequest->getInt(x1);
82 $x2 = $wgRequest->getInt(x2);
83 $y1 = $wgRequest->getInt(y1);
84 $y2 = $wgRequest->getInt(y2);
86 $resized_fn = resizeImage($file->getFullPath(), $x1, $y1, $x2, $y2);
87 uploadNewFile($file, $resized_fn);
91 if ( $file && $file->exists() ) {
92 $wgOut->addHTML("<p>Use your mouse to select the new area on the image below. When you are done, press crop.</p>\n");
95 $wgOut->addHTML("<div><img src=\"{$file->getUrl()}\" alt=\"source image\" id=\"sourceImage\" /></div>\n");
97 # add bottom of the template
98 $encComment = htmlspecialchars($wgRequest->getText('wpUploadDescription'));
99 $align1 = $wgContLang->isRTL() ? 'left' : 'right';
100 $align2 = $wgContLang->isRTL() ? 'right' : 'left';
101 $cols = intval($wgUser->getOption('cols'));
102 if( $wgUser->getOption( 'editwidth' ) ) {
103 $width = " style=\"width:100%\"";
107 $summary = wfMsgExt( 'fileuploadsummary', 'parseinline' );
109 $wgOut->addHTML("<form action=\"\" method=\"POST\">
110 <input type=\"hidden\" name=\"image\" value=\"{$image}\" />
111 <input type=\"hidden\" name=\"x1\" id=\"x1\" />
112 <input type=\"hidden\" name=\"y1\" id=\"y1\" />
113 <input type=\"hidden\" name=\"x2\" id=\"x2\" />
114 <input type=\"hidden\" name=\"y2\" id=\"y2\" />
115 <input type=\"hidden\" name=\"width\" id=\"width\" />
116 <input type=\"hidden\" name=\"height\" id=\"height\" />
117 <table border='0'><tr>
118 <td align='$align1'><label for='wpUploadDescription'>{$summary}</label></td>
120 <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$width}>$encComment</textarea>
124 <p><input type=\"submit\" value=\"Crop Image\" /></p>
128 $wgOut->setStatusCode( 404 );