Not logged in. · Lost password · Register
Forum: General Help and Support Syntax and Usage RSS
[solved] Embed / include Javascript in a page
Using Dynamic Drive's email riddler script to encrypt an email address within a page
Avatar
jheckmann #1
Member since May 2008 · 15 posts
Group memberships: Members
Show profile · Link to this post
Subject: [solved] Embed / include Javascript in a page
Well, this has been a frustrating morning.  Here's my account of the past few hours.  What am I doing wrong?  Please be gentle, I'm new.

How to include a simple Javascript script in a DokuWiki page

To avoid spam, we want to use the email riddler to encrypt a contact email address within a DokuWiki page.

We get the following generated code from the script wizard:

<script type="text/javascript">
/*<![CDATA[*/

/***********************************************
* Encrypt Email script- Please keep notice intact
* Tool URL: http://www.dynamicdrive.com/emailriddler/
* **********************************************/
<!-- Encrypted version of: avidwiki [at] ****************.*** //-->

var emailriddlerarray=[97,118,105,100,119,105,107,105,64,114,111,99,104,101,115,116,101,114,115,121,115,116,101,109,115,46,99,111,109]
var encryptedemail_id32='' //variable to contain encrypted email
for (var i=0; i<emailriddlerarray.length; i++)
 encryptedemail_id32+=String.fromCharCode(emailriddlerarray[i])

document.write('<a href="mailto:'+encryptedemail_id32+'?subject=Request for AvidWiki Support Product">Request it.</a>')

/*]]>*/
</script>

and save it in a Notepad file for later reference.

We read DokuWiki's documentation for including this script:

http://wiki.splitbrain.org/wiki:devel:javascript

Whew!  OK, let's decode this step by step.

First, we know we can't just paste this code into DokuWiki's editor for the page we want it in.  The documentation tells us we have to create a file named script.js in our template directory.  Which directory is that?  Much further in the documentation at JavaScript Dispatcher, we find the answer:

lib/tpl/*/script.js (only from current template)

which for us is:

/lib/tpl/monobook/script.js

Second, we know that the generated code was meant to be pasted into a .htm file as inline code.  It was not formatted as an external script (a .js file).  We need to delete the <script> and CDATA related tags at the beginning and end of the code. 

Third, we are told the Javascript code must pass the JSLint verifier.  We go to this tool, paste in the code, run the verifier, and it fails.  What now?

After an hour of research and fiddling with the code, there seems to be no good reason for the failure. Thinking about the intention behind this recommendation, and the philosophy of JSLint, we decide to go ahead and try the code as-is.

Next, we are told we need to do something with event handlers and DOM (document object model).  What?  This is getting confusing.

OK, here's the idea:  originally, the Javascript code would be placed within an HTML page right where it needed to be, the spot where the contact email address will appear.  Since we have moved the Javascript code to an external script, we need to give our code a name, and use that name to associate the code with the contact email address within the DokuWiki page.

It's a little unclear, but we have several choices for how to accomplish this - event handlers, inline scripts (isn't that where we started?!), and IDs.  Oh, and further in the documentation, include syntax.  What do we use?

Well, let's try inline script.  We look back at the original generated code and compare the tags; they're not quite the same, so we make the changes and embed the script into our DokuWiki page.

It doesn't work in Preview, nor after being Saved.  Now what?

Maybe include syntax?  This requires going back to a .js version, naming it something other than script.js, and adding a special comment in the DokuWiki page where the script should be run.  The script file needs to be placed in the same directory as the page .txt file.

OK, so I create emailriddler.js, place it in /data/pages/wiki/admin/, and edit my DokuWiki page to include the comment:

/* DOKUWIKI:include emailriddler.js */

That didn't work either.

It seems that embedding Javascript into a DokuWiki page using the editor is not possible.
This post was edited on 2008-07-02, 15:16 by jheckmann.
chi #2
Member since Jun 2006 · 1851 posts · Location: Munich Germany
Group memberships: Members, Super Mods, Wiki Managers
Show profile · Link to this post
Hmmm, why don't you just set the $conf['mailguard'] configuration option [1] to hex in the configuration manager?

[1] http://wiki.splitbrain.org/wiki:config#mailguard
Please add [SOLVED] to the initial thread subject if you feel your question has been answered.
If my answer doesn't make sense maybe your question didn't either - just visit http://facepalm.org.
Avatar
jheckmann #3
Member since May 2008 · 15 posts
Group memberships: Members
Show profile · Link to this post
I already have that set.  This is for a link to contact the administrator.  How do I embed that within a page's content?  What am I missing here?
Avatar
jheckmann #4
Member since May 2008 · 15 posts
Group memberships: Members
Show profile · Link to this post
This will be workable for me:

http://wiki.splitbrain.org/plugin:contact

I think I may not be the only person new to DokuWiki who has some HTML and JavaScript experience, who doesn't immediately see that a simple embedded Javascript with a document.write isn't compatible with DokuWiki, and (I think) would have to be replaced with a plugin, not something a beginner would do right away.
chi #5
Member since Jun 2006 · 1851 posts · Location: Munich Germany
Group memberships: Members, Super Mods, Wiki Managers
Show profile · Link to this post
In reply to post #3
Quote by jheckmann:
I already have that set.  This is for a link to contact the administrator.  How do I embed that within a page's content?  What am I missing here?

