Originally intended as a driver for testing wfUtf8ToHTML(), but also serves nicely...
[lhc/web/wiklou.git] / extensions / UnicodeConverter.php
1 <?php
2
3 # This is a simple example of a special page module
4 # Given a string in UTF-8, it converts it to HTML entities suitable for
5 # an ISO 8859-1 web page.
6
7 $wgExtensionFunctions[] = "wfUnicodeConverter";
8
9 function wfUnicodeConverter() {
10 class UnicodeConverter extends SpecialPage
11 {
12 function UnicodeConverter() {
13 SpecialPage::SpecialPage("UnicodeConverter");
14 }
15
16 function execute( $par ) {
17 global $wgRequest, $wgOut, $wgTitle;
18
19 $this->setHeaders();
20
21 $q = $wgRequest->getText( 'q' );
22 $encQ = htmlspecialchars( $q );
23 $action = $wgTitle->getLocalUrl();
24 $ok = wfMsg( "ok" );
25
26 $wgOut->addHTML( "
27 <form name=ucf method=post action=\"$action\">
28 <textarea rows=15 cols=80 name=q>
29 $encQ
30 </textarea><br />
31 <input type=submit name=submit value=\"$ok\"><br /><br />
32 </form>" );
33
34 if ( !is_null( $q ) ) {
35 $html = wfUtf8ToHTML( $q );
36 $wgOut->addHTML( "\n\n\n" . nl2br( $html ) . "\n<hr>\n" .
37 nl2br( htmlspecialchars( $html ) ) . "\n\n" );
38 }
39 }
40 }
41
42 global $wgMessageCache;
43 SpecialPage::addPage( new UnicodeConverter );
44 $wgMessageCache->addMessage( "unicodeconverter", "Unicode Converter" );
45
46 } # End of extension function
47 ?>