Extension:WclEditor/wclEditor.php

From MediaWiki.org

Jump to: navigation, search
<?php 
 
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
 
/*
 * wclEditor - The text editor for Mediawiki
 * Copyright (C) 2006 Shtriter Anrew
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://meta.wikimedia.org/wiki/wclEditor
 * 
 * File Name: wclEditor.php
 * 	This is the integration file for MediaWiki.
 * 	
 * 	It defines the FCKeditor class that can be used to create editor
 * 	instances in PHP pages on server side and integrates it in MW.
 * 
 * File Author:
 * 		Shtriter Andrew (Shtriter@gmail.com)
 * Based on:
 *	FCKeditor integration file for PHP. (fckeditor.php in tarball)
 *		http://prdownloads.sourceforge.net/fckeditor/FCKeditor_2.3b.tar.gz?download
 *	 		Frederico Caldeira Knabben (fredck@fckeditor.net)
 *			Marcus Bointon <coolbru@users.sourceforge.net>)
 *	and
 *
 *	FCKeditor integration file for MediaWiki.
 *		http://meta.wikimedia.org/wiki/FCKeditor/extension
 *	 		Frederico Caldeira Knabben (fredck@fckeditor.net)
 *
 */
 
 
//////////////////////////////////////////////////
//			MediaWiki integration			//
//////////////////////////////////////////////////
 
 if( !defined( 'MEDIAWIKI' ) ) {
  die();
}
 
$wgExtensionCredits['other'][] = array(
 
	"name" => "wclEditor extension",
	"author" => "Shriter Andrew",
	"version" => "wclEditor/mw-extension July 2006",
	"url" => "http://meta.wikimedia.org/wiki/wclEditor",
	"description" => "integrating the wclEditor"
 
 );
 
 
# REGISTER HOOKS

$wgHooks['EditPage::showEditForm:initial'][] 	= 'wfFCKeditorAddFCKScript';
 
 
function wfFCKeditorAddFCKScript ($q) { 
 
	global $wgOut, $wgScriptPath, $wgWCLeditorDir;
 
 
	$wgOut->addScript(<<<Script
<script type="text/javascript">alert('If you want to use wclEditor,\n' +
'replace the script call with your fckeditor.js (See wclEditor.php, line 85)')
</script>
 
//my own example: ($wgWCLeditorDir = '/extensions/wclEditor' in LocalSettings)
//<script type="text/javascript" src="$wgWCLeditorDir/FCKeditor/fckeditor.js"></script>
 
//you can also try to use online FCKeditor (not test - only suggestion)
//<script type="text/javascript" src="http://www.fckeditor/FCKeditor/fckeditor.js"></script>
 
//Import InstaView
<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Pilaf/InstaView/Devel&action=raw&ctype=text/javascript&dontcountme=s"></script>'
 
//Import Wikificator
<script type="text/javascript" src="http://meta.wikipedia.org/w/index.php?title=Wikificator/Wikificator.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'
 
/*//If you what to test outputs or debug wclEditor - include JS Diff too:
<script type="text/javascript" src="http://en.wikipedia.org/ww/index.php?title=User:Cacycle/diff.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'
*/
 
<script type="text/javascript">
 
//var oFCKeditor;
 
function onLoadFCK()
  {
  //alert('FCKeditor')
  var textarea = $('wpTextbox1');
  var newtbox = document.createElement('textarea')
  newtbox.id="wclEditor";
 
  var div = document.createElement('div');
  div.id = "wclEditor___Div";
  div.style.display = "none";
 
  div.appendChild( newtbox );
 
  textarea.parentNode.insertBefore( div , textarea.nextSibling );
 
  var oFCKeditor = new FCKeditor('wclEditor') ;
  oFCKeditor.ReplaceTextarea() ;
 
  oFCKeditor._InsertHtmlBefore( '<input type ="checkbox" name="Toggle_wclEditor" ' +
  'onClick="Toggle( this.checked )" id="Toggle_wclEditor" /> ' +
  '<label for="Toggle_wclEditor">Use wclEditor:</label>' , $('wpSummary').nextSibling );
  }
 
 
 
function $(aID)
  { 
  return (document.getElementById) ? document.getElementById(aID)
          : (document.layers) ? document.layers[aID] : document.all[aID];
  } 
 
function Toggle( useEditor )
  {
 
  //alert(useEditor);
 
  var toolbar, textarea;
 
  if (useEditor)
	{
	convertedWikiText = InstaView.convert($('wpTextbox1').value);
 
	var oFCKeditor = FCKeditorAPI.GetInstance('wclEditor') ;
	//alert( oFCKeditor );
 
	oFCKeditor.SetHTML( convertedWikiText );
 
	//$('wclEditor').value = convertedWikiText;
 
	//alert( convertedWikiText );
 
	}
  else 
  	{
  	var oFCKeditor = FCKeditorAPI.GetInstance('wclEditor');
  	var Text =  oFCKeditor.GetXHTML( );
 
//alert('Before process:\\n"'+Text+'"');
 
  	Text = Process( Text ) ;
 
  	//alert('After process:\\n"'+Text+'"');  	
  	$('wpTextbox1').value =  Text ;
 
  	}
 
  if (toolbar = $('toolbar')) toolbar.style.display =  useEditor ? 'none' : 'block' ;
  if (textarea = $('wpTextbox1')) textarea.style.display = useEditor ? 'none' : 'inline' ;
  if (editor = $('wclEditor___Div')) editor.style.display = useEditor ? 'block' : 'none' ;
 
  //if (!useEditor) $('Wikificator').click();
  //alert('Done');
  }
 
addOnloadHook(onLoadFCK);
 
</script>
Script
);
	/*
	// If you want to test the results of converts or debug wclEditor just uncomment this
	$wgOut->addHTML(<<<Html
<input onclick="InstaView.dump('wpTextbox1', 'InstaViewDump')" value="InstaView" style="font-style: italic;" type="button">
<input onclick="Html2Wiki(document.getElementById('wpTextbox1').value)" value="Html2Wiki" style="font-weight: bold;" type="button">
Diff Wi & IV
<span style="border: 2px solid navy; margin: 5px 0pt; padding: 5px;">
 
<input onclick="
			var Textbox = InstaView.el('wpTextbox1');
			InstaView.el('InstaViewDump').innerHTML =
				StringDiff( Textbox.value , InstaView.convert( Textbox.value ) );" 
 
	value="diff( wiki, html )" style="font-style: italic; font-weight: bold;" type="button">
 
<input onclick="
			var Textbox = InstaView.el('wpTextbox1');
			InstaView.el('InstaViewDump').innerHTML = 
				StringDiff( Textbox.value, Process( InstaView.convert( Textbox.value ) ))"
 
	value="diff( wiki, Wi(IV(t)))" style="font-style: italic; font-weight: bold;" type="button">
 
</span>
 
Html
);
*/
}
?>