Page 1 of 1

Enable/disable editor by session or user

PostPosted: Tue Jul 07, 2009 11:04 pm
by NickMDal
Hi. We are running WYM in our wikimedia installation. Is it possible to enable and disable the editor by user by session (reverting to regular wikicode)?

I am not a developer but need to find out if we need to have this coded or if there is a ready-made way to do this. Thanks for help.

Re: Enable/disable editor by session or user

PostPosted: Wed Jul 08, 2009 5:56 pm
by matthoughton
Could you check the session prior to running the javascript?

I do this in PHP by having a function to display the javascript:
Code: Select all
function wymEditor() {
      ?>
         <script type="text/javascript" src="jquery/jquery.js"></script>
         <script type="text/javascript" src="wymeditor/jquery.wymeditor.js"></script>

         <script type="text/javascript">

   jQuery(function() {

    jQuery('.wymeditor').wymeditor({
        skin: 'twopanels',
      //we customize the XHTML structure of WYMeditor by overwriting
      //the value of boxHtml. In this example, "CONTAINERS" and
      //"CLASSES" have been moved from "wym_area_right" to "wym_area_top":
      boxHtml:   "<div class='wym_box'>"
              + "<div class='wym_area_top'>"
              + WYMeditor.TOOLS
              + WYMeditor.CONTAINERS
              + "</div>"
              + "<div class='wym_area_left'></div>"
              + "<div class='wym_area_main''>"
              + WYMeditor.HTML
              + WYMeditor.IFRAME
              + WYMeditor.STATUS
              + "</div>"
              + "<div class='wym_area_bottom'>"
              + "</div>"
              + "</div>",
      //postInit is a function called when WYMeditor instance is ready
      //wym is the WYMeditor instance
      postInit: function(wym) {
            jQuery(wym._box).find(wym._options.iframeSelector)
                .css('height', '250px')
               


        }
    });
});

</script>
   <?php    
   }


Then depending on the session vars, you could choose not to run this function, leaving the user input as a text box.

e.g.

Code: Select all
if($_SESSION['user_wym']=='1') wymEditor();

Re: Enable/disable editor by session or user

PostPosted: Wed Jul 08, 2009 11:49 pm
by NickMDal
Thanks. This is very helpful.

I hate to ask such a basic question, but if the javascript function is bypassed, will the standard mediawiki editor then be automatically displayed? I guess this is not a mediawiki forum but I am just hoping to pass on what I can as a feature request for our site.

Re: Enable/disable editor by session or user

PostPosted: Thu Jul 09, 2009 4:05 pm
by matthoughton
Sorry I don't know how mediawiki works. If you could show code for the mediawiki implementation I may be able to advise you further. Alternatively, I don't know if anyone else on the forum knows it?

Re: Enable/disable editor by session or user

PostPosted: Thu Jul 09, 2009 8:03 pm
by mr_lundis
I think (if someone) Jacopo is the man to ask. He's the author of the WYMeditor plug-in for MediaWiki.

Re: Enable/disable editor by session or user

PostPosted: Thu Jul 09, 2009 9:07 pm
by NickMDal
Thanks. This is very helpful.

Re: Enable/disable editor by session or user

PostPosted: Wed Jun 30, 2010 8:30 am
by Jacopo
Hi NickMDal, sorry for this over-long delay, I haven't been checking the forum for a while. It might be irrelevant by now, but I thought answering couldn't hurt.

There is a preference for disabling the visual editor, it's called "wpWantTraditionalEditor" and should show up in the user preference page. It could also be done via Javascript by setting the traditional editing checkbox before the script kicks in, but the preference is probably a cleaner approach.

As for support, I maintain the extension and intend to keep it up to date (I use it on an internal wiki), but I don't have much time to add new features.