Ticket #2266: FCKed.patch

File FCKed.patch, 17.1 KB (added by Jack Phoenix, 15 years ago)

Patch to make the FCKeditor use standard coding style & updated $wgExtensionCredits with more accurate info

  • FCKeditor.body.php

     
    11<?php
    22
    3 class FCKeditor_MediaWiki
    4 {
     3class FCKeditor_MediaWiki {
    54        private $count = array();
    65        private $wgFCKBypassText = "";
    76        private $debug = 0;
     
    2827
    2928        static $messagesLoaded = false;
    3029
    31         function __call($m,$a)
    32         {
     30        function __call($m, $a) {
    3331                print "\n#### " . $m . "\n";
    3432                if (!isset($this->count[$m])) {
    3533                        $this->count[$m] = 0;
     
    3836                return true;
    3937        }
    4038
    41         function onMonoBookTemplateToolboxEnd()
    42         {
     39        function onMonoBookTemplateToolboxEnd() {
    4340                if ($this->debug) {
    4441                        print_r($this->count);
    4542                }
    4643        }
    4744
    48         private function getExcludedNamespaces()
    49         {
     45        private function getExcludedNamespaces() {
    5046                global $wgUser;
    5147
    5248                if ( is_null( $this->excludedNamespaces ) ) {
     
    6157                return $this->excludedNamespaces;
    6258        }
    6359
    64         public function onLanguageGetMagic(&$magicWords, $langCode)
    65         {
     60        public function onLanguageGetMagic(&$magicWords, $langCode) {
    6661                $magicWords['NORICHEDITOR'] = array( 0, '__NORICHEDITOR__' );
    6762               
    6863                return true;
    6964        }
    7065       
    71         public function onParserBeforeInternalParse(&$parser, &$text, &$strip_state)
    72         {
     66        public function onParserBeforeInternalParse(&$parser, &$text, &$strip_state) {
    7367                MagicWord::get( 'NORICHEDITOR' )->matchAndRemove( $text );
    7468               
    7569                return true;
    7670        }
    7771       
    78         public function onEditPageShowEditFormFields($pageEditor, $wgOut)
    79         {
     72        public function onEditPageShowEditFormFields($pageEditor, $wgOut) {
    8073                global $wgUser, $wgFCKEditorIsCompatible, $wgTitle, $wgVersion;
    8174
    8275                /*
     
    110103                return true;
    111104        }
    112105
    113         public function onEditPageBeforeConflictDiff($pageEditor, $wgOut)
    114         {
     106        public function onEditPageBeforeConflictDiff($pageEditor, $wgOut) {
    115107                global $fckPageEditor, $wgRequest;
    116108
    117109                /*
     
    124116                return true;
    125117        }
    126118       
    127         public function onSanitizerAfterFixTagAttributes($text, $element, &$attribs)
    128         {
     119        public function onSanitizerAfterFixTagAttributes($text, $element, &$attribs) {
    129120                $text = preg_match_all("/Fckmw\d+fckmw/", $text, $matches);
    130121               
    131122                if (!empty($matches[0][0])) {
     
    180171                }
    181172        }
    182173
    183         public function onCustomEditor(&$article, &$user)
    184         {
     174        public function onCustomEditor(&$article, &$user) {
    185175                global $wgRequest, $mediaWiki;
    186176
    187177                $action = $mediaWiki->getVal('Action');
     
    203193                return false;
    204194        }
    205195
    206         public function onEditPageBeforePreviewText(&$editPage, $previewOnOpen)
    207         {
     196        public function onEditPageBeforePreviewText(&$editPage, $previewOnOpen) {
    208197                global $wgUser, $wgRequest;
    209198
    210199                if ($wgUser->getOption( 'showtoolbar' ) && !$wgUser->getOption( 'riched_disable' ) && !$previewOnOpen ) {
     
    215204                return true;
    216205        }
    217206
    218         public function onEditPagePreviewTextEnd(&$editPage, $previewOnOpen)
    219         {
     207        public function onEditPagePreviewTextEnd(&$editPage, $previewOnOpen) {
    220208                global $wgUser;
    221209
    222210                if ($wgUser->getOption( 'showtoolbar' ) && !$wgUser->getOption( 'riched_disable' ) && !$previewOnOpen ) {
     
    226214                return true;
    227215        }
    228216
    229         public function onParserAfterTidy(&$parser, &$text)
    230         {
     217        public function onParserAfterTidy(&$parser, &$text) {
    231218                global $wgUseTeX, $wgUser, $wgTitle, $wgFCKEditorIsCompatible;
    232219
    233220                if (!$wgUser->getOption( 'showtoolbar' ) || $wgUser->getOption( 'riched_disable' ) || !$wgFCKEditorIsCompatible) {
     
    247234                return true;
    248235        }
    249236
    250         public function onMessagesPreLoad()
    251         {
     237        public function onMessagesPreLoad() {
    252238                global $wgMessageCache, $wgUser, $wgContLanguageCode;
    253239
    254240                if ( !self::$messagesLoaded ) {
     
    342328
    343329// Remove the mwSetupToolbar onload hook to avoid a JavaScript error with FF.
    344330if ( window.removeEventListener )
    345         window.removeEventListener( 'load', mwSetupToolbar, false ) ;
     331        window.removeEventListener( 'load', mwSetupToolbar, false );
    346332else if ( window.detachEvent )
    347         window.detachEvent( 'onload', mwSetupToolbar ) ;
     333        window.detachEvent( 'onload', mwSetupToolbar );
    348334       
    349 mwSetupToolbar = function() { return false ; } ;
     335mwSetupToolbar = function() { return false ; };
    350336
    351 function onLoadFCKeditor()
    352 {
    353         if ( document.getElementById('wpTextbox1') )
    354         {
    355                 var height = $wgFCKEditorHeight ;
     337function onLoadFCKeditor() {
     338        if ( document.getElementById('wpTextbox1') ) {
     339                var height = $wgFCKEditorHeight;
    356340               
    357                 if ( height == 0 )
    358                 {
     341                if ( height == 0 ) {
    359342                        // Get the window (inner) size.
    360                         var height = window.innerHeight || ( document.documentElement && document.documentElement.clientHeight ) || 550 ;
     343                        var height = window.innerHeight || ( document.documentElement && document.documentElement.clientHeight ) || 550;
    361344                       
    362345                        // Reduce the height to the offset of the toolbar.
    363                         var offset = document.getElementById('wikiPreview') || document.getElementById('toolbar') ;
    364                         while ( offset )
    365                         {
    366                                 height -= offset.offsetTop ;
    367                                 offset = offset.offsetParent ;
     346                        var offset = document.getElementById('wikiPreview') || document.getElementById('toolbar');
     347                        while ( offset ) {
     348                                height -= offset.offsetTop;
     349                                offset = offset.offsetParent;
    368350                        }
    369351                       
    370352                        // Add a small space to be left in the bottom.
    371                         height -= 20 ;
     353                        height -= 20;
    372354                }
    373355
    374356                // Enforce a minimum height.
    375                 height = ( !height || height < 300 ) ? 300 : height ;
     357                height = ( !height || height < 300 ) ? 300 : height;
    376358               
    377359                // Create the editor instance and replace the textarea.
    378                 var oFCKeditor = new FCKeditor('wpTextbox1') ;
    379                 oFCKeditor.BasePath = '$wgScriptPath/$wgFCKEditorDir/' ;
    380                 oFCKeditor.Config['CustomConfigurationsPath'] = '$wgScriptPath/$wgFCKEditorExtDir/fckeditor_config.js' ;
    381                 oFCKeditor.Config['EditorAreaCSS'] = "$wgScriptPath/$wgFCKEditorExtDir/css/fckeditor.css" ;
    382                 oFCKeditor.Height = height ;
    383                 oFCKeditor.ToolbarSet = '$wgFCKEditorToolbarSet' ;
    384                 oFCKeditor.ReplaceTextarea() ;
     360                var oFCKeditor = new FCKeditor('wpTextbox1');
     361                oFCKeditor.BasePath = '$wgScriptPath/$wgFCKEditorDir/';
     362                oFCKeditor.Config['CustomConfigurationsPath'] = '$wgScriptPath/$wgFCKEditorExtDir/fckeditor_config.js';
     363                oFCKeditor.Config['EditorAreaCSS'] = "$wgScriptPath/$wgFCKEditorExtDir/css/fckeditor.css";
     364                oFCKeditor.Height = height;
     365                oFCKeditor.ToolbarSet = '$wgFCKEditorToolbarSet';
     366                oFCKeditor.ReplaceTextarea();
    385367               
    386368                // Hide the default toolbar.
    387                 document.getElementById('toolbar').style.cssText = 'display:none;' ;
     369                document.getElementById('toolbar').style.cssText = 'display:none;';
    388370        }
    389371}
    390 addOnloadHook( onLoadFCKeditor ) ;
     372addOnloadHook( onLoadFCKeditor );
    391373</script>
    392374HEREDOC;
    393375
     
    411393var sajax_debug_mode = false;
    412394var sajax_request_type = "GET";
    413395
    414 function WikiToHTML_Result(result)
    415 {
     396function WikiToHTML_Result(result) {
    416397        var oEditor = FCKeditorAPI.GetInstance('wpTextbox1');
    417398        oEditor.SetHTML(result.responseText);
    418399}
    419 function WikiToHTML_Call()
    420 {
     400function WikiToHTML_Call() {
    421401        var oEditor = FCKeditorAPI.GetInstance('wpTextbox1');
    422402        sajax_do_call('wfSajaxWikiToHTML', [oEditor.GetHTML()], WikiToHTML_Result);
    423403}
     
    437417                $extraToggles = array_merge($extraToggles, self::$nsToggles);
    438418                return true;
    439419        }
    440 }
     420}
     421 No newline at end of file
  • FCKeditor.php

     
    33# Not a valid entry point, skip unless MEDIAWIKI is defined
    44if (!defined('MEDIAWIKI')) {
    55        echo <<<HEREDOC
    6 To install my extension, put the following line in LocalSettings.php:
     6To install FCKeditor, put the following line in LocalSettings.php:
    77require_once( "\$IP/extensions/FCKeditor/FCKeditor.php" );
    88HEREDOC;
    99        exit( 1 );
     
    3030require_once $IP . "/includes/EditPage.php";
    3131
    3232if (version_compare("1.12", $wgVersion, "<")) {
    33     require_once $IP . "/includes/Parser_OldPP.php";
    34     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "mw12/FCKeditorParser_OldPP.body.php";
     33        require_once $IP . "/includes/Parser_OldPP.php";
     34        require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "mw12/FCKeditorParser_OldPP.body.php";
     35} else {
     36        require_once $IP . "/includes/Parser.php";
     37        require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorParser.body.php";
    3538}
    36 else {
    37     require_once $IP . "/includes/Parser.php";
    38     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorParser.body.php";
    39 }
    4039
    4140require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorSajax.body.php";
    4241require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "FCKeditorParserOptions.body.php";
     
    4645require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "fckeditor" . DIRECTORY_SEPARATOR . "fckeditor.php";
    4746
    4847if (empty ($wgFCKEditorExtDir)) {
    49     $wgFCKEditorExtDir = "extensions/FCKeditor" ;
     48        $wgFCKEditorExtDir = "extensions/FCKeditor";
    5049}
    5150if (empty ($wgFCKEditorDir)) {
    52     $wgFCKEditorDir = "extensions/FCKeditor/fckeditor" ;
     51        $wgFCKEditorDir = "extensions/FCKeditor/fckeditor";
    5352}
    5453if (empty ($wgFCKEditorToolbarSet)) {
    55     $wgFCKEditorToolbarSet = "Wiki" ;
     54        $wgFCKEditorToolbarSet = "Wiki";
    5655}
    5756if (empty ($wgFCKEditorHeight)) {
    58     $wgFCKEditorHeight = "0" ; // "0" for automatic ("300" minimum).
     57        $wgFCKEditorHeight = "0"; // "0" for automatic ("300" minimum).
    5958}
    6059
    6160/**
     
    7170$wgAjaxExportList[] = 'wfSajaxSearchSpecialTagFCKeditor';
    7271
    7372$wgExtensionCredits['other'][] = array(
    74 "name" => "FCKeditor extension",
    75 "author" => "FCKeditor.net (inspired by the code written by Mafs [Meta])",
    76 "version" => 'fckeditor/mw-extension $Rev$ 2008',
    77 "url" => "http://meta.wikimedia.org/wiki/FCKeditor",
    78 "description" => "FCKeditor extension"
     73        'name' => 'FCKeditor',
     74        'author' => array('FCKeditor.net', 'Wikia'),
     75        'version' => 'fckeditor/mw-extension $Rev$ 2008',
     76        'url' => 'http://www.mediawiki.org/wiki/Extension:FCKeditor_%28by_FCKeditor_and_Wikia%29',
     77        'description' => 'FCKeditor (WYSIWYG editor) for editing wiki pages'
    7978);
    8079
    8180$fckeditor = new FCKeditor("fake");
    8281$wgFCKEditorIsCompatible = $fckeditor->IsCompatible();
    8382
    8483$oFCKeditorExtension = new FCKeditor_MediaWiki();
    85 $oFCKeditorExtension->registerHooks();
    86 
    87 
    88 
    89 
    90 
    91 
    92 
    93 
     84$oFCKeditorExtension->registerHooks();
     85 No newline at end of file
  • FCKeditorEditPage.body.php

     
    11<?php
    22
    3 class FCKeditorEditPage extends EditPage
    4 {
     3class FCKeditorEditPage extends EditPage {
    54        /**
    65         * Should we show a preview when the edit form is first shown?
    76         *
     
    7574                        $this->textbox1 = $_textbox1;
    7675                }
    7776        }
    78 }
     77}
     78 No newline at end of file
  • FCKeditorParser.body.php

     
    11<?php
    22
    3 class FCKeditorParser extends Parser
    4 {
     3class FCKeditorParser extends Parser {
    54        public static $fkc_mw_makeImage_options;
    65        protected $fck_mw_strtr_span;
    76        protected $fck_mw_strtr_span_counter=1;
  • FCKeditorParserOptions.body.php

     
    11<?php
    22
    3 class FCKeditorParserOptions extends ParserOptions
    4 {
    5         function getNumberHeadings() {return false;}
    6         function getEditSection() {return false;}
     3class FCKeditorParserOptions extends ParserOptions {
     4        function getNumberHeadings() { return false; }
     5        function getEditSection() { return false; }
    76
    87        function getSkin() {
    98                if ( !isset( $this->mSkin ) ) {
  • FCKeditorSajax.body.php

     
    11<?php
    22
    3 function wfSajaxGetMathUrl( $term )
    4 {
     3function wfSajaxGetMathUrl( $term ) {
    54        $originalLink = MathRenderer::renderMath( $term );
    65
    76        if (false == strpos($originalLink, "src=\"")) {
     
    1413        return $url;
    1514}
    1615
    17 function wfSajaxGetImageUrl( $term )
    18 {
     16function wfSajaxGetImageUrl( $term ) {
    1917        global $wgExtensionFunctions, $wgTitle;
    2018
    2119        $options = new FCKeditorParserOptions();
     
    3836        return $url;
    3937}
    4038
    41 function wfSajaxSearchSpecialTagFCKeditor($empty)
    42 {
     39function wfSajaxSearchSpecialTagFCKeditor($empty) {
    4340        global $wgParser;
    4441
    4542        $ret = "nowiki\nincludeonly\nonlyinclude\nnoinclude\ngallery\n";
     
    5148        return $ret;
    5249}
    5350
    54 function wfSajaxSearchImageFCKeditor( $term )
    55 {
     51function wfSajaxSearchImageFCKeditor( $term ) {
    5652        global $wgContLang, $wgOut;
    5753        $limit = 10;
    5854
     
    6561        if ( strlen( str_replace( '_', '', $term ) )<3 )
    6662        return "";
    6763
    68         $db =& wfGetDB( DB_SLAVE );
     64        $db = wfGetDB( DB_SLAVE );
    6965        $res = $db->select( 'page', 'page_title',
    7066        array(  'page_namespace' => NS_IMAGE,
    7167        "LOWER(page_title) LIKE '%". $db->strencode( $term2 ) ."%'" ),
     
    7470        );
    7571
    7672        $ret = "";
    77         $i=0;
     73        $i = 0;
    7874        while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
    7975                $ret .= $row->page_title ."\n";
    8076        }
     
    8480        return $ret;
    8581}
    8682
    87 function wfSajaxSearchArticleFCKeditor( $term )
    88 {
     83function wfSajaxSearchArticleFCKeditor( $term ) {
    8984        global $wgContLang, $wgOut;
    9085        $limit = 10;
    9186        $ns = NS_MAIN;
     
    112107                return "";
    113108        }
    114109
    115         $db =& wfGetDB( DB_SLAVE );
     110        $db = wfGetDB( DB_SLAVE );
    116111        $res = $db->select( 'page', 'page_title',
    117112        array(  'page_namespace' => $ns,
    118113        "LOWER(page_title) LIKE '%". $db->strencode( $term2 ) ."%'" ),
     
    121116        );
    122117
    123118        $ret = "";
    124         $i=0;
     119        $i = 0;
    125120        while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
    126121                if (isset($prefix) && !is_null($prefix)) {
    127122                        $ret .= $prefix;
     
    134129        return $ret;
    135130}
    136131
    137 function wfSajaxSearchTemplateFCKeditor($empty)
    138 {
     132function wfSajaxSearchTemplateFCKeditor($empty) {
    139133        global $wgContLang, $wgOut;
    140134        $ns = NS_TEMPLATE;
    141135
    142         $db =& wfGetDB( DB_SLAVE );
     136        $db = wfGetDB( DB_SLAVE );
    143137        $res = $db->select( 'page', 'page_title',
    144         array(  'page_namespace' => $ns),
     138        array( 'page_namespace' => $ns),
    145139        "wfSajaxSearch"
    146140        );
    147141
     
    153147        return $ret;
    154148}
    155149
    156 function wfSajaxWikiToHTML( $wiki )
    157 {
     150function wfSajaxWikiToHTML( $wiki ) {
    158151        global $wgTitle;
    159152
    160153        $options = new FCKeditorParserOptions();
     
    163156        $parser->setOutputType(OT_HTML);
    164157
    165158        return $parser->parse($wiki, $wgTitle, $options)->getText();
    166 }
     159}
     160 No newline at end of file
  • FCKeditorSkin.body.php

     
    11<?php
    22
    3 class FCKeditorSkin
    4 {
     3class FCKeditorSkin {
    54        private $skin;
    65
    76        /**
     
    1918         * @return string     *
    2019         */
    2120        function makeImageLinkObj( $nt, $label, $alt, $align = '', $params = array(), $framed = false,
    22         $thumb = false, $manual_thumb = '', $valign = '' )
    23         {
     21        $thumb = false, $manual_thumb = '', $valign = '' ) {
    2422                $orginal = $nt->getText();
    2523                $img   = new Image( $nt );
    2624                $imgName = $img->getName();
     
    3735
    3836                if ($found) {
    3937                        $ret .= "src=\"{$url}\" ";
    40                 }
    41                 else {
     38                } else {
    4239                        $ret .= "_fck_mw_valid=\"false"."\" ";
    4340                }
    4441                $ret .= "_fck_mw_filename=\"{$orginal}\" ";
     
    8380
    8481                if (!is_null($alt) && !empty($alt) && false !== strpos(FCKeditorParser::$fkc_mw_makeImage_options, $alt) && $alt != "Image:" . $orginal) {
    8582                        $ret .= "alt=\"".htmlspecialchars($alt)."\" ";
    86                 }
    87                 else {
     83                } else {
    8884                        $ret .= "alt=\"\" ";
    8985                }
    9086
     
    151147
    152148                if ($found) {
    153149                        $ret .= "src=\"{$url}\" ";
    154                 }
    155                 else {
     150                } else {
    156151                        $ret .= "_fck_mw_valid=\"false"."\" ";
    157152                }
    158153                $ret .= "_fck_mw_filename=\"{$orginal}\" ";
     
    201196
    202197                if (isset($fp['alt']) && !empty($fp['alt']) && false !== strpos(FCKeditorParser::$fkc_mw_makeImage_options, $fp['alt']) && $fp['alt'] != "Image:" . $orginal) {
    203198                        $ret .= "alt=\"".htmlspecialchars($fp['alt'])."\" ";
    204                 }
    205                 else {
     199                } else {
    206200                        $ret .= "alt=\"\" ";
    207201                }
    208202
     
    215209                return $ret;
    216210        }
    217211
    218         function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' )
    219         {
     212        function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
    220213                $fname = 'FCKeditorSkin::makeKnownLinkObj';
    221214                wfProfileIn( $fname );
    222215
     
    257250                return $r;
    258251        }
    259252
    260         function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' )
    261         {
     253        function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
    262254                # Fail gracefully
    263255                if ( ! isset($nt) ) {
    264256                        # throw new MWException();
     
    311303                                        $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDbKey() ) );
    312304                                        $class = 'new';
    313305                                }
    314                         }
    315                         // Mediawiki 1.10
    316                         else {
     306                        } else { // MediaWiki 1.10
    317307                                $img  = new Image( $title );
    318308                                if( $img->exists() ) {
    319309                                        $url  = $img->getURL();
     
    344334                return '<a href="'.$url.'">'.$text.'</a>';
    345335        }
    346336
    347         function __call( $m, $a)
    348         {
     337        function __call( $m, $a) {
    349338                return call_user_func_array( array( $this->skin, $m ), $a );
    350339        }
    351340
    352         function __construct( &$skin )
    353         {
     341        function __construct( &$skin ) {
    354342                $this->skin = $skin;
    355343        }
    356344}
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy