WikIAC:Estensioni/Rot13
Da WikIAC.
Permette di inserire facilmente del testo criptato con Rot13.
Viene visualizzato solo il testo criptato assieme a un link per sostituire il testo con la versione in chiaro.
Uso
- inserire uno spoiler in rot13
Il testo
<rot13>some spoiler</rot13>
Dovrebbe risultare in questo codice html
<span class="rot13">
<span>fbzr fcbvyre</span>
<span style="display:none;">some spoiler</span>
<a onclick="var p=this.parentNode;var h = p.firstChild;
while (h != null && (h.nodeType != 1 || h.tagName.match('/^span/i')))
{h=h.nextSibling;};
if (h == null){return false;}
var s = h.nextSibling;
while (s != null && (s.nodeType != 1 || s.tagName.match('/^span/i')))
{s=s.nextSibling;};
if (s == null){return false;}
s.style.display='inline';h.style.display='none';"
style="cursor: pointer; text-decoration: underline; font-style: italic;">(decritta)</a>
</span>
Test: fbzr fcbvyre (decritta)
Sviluppatori
Implementazione
File rot13.php:
<?php
/**
* Implements rot13 tag in wiki in the form of <rot13> text </rot13>.
* Will show rot13-ed text followed by an ecmascripted link to show original text.
* @author Elder <elder@ds3.it>
* @created 2006-09-29
*/
if ( ! defined( 'MEDIAWIKI' ) )
die();
$wgExtensionFunctions[] = "wfRot13Extension";
$wgExtensionCredits['parserhook'][] = array(
'name' => 'rot13',
'author' => 'Elder',
'description' => 'adds <rot13> for rot13 inline encryption',
'url' => 'http://iac.quasipercaso.com/WikIAC:Estensioni/Rot13'
);
function wfRot13Extension()
{
global $wgParser;
// register hook for rot13 tag rendering
$wgParser->setHook( "rot13", "renderRot13" );
}
/**
* The callback function for converting the input text to HTML output.
* The tag <rot13>some spoiler</rot13> will be converted in this html output:
* <span class="rot13">
* <span>fbzr fcbvyre</span>
* <span style="display:none;">some spoiler</span>
* <a onclick="var p=this.parentNode;var h = p.firstChild;
* while (h != null && (h.nodeType != 1 || h.tagName.match('/^span/i')))
* {h=h.nextSibling;};
* if (h == null){return false;}
* var s = h.nextSibling;
* while (s != null && (s.nodeType != 1 || s.tagName.match('/^span/i')))
* {s=s.nextSibling;};
* if (s == null){return false;}
* s.style.display='inline';h.style.display='none';"
* style="cursor: pointer; text-decoration: underline; font-style: italic;">(decritta)</a>
* </span>
*
* @param input the text contained in the rot13 tag
* @return html code with the crypted and the plain text
*/
function renderRot13($input, $argv, $parser = null)
{
if (!$parser) $parser =& $GLOBALS['wgParser'];
$crypted=str_rot13($input);
$output = "<span class=\"rot13\">\n".
"<span>".$crypted."</span>\n".
"<span style=\"display:none;\">".$input."</span>\n".
"<a onclick=\"var p=this.parentNode;var h = p.firstChild; \n".
"while (h != null && (h.nodeType != 1 || h.tagName.match('/^span/i')))\n".
"{h=h.nextSibling;};\n".
"if (h == null){return false;}\n".
"var s = h.nextSibling;\n".
"while (s != null && (s.nodeType != 1 || s.tagName.match('/^span/i')))\n".
"{s=s.nextSibling;};\n".
"if (s == null){return false;}\n".
"s.style.display='inline';h.style.display='none';\"\n".
"style=\"cursor: pointer; text-decoration: underline; font-style: italic;\">(decritta)</a>\n".
"</span>\n";
return $output;
}
/* vi:sw=2 ts=2 */
?>
- Note
Ho inserito il codice ecmascript inline perche' non so come includere un file ecmascript esterno.
Se fosse possibile inserire una funzione con un parametro in un file js, il codice html sarebbe piu' leggero perche' l'attributo onclick diventerebbe semplicemente "unRot13(this);" :)
Il js esterno dovrebbe definire la funzione unRot13(caller)
function unRot13(caller)
{
var p = this.parentNode;
var h = p.firstChild;
while (h != null && (h.nodeType != 1 || h.tagName.match('/^span/i')))
{
h = h.nextSibling;
};
if (h == null)
return false;
var s = h.nextSibling;
while (s != null && (s.nodeType != 1 || s.tagName.match('/^span/i')))
{
s = s.nextSibling;
};
if (s == null)
return false;
s.style.display = 'inline';
h.style.display = 'none';
}

