Originally intended as a driver for testing wfUtf8ToHTML(), but also serves nicely...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 15 May 2004 14:15:25 +0000 (14:15 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 15 May 2004 14:15:25 +0000 (14:15 +0000)
extensions/UnicodeConverter.php [new file with mode: 0644]

diff --git a/extensions/UnicodeConverter.php b/extensions/UnicodeConverter.php
new file mode 100644 (file)
index 0000000..b146db3
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+# This is a simple example of a special page module
+# Given a string in UTF-8, it converts it to HTML entities suitable for 
+# an ISO 8859-1 web page.
+
+$wgExtensionFunctions[] = "wfUnicodeConverter";
+
+function wfUnicodeConverter() {
+class UnicodeConverter extends SpecialPage
+{
+       function UnicodeConverter() {
+               SpecialPage::SpecialPage("UnicodeConverter");
+       }
+
+       function execute( $par ) {
+               global $wgRequest, $wgOut, $wgTitle;
+
+               $this->setHeaders();
+
+               $q = $wgRequest->getText( 'q' );
+               $encQ = htmlspecialchars( $q );
+               $action = $wgTitle->getLocalUrl();
+               $ok = wfMsg( "ok" );
+
+               $wgOut->addHTML( "
+<form name=ucf method=post action=\"$action\">
+<textarea rows=15 cols=80 name=q>
+$encQ
+</textarea><br />
+<input type=submit name=submit value=\"$ok\"><br /><br />
+</form>" );
+
+               if ( !is_null( $q ) ) {
+                       $html = wfUtf8ToHTML( $q );
+                       $wgOut->addHTML( "\n\n\n" . nl2br( $html ) . "\n<hr>\n" .
+                         nl2br( htmlspecialchars( $html ) ) . "\n\n" );
+               }
+       }
+}
+
+global $wgMessageCache;
+SpecialPage::addPage( new UnicodeConverter );
+$wgMessageCache->addMessage( "unicodeconverter", "Unicode Converter" );
+
+} # End of extension function
+?>