r14584 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14583‎ | r14584 | r14585 >
Date:02:56, 6 June 2006
Author:brion
Status:old
Tags:
Comment:
* (bug 6203) Allow '<nowiki>' sections to include spaces, so an old workaround works on versions of MediaWiki with security bugs fixed.
* Use onclick handler instead of javascript: URLs so validator whines less
* Switch around how encoding and display normalization is done to better handle multi-character strings, hopefully
Sometimes a Safari bug is triggered that causes some items not to work, probably related to weird scripting breakage I see intermittently on Bugzilla. It seems fixed in Safari nightlies, so hopefully someday it'll get fixed.
Modified paths:
  • /trunk/extensions/CharInsert/CharInsert.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CharInsert/CharInsert.php
@@ -1,5 +1,5 @@
22 <?php
3 -# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
 3+# Copyright (C) 2004,2006 Brion Vibber <brion@pobox.com>
44 # http://www.mediawiki.org/
55 #
66 # This program is free software; you can redistribute it and/or modify
@@ -51,11 +51,25 @@
5252 function charInsertLine( $data ) {
5353 return implode( "\n",
5454 array_map( 'charInsertItem',
55 - preg_split( '/\\s+/', $data ) ) );
 55+ preg_split( '/\\s+/', charInsertArmor( $data ) ) ) );
5656 }
5757
 58+function charInsertArmor( $data ) {
 59+ return preg_replace_callback(
 60+ '!<nowiki>(.*?)</nowiki>!i',
 61+ 'charInsertNowiki',
 62+ $data );
 63+}
 64+
 65+function charInsertNowiki( $matches ) {
 66+ return str_replace(
 67+ array( '\t', '\r', ' ' ),
 68+ array( '&#9;', '&#12;', '&#32;' ),
 69+ $matches[1] );
 70+}
 71+
5872 function charInsertItem( $data ) {
59 - $chars = array_map( 'charInsertCleanChar', explode( '+', $data ) );
 73+ $chars = explode( '+', $data );
6074 if( count( $chars ) > 1 ) {
6175 return charInsertChar( $chars[0], $chars[1], 'Click the character while selecting a text' );
6276 } elseif( count( $chars ) == 1 ) {
@@ -65,21 +79,9 @@
6680 }
6781 }
6882
69 -function charInsertCleanChar( $data ) {
70 - if( preg_match( '/^&#\d+;$/', $data ) ) {
71 - return $data;
72 - } elseif( preg_match( '/^&#x[0-9a-f]+;$/i', $data ) ) {
73 - return $data;
74 - } elseif( preg_match( '/^&[0-9a-z]+;$/i', $data ) ) {
75 - return $data;
76 - } else {
77 - return htmlspecialchars( $data, ENT_QUOTES );
78 - }
79 -}
80 -
8183 function charInsertChar( $start, $end = '', $title = null ) {
82 - $estart = htmlspecialchars( charInsertJsString( $start ) );
83 - $eend = htmlspecialchars( charInsertJsString( $end ) );
 84+ $estart = charInsertJsString( $start );
 85+ $eend = charInsertJsString( $end );
8486 if( $eend == '' ) {
8587 $inline = charInsertDisplay( $start );
8688 } else {
@@ -90,12 +92,16 @@
9193 } else {
9294 $extra = '';
9395 }
94 - return "<a href=\"javascript:insertTags('$estart','$eend','')\">$inline</a>";
 96+ return wfElement( 'a',
 97+ array(
 98+ 'onclick' => "insertTags('$estart','$eend','');return false",
 99+ 'href' => '#' ),
 100+ $inline );
95101 }
96102
97103 function charInsertJsString( $text ) {
98104 return strtr(
99 - $text,
 105+ charInsertDisplay( $text ),
100106 array(
101107 "\\" => "\\\\",
102108 "\"" => "\\\"",
@@ -109,7 +115,8 @@
110116 function charInsertDisplay( $text ) {
111117 static $invisibles = array( '&nbsp;', '&#160;' );
112118 static $visibles = array( '&amp;nbsp;', '&amp;#160;' );
113 - return str_replace( $invisibles, $visibles, $text );
 119+ return Sanitizer::decodeCharReferences(
 120+ str_replace( $invisibles, $visibles, $text ) );
114121 }
115122
116123 ?>

Status & tagging log