Changeset 2388 for MediaWiki/trunk/FCKeditor.body.php
- Timestamp:
- 2008-08-27 16:58:27 (4 months ago)
- Files:
-
- 1 modified
-
MediaWiki/trunk/FCKeditor.body.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
MediaWiki/trunk/FCKeditor.body.php
r2077 r2388 1 1 <?php 2 /** 3 * Options for FCKeditor 4 * [start with FCKeditor] 5 */ 6 define("RTE_VISIBLE", 1); 7 /** 8 * Options for FCKeditor 9 * [show toggle link] 10 */ 11 define('RTE_TOGGLE_LINK', 2); 12 /** 13 * Options for FCKeditor 14 * [show popup link] 15 */ 16 define('RTE_POPUP', 4); 2 17 3 18 class FCKeditor_MediaWiki { 19 public $showFCKEditor; 4 20 private $count = array(); 5 21 private $wgFCKBypassText = ""; … … 78 94 */ 79 95 if ( (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) || 80 in_array($wgTitle->getNamespace(), $this->getExcludedNamespaces()) || 96 in_array($wgTitle->getNamespace(), $this->getExcludedNamespaces()) || !($this->showFCKEditor & RTE_VISIBLE) || 81 97 false !== strpos($pageEditor->textbox1, "__NORICHEDITOR__") 82 98 ) { … … 269 285 global $wgFCKWikiTextBeforeParse; 270 286 287 if (!isset($this->showFCKEditor)) 288 { 289 $this->showFCKEditor = 0; 290 if ( !$wgUser->getOption( 'riched_start_disabled' ) ) { 291 $this->showFCKEditor += RTE_VISIBLE; 292 } 293 if ( $wgUser->getOption( 'riched_use_popup' ) ) { 294 $this->showFCKEditor += RTE_POPUP; 295 } 296 if ( $wgUser->getOption( 'riched_use_toggle' ) ) { 297 $this->showFCKEditor += RTE_TOGGLE_LINK; 298 } 299 } 300 301 if( (!empty($_SESSION['showMyFCKeditor'])) && ($wgUser->getOption( 'riched_toggle_remember_state' ))) 302 { 303 //clear RTE_VISIBLE flag 304 $this->showFCKEditor &= ~RTE_VISIBLE ; 305 //get flag from session 306 $this->showFCKEditor |= $_SESSION['showMyFCKeditor'] ; 307 } 308 271 309 if (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) { 272 310 return true; … … 281 319 } 282 320 283 $options = new FCKeditorParserOptions();284 $options->setTidy(true);285 $parser = new FCKeditorParser();286 $parser->setOutputType(OT_HTML);287 321 $wgFCKWikiTextBeforeParse = $form->textbox1; 288 $form->textbox1 = $parser->parse($form->textbox1, $wgTitle, $options)->getText(); 322 if ($this->showFCKEditor & RTE_VISIBLE) 323 { 324 $options = new FCKeditorParserOptions(); 325 $options->setTidy(true); 326 $parser = new FCKeditorParser(); 327 $parser->setOutputType(OT_HTML); 328 $form->textbox1 = $parser->parse($form->textbox1, $wgTitle, $options)->getText(); 329 } 289 330 290 331 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" ); … … 317 358 HEREDOC; 318 359 360 $script .= '<script type="text/javascript"> '; 319 361 if (!empty($userStyles)) { 320 $script .= ' 321 <script type="text/javascript"> 322 sEditorAreaCSS += ",'.implode(',', $userStyles).'"; 323 </script>'; 324 } 325 362 $script .= 'sEditorAreaCSS += ",'.implode(',', $userStyles).'";'; 363 } 364 $script .= ' 365 var showFCKEditor = '. $this->showFCKEditor .'; 366 var popup = false; //pointer to popup document 367 var firstLoad = true; 368 var editorMsgOn = "'. wfMsg( 'textrichditor' ) .'"; 369 var editorMsgOff = "'. wfMsg( 'tog-riched_disable' ) .'"; 370 var editorLink = "'. (($this->showFCKEditor & RTE_VISIBLE)? wfMsg( 'tog-riched_disable' ): wfMsg( 'textrichditor' )) .'"; 371 var saveSetting = '. ($wgUser->getOption( 'riched_toggle_remember_state' ) ? 1 : 0) .'; 372 var RTE_VISIBLE = '.RTE_VISIBLE.'; 373 var RTE_TOGGLE_LINK = '.RTE_TOGGLE_LINK.'; 374 var RTE_POPUP = '.RTE_POPUP.'; 375 376 377 var oFCKeditor = new FCKeditor( "wpTextbox1" ) ; 378 379 //Set config 380 oFCKeditor.BasePath = "'.$wgScriptPath.'/'.$wgFCKEditorDir.'/" ; 381 oFCKeditor.Config["CustomConfigurationsPath"] = "'.$wgScriptPath.'/'.$wgFCKEditorExtDir.'/fckeditor_config.js" ; 382 oFCKeditor.Config["EditorAreaCSS"] = "'.$wgScriptPath.'/'.$wgFCKEditorExtDir.'/css/fckeditor.css" ; 383 oFCKeditor.ToolbarSet = "'. $wgFCKEditorToolbarSet .'" ; 384 oFCKeditor.ready = true; 385 '; 386 $script .= '</script>'; 387 388 $newWinMsg = wfMsg('rich_editor_new_window'); 326 389 $script .= <<<HEREDOC 327 390 <script type="text/javascript"> 328 391 329 // Remove the mwSetupToolbar onload hook to avoid a JavaScript error with FF. 330 if ( window.removeEventListener ) 331 window.removeEventListener( 'load', mwSetupToolbar, false ) ; 332 else if ( window.detachEvent ) 333 window.detachEvent( 'onload', mwSetupToolbar ) ; 334 335 mwSetupToolbar = function() { return false ; } ; 392 //IE hack to call func from popup 393 function FCK_sajax(func_name, args, target) { 394 sajax_request_type = 'POST' ; 395 sajax_do_call(func_name, args, function (x) { 396 // I know this is function, not object 397 target(x); 398 } 399 ); 400 } 336 401 337 402 function onLoadFCKeditor() 338 403 { 339 if ( document.getElementById('wpTextbox1') ) 404 if (!(showFCKEditor & RTE_VISIBLE)) 405 showFCKEditor += RTE_VISIBLE; 406 firstLoad = false; 407 realTextarea = document.getElementById('wpTextbox1'); 408 if ( realTextarea ) 340 409 { 341 410 var height = $wgFCKEditorHeight ; 342 411 realTextarea.style.display = 'none'; 343 412 if ( height == 0 ) 344 413 { … … 362 431 363 432 // Create the editor instance and replace the textarea. 364 var oFCKeditor = new FCKeditor('wpTextbox1') ;365 oFCKeditor.BasePath = '$wgScriptPath/$wgFCKEditorDir/' ;366 oFCKeditor.Config['CustomConfigurationsPath'] = '$wgScriptPath/$wgFCKEditorExtDir/fckeditor_config.js' ;367 oFCKeditor.Config['EditorAreaCSS'] = "$wgScriptPath/$wgFCKEditorExtDir/css/fckeditor.css" ;368 433 oFCKeditor.Height = height ; 369 oFCKeditor.ToolbarSet = '$wgFCKEditorToolbarSet' ;370 434 oFCKeditor.ReplaceTextarea() ; 371 435 372 436 // Hide the default toolbar. 373 document.getElementById('toolbar').style. cssText = 'display:none;' ;437 document.getElementById('toolbar').style.display = 'none' ; 374 438 // do things with CharInsert for example 375 439 … … 378 442 edittools_markup.style.display = 'none' ; 379 443 } 380 insertTags = function (tagOpen, tagClose, sampleText)444 FCKeditorInsertTags = function (tagOpen, tagClose, sampleText, oDoc) 381 445 { 382 446 var txtarea; 383 447 384 if ( !(typeof( FCK) == "undefined") && !(typeof(FCK.EditingArea) == "undefined") )448 if ( !(typeof(oDoc.FCK) == "undefined") && !(typeof(oDoc.FCK.EditingArea) == "undefined") ) 385 449 { 386 txtarea = FCK.EditingArea.Textarea ;387 } 388 else if ( document.editform)450 txtarea = oDoc.FCK.EditingArea.Textarea ; 451 } 452 else if (oDoc.editform) 389 453 { 390 454 // if we have FCK enabled, behave differently... 391 FCKarea = document.getElementById( oFCKeditor.InstanceName ) ; 392 if ( FCKarea.style.display == 'none' ) 455 if ( showFCKEditor & RTE_VISIBLE ) 393 456 { 394 SRCiframe = document.getElementById ('wpTextbox1___Frame') ;457 SRCiframe = oDoc.getElementById ('wpTextbox1___Frame') ; 395 458 if ( SRCiframe ) 396 459 { 397 460 if (window.frames[SRCiframe]) 398 SRCdoc = window.frames[SRCiframe]. document;461 SRCdoc = window.frames[SRCiframe].oDoc ; 399 462 else 400 463 SRCdoc = SRCiframe.contentDocument ; … … 415 478 else 416 479 { 417 txtarea = document.editform.wpTextbox1 ;480 txtarea = oDoc.editform.wpTextbox1 ; 418 481 } 419 482 } … … 421 484 { 422 485 // some alternate form? take the first one we can find 423 var areas = document.getElementsByTagName( 'textarea' ) ;486 var areas = oDoc.getElementsByTagName( 'textarea' ) ; 424 487 txtarea = areas[0] ; 425 488 } … … 427 490 var selText, isSample = false ; 428 491 429 if ( document.selection && document.selection.createRange )492 if ( oDoc.selection && oDoc.selection.createRange ) 430 493 { // IE/Opera 431 494 432 495 //save window scroll position 433 if ( document.documentElement && document.documentElement.scrollTop )434 var winScroll = document.documentElement.scrollTop ;435 else if ( document.body )436 var winScroll = document.body.scrollTop ;496 if ( oDoc.documentElement && oDoc.documentElement.scrollTop ) 497 var winScroll = oDoc.documentElement.scrollTop ; 498 else if ( oDoc.body ) 499 var winScroll = oDoc.body.scrollTop ; 437 500 438 501 //get current selection 439 502 txtarea.focus() ; 440 var range = document.selection.createRange() ;503 var range = oDoc.selection.createRange() ; 441 504 selText = range.text ; 442 505 //insert tags 443 checkSelected Text();506 checkSelected(); 444 507 range.text = tagOpen + selText + tagClose ; 445 508 //mark sample text as selected … … 453 516 range.select(); 454 517 //restore window scroll position 455 if ( document.documentElement && document.documentElement.scrollTop )456 document.documentElement.scrollTop = winScroll ;457 else if ( document.body )458 document.body.scrollTop = winScroll ;518 if ( oDoc.documentElement && oDoc.documentElement.scrollTop ) 519 oDoc.documentElement.scrollTop = winScroll ; 520 else if ( oDoc.body ) 521 oDoc.body.scrollTop = winScroll ; 459 522 460 523 } … … 500 563 } 501 564 } 502 addOnloadHook( onLoadFCKeditor ) ; 503 </script> 565 function checkSelected() 566 { 567 if (!selText) { 568 selText = sampleText; 569 isSample = true; 570 } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char 571 selText = selText.substring(0, selText.length - 1); 572 tagClose += ' ' 573 } 574 } 575 function initEditor() 576 { 577 var toolbar = document.getElementById('toolbar') ; 578 //show popup or toogle link 579 if (showFCKEditor & (RTE_POPUP|RTE_TOGGLE_LINK)){ 580 //add new toolbar before wiki toolbar 581 var fckTools = document.createElement('div'); 582 fckTools.setAttribute('id', 'fckTools'); 583 toolbar.parentNode.insertBefore( fckTools, toolbar ); 584 585 var SRCtextarea = document.getElementById( "wpTextbox1" ) ; 586 if (showFCKEditor & RTE_VISIBLE) SRCtextarea.style.display = "none"; 587 } 588 589 if (showFCKEditor & RTE_TOGGLE_LINK) 590 { 591 fckTools.innerHTML='[<a class="fckToogle" id="toggle_wpTextbox1" href="javascript:void(0)" onclick="ToggleFCKEditor(\'toggle\',\'wpTextbox1\')">'+ editorLink +'</a>] '; 592 } 593 if (showFCKEditor & RTE_POPUP) 594 { 595 var style = (showFCKEditor & RTE_VISIBLE) ? 'style="display:none"' : ""; 596 fckTools.innerHTML+='<span ' + style + ' id="popup_wpTextbox1">[<a class="fckPopup" href="javascript:void(0)" onclick="ToggleFCKEditor(\'popup\',\'wpTextbox1\')">{$newWinMsg}</a>]</span>'; 597 } 598 599 if (showFCKEditor & RTE_VISIBLE) 600 { 601 if ( toolbar ) //insert wiki buttons 602 { 603 // Remove the mwSetupToolbar onload hook to avoid a JavaScript error with FF. 604 if ( window.removeEventListener ) 605 window.removeEventListener( 'load', mwSetupToolbar, false ) ; 606 else if ( window.detachEvent ) 607 window.detachEvent( 'onload', mwSetupToolbar ) ; 608 mwSetupToolbar = function() { return false ; } ; 609 610 for (var i = 0; i < mwEditButtons.length; i++) { 611 mwInsertEditButton(toolbar, mwEditButtons[i]); 612 } 613 for (var i = 0; i < mwCustomEditButtons.length; i++) { 614 mwInsertEditButton(toolbar, mwCustomEditButtons[i]); 615 } 616 } 617 onLoadFCKeditor(); 618 } 619 return true; 620 } 621 addOnloadHook( initEditor ); 622 504 623 HEREDOC; 505 624 506 /* 507 $script .= <<<HEREDOC 508 <script type="text/javascript"> 509 function showSource() { 510 var wp = document.getElementById("wpDiff"); 511 var s = document.createElement("input"); 512 s.type="submit"; 513 s.value="Wiki2HTML"; 514 s.name="Wiki2HTML"; 515 s.onclick = function wiki2html() { 516 var oEditor = FCKeditorAPI.GetInstance('wpTextbox1'); 517 WikiToHTML_Call(); 518 return false; 519 } 520 wp.parentNode.insertBefore(s, wp.nextSibling); 521 } 522 523 var sajax_debug_mode = false; 524 var sajax_request_type = "GET"; 525 526 function WikiToHTML_Result(result) { 527 var oEditor = FCKeditorAPI.GetInstance('wpTextbox1'); 528 oEditor.SetHTML(result.responseText); 529 } 530 function WikiToHTML_Call() { 531 var oEditor = FCKeditorAPI.GetInstance('wpTextbox1'); 532 sajax_do_call('wfSajaxWikiToHTML', [oEditor.GetHTML()], WikiToHTML_Result); 533 } 534 535 addOnloadHook(showSource); 536 </script> 625 if ($this->showFCKEditor & (RTE_TOGGLE_LINK | RTE_POPUP) ){ 626 //add toogle link and handler 627 $script .= <<<HEREDOC 628 629 function ToggleFCKEditor(mode, objId) 630 { 631 var SRCtextarea = document.getElementById( objId ) ; 632 if(mode == 'popup'){ 633 if (( showFCKEditor & RTE_VISIBLE) && ( FCKeditorAPI )) //if FCKeditor is up-to-date 634 { 635 var oEditorIns = FCKeditorAPI.GetInstance( objId ); 636 var text = oEditorIns.GetData( oEditorIns.Config.FormatSource ); 637 SRCtextarea.value = text; //copy text to textarea 638 } 639 FCKeditor_OpenPopup('oFCKeditor',objId); 640 return true; 641 } 642 643 var oToggleLink = document.getElementById('toggle_'+ objId ); 644 var oPopupLink = document.getElementById('popup_'+ objId ); 645 646 if ( firstLoad ) 647 { 648 // firstLoad = true => FCKeditor start invisible 649 if (oToggleLink) oToggleLink.innerHTML = "Loading..."; 650 sajax_request_type = 'POST' ; 651 oFCKeditor.ready = false; 652 sajax_do_call('wfSajaxWikiToHTML', [SRCtextarea.value], function ( result ){ 653 if ( firstLoad ) //still 654 { 655 SRCtextarea.value = result.responseText; //insert parsed text 656 onLoadFCKeditor(); 657 if (oToggleLink) oToggleLink.innerHTML = editorMsgOff; 658 oFCKeditor.ready = true; 659 } 660 }); 661 return true; 662 } 663 664 if (!oFCKeditor.ready) return false; //sajax_do_call in action 665 if (!FCKeditorAPI) return false; //not loaded yet 666 var oEditorIns = FCKeditorAPI.GetInstance( objId ); 667 var oEditorIframe = document.getElementById( objId+'___Frame' ); 668 var FCKtoolbar = document.getElementById('toolbar'); 669 var bIsWysiwyg = ( oEditorIns.EditMode == FCK_EDITMODE_WYSIWYG ); 670 671 //FCKeditor visible -> hidden 672 if ( showFCKEditor & RTE_VISIBLE) 673 { 674 var text = oEditorIns.GetData( oEditorIns.Config.FormatSource ); 675 SRCtextarea.value = text; 676 if ( bIsWysiwyg ) oEditorIns.SwitchEditMode(); //switch to plain 677 var text = oEditorIns.GetData( oEditorIns.Config.FormatSource ); 678 //copy from FCKeditor to textarea 679 SRCtextarea.value = text; 680 if (saveSetting) 681 { 682 sajax_request_type = 'GET' ; 683 sajax_do_call( 'wfSajaxToggleFCKeditor', ['hide'], function(){} ) ; //remember closing in session 684 } 685 if (oToggleLink) oToggleLink.innerHTML = editorMsgOn; 686 if (oPopupLink) oPopupLink.style.display = ''; 687 showFCKEditor -= RTE_VISIBLE; 688 oEditorIframe.style.display = 'none'; 689 FCKtoolbar.style.display = ''; 690 SRCtextarea.style.display = ''; 691 } 692 //FCKeditor hidden -> visible 693 else 694 { 695 if ( bIsWysiwyg ) oEditorIns.SwitchEditMode(); //switch to plain 696 SRCtextarea.style.display = 'none'; 697 //copy from textarea to FCKeditor 698 oEditorIns.EditingArea.Textarea.value = SRCtextarea.value 699 FCKtoolbar.style.display = 'none'; 700 oEditorIframe.style.display = ''; 701 if ( !bIsWysiwyg ) oEditorIns.SwitchEditMode(); //switch to WYSIWYG 702 showFCKEditor += RTE_VISIBLE; // showFCKEditor+=RTE_VISIBLE 703 if (oToggleLink) oToggleLink.innerHTML = editorMsgOff; 704 if (oPopupLink) oPopupLink.style.display = 'none'; 705 } 706 return true; 707 } 708 537 709 HEREDOC; 538 */ 710 } 711 712 if($this->showFCKEditor & RTE_POPUP){ 713 $script .= <<<HEREDOC 714 715 function FCKeditor_OpenPopup(jsID, textareaID) 716 { 717 popupUrl = '${wgFCKEditorExtDir}/FCKeditor.popup.html'; 718 popupUrl = popupUrl + '?var='+ jsID + '&el=' + textareaID; 719 window.open(popupUrl, null, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=1,dependent=yes'); 720 return 0; 721 } 722 HEREDOC; 723 } 724 $script .= "</script>"; 539 725 540 726 $wgOut->addScript($script); … … 545 731 public function onUserToggles( &$extraToggles ) { 546 732 $extraToggles[] = 'riched_disable'; 733 $extraToggles[] = 'riched_start_disabled'; 734 $extraToggles[] = 'riched_use_popup'; 735 $extraToggles[] = 'riched_use_toggle'; 736 $extraToggles[] = 'riched_toggle_remember_state'; 737 547 738 $extraToggles = array_merge($extraToggles, self::$nsToggles); 548 739 return true;