From 1b562068b62d4082eeec681e881a9e354d34398d Mon Sep 17 00:00:00 2001 From: Erik Moeller Date: Thu, 24 Mar 2005 13:30:09 +0000 Subject: [PATCH] Preliminary support for application/external-editor allows editing wiki pages or files with an external application, by using an intermediate helper application (such as the reference one in extensions/ee) which fetches the data and transmits the changes back to the server. This version adds external editor support for uploaded files, as well as for pages. More operations, such as diffs and merges, should support application/external-editor in the future. See extensions/ee/README for some more info on the concept. Documentation will also be placed on http://meta.wikimedia.org/wiki/Help:External_editors --- includes/DefaultSettings.php | 6 +++ includes/ExternalEdit.php | 65 +++++++++++++++++++++++++++++++++ includes/ImagePage.php | 20 +++++++++- includes/SpecialPreferences.php | 4 +- index.php | 20 ++++++++-- skins/common/common.css | 15 ++++++++ skins/monobook/main.css | 15 ++++++++ 7 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 includes/ExternalEdit.php diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 7245ef54de..4b65d014d9 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1183,6 +1183,12 @@ $wgNoFollowLinks = true; */ $wgMinimalPasswordLength = 0; +/** + * Activate external editor interface for files and pages + * See http://meta.wikimedia.org/wiki/Help:External_editors + */ +$wgUseExternalEditor = true; + /** Whether or not to sort special pages in Special:Specialpages */ $wgSortSpecialPages = true; diff --git a/includes/ExternalEdit.php b/includes/ExternalEdit.php new file mode 100644 index 0000000000..2a27ce5d2b --- /dev/null +++ b/includes/ExternalEdit.php @@ -0,0 +1,65 @@ + + * @package MediaWiki + */ + +/** + * + * @package MediaWiki + * + * Support for external editors to modify both text and files + * in external application. It works as follows: MediaWiki + * sends a meta-file with the MIME type 'application/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 ExternalEdit ( $article, $mode ) { + global $wgInputEncoding; + $this->mArticle =& $article; + $this->mTitle =& $article->mTitle; + $this->mCharset = $wgInputEncoding; + $this->mMode = $mode; + } + + function edit() { + global $wgUser, $wgOut, $wgScript, $wgServer; + $wgOut->disable(); + $name=$this->mTitle->getText(); + $pos=strrpos($name,".")+1; + header ( "Content-type: application/external-editor; charset=".$this->mCharset ); + 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"; + $url=$wgServer . Image::newFromTitle( $this->mTitle )->getURL(); + $extension=substr($name, $pos); + } + $control= +" +[Process] +Type=$type +Engine=MediaWiki +Script={$wgServer}{$wgScript} + +[File] +Extension=$extension +URL=$url"; + echo $control; + + + } +} +?> diff --git a/includes/ImagePage.php b/includes/ImagePage.php index d0285e8960..5514333330 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -21,11 +21,15 @@ class ImagePage extends Article { // available in doDelete etc. function view() { + global $wgUseExternalEditor; if( $this->mTitle->getNamespace() == NS_IMAGE ) { $this->openShowImage(); } Article::view(); + if($wgUseExternalEditor) { + $this->externalEditorLink(); + } # If the article we've just shown is in the "Image" namespace, # follow it with the history list and link list for the image @@ -41,7 +45,8 @@ class ImagePage extends Article { function openShowImage() { global $wgOut, $wgUser, $wgImageLimits, $wgRequest, - $wgUseImageResize, $wgRepositoryBaseUrl; + $wgUseImageResize, $wgRepositoryBaseUrl, + $wgUseExternalEditor; $this->img = Image::newFromTitle( $this->mTitle ); $full_url = $this->img->getViewURL(); $anchoropen = ''; @@ -116,12 +121,25 @@ class ImagePage extends Article { $sharedtext.=""; $wgOut->addWikiText($sharedtext); } + } } + function externalEditorLink() + { + global $wgUser,$wgOut; + $sk = $wgUser->getSkin(); + $wgOut->addHTML("
"); + $wgOut->addHTML($sk->makeKnownLink($this->mTitle->getPrefixedDBkey(),wfMsg("edit-externally"), + "action=edit&externaledit=true&mode=file")); + $wgOut->addWikiText("
".wfMsg("edit-externally-help")); + $wgOut->addHTML("

"); + + } function closeShowImage() { # For overloading + } /** diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index bfbe8f466a..0cc5b2f806 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -634,7 +634,9 @@ class PreferencesForm { $this->getToggle( "previewonfirst" ) . $this->getToggle( "previewontop" ) . $this->getToggle( "watchdefault" ) . - $this->getToggle( "minordefault" ) . " + $this->getToggle( "minordefault" ) . + $this->getToggle( "externaleditor" ) . + "
diff --git a/index.php b/index.php index 47668c46e4..6dc447355a 100644 --- a/index.php +++ b/index.php @@ -167,10 +167,22 @@ if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) { User::SetupSession(); } # Continue... - case 'edit': - require_once( 'includes/EditPage.php' ); - $editor = new EditPage( $wgArticle ); - $editor->submit(); + case 'edit': + $internal = $wgRequest->getVal( 'internaledit' ); + $external = $wgRequest->getVal( 'externaledit' ); + $section = $wgRequest->getVal( 'section' ); + $oldid = $wgRequest->getVal( 'oldid' ); + if(!$wgUseExternalEditor || $action=='submit' || $internal || + $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) { + require_once( 'includes/EditPage.php' ); + $editor = new EditPage( $wgArticle ); + $editor->submit(); + } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) { + require_once( 'includes/ExternalEdit.php' ); + $mode = $wgRequest->getVal( 'mode' ); + $extedit = new ExternalEdit( $wgArticle, $mode ); + $extedit->edit(); + } break; case 'history': if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) { diff --git a/skins/common/common.css b/skins/common/common.css index cab9c390a7..53f95ecc3d 100644 --- a/skins/common/common.css +++ b/skins/common/common.css @@ -303,3 +303,18 @@ span.changedby { text-align: center; color: #cc0000; } +.editExternally { + border-style:solid; + border-width:1px; + border-color:gray; + background: #ffffff; + padding:3px; + margin-top:0.5em; + float:left; + font-size:small; + text-align:center; +} +.editExternallyHelp { + font-style:italic; + color:gray; +} \ No newline at end of file diff --git a/skins/monobook/main.css b/skins/monobook/main.css index 52422eb0a4..d43d3581f6 100644 --- a/skins/monobook/main.css +++ b/skins/monobook/main.css @@ -1091,3 +1091,18 @@ span.changedby { text-align: center; color: #cc0000; } +.editExternally { + border-style:solid; + border-width:1px; + border-color:gray; + background: #ffffff; + padding:3px; + margin-top:0.5em; + float:left; + font-size:small; + text-align:center; +} +.editExternallyHelp { + font-style:italic; + color:gray; +} \ No newline at end of file -- 2.20.1