58b4794a8dfe6bc9204e660fadf0a6e3cc6b4e94
[editimage_extension] / EditImage_body.php
1 <?php
2 function efRunEditImage( $par ) {
3     EditImage::run( $par );
4 }
5     
6 function resizeImage ( $x1, $y1, $x2, $y2 ) {
7 }
8  
9 class EditImage extends SpecialPage {
10     function EditImage() {
11         SpecialPage::SpecialPage("EditImage", '', true, 'efRunEditImage');
12         wfLoadExtensionMessages('EditImage');
13     } 
14     
15     function run( $par ) {
16         global $wgRequest, $wgOut;
17
18         # add the javascript
19         global $wgJsMimeType, $wgScriptPath ;
20         $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/prototype.js\"></script>\n");
21         $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/lib/scriptaculous.js\"></script>\n");
22         $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/cropper.js\"></script>\n");
23         $wgOut->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/EditImage/EditImage.js\"></script>\n");
24
25         # try to find the image that the user entered
26         $image = $wgRequest->getText('image');
27         $title = Title::newFromText( $image, NS_IMAGE );
28
29         if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) {
30             $wgOut->addWikiText("Sorry, can't find that image!");
31         } else {
32             # see if we're passed editing information
33             if ($wgRequest->wasPosted()) {
34                 $x1 = $wgRequest->getInt(x1);
35                 $x2 = $wgRequest->getInt(x2);
36                 $y1 = $wgRequest->getInt(x1);
37                 $y2 = $wgRequest->getInt(y2);
38
39                 resizeImage($x1, $y1, $x2, $y2);
40                 $wgOut->addHTML("x1: $x1<br />x2: $x2<br />");
41
42             } else {
43
44                 $file = wfFindFile( $title );
45                 if ( $file && $file->exists() ) {
46                     $wgOut->addHTML("<p>Use your mouse to select the new area on the image below. When you are done, press crop.</p>\n");
47
48                     # add image
49                     $wgOut->addHTML("<div><img src=\"{$file->getUrl()}\" alt=\"source image\" id=\"sourceImage\" width=\"500\" height=\"333\" /></div>\n");
50
51                     # add bottom of the template
52                     $wgOut->addHTML("<form action=\"\" method=\"POST\">
53                                      <input type=\"hidden\" name=\"image\" value=\"{$image}\" />
54                                      <input type=\"hidden\" name=\"x1\" id=\"x1\" />
55                                      <input type=\"hidden\" name=\"y1\" id=\"y1\" />
56                                      <input type=\"hidden\" name=\"x2\" id=\"x2\" />
57                                      <input type=\"hidden\" name=\"y2\" id=\"y2\" />
58                                      <input type=\"hidden\" name=\"width\" id=\"width\" />
59                                      <input type=\"hidden\" name=\"height\" id=\"height\" />
60                                      <p><input type=\"submit\" value=\"Save\" /></p>
61                                      </form>");
62
63                 } else {
64                     $wgOut->setStatusCode( 404 );
65                 }
66             }
67
68         }
69
70     }
71
72 }
73
74 ?>

Benjamin Mako Hill || Want to submit a patch?