Preliminary support for application/external-editor
authorErik Moeller <erik@users.mediawiki.org>
Thu, 24 Mar 2005 13:30:09 +0000 (13:30 +0000)
committerErik Moeller <erik@users.mediawiki.org>
Thu, 24 Mar 2005 13:30:09 +0000 (13:30 +0000)
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
includes/ExternalEdit.php [new file with mode: 0644]
includes/ImagePage.php
includes/SpecialPreferences.php
index.php
skins/common/common.css
skins/monobook/main.css

index 7245ef5..4b65d01 100644 (file)
@@ -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 (file)
index 0000000..2a27ce5
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * License: Public domain
+ *
+ * @author Erik Moeller <moeller@scireview.de>
+ * @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;
+
+
+       }
+}
+?>
index d0285e8..5514333 100644 (file)
@@ -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.="</div>";
                                $wgOut->addWikiText($sharedtext);
                        }
+                       
                }
        }
        
+       function externalEditorLink()
+       {
+               global $wgUser,$wgOut;
+               $sk = $wgUser->getSkin();
+               $wgOut->addHTML("<div class=\"editExternally\">");
+               $wgOut->addHTML($sk->makeKnownLink($this->mTitle->getPrefixedDBkey(),wfMsg("edit-externally"),
+               "action=edit&externaledit=true&mode=file"));
+               $wgOut->addWikiText("<div class=\"editExternallyHelp\">".wfMsg("edit-externally-help"));
+               $wgOut->addHTML("</div><br clear=\"all\">");
+                       
+       }
        function closeShowImage()
        {
                # For overloading
+                       
        }
 
        /**
index bfbe8f4..0cc5b2f 100644 (file)
@@ -634,7 +634,9 @@ class PreferencesForm {
                $this->getToggle( "previewonfirst" ) .
                $this->getToggle( "previewontop" ) .
                $this->getToggle( "watchdefault" ) .
-               $this->getToggle( "minordefault" ) . "
+               $this->getToggle( "minordefault" ) . 
+               $this->getToggle( "externaleditor" ) .
+               "
        </fieldset>
        
        <fieldset>
index 47668c4..6dc4473 100644 (file)
--- 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')) {
index cab9c39..53f95ec 100644 (file)
@@ -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
index 52422eb..d43d358 100644 (file)
@@ -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