wiki.techinc.nl/includes/ExternalEdit.php
Brian Wolff 6ca0ea07a2 (bug 26716, well partially anyways. kind of second half of r80608) Add a comment to external editor ini control file explaining
what it is. This will give people who accidently select the preference a fighting chance to debug what is going on.

Of course, since it has a mime type of application/x-external-edit (or something like that), and the download would have
a .php extension, the chance they will open it in a text editor is pretty slim...

See bug 2760 for proposal to just kill the preference altogether.
2011-01-20 01:49:49 +00:00

75 lines
2.2 KiB
PHP

<?php
/**
* External editors support
*
* License: Public domain
*
* @file
* @author Erik Moeller <moeller@scireview.de>
*/
/**
* Support for external editors to modify both text and files
* in external applications. It works as follows: MediaWiki
* sends a meta-file with the MIME type 'application/x-external-editor'
* to the client. The user has to associate that MIME type with
* a helper application (a reference implementation in Perl
* can be found in extensions/ee), which will launch the editor,
* and save the modified data back to the server.
*
*/
class ExternalEdit {
function __construct( $article, $mode ) {
global $wgInputEncoding;
$this->mArticle =& $article;
$this->mTitle =& $article->mTitle;
$this->mCharset = $wgInputEncoding;
$this->mMode = $mode;
}
function edit() {
global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang;
$wgOut->disable();
$name=$this->mTitle->getText();
$pos=strrpos($name,".")+1;
header ( "Content-type: application/x-external-editor; charset=".$this->mCharset );
header( "Cache-control: no-cache" );
# $type can be "Edit text", "Edit file" or "Diff text" at the moment
# See the protocol specifications at [[m:Help:External editors/Tech]] for
# details.
if(!isset($this->mMode)) {
$type="Edit text";
$url=$this->mTitle->getFullURL("action=edit&internaledit=true");
# *.wiki file extension is used by some editors for syntax
# highlighting, so we follow that convention
$extension="wiki";
} elseif($this->mMode=="file") {
$type="Edit file";
$image = wfLocalFile( $this->mTitle );
$url = $image->getFullURL();
$extension=substr($name, $pos);
}
$special=$wgLang->getNsText(NS_SPECIAL);
$control = <<<CONTROL
; You're seeing this file because you're using Mediawiki's External Editor
; feature. This is probably because you selected use external editor
; in your preferences. To edit normally, either disable that preference
; or go to the URL $url .
; See http://www.mediawiki.org/wiki/Manual:External_editors for details.
[Process]
Type=$type
Engine=MediaWiki
Script={$wgServer}{$wgScript}
Server={$wgServer}
Path={$wgScriptPath}
Special namespace=$special
[File]
Extension=$extension
URL=$url
CONTROL;
echo $control;
}
}