* Using Database::select() instead of a raw SQL query
[lhc/web/wiklou.git] / includes / ExternalEdit.php
1 <?php
2 /**
3 * License: Public domain
4 *
5 * @author Erik Moeller <moeller@scireview.de>
6 * @package MediaWiki
7 */
8
9 /**
10 *
11 * @package MediaWiki
12 *
13 * Support for external editors to modify both text and files
14 * in external applications. It works as follows: MediaWiki
15 * sends a meta-file with the MIME type 'application/x-external-editor'
16 * to the client. The user has to associate that MIME type with
17 * a helper application (a reference implementation in Perl
18 * can be found in extensions/ee), which will launch the editor,
19 * and save the modified data back to the server.
20 *
21 */
22
23 class ExternalEdit {
24
25 function ExternalEdit ( $article, $mode ) {
26 global $wgInputEncoding;
27 $this->mArticle =& $article;
28 $this->mTitle =& $article->mTitle;
29 $this->mCharset = $wgInputEncoding;
30 $this->mMode = $mode;
31 }
32
33 function edit() {
34 global $wgUser, $wgOut, $wgScript, $wgScriptPath, $wgServer,
35 $wgLang;
36 $wgOut->disable();
37 $name=$this->mTitle->getText();
38 $pos=strrpos($name,".")+1;
39 header ( "Content-type: application/x-external-editor; charset=".$this->mCharset );
40
41 # $type can be "Edit text", "Edit file" or "Diff text" at the moment
42 # See the protocol specifications at [[m:Help:External editors/Tech]] for
43 # details.
44 if(!isset($this->mMode)) {
45 $type="Edit text";
46 $url=$this->mTitle->getFullURL("action=edit&internaledit=true");
47 # *.wiki file extension is used by some editors for syntax
48 # highlighting, so we follow that convention
49 $extension="wiki";
50 } elseif($this->mMode=="file") {
51 $type="Edit file";
52 $image = Image::newFromTitle( $this->mTitle );
53 $img_url = $image->getURL();
54 if(strpos($img_url,"://")) {
55 $url = $img_url;
56 } else {
57 $url = $wgServer . $img_url;
58 }
59 $extension=substr($name, $pos);
60 }
61 $special=$wgLang->getNsText(NS_SPECIAL);
62 $control = <<<CONTROL
63 [Process]
64 Type=$type
65 Engine=MediaWiki
66 Script={$wgServer}{$wgScript}
67 Server={$wgServer}
68 Path={$wgScriptPath}
69 Special namespace=$special
70
71 [File]
72 Extension=$extension
73 URL=$url
74 CONTROL;
75 echo $control;
76 }
77 }
78 ?>