Index: common/log.php
===================================================================
--- common/log.php	(revision 931)
+++ common/log.php	(working copy)
@@ -299,7 +299,11 @@
             $msg .= "Full server log:\n";
             global $execution_stats;
             $msg .= $execution_stats['log_copy'];
-            print("<pre>".htmlentities($msg)."</pre>");
+            if (function_exists("html_escape")) {
+                print("<pre>".html_escape($msg)."</pre>");
+            } else {
+                print("<pre>".htmlentities($msg)."</pre>");
+            }
         }
         if (IA_HTTP_ENV && !IA_DEVELOPMENT_MODE) {
             header('HTTP/1.0 500 Internal Error');
Index: tests/attachment.php
===================================================================
--- tests/attachment.php	(revision 931)
+++ tests/attachment.php	(working copy)
@@ -40,10 +40,10 @@
 $res = curl_test(array(
         'url' => url_attachment_list('sandbox/test_page'),
 ));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
         url_attachment('sandbox/test_page', 'test_file'))));
 // FIXME: this shouldn't be visible
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
             url_attachment_delete('sandbox/test_page', 'test_file'))));
 
 log_print("Anon tries to delete attachment, fails");
@@ -56,7 +56,7 @@
 $res = curl_test(array(
         'url' => url_attachment_list('sandbox/test_page'),
 ));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
             url_attachment('sandbox/test_page', 'test_file'))));
 
 log_print("Admin deletes attachment, OK");
@@ -70,7 +70,7 @@
 $res = curl_test(array(
         'url' => url_attachment_list('sandbox/test_page', 'test_file'),
 ));
-log_assert(!strstr($res['content'], htmlentities(
+log_assert(!strstr($res['content'], html_escape(
             url_attachment('sandbox/test_page', 'test_file'))));
 
 log_print("Dude 1 attaches 5 files");
@@ -128,12 +128,12 @@
         'user' => 'test_admin',
 ));
 for ($i = 1; $i <= 5; ++$i) {
-    log_assert(strstr($res['content'], htmlentities(
+    log_assert(strstr($res['content'], html_escape(
                 url_attachment('sandbox/test_page', "test_file_$i"))));
 }
-log_assert(strstr(strtolower($res['content']), htmlentities(
+log_assert(strstr(strtolower($res['content']), html_escape(
             url_user_profile('test_dude1'))));
-log_assert(!strstr(strtolower($res['content']), htmlentities(
+log_assert(!strstr(strtolower($res['content']), html_escape(
             url_user_profile('test_dude2'))));
 
 log_print("Admin moves the spammed page.");
Index: tests/textblock.php
===================================================================
--- tests/textblock.php	(revision 931)
+++ tests/textblock.php	(working copy)
@@ -137,11 +137,11 @@
 ));
 log_assert_equal($res['url'],  url_absolute(
             url_textblock_history('sandbox/test_page')));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
                 url_textblock_diff('sandbox/test_page', 1, 4))));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
                 url_textblock_restore('sandbox/test_page', 2))));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
                 url_textblock_revision('sandbox/test_page', 3))));
 
 
@@ -203,11 +203,11 @@
 ));
 log_assert_equal($res['url'],  url_absolute(
             url_textblock_history('sandbox/test_page_2', true)));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
                 url_textblock_diff('sandbox/test_page_2', 1, 4))));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
                 url_textblock_restore('sandbox/test_page_2', 2))));
