Changeset 324
- Timestamp:
- 02/21/2007 05:27:02 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 16 modified
-
actions/files.php (modified) (1 diff)
-
actions/image.php (modified) (1 diff)
-
actions/recentchanges.php (modified) (1 diff)
-
actions/textsearchexpanded.php (modified) (2 diffs)
-
actions/usersettings.php (modified) (3 diffs)
-
formatters/code.php (modified) (1 diff)
-
formatters/email.php (modified) (1 diff)
-
formatters/ini.php (modified) (2 diffs)
-
formatters/wakka.php (modified) (3 diffs)
-
handlers/page/edit.php (modified) (5 diffs)
-
handlers/page/processcomment.php (modified) (1 diff)
-
handlers/page/recentchanges.xml.mm.php (modified) (2 diffs)
-
handlers/page/recentchanges.xml.php (modified) (1 diff)
-
handlers/page/referrers_sites.php (modified) (2 diffs)
-
handlers/page/revisions.xml.php (modified) (1 diff)
-
libs/Wakka.class.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/actions/files.php
r294 r324 28 28 * @uses Wakka::IsAdmin() 29 29 * @uses Wakka::MiniHref() 30 * @uses Wakka::htmlspecialchars_ent() 30 31 * 31 32 * @todo security: check file type, not only extension -
trunk/actions/image.php
r161 r324 10 10 * @uses Wakka::Link() 11 11 * @uses Wakka::ReturnSafeHTML() 12 * @uses Wakka::htmlspecialchars_ent() 12 13 * @input string $url mandatory: URL of image to be embedded 13 14 * @input string $link optional: target link for image (optional). Supports URL, WikiName links, InterWiki links etc. -
trunk/actions/recentchanges.php
r294 r324 17 17 * @uses Wakka::HasAccess() 18 18 * @uses Wakka::LoadUser() 19 * @uses Wakka::htmlspecialchars_ent() 19 20 * 20 21 * @todo make datetime format configurable; -
trunk/actions/textsearchexpanded.php
r274 r324 82 82 $matchString[0] = array_splice($matchString[0], SEARCH_MAX_SNIPPETS, count($matchString)); 83 83 } 84 $text = $this->htmlspecialchars_ent(implode('<br />', $matchString[0])); 85 $text = str_replace('<br />', '…<br />…', $text); 84 $text = $this->htmlspecialchars_ent(implode('<br />', $matchString[0])); //TODO could be done in a single step 85 $text = str_replace('<br />', '…<br />…', $text); //TODO could be done in a single step 86 86 # CSS-driven highlighting, tse stands for textsearchexpanded. We highlight $text in 2 steps, 87 87 # We do not use <span>..</span> with preg_replace to ensure that the tag `span' won't be replaced if … … 107 107 break; 108 108 } 109 printf(SEARCH_RESULTS.": <strong>".$match_str."</strong> for <strong>".$this->htmlspecialchars_ent($phrase)."</strong><br />\n", $total_results); #i18n109 printf(SEARCH_RESULTS.": <strong>".$match_str."</strong> for <strong>".$this->htmlspecialchars_ent($phrase)."</strong><br />\n", $total_results); 110 110 $result_page_list = $this->ReturnSafeHtml($result_page_list); 111 111 echo '<ol>'.$result_page_list.'</ol>'."\n"; -
trunk/actions/usersettings.php
r313 r324 12 12 * @author {@link http://wikkawiki.org/NilsLindenberg Nils Lindenberg} (possibility to restrict registration) 13 13 * 14 * @uses Wakka::htmlspecialchars_ent() 15 * 14 16 * @todo use different actions for registration / login / user settings; 15 17 * @todo add documentation links or short explanations for each option; … … 97 99 98 100 // validate form input 99 switch (TRUE)101 switch (TRUE) 100 102 { 101 103 case (strlen($email) == 0): //email is empty … … 148 150 <input type="hidden" name="action" value="update" /> 149 151 <?php printf(USER_LOGGED_IN_AS_CAPTION, $this->Link($user['name'])); ?> 150 <input id="logout" type="button" value="<?php echo LOGOUT_BUTTON; ?>" onclick="document.location='<?php echo $this-> href('', '', 'action=logout'); ?>'" />152 <input id="logout" type="button" value="<?php echo LOGOUT_BUTTON; ?>" onclick="document.location='<?php echo $this->Href('', '', 'action=logout'); ?>'" /> 151 153 </fieldset> 152 154 -
trunk/formatters/code.php
r161 r324 7 7 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 8 8 * @filesource 9 * 10 * @uses Wakka::hsc_secure() 9 11 */ 10 print("<pre>".htmlspecialchars($text, ENT_QUOTES)."</pre>"); 12 echo '<pre>'.$this->hsc_secure($text,ENT_QUOTES).'</pre>'; #427 11 13 ?> -
trunk/formatters/email.php
r161 r324 7 7 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 8 8 * @filesource 9 * 10 * @uses Wakka::htmlspecialchars_ent() 9 11 */ 10 12 -
trunk/formatters/ini.php
r161 r324 7 7 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 8 8 * @filesource 9 * 10 * @uses Wakka::hsc_secure() 9 11 */ 10 12 11 $text = htmlspecialchars($text, ENT_QUOTES);13 $text = $this->hsc_secure($text,ENT_QUOTES); #427 12 14 13 15 $text = preg_replace("/([=,\|]+)/m","<span style=\"color:#4400DD\">\\1</span>",$text); … … 16 18 $text = preg_replace("/^(\[.*\])/m","<strong style=\"color:#AA0000;background:#EEE0CC\">\\1</strong>",$text); 17 19 print "<pre>".$text."</pre>"; 18 19 20 ?> -
trunk/formatters/wakka.php
r294 r324 16 16 * @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} (grab handler and filename support for codeblocks) 17 17 * @author {@link http://wikkawiki.org/TormodHaugen Tormod Haugen} (table formatter support) 18 * 19 * @uses Wakka::htmlspecialchars_ent() 18 20 * 19 21 * @todo add support for formatter plugins; … … 488 490 } 489 491 // use GeSHi for highlighting 490 $output .= $wakka->GeSHi_Highlight($code, $language, $start); 492 $output .= $wakka->GeSHi_Highlight($code, $language, $start); //TODO make GeSHi_Highlight() add a "\n" at the end (as well as the comments, maybe) 491 493 } 492 494 // check Wikka highlighter path is set and if we have an internal Wikka highlighter … … 671 673 // WARNING: JS vulnerability: two minus signs are not allowed in a comment, so we replace any occurence of them by underscore. 672 674 // Consider the code ||(p--><font size=1px><a href=...<!--:blabla 673 // When migrating to utf-8, we could use str_replace('--', 'ââ', $key) to make things more pretty. 675 // When migrating to utf-8, we could use str_replace('--', 'ââ', $key) to make things more pretty. //TODO garbled ... mdash? 674 676 echo '<!--Cannot find attribute for key "'.str_replace('--', '__', $key).'" from hints given.-->'."\n"; 675 677 } -
trunk/handlers/page/edit.php
r320 r324 28 28 * @uses Wakka::Href() 29 29 * @uses Wakka::htmlspecialchars_ent() 30 * @uses Wakka::hsc_secure() 30 31 * @uses Wakka::LoadSingle() 31 32 * @uses Wakka::Redirect() … … 140 141 } 141 142 142 //checkif edit_notes are enabled143 // create edit note field if edit_notes are enabled 143 144 if ($this->config['require_edit_note'] != 2) 144 145 { 145 #$edit_note_field = '<input id="note" size="'.MAX_EDIT_NOTE_LENGTH.'" type="text" name="note" value="'.htmlspecialchars($note).'" '.$highlight_note.'/> <label for="note">'.EDIT_NOTE_LABEL.'</label><br />'."\n"; 146 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 147 // so we use hsc_secure() on the edit note (as on the body) 146 148 $edit_note_field = '<input id="note" size="'.MAX_EDIT_NOTE_LENGTH.'" type="text" name="note" value="'.$this->hsc_secure($note).'" '.$highlight_note.'/> <label for="note">'.EDIT_NOTE_LABEL.'</label><br />'."\n"; #427 147 149 } … … 164 166 if (isset($_POST['submit']) && $_POST['submit'] == EDIT_PREVIEW_BUTTON) 165 167 { 166 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them167 // so we use htmlspecialchars on the edit note (as on the body)168 168 $preview_buttons = '<fieldset><legend>'.EDIT_STORE_PAGE_LEGEND.'</legend>'."\n". 169 169 $edit_note_field. … … 176 176 $preview_form .= '<input type="hidden" name="previous" value="'.$previous.'" />'."\n". 177 177 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 178 // hence h tmlspecialchars() instead of htmlspecialchars_ent() which UNescapes entities!179 #'<input type="hidden" name="body" value="'.htmlspecialchars($body).'" />'."\n";178 // hence hsc_secure() instead of htmlspecialchars_ent() which UNescapes entities! 179 // JW/2007-02-20: why is this? wouldn't it be easier for the person editing to show actual characters instead of entities? 180 180 '<input type="hidden" name="body" value="'.$this->hsc_secure($body).'" />'."\n"; #427 181 181 $preview_form .= $preview_buttons."\n"; … … 232 232 $output .= '<input type="hidden" name="previous" value="'.$previous.'" />'."\n". 233 233 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them 234 // hence h tmlspecialchars() instead of htmlspecialchars_ent() which UNescapes entities!235 #'<textarea id="body" name="body">'.htmlspecialchars($body).'</textarea><br />'."\n";234 // hence hsc_secure() instead of htmlspecialchars_ent() which UNescapes entities! 235 // JW/2007-02-20: why is this? wouldn't it be easier for the person editing to show actual characters instead of entities? 236 236 '<textarea id="body" name="body">'.$this->hsc_secure($body).'</textarea><br />'."\n"; #427 237 //note add Edit238 // We need to escape ALL entity refs before display so we display them _as_ entities instead of interpreting them239 // so we use htmlspecialchars on the edit note (as on the body)240 // JW/2007-02-20: why is this? wouldn't it be easier for the preson editing to show actual characters instead of entities?241 237 if ($buttons_position == 'bottom') 242 238 { -
trunk/handlers/page/processcomment.php
r295 r324 16 16 * @uses Wakka::SaveComment() 17 17 * @uses Wakka::UserIsOwner() 18 * @uses Wakka::htmlspecialchars_ent() 19 * 18 20 * @todo move main <div> to templating class 19 21 */ -
trunk/handlers/page/recentchanges.xml.mm.php
r161 r324 40 40 if (($c <= $max) || !$max) 41 41 { 42 $pageuser = $this->htmlspecialchars_ent($page[ "user"], '', '','XML'); #Just in case...43 $pagetag = $this->htmlspecialchars_ent($page[ "tag"], '', '','XML');42 $pageuser = $this->htmlspecialchars_ent($page['user'],ENT_COMPAT,'XML'); #Just in case... 43 $pagetag = $this->htmlspecialchars_ent($page['tag'],ENT_COMPAT,'XML'); 44 44 45 45 // day header … … 57 57 $timeformatted = date("H:i T", strtotime($page["time"])); 58 58 $xml .= "<node LINK=\"$pagelink/revisions\" TEXT=\"Revision time: $timeformatted\"/>\n"; 59 if ($pagenote = $this->htmlspecialchars_ent($page[ "note"], '', '','XML')) {59 if ($pagenote = $this->htmlspecialchars_ent($page['note'],ENT_COMPAT,'XML')) { 60 60 $xml .= "<node TEXT=\"$pageuser: $pagenote\"/>\n"; 61 61 } else { -
trunk/handlers/page/recentchanges.xml.php
r323 r324 50 50 $xml .= "<title>".$this->htmlspecialchars_ent($page["tag"])."</title>\n"; 51 51 $xml .= "<link>".$this->Href("show", $page["tag"], "time=".urlencode($page["time"]))."</link>\n"; 52 #$xml .= "\t<description>".sprintf(WIKKA_REV_WHEN_BY_WHO, $page['time'], $this->htmlspecialchars_ent($page["user"], '', '', 'XML')).($page['note'] ? ' - '.$this->htmlspecialchars_ent($page['note'], '', '', 'XML') : '')."</description>\n";53 52 $xml .= "\t<description>".sprintf(WIKKA_REV_WHEN_BY_WHO, $page['time'], $this->htmlspecialchars_ent($page["user"], '', '', 'XML')).($page['note'] ? ' - '.$this->htmlspecialchars_ent($page['note'],ENT_COMPAT,'XML') : '')."</description>\n"; 54 53 //$xml .= "\t<guid>".$page["id"]."</guid>"; -
trunk/handlers/page/referrers_sites.php
r294 r324 16 16 * @uses Wakka::GetUser() 17 17 * @uses Wakka::Href() 18 * @uses Wakka::htmlspecialchars_ent() 18 19 * 19 20 * @todo move <div> to template … … 101 102 foreach ($referrer_sites as $site => $site_count) 102 103 { 104 $site_esc = $this->htmlspecialchars_ent($site); 103 105 print("<tr>"); 104 106 print("<td width=\"30\" align=\"right\" valign=\"top\" style=\"padding-right: 10px\">$site_count</td>"); 105 print("<td valign=\"top\">" . (($site != "unknown") ? "<a href=\"http://".$ this->htmlspecialchars_ent($site)."\">".$this->htmlspecialchars_ent($site)."</a>" : $site) . "</a> ".($IsAdmin ? "[<a href=\"".$this->href("delete_referrer", "", "spam_site=").$this->htmlspecialchars_ent($site)."&redirect=".$this->GetMethod().'">'.BLACKLIST_LINK_DESC."</a>]" : "")."</td>");107 print("<td valign=\"top\">" . (($site != "unknown") ? "<a href=\"http://".$site_esc."\">".$site_esc."</a>" : $site) . "</a> ".($IsAdmin ? "[<a href=\"".$this->href("delete_referrer", "", "spam_site=").$site_esc."&redirect=".$this->GetMethod().'">'.BLACKLIST_LINK_DESC."</a>]" : "")."</td>"); 106 108 print("</tr>\n"); 107 109 } -
trunk/handlers/page/revisions.xml.php
r323 r324 46 46 $xml .= "<title>".$page["time"]."</title>\n"; 47 47 $xml .= '<link>'.$this->Href('show', '', 'time='.urlencode($page['time'])).'</link>'."\n"; 48 #$xml .= '<description>'.sprintf(REVISIONS_EDITED_BY, $this->htmlspecialchars_ent($page["user"])).($page['note'] ? ' - '.$this->htmlspecialchars_ent($page['note'], '', '', 'XML') : '')."</description>\n";49 48 $xml .= '<description>'.sprintf(REVISIONS_EDITED_BY, $this->htmlspecialchars_ent($page["user"])).($page['note'] ? ' - '.$this->htmlspecialchars_ent($page['note'],ENT_COMPAT,'XML') : '')."</description>\n"; 50 49 $xml .= "\t<pubDate>".date("r",strtotime($page["time"]))."</pubDate>\n"; -
trunk/libs/Wakka.class.php
r320 r324 399 399 400 400 /** 401 # * Wrapper around PHP's htmlspecialchars() which preserves (repairs) entity references.402 401 * Wrapper around hsc_secure() which preserves entity references. 403 402 * 404 # * The function accepts the same parameters as htmlspecialchars() in PHP and passes them on 405 # * to that function. 406 * The function accepts the same parameters as htmlspecialchars() in PHP and 407 * passes them on to our hsc_secure() replacement for that function. 408 * 409 * One default here is different here from that in htmlspecialchars() in PHP: 410 * charset is set to UTF-8 so we're ready for UTF-8 support (and as long as we don't support 411 * that there should be no difference with Latin-1); on systems where the charset parameter 412 * is not available or UTF-8 is not supported this will revert to Latin-1 (ISO-8859-1). 413 * ### updatee ^^ 414 * 415 # * The function first applies htmlspecialchars() to the input string and then "unescapes" 416 * The function first applies hsc_secure() to the input string and then "unescapes" 417 * character entity references and numeric character references (both decimal and hexadecimal). 418 * Entities are recognized also if the ending semicolon is omitted at the end or before a 419 * newline or tag but for consistency the semicolon is always added in the output where it was 420 * omitted. 421 * 422 * NOTE: 423 # * Where code should be rendered _as_code_ the original PHP function should be used so that 424 * Where code should be rendered _as_code_ hsc_secure() should be used directly so that 425 * entity references are also rendered as such instead of as their corresponding characters. 426 * 427 * NOTE2: 403 * The first two parameters for this function as the same as those for 404 * htmlspecialchars() in PHP: the text to be treated, and an optional 405 * parameter determining how to handle quotes; both these parameters are 406 * passed on to our hsc_secure() replacement for htmlspecialchars(). 407 * 408 * Since hsc_secure() does not need a character set parameter, we don't 409 * have that here any more either. 410 * 411 * A third 'doctype' parameter is for local use only and determines how 412 * pre-existing entity references are treated after hsc_secure() has done 413 * its work: numeic entity references are always "unescaped' since they are 414 * valid for both HTML and XML doctypes; for XML the named entity references 415 * for the special characters are unescaped as well, while for for HTML any 416 * named entity reference is unescaped. This parameter is optional and 417 * defaults to HTML. 418 * 419 * The function first applies hsc_secure() to the input string and then 420 * "unescapes" character entity references and numeric character references 421 * (both decimal and hexadecimal). 422 * Entities are recognized also if the ending semicolon is omitted at the 423 * end or before a newline or tag but for consistency the semicolon is 424 * always added in the output where it was omitted. 425 * 426 * Usage note: 427 * Where code should be rendered <em>as code</em> hsc_secure() should be 428 * used directly so that entity references are also rendered as such instead 429 * of as their corresponding characters. 430 * 431 * Documentation note: 428 432 * It seems the $doctype parameter was added in 1.1.6.2; version should have 429 433 * been bumped up to 1.1, and the param documented. We'll assume the updated … … 437 441 * @uses Wakka::hsc_secure() 438 442 * @param string $text required: text to be converted 439 * @param integer $quote_style optional: quoting style - can be ENT_COMPAT (default, escape 440 * only double quotes), ENT_QUOTES (escape both double and single quotes) or 441 * ENT_NOQUOTES (don't escape any quotes) 442 * @param string $charset optional: charset to use while converting; default UTF-8 443 * (overriding PHP's default ISO-8859-1) 443 * @param integer $quote_style optional: quoting style - can be ENT_COMPAT 444 * (default, escape only double quotes), ENT_QUOTES (escape both 445 * double and single quotes) or ENT_NOQUOTES (don't escape any 446 * quotes) 444 447 * @param string $doctype 'HTML' (default) or 'XML'; for XML only the XML 445 448 * standard entities are unescaped so we'll have valid XML content 446 * @return string converted string with escaped special characted but entity references intact 447 * 448 * @todo rewrite to eliminate the $charset parameter which is suplerflous 449 * for our hsc_secure() replacement function. 450 * @todo extend valid character entities for XML with 'apos' 451 * @todo (later) support full range of situations where (in SGML) a terminating ; may legally 452 * be omitted (end, newline and tag are merely the most common ones). 453 * @todo (maybe) recognize valid html entities and only leave those alone, thus transform &error; to &error; 454 */ 455 function htmlspecialchars_ent($text,$quote_style=ENT_COMPAT,$charset='UTF-8',$doctype='HTML') 456 { 449 * @return string converted string with escaped special characted but 450 * entity references intact 451 * 452 * @todo (maybe) recognize valid html entities and only leave those 453 * alone, thus transform &error; to &error; 454 * @todo later - maybe) support full range of situations where (in SGML) 455 * a terminating ; may legally be omitted (end, newline and tag are 456 * merely the most common ones); such usage is quite rare though 457 * and may not be worth the effort 458 */ 459 function htmlspecialchars_ent($text,$quote_style=ENT_COMPAT,$doctype='HTML') 460 { 461 // re-establish default if overwritten because of third parameter 462 // [ENT_COMPAT] => 2 463 // [ENT_QUOTES] => 3 464 // [ENT_NOQUOTES] => 0 465 if (!in_array($quote_style,array(ENT_COMPAT,ENT_QUOTES,ENT_NOQUOTES))) { 466 $quote_style = ENT_COMPAT; 467 } 468 457 469 // define patterns 458 $alpha = '[a-z]+'; # character entity reference todo: $alpha='eacute|egrave|ccirc|...' 459 $ignore_case = 'i'; 460 if ($doctype == 'XML') 470 $terminator = ';|(?=($|[\n<]|<))'; // semicolon; or end-of-string, newline or tag 471 $numdec = '#[0-9]+'; // numeric character reference (decimal) 472 $numhex = '#x[0-9a-f]+'; // numeric character reference (hexadecimal) 473 if ($doctype == 'XML') // pure XML allows only named entities for special chars 461 474 { 462 475 // only valid named entities in XML (case-sensitive) 463 $ alpha= 'lt|gt|quot|apos|amp';476 $named = 'lt|gt|quot|apos|amp'; 464 477 $ignore_case = ''; 465 // enforce defaults if defaults were "undefaulted"466 if ($quote_style === '') $quote_style = ENT_COMPAT;467 if ($charset === '') $charset = 'UTF-8';468 }469 $numdec = '#[0-9]+'; # numeric character reference (decimal)470 $numhex = '#x[0-9a-f]+'; # numeric character reference (hexadecimal)471 $terminator = ';|(?=($|[\n<]|<))'; # semicolon; or end-of-string, newline or tag472 $entitystring = $alpha.'|'.$numdec.'|'.$numhex;478 $entitystring = $named.'|'.$numdec.'|'.$numhex; 479 } 480 else // (X)HTML 481 { 482 $alpha = '[a-z]+'; // character entity reference TODO $named='eacute|egrave|ccirc|...' 483 $ignore_case = 'i'; // names can consist of upper and lower case letters 484 $entitystring = $alpha.'|'.$numdec.'|'.$numhex; 485 } 473 486 $escaped_entity = '&('.$entitystring.')('.$terminator.')'; 474 487 475 #// execute PHP built-in function, passing on optional parameters476 #$output = htmlspecialchars($text,$quote_style,$charset);477 488 // execute our replacement hsc_secure() function, passing on optional parameters 478 $output = $this->hsc_secure($text,$quote_style,$charset); 489 $output = $this->hsc_secure($text,$quote_style); 490 479 491 // "repair" escaped entities 480 492 // modifiers: s = across lines, i = case-insensitive 481 493 $output = preg_replace('/'.$escaped_entity.'/s'.$ignore_case,"&$1;",$output); 494 482 495 // return output 483 496 return $output; … … 1280 1293 } 1281 1294 if ($ping["history"]) $rpcRequest .= "<member>\n<name>history</name>\n<value>".$ping["history"]."</value>\n</member>\n"; 1282 if ($ping["changelog"]) $rpcRequest .= "<member>\n<name>changelog</name>\n<value>".$this->htmlspecialchars_ent($ping["changelog"], '', '', 'XML')."</value>\n</member>\n"; 1295 #if ($ping["changelog"]) $rpcRequest .= "<member>\n<name>changelog</name>\n<value>".$this->htmlspecialchars_ent($ping["changelog"], '', '', 'XML')."</value>\n</member>\n"; 1296 if ($ping["changelog"]) $rpcRequest .= "<member>\n<name>changelog</name>\n<value>".$this->htmlspecialchars_ent($ping["changelog"],ENT_COMPAT,'XML')."</value>\n</member>\n"; 1283 1297 $rpcRequest .= "</struct>\n</value>\n</param>\n"; 1284 1298 $rpcRequest .= "</params>\n";