Index: /MediaWiki/trunk/FCKeditor.body.php
===================================================================
--- /MediaWiki/trunk/FCKeditor.body.php	(revision 1664)
+++ /MediaWiki/trunk/FCKeditor.body.php	(revision 1665)
@@ -71,4 +71,5 @@
 		$wgHooks['EditPageBeforePreviewText'][]         = array($this, 'onEditPageBeforePreviewText');
 		$wgHooks['EditPagePreviewTextEnd'][]            = array($this, 'onEditPagePreviewTextEnd');
+		$wgHooks['CustomEditor']                        = array($this, 'onCustomEditor');
 
 		if ($this->debug) {
@@ -87,7 +88,30 @@
 
 			foreach ($opcje as $o) {
-				$wgHooks[$o][] = $this;
+				$wgHooks[$o][] = array($this, str_replace(":", "_", $o));
 			}
 		}
+	}
+
+	public function onCustomEditor(&$article, &$user)
+	{
+		global $wgRequest, $mediaWiki;
+
+		$action = $mediaWiki->getVal('Action');
+
+		$internal = $wgRequest->getVal( 'internaledit' );
+		$external = $wgRequest->getVal( 'externaledit' );
+		$section = $wgRequest->getVal( 'section' );
+		$oldid = $wgRequest->getVal( 'oldid' );
+		if( !$mediaWiki->getVal( 'UseExternalEditor' ) || $action=='submit' || $internal ||
+		$section || $oldid || ( !$user->getOption( 'externaleditor' ) && !$external ) ) {
+			$editor = new FCKeditorEditPage( $article );
+			$editor->submit();
+		} elseif( $mediaWiki->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
+			$mode = $wgRequest->getVal( 'mode' );
+			$extedit = new ExternalEdit( $article, $mode );
+			$extedit->edit();
+		}
+
+		return false;
 	}
 
Index: /MediaWiki/trunk/FCKeditor.php
===================================================================
--- /MediaWiki/trunk/FCKeditor.php	(revision 1664)
+++ /MediaWiki/trunk/FCKeditor.php	(revision 1665)
@@ -29,8 +29,10 @@
 require_once $IP . "/includes/ParserOptions.php";
 require_once $IP . "/includes/Parser.php";
+require_once $IP . "/includes/EditPage.php";
 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorSajax.body.php";
 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorParser.body.php";
 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorParserOptions.body.php";
 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorSkin.body.php";
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorEditPage.body.php";
 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditor.body.php";
 require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "fckeditor" . DIRECTORY_SEPARATOR . "fckeditor.php";
Index: /MediaWiki/trunk/FCKeditorEditPage.body.php
===================================================================
--- /MediaWiki/trunk/FCKeditorEditPage.body.php	(revision 1665)
+++ /MediaWiki/trunk/FCKeditorEditPage.body.php	(revision 1665)
@@ -0,0 +1,43 @@
+<?php
+
+class FCKeditorEditPage extends EditPage
+{
+	/**
+	 * Should we show a preview when the edit form is first shown?
+	 *
+	 * @return bool
+	 */
+	protected function previewOnOpen() {
+		global $wgRequest, $wgUser;
+		if( $wgRequest->getVal( 'preview' ) == 'yes' ) {
+			// Explicit override from request
+			return true;
+		} elseif( $wgRequest->getVal( 'preview' ) == 'no' ) {
+			// Explicit override from request
+			return false;
+		} elseif( $this->section == 'new' ) {
+			// Nothing *to* preview for new sections
+			return false;
+		} elseif( ( $wgRequest->getVal( 'preload' ) !== '' || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
+			// Standard preference behaviour
+			return true;
+		} elseif( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) {
+			// Categories are special
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
+	function getPreviewText() {
+		if (!$this->isCssJsSubpage) {
+			wfRunHooks( 'EditPageBeforePreviewText', array( &$this, $this->previewOnOpen() ) );
+			$result = parent::getPreviewText();
+			wfRunHooks( 'EditPagePreviewTextEnd', array( &$this, $this->previewOnOpen() ) );
+		}
+		else {
+			$result = parent::getPreviewText();
+		}
+		return $result;
+	}
+}
