TinyMCE

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Diberri (talk | contribs) at 15:35, 17 September 2006 (→‎problems with templates: fixed in H::WC::MediaWiki 0.55). It may differ significantly from the current version.

Please read the article on WYSIWYM for more information on WYSIWYG editors in WikiMedia.

You can also download the following patch: http://www.logicsupply.com/pub/wysiwyg.patch.zip. This patch integrates TinyMCE into MediaWiki version 1.5.7 (used to be 1.5.2). The TinyMCE source is included in the patch. I've added an option to the user preferences to enable or disable the editor on a per user basis. All HTML is converted to appropriate wiki markup before previewing/saving.

Limitations include:

  • Links and images must still be specified using wiki markup
  • Preformatted text (lines starting with whitespace) doesn't survive the trip to and from HTML
  • Some features, like underline and strikethrough, have no effect.
  • Editing pages using templates will break the template usage.

If someone wants to hack TinyMCE to make these features work, they're more than welcome.

This implementation makes use of html2wiki, a trivial utility written in perl. Download the script, and put it in the $PATH somewhere (probably /usr/local/bin):

$ wget http://www.logicsupply.com/pub/html2wiki
$ sudo mv html2wiki /usr/local/bin

To use html2wiki, you will need the perl module HTML::WikiConverter. If you have CPAN installed, you can type:

# cpan
cpan> install HTML::WikiConverter
cpan> install HTML::WikiConverter::MediaWiki

Otherwise, you will need to download this module (as well as any dependencies) from the CPAN website. Please note that if you get no output on when previewing or saving you may need to specify the MediaWiki dialect. Find file includes/EditPage.php and edit the process description at the begining to be:

$html2wiki = 'html2wiki --dialect MediaWiki';

If you are using HTML::Converter v.0.52, you will need to pass an encoding type to html2wiki. Find file includes/EditPage.php and edit the process description at the begining to be:

$html2wiki = 'html2wiki --dialect MediaWiki --encoding=utf-8';

To use the patch, type at a command prompt:

$ wget http://www.logicsupply.com/pub/wysiwyg.patch.zip
$ unzip wysiwyg.patch.zip
$  mv wysiwyg.patch [WIKIROOT]
$ cd [WIKIROOT]
$ patch --backup -p1 < wysiwyg.patch

Watch the output of the patch command carefully, and make sure everything went smoothly.

Test the preview and save features as well as basic editing commands. If everything looks good, you may want to remove the backup files created by patch.

Manually fetching images should no longer be necessary:

After patching you will need to install the images used for toolbar buttons from the latest TinyMCE editor download (download here). From the archive's jscripts subdirectory, copy the contents of the tiny_mce/themes/advanced/images and tiny_mce/plugins/table/images directories into the javascript subdirectory of your MediaWiki install. (Nothing else from the TinyMCE download is needed, so the rest can be discarded).

If you see blank main page after patching, then it can be problem with permisions. Setting permisions to 777 will not help and is insecure. I recomend changing owner recursively for the whole wiki folder. You can do that by command chown. If it doesn't help then try to figure out what's wrong by adding these lines to the begining of file index.php(placed in main wiki folder)
error_reporting( E_ALL );
@ini_set( "display_errors", true );

This patch is courtesy of Logic Supply. Please direct all emails regarding the patch to Forest Bond <forest@logicsupply.com>. Patch last modified 12/6/2005.

Please note, this patch is certainly not perfect.

The following paragraph is obsolete, as creating links using TinyMCE is no longer an option. All links/images must be speicified using wiki markup e.g. [[Page Name]], [url Link Text], etc...

I suggest you use the option "Use wiki-style links in WYSIWYG." Please note, to create internal links using the TinyMCE interface, you should just set the URL to the page title you are trying to link to. This will only work, however, if the link text matches the link URL.

Note: This patch requires PHP 4.3.0 or later. You can make it work with 4.2.2 by changing the html2wiki function in EditPage.php to something like this:

function html2wiki($html)
{
  $html = "<html>\n<body>\n" . wysiwyg_preproc($html) . "</body>\n</html>\n";
  $tempfname = tempnam( '/tmp', 'mce' );
  $tempfile = fopen( $tempfname, 'w' );
  fwrite( $tempfile, $html );
  fclose( $tempfile );
  $pipe = popen( "html2wiki --dialect MediaWiki $tempfname", 'r' );
  while( ! feof( $pipe ) ) {
    $output .= fgets($pipe);
  }
  pclose( $pipe );
  unlink( $tempfname );
  return wysiwyg_postproc($output);
}


Using MediaWiki 1.5.3 on Linux I had to remove an empty line at the end of EditPage.php because I got error messages in the html user interface. Edit does work but after saving an empty page is stored.



Hi, I'm trying to integrate TinyMCE into MediaWiki 1.5.6. The editor works, however I also have the problem of saving an empty page.

Is there a fix for this yet? I tried:

  • removing the empty line at the end of EditPage.php
  • adding the dialect: "$html2wiki = 'html2wiki --dialect MediaWiki';" in EditPage.php.

Any ideas to solve the problem? It's quite urgent.


UPDATE: I was able to fix the problem. Here's my solution. I hope it helps others having the same problem. The saved text disappeared because html2wiki didn't run correctly.

  • Although the installation went fine, the MediaWiki dialect was not installed. If it is installed you should have a file MediaWiki.pm somewhere in your Perl directory. I fixed this by running:
perl -MCPAN -e 'install HTML::WikiConverter::MediaWiki'
  • To test if html2wiki worked I created a simple html file and ran:
html2wiki --dialect=MediaWiki test.html 

It complained about an encoding parameter (undef).

  • I tried running:
html2wiki --dialect=MediaWiki --encoding=utf-8 test.html 

and it worked fine.

  • So to make it work in the MediaWiki, I changed EditPage.php:
$html2wiki = 'html2wiki'

to

$html2wiki = 'html2wiki --dialect=MediaWiki --encoding=utf-8';

(note: this seems a little strange, as the html2wiki program doesn't parse command-line parameters... Did someone add this functionality, and, if so, where can the updated version be found?)


Web Server Environment

Please note that your web server's path must include the directory containing html2wiki. In other words, if html2wiki is in /usr/local/bin, this must be contained in the $PATH environment variable for your server's environment (which may be different from your login environment). If you are getting blank pages saved, you might try explicitly setting (in EditPage.php):

$html2wiki = '/usr/local/bin/html2wiki';

problems with templates

{{Templates}} seem horribly broken with this system. The html2wiki surrounds it in <nowiki>, and they don't get parsed. Altering HTML::WikiConverter::MediaWiki to prevent this from happening results in the templates getting parsed twice, which really breaks things. Any thoughts? 207.93.211.50 17:00, 23 August 2006 (UTC)[reply]

I've added a "preserve_templates" attribute to HTML::WikiConverter::MediaWiki 0.55 which should remedy the problem. Pass it a true value when setting up the dialect and you'll be golden:
   use HTML::WikiConverter;
   my $wc = new HTML::WikiConverter( dialect => 'MediaWiki', preserve_templates => 1 );
   print $wc->html2wiki( '{{template}}' );
This will have to be adapted to the html2wiki script that TinyMCE uses. Cheers, Diberri 15:35, 17 September 2006 (UTC)[reply]