Extension:WclEditor/wclEditor.php

<?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 ) *	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"

);


 * 1) REGISTER HOOKS

$wgHooks['EditPage::showEditForm:initial'][] 	= 'wfFCKeditorAddFCKScript';

function wfFCKeditorAddFCKScript ($q) {

global $wgOut, $wgScriptPath, $wgWCLeditorDir;

$wgOut->addScript(<<alert('If you want to use wclEditor,\n' + 'replace the script call with your fckeditor.js (See wclEditor.php, line 85)')

//my own example: ($wgWCLeditorDir = '/extensions/wclEditor' in LocalSettings) //

//you can also try to use online FCKeditor (not test - only suggestion) //

//Import InstaView  '

//Import Wikificator  '

/*//If you what to test outputs or debug wclEditor - include JS Diff too:  '



//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( ' ' +  'Use wclEditor: ', $('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 );	/*	// If you want to test the results of converts or debug wclEditor just uncomment this	$wgOut->addHTML(<<  Diff Wi & IV





Html ); } ?>