ExternalEdit.php 1.9 KB

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