The thing is that your script does something similar as the mailguard setting, except that it doesn't scramble the email address to be represented as hex values but as ASCII (I can actually "read" the mail address by looking at the "emailriddlerarray"), which makes it rather pointless (this has hardly has anything to do with encryption).
Please add [SOLVED] to the initial thread subject if you feel your question has been answered.
If my answer doesn't make sense maybe your question didn't either - just visit http://facepalm.org.
Avatar
ach (Administrator) #6
Member since May 2006 · 1864 posts · Location: London, UK
Group memberships: Administrators, Members, Super Mods, Wiki Managers
Show profile · Link to this post
In reply to post #1
Firstly, the page you are referring to (http://wiki.splitbrain.org/wiki:devel:javascript) is NOT intended for small JavaScript snippets like yours. And it is not intended to explain how to "embed Javascript into a DokuWiki page *using the editor*". It is rather intended for "proper" scripts ... and hints that those tiny snippets are "bad". Those are just recommendations, but that does not mean it is not possible to be done "the old way".

Here are the simplest ways (none should take more than five minutes) of including JavaScript snippets ("the dirty way"):

1. include it (inline) in your template's main.php (disadvantage: it's not inside the wiki content)
2. turn on html and paste it between <html> and </html> (disadvantage: should only be done in closed wikis, because of security reasons)
3. (mis)use entities.local.conf to make a shortcut to eg. "ADMINMAIL" (then the javascript should be all in one line)

I can think of many more (cleaner) ways, but they will get a bit more complicated ... and, sorry, you would need to have knowledge of JavaScript and/or PHP.

Quote by jheckmann on 2008-05-29, 14:38:
Third, we are told the Javascript code must pass the JSLint verifier.  We go to this tool, paste in the code, run the verifier, and it fails.  What now?

After an hour of research and fiddling with the code, there seems to be no good reason for the failure.

Well, I can see several errors at once ... ;-)
This post was edited on 2008-06-11, 01:33 by ach.
Avatar
jheckmann #7
Member since May 2008 · 15 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #5
Quote by chi on 2008-06-01, 16:15:
Quote by jheckmann:
I already have that set.  This is for a link to contact the administrator.  How do I embed that within a page's content?  What am I missing here?

The thing is that your script does something similar as the mailguard setting, except that it doesn't scramble the email address to be represented as hex values but as ASCII (I can actually "read" the mail address by looking at the "emailriddlerarray"), which makes it rather pointless (this has hardly has anything to do with encryption).

Of course, you are entitled to your opinion.  Remember, some of us who are new to Dokuwiki have been creating websites "the old way".  This script has proved itself; yes, you can "read" the email address, but it completely foils automated readers.  The sites it has been used on receive no spam, which is the point ;-).

As I tried to explain before, I'm trying to create a page that a wiki reader can use to contact the administrator, and at the same time protect the administrator email address from spam.  Is there something about mailguard that would help me do both?  If so, please explain it.
Avatar
jheckmann #8
Member since May 2008 · 15 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #6
Quote by ach on 2008-06-11, 01:28:
Firstly, the page you are referring to (http://wiki.splitbrain.org/wiki:devel:javascript) is NOT intended for small JavaScript snippets like yours.

Thank you... it may be helpful to others if this would be STATED CLEARLY on that page, or somewhere.  It ain't obvious.
Quote by ach on 2008-06-11, 01:28:
Here are the simplest ways (none should take more than five minutes) of including JavaScript snippets ("the dirty way"):
Agreed, these are all "dirty" and introduce maintenance or security problems as you point out.  When I said it was "not possible", I didn't mean that some way couldn't be found to hack it in.  I meant it didn't seem to be a feature, or part of the design of DokuWiki, to allow the insertion of this kind of code.  

Quote by ach on 2008-06-11, 01:28:
Well, I can see several errors at once ... ;-)

Well, OK, you have more training/experience in this particular language than I do.  I'm retired on disability, struggling along with open source/free tools, self-taught.  I appreciate Forums like this one where someone like me can learn from those who are willing to share their knowledge.

JSLint didn't exist when I learned Javascript.  The language evolved when I wasn't looking...<sigh>
chi #9
Member since Jun 2006 · 1851 posts · Location: Munich Germany
Group memberships: Members, Super Mods, Wiki Managers
Show profile · Link to this post
In reply to post #7
Quote by jheckmann:
As I tried to explain before, I'm trying to create a page that a wiki reader can use to contact the administrator, and at the same time protect the administrator email address from spam.  Is there something about mailguard that would help me do both?  If so, please explain it.

What I am trying to tell you is that your method scrambles the email address to ASCII values and the mailguard setting scrambles it to HEX values. There is almost no difference between both methods. Most, if not all up to this point, automated email harversters fail at reading HEX encoded email addresses. You, and your administrator, should be save enough by setting the mailguard option to HEX. As an example, I've written the email address dokuwiki [at] chimeric [dot] de at http://wiki.splitbrain.org (which uses the mailguard setting as well) on every plugin page I've created and received no SPAM to this address until today.
Please add [SOLVED] to the initial thread subject if you feel your question has been answered.
If my answer doesn't make sense maybe your question didn't either - just visit http://facepalm.org.
This post was edited on 2008-06-23, 23:40 by chi.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2017-04-30, 09:08:45 (UTC +02:00)