-log_assert(strstr($res['content'], htmlentities(
+log_assert(strstr($res['content'], html_escape(
                 url_textblock_revision('sandbox/test_page_2', 3))));
 
 
Index: tests/user_page.php
===================================================================
--- tests/user_page.php	(revision 931)
+++ tests/user_page.php	(working copy)
@@ -39,11 +39,11 @@
 ));
 log_assert(strstr($res['content'], "xzx-content-xzx"));
 log_assert(strstr($res['content'], "xzx-title-xzx"));
-log_assert(stristr($res['content'], "<a href=\"".htmlentities(
+log_assert(stristr($res['content'], "<a href=\"".html_escape(
             url_user_profile('test_dude1'))));
-log_assert(stristr($res['content'], "<a href=\"".htmlentities(
+log_assert(stristr($res['content'], "<a href=\"".html_escape(
             url_user_rating('test_dude1'))));
-log_assert(stristr($res['content'], "<a href=\"".htmlentities(
+log_assert(stristr($res['content'], "<a href=\"".html_escape(
             url_user_stats('test_dude1'))));
 
 log_print("Dude2 tries to edit dude1's page, fails");
@@ -142,11 +142,11 @@
 ));
 log_assert(strstr($res['content'], "admin-title-admin"));
 log_assert(strstr($res['content'], "admin-content-admin"));
-log_assert(stristr($res['content'], "<a href=\"".htmlentities(
+log_assert(stristr($res['content'], "<a href=\"".html_escape(
             url_user_profile('test_dude2'))));
-log_assert(stristr($res['content'], "<a href=\"".htmlentities(
+log_assert(stristr($res['content'], "<a href=\"".html_escape(
             url_user_rating('test_dude2'))));
-log_assert(stristr($res['content'], "<a href=\"".htmlentities(
+log_assert(stristr($res['content'], "<a href=\"".html_escape(
             url_user_stats('test_dude2'))));
 
 test_cleanup();
Index: www/format/form.php
===================================================================
--- www/format/form.php	(revision 931)
+++ www/format/form.php	(working copy)
@@ -36,7 +36,7 @@
                 $errors['values'] = 'Need to specify possible values';
             } else {
                 foreach ($values as $key => $val) {
-                    if (htmlentities($key) != $key) {
+                    if (html_escape($key) != $key) {
                         $errors['values'] = "Bad value '$key'";
                     }
                 }
Index: www/format/format.php
===================================================================
--- www/format/format.php	(revision 931)
+++ www/format/format.php	(working copy)
@@ -19,9 +19,9 @@
 
         log_assert(preg_match("/[a-z][a-z_0-9]*/", $k), "Invalid attrib '$k'");
         if ($result == "") {
-            $result .= "$k=\"".htmlentities($v, ENT_COMPAT, "utf-8")."\"";
+            $result .= "$k=\"".html_escape($v)."\"";
         } else {
-            $result .= " $k=\"".htmlentities($v, ENT_COMPAT, "utf-8")."\"";
+            $result .= " $k=\"".html_escape($v)."\"";
         }
     }
 
@@ -52,7 +52,7 @@
         return "<$tag ".format_attribs($attribs)." />";
     } else {
         if ($escape) {
-            $content = htmlentities($content, ENT_COMPAT, "utf-8");
+            $content = html_escape($content);
         }
         return "<$tag ".format_attribs($attribs).">$content</$tag>";
     }
@@ -85,7 +85,7 @@
 // Html content not supported because of format_highlight_access_key.
 function format_link_access($url, $content, $key, $attr = array()) {
     $attr['accesskey'] = $key;
-    $content = format_highlight_access_key(htmlentities($content, ENT_COMPAT, "utf-8"), $key);
+    $content = format_highlight_access_key(html_escape($content), $key);
     return format_link($url, $content, false, $attr);
 }
 
@@ -127,8 +127,8 @@
 // Format a tiny user link, with a 16x16 avatar.
 // FIXME: proper styling
 function format_user_tiny($user_name, $user_fullname, $rating = null) {
-    $user_url = htmlentities(url_user_profile($user_name));
-    $user_fullname = htmlentities($user_fullname, ENT_COMPAT, "utf-8");
+    $user_url = html_escape(url_user_profile($user_name));
+    $user_fullname = html_escape($user_fullname);
 
     $rbadge = format_user_ratingbadge($user_name, $rating);
 
@@ -149,8 +149,8 @@
 // Format a tiny user link, with a 32x32 avatar.
 // FIXME: proper styling
 function format_user_normal($user_name, $user_fullname, $rating = null) {
-    $user_url = htmlentities(url_user_profile($user_name));
-    $user_fullname = htmlentities($user_fullname, ENT_COMPAT, "utf-8");
+    $user_url = html_escape(url_user_profile($user_name));
+    $user_fullname = html_escape($user_fullname);
 
     $rbadge = format_user_ratingbadge($user_name, $rating);
 
@@ -202,7 +202,7 @@
         $class = rating_group($rating);
         $rating = rating_scale($rating);
         $att = array(
-            'title' => 'Rating '.htmlentities($username).': '.$rating,
+            'title' => 'Rating '.html_escape($username).': '.$rating,
             'class' => 'rating-badge-'.$class,
         );
         return format_link(url_user_rating($username), '&bull;', false, $att);
@@ -219,7 +219,7 @@
 // FIXME: user timezone, user format, etc.
 // global identityUser;
 //
-// HTML safe(don't pass through htmlentities.)
+// HTML safe(don't pass through html_escape.)
 function format_date($date, $format = null) {
     if (is_db_date($date)) {
         $timestamp = db_date_parse($date);
Index: www/format/table.php
===================================================================
--- www/format/table.php	(revision 931)
+++ www/format/table.php	(working copy)
@@ -92,7 +92,7 @@
             }
 
             $key = getattr($column, 'key');
-            $caption = htmlentities(getattr($column, 'title', $key));
+            $caption = html_escape(getattr($column, 'title', $key));
 
             // sortable columns
             if ($key && getattr($column, 'sortable')) {
@@ -105,7 +105,7 @@
                     $span_class = '';
                 }
 
-                $caption .= '&nbsp;<span class="sort-field'.htmlentities($span_class).'">'
+                $caption .= '&nbsp;<span class="sort-field'.html_escape($span_class).'">'
                            ._format_sort_link($options, $key, $a_direction)
                            .'</span> ';
             }
@@ -145,7 +145,7 @@
             $result .= '<tr>';
         }
         else {
-            $result .= '<tr class="'.htmlentities($class).'">';
+            $result .= '<tr class="'.html_escape($class).'">';
         }
 
         // Dump the actual data.
Index: www/macros/macro_debug.php
===================================================================
--- www/macros/macro_debug.php	(revision 931)
+++ www/macros/macro_debug.php	(working copy)
@@ -8,7 +8,7 @@
     $res = "<p>Debug macro listing args</p>";
     $res .= '<pre>';
     $ncargs = $args;
-    $res .= htmlentities(print_r($ncargs, true));
+    $res .= html_escape(print_r($ncargs, true));
     $res .= '</pre>';
 
     return $res;
Index: www/macros/macro_gallery.php
===================================================================
--- www/macros/macro_gallery.php	(revision 931)
+++ www/macros/macro_gallery.php	(working copy)
@@ -43,7 +43,7 @@
     foreach ($atts as $attach) {
         $thumbsrc = url_image_resize($attach['page'], $attach['name'], "130x80");
         $fullsrc = url_image_resize($attach['page'], $attach['name'], null);
-        $buffer .= "<a href=\"".htmlentities($fullsrc)."\"><img src=\"".htmlentities($thumbsrc)."\" alt=\"".htmlentities($attach['page'])."\" /></a>";
+        $buffer .= "<a href=\"".html_escape($fullsrc)."\"><img src=\"".html_escape($thumbsrc)."\" alt=\"".html_escape($attach['page'])."\" /></a>";
     }
     $buffer .= '</div>';
     $buffer .= format_pager($options);
Index: www/macros/macro_hello.php
===================================================================
--- www/macros/macro_hello.php	(revision 931)
+++ www/macros/macro_hello.php	(working copy)
@@ -5,7 +5,7 @@
 // There is an extra global argument called page_name.
 function macro_hello($args) {
     $target = getattr($args, 'target', 'anonim');
-    return '<strong>Hello, '.htmlentities($target).'</strong>';
+    return '<strong>Hello, '.html_escape($target).'</strong>';
 }
 
 ?>
Index: www/macros/macro_news.php
===================================================================
--- www/macros/macro_news.php	(revision 931)
+++ www/macros/macro_news.php	(working copy)
@@ -18,7 +18,7 @@
     $res .= format_pager($options);
     foreach ($subpages as $subpage) {
         $res .= '<div class="item">';
-        $res .= '<span class="date">'.htmlentities(date('d M Y', strtotime($subpage['creation_timestamp']))).'</span>';
+        $res .= '<span class="date">'.html_escape(date('d M Y', strtotime($subpage['creation_timestamp']))).'</span>';
 
         $url = url_textblock($subpage['name']);
         $text = wiki_process_textblock_recursive($subpage);
Index: www/macros/macro_remotebox.php
===================================================================
--- www/macros/macro_remotebox.php	(revision 931)
+++ www/macros/macro_remotebox.php	(working copy)
@@ -22,7 +22,7 @@
     $buffer = '';
     $buffer .= '<div id="remotebox">remote content</div>';
     $buffer .= '<script type="text/javascript">RemoteBox_Url="';
-    $buffer .= htmlentities($args['url']);
+    $buffer .= html_escape($args['url']);
     $buffer .= '";</script>';
 
     return $buffer;
Index: www/macros/macro_roundparam.php
===================================================================
--- www/macros/macro_roundparam.php	(revision 931)
+++ www/macros/macro_roundparam.php	(working copy)
@@ -52,7 +52,7 @@
     }
     switch ($param) {
         case 'title':
-            $html .= htmlentities($round['title']);
+            $html .= html_escape($round['title']);
             break;
 
         case 'start_time':
@@ -60,18 +60,18 @@
             break;
 
         case 'id':
-            $html .= htmlentities($round['id']);
+            $html .= html_escape($round['id']);
             break;
 
         default:
             if (!isset($params[$param])) {
                 if (isset($args['default_value'])) {
-                    $html .= htmlentities($args['default_value']);
+                    $html .= html_escape($args['default_value']);
                 } else {
                     $html .= macro_error("Round doesn't have parameter '$param'");
                 }
             } else {
-                $html .= htmlentities($params[$param]);
+                $html .= html_escape($params[$param]);
             }
     }
     if ($strong) {
Index: www/macros/macro_roundregister.php
===================================================================
--- www/macros/macro_roundregister.php	(revision 931)
+++ www/macros/macro_roundregister.php	(working copy)
@@ -30,7 +30,7 @@
     if ($is_registered) {
         $class = "round-registered";
         $msg = "Te-ai inscris la <em>{$round['title']}</em>."
-               ." <a href=\"".htmlentities(url_round_register_view($round['id']))."\">"
+               ." <a href=\"".html_escape(url_round_register_view($round['id']))."\">"
                ."Vezi cine s-a mai inscris"
                ."</a>.";
     }
@@ -39,13 +39,13 @@
         if ('waiting' == $round['state']) {
             $class = "round-register";
             $msg = "<p>Nu esti inscris la "
-                   ."<em>".htmlentities($round['title'])."</em>!   "
+                   ."<em>".html_escape($round['title'])."</em>!   "
                    ."Daca vrei sa ti se modifice modifice rating-ul dupa "
                    ."acest concurs trebuie sa te inscrii pana la ora "
                    .format_date($round['start_time'], "%H:%M, %d&nbsp;%b&nbsp;%Y.")."</p>"
-                   ."<p><a href=\"".htmlentities(url_round_register($round['id']))."\">"
+                   ."<p><a href=\"".html_escape(url_round_register($round['id']))."\">"
                    ."<strong>Inscrie-te acum!</strong></a> &nbsp; "
-                   ." <a href=\"".htmlentities(url_round_register_view($round['id']))."\">"
+                   ." <a href=\"".html_escape(url_round_register_view($round['id']))."\">"
                    ."Vezi cine e inscris"
                    ."</a></p>"
                    ."<p>Poti sa participi la concurs si fara sa te inscrii "
@@ -54,14 +54,14 @@
         elseif ('running' == $round['state']) {
             $class = "round-expired";
             $msg = "<p>Nu se mai pot face inscrieri la "
-                   ."<em>".htmlentities($round['title'])."</em> "
+                   ."<em>".html_escape($round['title'])."</em> "
                    ."<strong><em>insa mai poti participa</em></strong>.</p>"
                    ."<p>Trebuia sa te inscrii inainte de ora "
                    .format_date($round['start_time'], "%H:%M, %d&nbsp;%b&nbsp;%Y")
                    ." daca vroiai sa ti se modifice rating-ul la finalul "
                    ."rundei. Acum poti sa participi dar nu ti se va modifica "
                    ."rating-ul.</p>"
-                   ."<p><a href=\"".htmlentities(url_round_register_view($round['id']))."\">"
+                   ."<p><a href=\"".html_escape(url_round_register_view($round['id']))."\">"
                    ."Vezi cine s-a inscris"
                    ."</a></p>";
         }
@@ -69,9 +69,9 @@
             // 'complete' == $round['state']
             $class = "round-expired";
             $msg = "<p>Nu se mai pot face inscrieri la "
-                   ."<em>".htmlentities($round['title'])."</em>. "
+                   ."<em>".html_escape($round['title'])."</em>. "
                    ."Runda s-a incheiat.</p>"
-                   ."<p><a href=\"".htmlentities(url_round_register_view($round['id']))."\">"
+                   ."<p><a href=\"".html_escape(url_round_register_view($round['id']))."\">"
                    ."Vezi cine s-a inscris"
                    ."</a></p>";
         }
Index: www/macros/macro_stars.php
===================================================================
--- www/macros/macro_stars.php	(revision 931)
+++ www/macros/macro_stars.php	(working copy)
@@ -40,7 +40,7 @@
             $img = 'half';
 
         $url = url_absolute(url_static("images/stars/{$type}-{$img}.png"));
-        $html .= "<img src=\"".htmlentities($url)."\" alt=\"{$type}\"/>";
+        $html .= "<img src=\"".html_escape($url)."\" alt=\"{$type}\"/>";
     }
     $html .= "</span>";
 
Index: www/macros/macro_tableofcontents.php
===================================================================
--- www/macros/macro_tableofcontents.php	(revision 931)
+++ www/macros/macro_tableofcontents.php	(working copy)
@@ -10,7 +10,7 @@
     $subpages = textblock_get_by_prefix($prefix, false, false);
 
     $res = '<div class="macro-toc">';
-    $res .= "<p>Table of contents for ".htmlentities($prefix)."</p><ul>";
+    $res .= "<p>Table of contents for ".html_escape($prefix)."</p><ul>";
     for ($i = 0; $i < count($subpages); ++$i) {
         $title = $subpages[$i]['title'];
         $link = url_textblock($subpages[$i]['name']);
Index: www/macros/macro_taskparam.php
===================================================================
--- www/macros/macro_taskparam.php	(revision 931)
+++ www/macros/macro_taskparam.php	(working copy)
@@ -49,26 +49,26 @@
     // serve desired value
     switch ($param) {
         case 'title':
-            return htmlentities($task['title']);
+            return html_escape($task['title']);
 
         case 'author':
-            return htmlentities($task['author']);
+            return html_escape($task['author']);
 
         case 'source':
-            return htmlentities($task['source']);
+            return html_escape($task['source']);
 
         case 'type':
-            return htmlentities($task['type']);
+            return html_escape($task['type']);
 
         case 'id':
-            return htmlentities($task['id']);
+            return html_escape($task['id']);
 
         case 'owner':	    
 	    if( $task['user_id']=='0' ) {
 		return '';
 	    }
 	    $user = user_get_by_id( $task['user_id'] );	    
-            return htmlentities($user['full_name']);
+            return html_escape($user['full_name']);
 
         case 'formatted_owner':
 	    if( $task['user_id']=='0' ) {
@@ -81,12 +81,12 @@
         default:
             if (!isset($params[$param])) {
                 if (isset($args['default_value'])) {
-                    return htmlentities($args['default_value']);
+                    return html_escape($args['default_value']);
                 } else {
                     return macro_error("Task doesn't have parameter '$param'");
                 }
             } else {
-                return htmlentities($params[$param]);
+                return html_escape($params[$param]);
             }
     }
 }
Index: www/macros/macro_tasksubmit.php
===================================================================
--- www/macros/macro_tasksubmit.php	(revision 931)
+++ www/macros/macro_tasksubmit.php	(working copy)
@@ -25,7 +25,7 @@
     }
 
     if (identity_is_anonymous()) {
-        $url = htmlentities(url_login());
+        $url = html_escape(url_login());
         return macro_message("Trebuie sa te autentifici pentru a trimite solutii. <a href=\"{$url}\">Click aici</a>", true);
     }
 
@@ -38,12 +38,12 @@
     ob_start();
 ?>
 
-<a href="<?= htmlentities(url_monitor()."?task=".$task['id']."&user=".$identity_user['username']) ?>">Vezi solutiile trimise de tine</a>
+<a href="<?= html_escape(url_monitor()."?task=".$task['id']."&user=".$identity_user['username']) ?>">Vezi solutiile trimise de tine</a>
 
-<form enctype="multipart/form-data" action="<?= htmlentities(url_submit()) ?>" method="post" class="inlineSubmit" id="task_submit">
+<form enctype="multipart/form-data" action="<?= html_escape(url_submit()) ?>" method="post" class="inlineSubmit" id="task_submit">
 
-<input type="hidden" id="output_only" value="<?= 'output-only' == $task['type'] ? htmlentities($task['id']) : '' ?>" />
-<input type="hidden" name="task_id" value="<?= htmlentities($task['id']) ?>" id="form_task" />
+<input type="hidden" id="output_only" value="<?= 'output-only' == $task['type'] ? html_escape($task['id']) : '' ?>" />
+<input type="hidden" name="task_id" value="<?= html_escape($task['id']) ?>" id="form_task" />
 
 <ul class="form">
 
Index: www/macros/macro_userinfo.php
===================================================================
--- www/macros/macro_userinfo.php	(revision 931)
+++ www/macros/macro_userinfo.php	(working copy)
@@ -30,14 +30,14 @@
             // FIXME: display e-mail only for admins
             return macro_error("Adresa de email este ascunsa");
         case 'fullname':
-            return htmlentities($user['full_name']);
+            return html_escape($user['full_name']);
         case 'username':
-            return htmlentities($user['username']);
+            return html_escape($user['username']);
         case 'security':
-            return htmlentities($user['security_level']);
+            return html_escape($user['security_level']);
         case 'rating':
             if ($user['rating_cache']) {
-                return htmlentities(rating_scale($user['rating_cache']));
+                return html_escape(rating_scale($user['rating_cache']));
             } else {
                 return 'n/a';
             }
Index: www/macros/macros.php
===================================================================
--- www/macros/macros.php	(revision 931)
+++ www/macros/macros.php	(working copy)
@@ -10,13 +10,13 @@
 // Format an error message as a html div.
 // Can be returned from macros.
 function macro_error($text, $raw_html = false) {
-    return '<div class="macroError">' . ($raw_html ? $text : htmlentities($text)) . '</div>';
+    return '<div class="macroError">' . ($raw_html ? $text : html_escape($text)) . '</div>';
 }
 
 // Format message as a html div.
 // Can be returned from macros.
 function macro_message($text, $raw_html = false) {
-    return '<div class="macroMessage">' . ($raw_html ? $text : htmlentities($text)) . '</div>';
+    return '<div class="macroMessage">' . ($raw_html ? $text : html_escape($text)) . '</div>';
 }
 
 // Preset error message for insufficient privileges.
Index: www/utilities.php
===================================================================
--- www/utilities.php	(revision 931)
+++ www/utilities.php	(working copy)
@@ -2,10 +2,10 @@
 
 require_once(IA_ROOT_DIR."www/url.php");
 
-// Escapes a string from html. Better than html entities because it's
-// shorter and it handles utf-8.
-function xmlesc($arg) {
-    return htmlentities($arg, ENT_COMPAT, 'UTF-8');
+// Wrapper around htmlentities which defaults charset to UTF-8
+function html_escape($string, $quote_style = ENT_COMPAT, $charset = "UTF-8")
+{
+    return htmlentities($string, $quote_style, $charset);
 }
 
 function request($param, $default = null) {
Index: www/views/account.php
===================================================================
--- www/views/account.php	(revision 931)
+++ www/views/account.php	(working copy)
@@ -4,7 +4,7 @@
 include('tags_header.php');
 ?>
 
-<h1><?= htmlentities($view['title']) ?></h1>
+<h1><?= html_escape($view['title']) ?></h1>
 
 <div id="sidebar2">
 <div class="section">
@@ -23,10 +23,10 @@
 
 </div>
 
-<form enctype="multipart/form-data" action="<?= htmlentities($action) ?>" method="post" class="profile clear" <?= tag_form_event() ?>>
+<form enctype="multipart/form-data" action="<?= html_escape($action) ?>" method="post" class="profile clear" <?= tag_form_event() ?>>
 
 <fieldset>
-    <legend><img src="<?= htmlentities(url_static('images/icons/key.gif')) ?>" alt="!" /> Informatii legate de securitate</legend>
+    <legend><img src="<?= html_escape(url_static('images/icons/key.gif')) ?>" alt="!" /> Informatii legate de securitate</legend>
     <ul class="form">
         <li>
             <label for='form_passwordold'>Parola curenta</label>
@@ -91,7 +91,7 @@
             <?php
                 // display avatar
                 $avatar_url = url_user_avatar($user['username'], "150x150");
-                echo '<img class="avatar" src="'.htmlentities($avatar_url).'" alt="avatar"/>';
+                echo '<img class="avatar" src="'.html_escape($avatar_url).'" alt="avatar"/>';
             ?>
         </li>
         <li>
Index: www/views/attachment.php
===================================================================
--- www/views/attachment.php	(revision 931)
+++ www/views/attachment.php	(working copy)
@@ -3,7 +3,7 @@
 <h1>Ataseaza la pagina <?= format_link(url_textblock($view['page_name']), $view['page_name']) ?></h1>
 
 <form enctype="multipart/form-data"
-      action="<?= htmlentities(url_attachment_new($page_name)) ?>"
+      action="<?= html_escape(url_attachment_new($page_name)) ?>"
       method="post"
       class="clear">
 <fieldset>
Index: www/views/blog_admin.php
===================================================================
--- www/views/blog_admin.php	(revision 931)
+++ www/views/blog_admin.php	(working copy)
@@ -1,6 +1,6 @@
 <?php include('views/header.php'); ?>
 <h1>Administrare <?= format_link(url_textblock($page['name']), $page['title']) ?></h1>
-<form action="<?= htmlentities(getattr($view, 'action')) ?>" method="post">
+<form action="<?= html_escape(getattr($view, 'action')) ?>" method="post">
  <fieldset>
   <legend>Informatii generale</legend>
   <ul class="form">
Index: www/views/blog_index.php
===================================================================
--- www/views/blog_index.php	(revision 931)
+++ www/views/blog_index.php	(working copy)
@@ -20,7 +20,7 @@
     echo '<div class="item">';
     echo '<span class="date">';
     echo format_user_link($subpage["user_name"], $subpage["user_fullname"]).' &#8226; ';
-    echo htmlentities(date('d M Y', strtotime($subpage['creation_timestamp'])));
+    echo html_escape(date('d M Y', strtotime($subpage['creation_timestamp'])));
     echo '</span>';
 
     $url = url_textblock($subpage['name']);
Index: www/views/blog_view.php
===================================================================
--- www/views/blog_view.php	(revision 931)
+++ www/views/blog_view.php	(working copy)
@@ -30,7 +30,7 @@
     echo format_link(url_blog($tag['tag_name']), $tag['tag_name'], true).' ';
 }
 echo '<br/>';
-echo 'Creat la '.htmlentities($first_textblock['creation_timestamp']).' de '.format_user_link($first_textblock["user_name"], $first_textblock["user_fullname"]);
+echo 'Creat la '.html_escape($first_textblock['creation_timestamp']).' de '.format_user_link($first_textblock["user_name"], $first_textblock["user_fullname"]);
 echo '</div>';
 // blog comments
 echo '<div id="comentarii">';
Index: www/views/changes.php
===================================================================
--- www/views/changes.php	(revision 931)
+++ www/views/changes.php	(working copy)
@@ -7,7 +7,7 @@
 
 <h1>Ultimele modificari de pe infoarena</h1>
 
-<a class="feed" href="<?= htmlentities(url_absolute(url_changes_rss())) ?>" title="RSS Modificari" >RSS</a>
+<a class="feed" href="<?= html_escape(url_absolute(url_changes_rss())) ?>" title="RSS Modificari" >RSS</a>
 
 <ul class="changes">
 <?php foreach ($revisions as $rev) { ?>
Index: www/views/form_login.php
===================================================================
--- www/views/form_login.php	(revision 931)
+++ www/views/form_login.php	(working copy)
@@ -1,6 +1,6 @@
-<form action="<?= htmlentities(url_login()) ?>" method="post" class="login">
+<form action="<?= html_escape(url_login()) ?>" method="post" class="login">
 <fieldset>
-    <legend><img src="<?= htmlentities(url_static('images/icons/login.png')) ?>" alt="!" /> Autentificare</legend>
+    <legend><img src="<?= html_escape(url_static('images/icons/login.png')) ?>" alt="!" /> Autentificare</legend>
     <ul class="form">
 <?= view_form_field_li(array(
         'name' => 'Cont de utilizator',
Index: www/views/google_search.php
===================================================================
--- www/views/google_search.php	(revision 931)
+++ www/views/google_search.php	(working copy)
@@ -1,7 +1,7 @@
 <!-- Google CSE Search Box Begins -->
   <form id="searchbox_010130381492294265836:kw-fmmvpxco" action="http://infoarena.ro/search">
   <fieldset>
-  <legend><img src="<?= htmlentities(url_static('images/icons/search.png')) ?>" alt="!" /> Cautare</legend>
+  <legend><img src="<?= html_escape(url_static('images/icons/search.png')) ?>" alt="!" /> Cautare</legend>
     <input type="hidden" name="cx" value="010130381492294265836:kw-fmmvpxco" />
     <input type="hidden" name="cof" value="FORID:9" />
     <input name="q" type="text" size="22" />
Index: www/views/google_search_results.php
===================================================================
--- www/views/google_search_results.php	(revision 931)
+++ www/views/google_search_results.php	(working copy)
@@ -1,6 +1,6 @@
 <?php include('header.php'); ?>
 
-<h1><?= htmlentities($view['title']) ?></h1>
+<h1><?= html_escape($view['title']) ?></h1>
 
 <!-- Google Search Result Snippet Begins -->
   <div id="results_010130381492294265836:kw-fmmvpxco"></div>
Index: www/views/header.php
===================================================================
--- www/views/header.php	(revision 931)
+++ www/views/header.php	(working copy)
@@ -13,7 +13,7 @@
     log_assert(is_array($view['form_errors']));
     log_assert(is_array($view['form_values']));
     foreach ($form_values as $k => $v) {
-        if (htmlentities($k) != $k) {
+        if (html_escape($k) != $k) {
             log_error("Form field $k contains special html chars.");
         }
     }
@@ -26,30 +26,30 @@
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     <meta name="verify-v1" content="j9UCDYvsDL2pLtkJDDkE4HnHVmXakgvz30vOyIJ+6cI=" />
-    <title><?= htmlentities(getattr($view, 'title'), ENT_COMPAT, "utf-8") ?></title>
+    <title><?= html_escape(getattr($view, 'title')) ?></title>
 
-    <link type="text/css" rel="stylesheet" href="<?= htmlentities(url_static('css/sitewide.css')) ?>"/>
-    <link type="text/css" rel="stylesheet" href="<?= htmlentities(url_static('css/iconize.css')) ?>"/>
-    <link type="text/css" rel="stylesheet" href="<?= htmlentities(url_static('css/screen.css')) ?>"/>
-    <link type="text/css" rel="stylesheet" href="<?= htmlentities(url_static('css/tabber.css')) ?>"/>
-    <link type="text/css" rel="stylesheet" href="<?= htmlentities(url_static('css/SyntaxHighlighter.css')) ?>"/>
-    <link type="text/css" rel="stylesheet" href="<?= htmlentities(url_static('css/print.css')) ?>" media="print" />
+    <link type="text/css" rel="stylesheet" href="<?= html_escape(url_static('css/sitewide.css')) ?>"/>
+    <link type="text/css" rel="stylesheet" href="<?= html_escape(url_static('css/iconize.css')) ?>"/>
+    <link type="text/css" rel="stylesheet" href="<?= html_escape(url_static('css/screen.css')) ?>"/>
+    <link type="text/css" rel="stylesheet" href="<?= html_escape(url_static('css/tabber.css')) ?>"/>
+    <link type="text/css" rel="stylesheet" href="<?= html_escape(url_static('css/SyntaxHighlighter.css')) ?>"/>
+    <link type="text/css" rel="stylesheet" href="<?= html_escape(url_static('css/print.css')) ?>" media="print" />
     <link rel="icon" href="<?= IA_URL."favicon.ico" ?>" type="image/vnd.microsoft.icon" />
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/config.js.php')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/MochiKit.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/default.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/tabber-minimized.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/submit.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/remotebox.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/sh/shCore.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/sh/shBrushCpp.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/sh/shBrushDelphi.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/sh/shBrushJava.js')) ?>"></script>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/sh/shInit.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/config.js.php')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/MochiKit.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/default.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/tabber-minimized.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/submit.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/remotebox.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/sh/shCore.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/sh/shBrushCpp.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/sh/shBrushDelphi.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/sh/shBrushJava.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/sh/shInit.js')) ?>"></script>
 
     <?= getattr($view, 'head') ?>
 </head>
-<body id="infoarena" <?= getattr($view, 'body_onload') ? ' onload="' . htmlentities(getattr($view, 'body_onload')) . '"' : '' ?>>
+<body id="infoarena" <?= getattr($view, 'body_onload') ? ' onload="' . html_escape(getattr($view, 'body_onload')) . '"' : '' ?>>
 <div id="page">
 
 <?php
@@ -64,19 +64,19 @@
 <div id="content_small" class="clear">
 <div id="sidebar">
     <ul id="nav" class="clear">
-        <li><a href="<?= htmlentities(url_home()) ?>">Home</a></li>
+        <li><a href="<?= html_escape(url_home()) ?>">Home</a></li>
         <li><?= format_link_access(url_textblock('arhiva'), "Arhiva de probleme", 'a') ?></li>
-        <li><a href="<?= htmlentities(url_textblock('concursuri')) ?>">Concursuri</a></li>
-        <li><a href="<?= htmlentities(url_textblock('clasament-rating')) ?>">Clasament</a></li>
-        <li><a href="<?= htmlentities(url_textblock('articole')) ?>">Articole</a></li>
-        <li><a href="<?= htmlentities(url_textblock('downloads')) ?>">Downloads</a></li>
-        <li><a href="<?= htmlentities(url_textblock('links')) ?>">Links</a></li>
-        <li><a href="<?= htmlentities(url_textblock('documentatie')) ?>">Documentatie</a></li>
-        <li><a href="<?= htmlentities(url_textblock('despre-infoarena')) ?>">Despre infoarena</a></li>
+        <li><a href="<?= html_escape(url_textblock('concursuri')) ?>">Concursuri</a></li>
+        <li><a href="<?= html_escape(url_textblock('clasament-rating')) ?>">Clasament</a></li>
+        <li><a href="<?= html_escape(url_textblock('articole')) ?>">Articole</a></li>
+        <li><a href="<?= html_escape(url_textblock('downloads')) ?>">Downloads</a></li>
+        <li><a href="<?= html_escape(url_textblock('links')) ?>">Links</a></li>
+        <li><a href="<?= html_escape(url_textblock('documentatie')) ?>">Documentatie</a></li>
+        <li><a href="<?= html_escape(url_textblock('despre-infoarena')) ?>">Despre infoarena</a></li>
         <li class="separator"><hr/></li>
         <li><?= format_link_access(url_monitor(array('user' => identity_get_username())), "Monitorul de evaluare", 'm') ?></li>
         <?php if (!identity_is_anonymous()) { ?>
-        <li><a href="<?= htmlentities(url_submit()) ?>"><strong>Trimite solutii</strong></a></li>
+        <li><a href="<?= html_escape(url_submit()) ?>"><strong>Trimite solutii</strong></a></li>
         <li><?= format_link_access(url_account(), "Contul meu", 'c') ?></li>
         <?php } ?>
         </ul>
@@ -100,7 +100,7 @@
     <?php } ?>
     <p class="user-count"><?php echo user_count(); ?> membri inregistrati</p>
     <div id="srv_time" class="user-count" align="center"></div>
-    <script type="text/javascript" src="<?= htmlentities(url_static('js/time.js')) ?>"></script>
+    <script type="text/javascript" src="<?= html_escape(url_static('js/time.js')) ?>"></script>
     <script type="text/javascript">loadTime(<?= format_date(null, "%H, %M, %S");?>);</script>
 
     <?php include(IA_ROOT_DIR.'www/views/sidebar_ad.php'); ?>
@@ -115,7 +115,7 @@
     foreach ($recent_pages as $rec_key => $rec_entry) {
         list($rec_url, $rec_title) = $rec_entry;
 
-        $rec_title = htmlentities($rec_title);
+        $rec_title = html_escape($rec_title);
 
         if ($bstring) {
             $bstring .= ' <span class="separator">|</span> ';
@@ -124,7 +124,7 @@
             $bstring .= "<strong>{$rec_title}</strong>";
         }
         else {
-            $bstring .= "<a href=\"" . htmlentities($rec_url) . "\">{$rec_title}</a>";
+            $bstring .= "<a href=\"" . html_escape($rec_url) . "\">{$rec_title}</a>";
         }
     }
     echo '<p id="breadcrumbs">Pagini recente &raquo; ' . $bstring . '</p>';
@@ -136,7 +136,7 @@
     // display flash message
     if (isset($_SESSION['_ia_flash'])) { ?>
 
-<div id="flash" class="flash <?= htmlentities(getattr($_SESSION, '_ia_flash_class')) ?>"><?= htmlentities($_SESSION['_ia_flash']) ?></div>
+<div id="flash" class="flash <?= html_escape(getattr($_SESSION, '_ia_flash_class')) ?>"><?= html_escape($_SESSION['_ia_flash']) ?></div>
 
 <?php
         // clear flash message 
Index: www/views/job_detail.php
===================================================================
--- www/views/job_detail.php	(revision 931)
+++ www/views/job_detail.php	(working copy)
@@ -9,7 +9,7 @@
 
 ?>
 
-<h1><?= htmlentities($view['title']) ?></h1>
+<h1><?= html_escape($view['title']) ?></h1>
 
 <table class="job">
 <tr>
@@ -22,14 +22,14 @@
     <th class="task-id">Problema</th>
     <td class="task-id"><?= format_link(url_textblock($job['task_page_name']), $job['task_title']) ?></td>
     <th class="score">Scor</th>
-    <td class="score"><?= htmlentities($job['score']) ?></td>
+    <td class="score"><?= html_escape($job['score']) ?></td>
 </tr>
 </tr>
 <tr>
     <th class="compiler-id">Compilator</th>
-    <td class="compiler-id"><?= htmlentities($job['compiler_id']) ?></td>
+    <td class="compiler-id"><?= html_escape($job['compiler_id']) ?></td>
     <th class="status">Status</th>
-    <td class="status"><strong><?= htmlentities($job['status']) ?></strong></td>
+    <td class="status"><strong><?= html_escape($job['status']) ?></strong></td>
 </tr>
 <tr>
     <th class="round-id">Runda</th>
@@ -49,7 +49,7 @@
 <p>Aceasta sursa nu a fost evaluata inca.</p>
 <?php } else { ?>
     <div class="job-eval-log">
-<?= htmlentities($job['eval_log']) ?>
+<?= html_escape($job['eval_log']) ?>
     </div>
 <?php } ?>
 
@@ -75,7 +75,7 @@
         echo '<td class="number">'.$test['test_number'].'</td>';
         echo '<td class="number">'.$test['exec_time'].'ms</td>';
         echo '<td class="number">'.$test['mem_used'].'kb</td>';
-        echo '<td>'.htmlentities($test['grader_message']).'</td>';
+        echo '<td>'.html_escape($test['grader_message']).'</td>';
         echo '<td class="number">'.$test['points'].'</td>';
         if ($show_groups && $test['test_group'] != $last_group) {
             $last_group = $test['test_group'];
Index: www/views/job_view_source.php
===================================================================
--- www/views/job_view_source.php	(revision 931)
+++ www/views/job_view_source.php	(working copy)
@@ -17,14 +17,14 @@
     <th class="task-id">Problema</th>
     <td class="task-id"><?= format_link(url_textblock($job['task_page_name']), $job['task_title']) ?></td>
     <th class="score">Scor</th>
-    <td class="score"><?= htmlentities($job['score']) ?></td>
+    <td class="score"><?= html_escape($job['score']) ?></td>
 </tr>
 </tr>
 <tr>
     <th class="compiler-id">Compilator</th>
-    <td class="compiler-id"><?= htmlentities($job['compiler_id']) ?></td>
+    <td class="compiler-id"><?= html_escape($job['compiler_id']) ?></td>
     <th class="status">Status</th>
-    <td class="status"><strong><?= htmlentities($job['status']) ?></strong></td>
+    <td class="status"><strong><?= html_escape($job['status']) ?></strong></td>
 </tr>
 <tr>
     <th class="round-id">Runda</th>
@@ -45,7 +45,7 @@
 <?php
     echo '<div class="code">';
     echo "<textarea name=\"code\" class=\"{$lang}\" cols=\"60\" rows=\"10\">";
-    echo htmlentities($job['file_contents']);
+    echo html_escape($job['file_contents']);
     echo '</textarea></div>';
     include('footer.php');
 ?>
Index: www/views/listattach.php
===================================================================
--- www/views/listattach.php	(revision 931)
+++ www/views/listattach.php	(working copy)
@@ -51,7 +51,7 @@
     global $page_name;
     
     $delurl = '<a href="';
-    $delurl .= htmlentities(url_attachment_delete($page_name, $row['name']));
+    $delurl .= html_escape(url_attachment_delete($page_name, $row['name']));
     $delurl .= "\" onclick=\"return confirm('Aceasta actiune este ireversibila! Doresti sa continui?')\">Sterge</a>";
     $renurl = '<a href="#" id="rename_link_'.$row['id'].'" onclick="rename_form('.$row['id'].')">Redenumeste</a>';
 
Index: www/views/login.php
===================================================================
--- www/views/login.php	(revision 931)
+++ www/views/login.php	(working copy)
@@ -1,10 +1,10 @@
 <?php include(IA_ROOT_DIR.'www/views/header.php'); ?>
 
-<h1><?= htmlentities($title) ?></h1>
+<h1><?= html_escape($title) ?></h1>
 
 <p>Daca nu esti inregistrat deja, te poti
 <?= format_link(url_register(), "inregistra aici") ?>;
-daca ti-ai uitat parola, o poti <a href="<?= htmlentities(url_resetpass()) ?>">reseta aici</a>.</p>
+daca ti-ai uitat parola, o poti <a href="<?= html_escape(url_resetpass()) ?>">reseta aici</a>.</p>
 
 <?php include(IA_ROOT_DIR.'www/views/form_login.php'); ?>
 
Index: www/views/monitor.php
===================================================================
--- www/views/monitor.php	(revision 931)
+++ www/views/monitor.php	(working copy)
@@ -6,21 +6,21 @@
 require_once(IA_ROOT_DIR."www/format/form.php");
 
 if (!$display_only_table) {
-    $view['head'] = '<script type="text/javascript" src="'.htmlentities(url_static('js/monitor.js')).'"></script>';
+    $view['head'] = '<script type="text/javascript" src="'.html_escape(url_static('js/monitor.js')).'"></script>';
     include('header.php');
 }
 
 if (!$display_only_table && identity_can('job-reeval') && $view['total_entries'] <= IA_REEVAL_MAXJOBS) {
-    echo '<form enctype="multipart/form-data" action="'.htmlentities(url_reeval($view['filters'])).'" 
+    echo '<form enctype="multipart/form-data" action="'.html_escape(url_reeval($view['filters'])).'" 
                method="post" class="reeval" id="job_reeval" onsubmit="return confirm(\'Se vor reevalua '.
-               htmlentities($view['total_entries']).' job-uri! Continuam?\')">';
+               html_escape($view['total_entries']).' job-uri! Continuam?\')">';
     echo '<ul class="form hollyfix"><li id="field_submit">';
     echo '<input type="submit" class="button important" value="Re-evalueaza!" id="form_reeval" />';
     echo '</li></ul></form>';
 }
 
 if (!$display_only_table) {
-    echo '<h1>'.htmlentities($view['title']).'</h1>';
+    echo '<h1>'.html_escape($view['title']).'</h1>';
 }
 
 $tabs = array();
@@ -68,10 +68,10 @@
         $url = url_job_detail($row['id']);
         if ($row['status'] == 'done') {
             if (identity_can("job-view-score", $row)) {
-                $msg = htmlentities(sprintf("%s: %s puncte",
+                $msg = html_escape(sprintf("%s: %s puncte",
                     $row['eval_message'], $row['score']));
             } else {
-                $msg = htmlentities( $row['eval_message'] );
+                $msg = html_escape( $row['eval_message'] );
             }
             $msg = "<span style=\"job-status-done\">$msg</span>";
             return format_link($url, $msg, false);
Index: www/views/projector.php
===================================================================
--- www/views/projector.php	(revision 931)
+++ www/views/projector.php	(working copy)
@@ -26,7 +26,7 @@
 include(IA_ROOT_DIR.'www/views/header.php');
 
 if (!$display_only_table) {
-    echo '<h1>'.htmlentities($view['title']).'</h1>';
+    echo '<h1>'.html_escape($view['title']).'</h1>';
 }
 
 echo "<div id=\"monitor-table\">";
@@ -38,7 +38,7 @@
     function format_state($row) {
         $url = url_job_detail($row['id']);
         if ($row['status'] == 'done') {
-            $msg = htmlentities(sprintf("%s: %s puncte",
+            $msg = html_escape(sprintf("%s: %s puncte",
                     $row['eval_message'], $row['score']));
             $msg = "<span style=\"job-status-done\">$msg</span>";
             return format_link($url, $msg, false);
Index: www/views/register.php
===================================================================
--- www/views/register.php	(revision 931)
+++ www/views/register.php	(working copy)
@@ -1,8 +1,8 @@
 <?php include('header.php'); ?>
 
-<h1><?= htmlentities($view['title']) ?></h1>
+<h1><?= html_escape($view['title']) ?></h1>
 
-<p>Daca esti deja inregistrat te poti <a href="<?= htmlentities(url_login()) ?>">autentifica aici</a>; daca ti-ai uitat parola, o poti <a href="<?= htmlentities(url_resetpass()) ?>">reseta aici</a>.</p>
+<p>Daca esti deja inregistrat te poti <a href="<?= html_escape(url_login()) ?>">autentifica aici</a>; daca ti-ai uitat parola, o poti <a href="<?= html_escape(url_resetpass()) ?>">reseta aici</a>.</p>
 
 <div id="sidebar2">
 <div class="section">
@@ -24,9 +24,9 @@
 
 </div>
 
-<form enctype="multipart" action="<?= htmlentities($action) ?>" method="post" class="profile clear">
+<form enctype="multipart" action="<?= html_escape($action) ?>" method="post" class="profile clear">
 <fieldset>
-    <legend><img src="<?= htmlentities(url_static('images/icons/key.gif')) ?>" alt="!" /> Utilizator infoarena</legend>
+    <legend><img src="<?= html_escape(url_static('images/icons/key.gif')) ?>" alt="!" /> Utilizator infoarena</legend>
     <ul class="form">
         <li>
             <label for='form_username'>Nume cont utilizator</label>
@@ -84,7 +84,7 @@
         <?= ferr_span('tnc') ?>
         <input type="checkbox" <?php if (fval('tnc'))
             echo 'checked="checked"'; ?> name="tnc" id="form_tnc"/>
-        <label for="form_tnc" class="checkbox">Sunt de acord cu <a href="<?= htmlentities(url_textblock('termeni-si-conditii')) ?>">termenii si conditiile de utilizare</a> ale site-ului infoarena</label>
+        <label for="form_tnc" class="checkbox">Sunt de acord cu <a href="<?= html_escape(url_textblock('termeni-si-conditii')) ?>">termenii si conditiile de utilizare</a> ale site-ului infoarena</label>
     </li>
     <li>
         <input type="submit" value="Inregistreaza-ma" id="form_submit" class="button important" />
Index: www/views/resetpass.php
===================================================================
--- www/views/resetpass.php	(revision 931)
+++ www/views/resetpass.php	(working copy)
@@ -2,12 +2,12 @@
     include('header.php');
 ?>
 
-<h1><?= htmlentities($title) ?></h1>
+<h1><?= html_escape($title) ?></h1>
 
 <p>Introdu numele de utilizator sau adresa de e-mail cu care te-ai inregistrat pe site.</p>
 <p>Iti vom trimite pe e-mail instructiuni pentru a-ti reseta parola.</p>
 
-<form action="<?= htmlentities(url_resetpass()) ?>" method="post" class="login clear">
+<form action="<?= html_escape(url_resetpass()) ?>" method="post" class="login clear">
 <fieldset>
     <legend>Date de identificare</legend>
     <ul class="form">
Index: www/views/revision_warning.php
===================================================================
--- www/views/revision_warning.php	(revision 931)
+++ www/views/revision_warning.php	(working copy)
@@ -1,5 +1,5 @@
 <div class="warning">
-    Atentie! Aceasta pagina nu este actuala (este varianta de la <?= htmlentities($textblock['timestamp']) ?>)</br>
+    Atentie! Aceasta pagina nu este actuala (este varianta de la <?= html_escape($textblock['timestamp']) ?>)</br>
     <?php
     if ($view['revision'] > 1) {
         echo format_link(url_textblock_revision($view['page_name'], $view['revision'] - 1), "Revizia anterioara");
Index: www/views/round_create.php
===================================================================
--- www/views/round_create.php	(revision 931)
+++ www/views/round_create.php	(working copy)
@@ -18,9 +18,9 @@
 
 ?>
 
-<h1><?= htmlentities($title) ?></h1>
+<h1><?= html_escape($title) ?></h1>
 
-<form action="<?= htmlentities(url_round_create()) ?>"
+<form action="<?= html_escape(url_round_create()) ?>"
       method="post"
       class="task create clear">
  <fieldset>
Index: www/views/round_edit.php
===================================================================
--- www/views/round_edit.php	(revision 931)
+++ www/views/round_edit.php	(working copy)
@@ -4,9 +4,9 @@
 if (!isset($view['head'])) {
     $view['head'] = "";
 }
-$view['head'] .= "<script type=\"text/javascript\" src=\"" . htmlentities(url_static("js/dual.js")) . "\" ></script>";
-$view['head'] .= "<script type=\"text/javascript\" src=\"" . htmlentities(url_static("js/roundedit.js")) . "\" ></script>";
-$view['head'] .= "<script type=\"text/javascript\" src=\"" . htmlentities(url_static("js/parameditor.js")) . "\" ></script>";
+$view['head'] .= "<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/dual.js")) . "\" ></script>";
+$view['head'] .= "<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/roundedit.js")) . "\" ></script>";
+$view['head'] .= "<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/parameditor.js")) . "\" ></script>";
 
 require_once(IA_ROOT_DIR."common/round.php");
 require_once(IA_ROOT_DIR."www/format/form.php");
@@ -80,7 +80,7 @@
     </div>
 <?php } ?>
 
-<form action="<?= htmlentities(getattr($view, 'action')) ?>" method="post" class="task" <?= tag_form_event() ?>>
+<form action="<?= html_escape(getattr($view, 'action')) ?>" method="post" class="task" <?= tag_form_event() ?>>
  <fieldset>
   <legend>Informatii generale</legend>
   <ul class="form">
Index: www/views/round_register.php
===================================================================
--- www/views/round_register.php	(revision 931)
+++ www/views/round_register.php	(working copy)
@@ -6,7 +6,7 @@
 
 <?php wiki_include('template/inscriere', array('round' => $round['id'])) ?>
 
-<form action="<?= htmlentities(getattr($view, 'action')) ?>" method="post" class="register">
+<form action="<?= html_escape(getattr($view, 'action')) ?>" method="post" class="register">
     <ul class="form">
         <li id="form_submit">
             <input type="submit" value="Confirma inscrierea" id="form_submit" class="button important" />
Index: www/views/rss.php
===================================================================
--- www/views/rss.php	(revision 931)
+++ www/views/rss.php	(working copy)
@@ -14,22 +14,22 @@
 echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
 echo '<rss version="2.0">'."\n";
 echo '<channel>'."\n";
-echo '<title>'.xmlesc(getattr($view['channel'], 'title')).'</title>'."\n";
-echo '<link>'.xmlesc(getattr($view['channel'], 'link')).'</link>'."\n";
-echo '<description>'.xmlesc(getattr($view['channel'], 'description')).'</description>'."\n";
+echo '<title>'.html_escape(getattr($view['channel'], 'title')).'</title>'."\n";
+echo '<link>'.html_escape(getattr($view['channel'], 'link')).'</link>'."\n";
+echo '<description>'.html_escape(getattr($view['channel'], 'description')).'</description>'."\n";
 
 foreach ($optional['channel'] as $hash_key => $hash_value) {
     if (getattr($view['channel'], $hash_value)) {
         echo '<'.$hash_value.'>';
-        echo xmlesc($view['channel'][$hash_value]);
+        echo html_escape($view['channel'][$hash_value]);
         echo '</'.$hash_value.">\n";
     }
 }
 
 foreach ($view['item'] as $v) {
     echo '<item>'."\n";
-    echo '<title>'.xmlesc(getattr($v, 'title')).'</title>'."\n";
-    echo '<link>'.xmlesc(getattr($v, 'link')).'</link>'."\n";
+    echo '<title>'.html_escape(getattr($v, 'title')).'</title>'."\n";
+    echo '<link>'.html_escape(getattr($v, 'link')).'</link>'."\n";
     foreach ($optional['item'] as $hash_key => $hash_value) {
         if (getattr($v, $hash_value)) {
             echo '<'.$hash_value;
@@ -38,19 +38,19 @@
                     if ($attr_name == 'value') {
                         continue;
                     }
-                    echo ' '.xmlesc($attr_name).'="'.xmlesc($attr_value).'"';
+                    echo ' '.html_escape($attr_name).'="'.html_escape($attr_value).'"';
                 }
             }
             echo '>';
             if (is_array($v[$hash_value])) {
-                echo xmlesc($v[$hash_value]['value']);
+                echo html_escape($v[$hash_value]['value']);
             } else {
-                echo xmlesc($v[$hash_value]);
+                echo html_escape($v[$hash_value]);
             }
             echo '</'.$hash_value.">\n";
         }
     }
-    echo '<description>'.xmlesc(getattr($v, 'description')).'</description>'."\n";
+    echo '<description>'.html_escape(getattr($v, 'description')).'</description>'."\n";
     echo '</item>'."\n";
 }
 
Index: www/views/sitewide.php
===================================================================
--- www/views/sitewide.php	(revision 931)
+++ www/views/sitewide.php	(working copy)
@@ -17,7 +17,7 @@
         <div id="userbox">
         <?= format_link(url_user_profile($username, true), format_user_avatar($username, 50, 50, true), false) ?>
             <span class="user">
-                <strong><?= htmlentities($identity_user['full_name']) ?></strong><br/>
+                <strong><?= html_escape($identity_user['full_name']) ?></strong><br/>
                 <?= format_user_ratingbadge($username, $identity_user['rating_cache']) ?>
                 <?= format_link_access(url_user_profile($username, true), $username, 'p') ?><br/>
                 <?= format_link(url_logout(), "logout", true, array('class' => 'logout')) ?> |
@@ -139,7 +139,7 @@
         log_execution_stats();
         $buffer = $execution_stats['log_copy'];
         echo '<textarea id="log" rows="50" cols="80">';
-        echo htmlentities($buffer);
+        echo html_escape($buffer);
         echo '</textarea>';
     }
 ?>
Index: www/views/submit.php
===================================================================
--- www/views/submit.php	(revision 931)
+++ www/views/submit.php	(working copy)
@@ -13,7 +13,7 @@
 
 ?>
 
-<h1><?= htmlentities($title)  ?></h1>
+<h1><?= html_escape($title)  ?></h1>
 
 <div id="sidebar2">
 <div class="section">
@@ -24,9 +24,9 @@
 </div>
 </div>
 
-<form enctype="multipart/form-data" action="<?= htmlentities(url_submit()) ?>" method="post" class="submit" id="task_submit">
+<form enctype="multipart/form-data" action="<?= html_escape(url_submit()) ?>" method="post" class="submit" id="task_submit">
 
-<input type="hidden" id="output_only" value="<?= htmlentities(':'.join(':', $output_only_ids).':') ?>" />
+<input type="hidden" id="output_only" value="<?= html_escape(':'.join(':', $output_only_ids).':') ?>" />
 
 <ul class="form hollyfix">
     <li id="field_task">
@@ -34,7 +34,7 @@
         <select name="task_id" id="form_task">
             <option value="">[ Alegeti problema ]</option>
 <?php foreach ($tasks as $task) {  ?>
-            <option value="<?= htmlentities($task['id']) ?>"<?= fval('task_id') == $task['id'] ? ' selected="selected"' : '' ?>><?= htmlentities($task['title']) ?></option>
+            <option value="<?= html_escape($task['id']) ?>"<?= fval('task_id') == $task['id'] ? ' selected="selected"' : '' ?>><?= html_escape($task['title']) ?></option>
 <?php } ?>
         </select>
         <?= ferr_span('task_id') ?>
Index: www/views/tags_header.php
===================================================================
--- www/views/tags_header.php	(revision 931)
+++ www/views/tags_header.php	(working copy)
@@ -9,8 +9,8 @@
 // Format a tag input box
 // FIXME: Width parameter does not work, I hate CSS
 function tag_format_input_box($value = null, $width = "50", $name = "tags") {
-    $esc_name = htmlentities($name);
-    $esc_width = htmlentities($width);
+    $esc_name = html_escape($name);
+    $esc_width = html_escape($width);
     // presume $value is html-escaped
 
     $output = '<li><label for="form_'.$esc_name.'">Tag-uri</label>';
@@ -25,13 +25,13 @@
     }
     $output .= ' />';
     $output .= '<script type="text/javascript" language="JavaScript" src="'.
-                htmlentities(url_static("js/wick.js")).'"></script>';
+                html_escape(url_static("js/wick.js")).'"></script>';
     $output .= "</label></li>";
     return $output;
 }
 ?>
 
-<link rel="stylesheet" type="text/css" href="<?= htmlentities(url_static("css/wick.css")) ?> " />
+<link rel="stylesheet" type="text/css" href="<?= html_escape(url_static("css/wick.css")) ?> " />
 <script type="text/javascript" language="JavaScript">
 function checkForm() {
     answer = true;
@@ -44,7 +44,7 @@
 $tag_names = tag_get_all_names();
 echo  "collection = [\n";
 foreach ($tag_names as $tag) {
-    echo "'".htmlentities($tag['name'])."',\n";
+    echo "'".html_escape($tag['name'])."',\n";
 }
 echo "];\n";
 ?>
Index: www/views/task_create.php
===================================================================
--- www/views/task_create.php	(revision 931)
+++ www/views/task_create.php	(working copy)
@@ -19,9 +19,9 @@
 
 ?>
 
-<h1><?= htmlentities($title) ?></h1>
+<h1><?= html_escape($title) ?></h1>
 
-<form action="<?= htmlentities(url_task_create()) ?>" method="post" class="task create clear">
+<form action="<?= html_escape(url_task_create()) ?>" method="post" class="task create clear">
 <fieldset>
 <legend>Informatii initiale</legend>
     <ul class="form">
Index: www/views/task_edit.php
===================================================================
--- www/views/task_edit.php	(revision 931)
+++ www/views/task_edit.php	(working copy)
@@ -4,7 +4,7 @@
 require_once(IA_ROOT_DIR."www/format/form.php");
 
 $view['head'] = getattr($view, 'head').
-    "<script type=\"text/javascript\" src=\"" . htmlentities(url_static("js/parameditor.js")) . "\"></script>";
+    "<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/parameditor.js")) . "\"></script>";
 
 include('views/header.php');
 include('views/tags_header.php');
@@ -62,9 +62,9 @@
 
 ?>
 
-<h1>Editare <a href="<?= htmlentities(url_task($view['task_id'])) ?>"><?= htmlentities($view['title']) ?></a></h1>
+<h1>Editare <a href="<?= html_escape(url_task($view['task_id'])) ?>"><?= html_escape($view['title']) ?></a></h1>
 
-<form action="<?= htmlentities(url_task_edit($task_id)) ?>"
+<form action="<?= html_escape(url_task_edit($task_id)) ?>"
       method="post"
       class="task"
       <?= tag_form_event() ?>>
Index: www/views/textblock_diff.php
===================================================================
--- www/views/textblock_diff.php	(revision 931)
+++ www/views/textblock_diff.php	(working copy)
@@ -19,14 +19,14 @@
             foreach ($op['lines'] as $line) {
                 $output = "";
                 if (!is_array($line)) {
-                    $output = htmlentities($line, ENT_COMPAT, "utf-8");
+                    $output = html_escape($line);
                 } else {
                     // line contains inline diff
                     foreach ($line as $chunk) {
                         if ($chunk['type'] != 'normal') {
                             $output .= '<'.$chunk['type'].'>';
                         }
-                        $output .= htmlentities($chunk['string'], ENT_COMPAT, "utf-8"); 
+                        $output .= html_escape($chunk['string']); 
                         if ($chunk['type'] != 'normal') {
                             $output .= '</'.$chunk['type'].'>';
                         }
Index: www/views/textblock_edit.php
===================================================================
--- www/views/textblock_edit.php	(revision 931)
+++ www/views/textblock_edit.php	(working copy)
@@ -1,15 +1,15 @@
 <?php
 
 // link JS
-$view['head'] = getattr($view, 'head')."<script type=\"text/javascript\" src=\"" . htmlentities(url_static("js/wikiedit.js")) . "\"></script>";
+$view['head'] = getattr($view, 'head')."<script type=\"text/javascript\" src=\"" . html_escape(url_static("js/wikiedit.js")) . "\"></script>";
 
 include('views/header.php');
 include('views/tags_header.php');
 ?>
 
-<form accept-charset="utf-8" action="<?= htmlentities(url_textblock_edit($page_name)) ?>" method="post" id="form_wikiedit" <?= tag_form_event() ?>>
-<input type="hidden" id="form_page_name" value="<?= htmlentities(isset($page_name) ? $page_name : '') ?>" />
-<input type="hidden" name="last_revision" value="<?=htmlentities($last_revision)?>" />
+<form accept-charset="utf-8" action="<?= html_escape(url_textblock_edit($page_name)) ?>" method="post" id="form_wikiedit" <?= tag_form_event() ?>>
+<input type="hidden" id="form_page_name" value="<?= html_escape(isset($page_name) ? $page_name : '') ?>" />
+<input type="hidden" name="last_revision" value="<?=html_escape($last_revision)?>" />
 
 <?php if (ferr('was_modified', false)) { ?>
 <div class="wiki_was_modified"><?= ferr('was_modified', false); ?></div>
@@ -42,7 +42,7 @@
     <?php if (array_key_exists('security', $form_values)) { ?>
     <li id="field_security">
         <label for="form_security">Nivel de securitate al paginii
-        <a href="<?= htmlentities(url_textblock('documentatie/securitate')) ?>">(?)</a></label> 
+        <a href="<?= html_escape(url_textblock('documentatie/securitate')) ?>">(?)</a></label> 
         <input type="text" name="security" value="<?= fval('security') ?>" id="form_security"/>
         <?= ferr_span('security') ?>
     </li>
Index: www/views/textblock_move.php
===================================================================
--- www/views/textblock_move.php	(revision 931)
+++ www/views/textblock_move.php	(working copy)
@@ -1,8 +1,8 @@
 <?php include('header.php'); ?>
 
-<h1><?= htmlentities($title) ?></h1>
+<h1><?= html_escape($title) ?></h1>
 
-<form action="<?= htmlentities(url_textblock_move($page_name)) ?>" method="post" class="move clear">
+<form action="<?= html_escape(url_textblock_move($page_name)) ?>" method="post" class="move clear">
 <fieldset>
     <ul class="form">
         <li>
Index: www/views/utilities.php
===================================================================
--- www/views/utilities.php	(revision 931)
+++ www/views/utilities.php	(working copy)
@@ -13,7 +13,7 @@
     }
 
     if ($escape_html) {
-        return htmlentities(getattr($view['form_values'], $param_name), ENT_COMPAT, "utf-8");
+        return html_escape(getattr($view['form_values'], $param_name));
     } else {
         return getattr($view['form_values'], $param_name);
     }
@@ -42,7 +42,7 @@
     global $view;
 
     if ($escape_html) {
-        return htmlentities(getattr($view['form_errors'], $param_name), ENT_COMPAT, "utf-8");
+        return html_escape(getattr($view['form_errors'], $param_name));
     } else {
         return getattr($view['form_errors'], $param_name);
     }
Index: www/wiki/MyTextile.php
===================================================================
--- www/wiki/MyTextile.php	(revision 931)
+++ www/wiki/MyTextile.php	(working copy)
@@ -4,6 +4,7 @@
 require_once(IA_ROOT_DIR."common/attachment.php");
 require_once(IA_ROOT_DIR."common/string.php");
 require_once(IA_ROOT_DIR."www/wiki/latex.php");
+require_once(IA_ROOT_DIR."www/utilities.php");
 
 class MyTextile extends Textile {
     // FIXME: If you see a pointless textile error try tweaking this value.
@@ -74,7 +75,7 @@
             // put javascript dp.SyntaxHighlighter at work
             return "\n<div class=\"code\">"
                    ."<textarea name=\"code\" class=\"{$lang}\" cols=\"60\" rows=\"10\">"
-                   .htmlentities($text) . "</textarea></div>\n";
+                   .html_escape($text) . "</textarea></div>\n";
         }
         else {
             return macro_error("Can't handle ==$type| block.");
@@ -154,7 +155,7 @@
                     //log_warn("Invalid resize instructions '$extra'");
                     $extra = '';
                 }
-                $args['src'] = htmlentities(url_absolute(url_image_resize($matches[1], $matches[2], $extra)));
+                $args['src'] = html_escape(url_absolute(url_image_resize($matches[1], $matches[2], $extra)));
                 $allowed = true;
 
                 // Test if $srcpath references an internal url that is NOT a textblock
@@ -219,7 +220,7 @@
         }
         else {
             $html = macro_error("LaTeX support is disabled.");
-            $html .= "<pre>".htmlentities($str).'</pre>';
+            $html .= "<pre>".html_escape($str).'</pre>';
         }
 
         if ($this->error_reporting_level === false) {
Index: www/wiki/latex.php
===================================================================
--- www/wiki/latex.php	(revision 931)
+++ www/wiki/latex.php	(working copy)
@@ -58,7 +58,7 @@
         $style_css = " align=absmiddle";
     }
 
-    $alt_latex_formula = htmlentities($latex_formula, ENT_QUOTES);
+    $alt_latex_formula = html_escape($latex_formula, ENT_QUOTES);
     $alt_latex_formula = str_replace("\r","&#13;",$alt_latex_formula);
     $alt_latex_formula = str_replace("\n","&#10;",$alt_latex_formula);
 
