Index: trunk/extensions/Plotters/PlottersParser.php |
— | — | @@ -57,11 +57,10 @@ |
58 | 58 | foreach ( $arguments as $argument ) { |
59 | 59 | $subargumentarr = explode( ',', $argument ); |
60 | 60 | foreach ( $subargumentarr as &$singleargument ) { |
61 | | - $singleargument = htmlentities( $singleargument, ENT_QUOTES ); |
62 | | - |
63 | 61 | // Fix escaped separators |
64 | 62 | $singleargument = preg_replace( "/§UNIQ§/", ":", $singleargument ); |
65 | 63 | $singleargument = preg_replace( "/§UNIQ2§/", ",", $singleargument ); |
| 64 | + $singleargument = htmlentities( $singleargument, ENT_QUOTES ); |
66 | 65 | } |
67 | 66 | $this->argumentArray["preprocessorarguments"][] = $subargumentarr; |
68 | 67 | } |
— | — | @@ -78,16 +77,15 @@ |
79 | 78 | // Parse and sanitize arguments |
80 | 79 | $arguments = explode( ',', $argv["scriptarguments"] ); |
81 | 80 | foreach ( $arguments as $argument ) { |
82 | | - $argument = htmlentities( $argument, ENT_QUOTES ); |
83 | | - |
84 | 81 | // Fix escaped separators |
85 | 82 | $argument = preg_replace( "/§UNIQ§/", ",", $argument ); |
| 83 | + $argument = htmlentities( $argument, ENT_QUOTES ); |
86 | 84 | $this->argumentArray["scriptarguments"][] = $argument; |
87 | 85 | } |
88 | 86 | Plotter::debug( 'plot script argument values: ', $this->argumentArray["scriptarguments"] ); |
89 | 87 | } |
90 | 88 | if ( isset( $argv["datasep"] ) ) { |
91 | | - $this->argumentArray["datasep"] = htmlentities( $argv["datasep"], ENT_QUOTES ); |
| 89 | + $this->argumentArray["datasep"] = $argv["datasep"]; |
92 | 90 | } |
93 | 91 | if ( isset( $argv["width"] ) ) { |
94 | 92 | $this->argumentArray["width"] = preg_replace( '/[^0-9]/', '', $argv["width"] ); |
— | — | @@ -102,10 +100,9 @@ |
103 | 101 | // Parse and sanitize arguments |
104 | 102 | $labels = explode( ',', $argv["labels"] ); |
105 | 103 | foreach ( $labels as $label ) { |
106 | | - $label = htmlentities( $label, ENT_QUOTES ); |
107 | | - |
108 | 104 | // Fix escaped separators |
109 | 105 | $label = preg_replace( "/§UNIQ§/", ",", $label ); |
| 106 | + $label = htmlentities( $label, ENT_QUOTES ); |
110 | 107 | $this->argumentArray["labels"][] = $label; |
111 | 108 | } |
112 | 109 | } |
— | — | @@ -119,12 +116,11 @@ |
120 | 117 | // Parse and sanitize data |
121 | 118 | $lines = preg_split( "/\n/", $input, -1, PREG_SPLIT_NO_EMPTY ); |
122 | 119 | foreach ( $lines as $line ) { |
123 | | - $values = explode( ',', $line ); |
| 120 | + $values = explode( $sep, $line ); |
124 | 121 | foreach ( $values as &$value ) { |
125 | | - $value = htmlentities( $value, ENT_QUOTES ); |
126 | | - |
127 | 122 | // Fix escaped separators |
128 | | - $value = preg_replace( "/§UNIQ§/", "\\$sep", $value ); |
| 123 | + $value = preg_replace( "/§UNIQ§/", "$sep", $value ); |
| 124 | + $value = htmlentities( $value, ENT_QUOTES ); |
129 | 125 | } |
130 | 126 | $this->dataArray[] = $values; |
131 | 127 | Plotter::debug( 'plot data values: ', $values ); |
Index: trunk/extensions/Plotters/Plotters.php |
— | — | @@ -50,7 +50,8 @@ |
51 | 51 | $wgSpecialPageGroups['Plotters'] = 'wiki'; |
52 | 52 | |
53 | 53 | // sane defaults. always initialize to avoid register_globals vulnerabilities |
54 | | -$wgPlotterExtensionPath = $wgScriptPath . '/extensions/Plotter'; |
| 54 | +$wgPlotterExtensionPath = $wgScriptPath . '/extensions/Plotters'; |
| 55 | +$wgPlotterJavascriptPath = $wgScriptPath . '/extensions/Plotters'; |
55 | 56 | |
56 | 57 | function wfPlottersArticleSaveComplete( &$article, &$wgUser, &$text ) { |
57 | 58 | // update cache if MediaWiki:Plotters-definition was edited |
Index: trunk/extensions/Plotters/PlottersClass.php |
— | — | @@ -95,10 +95,11 @@ |
96 | 96 | for ( $i = 0; $i < count( $this->argumentArray["labels"] ); $i++ ) { |
97 | 97 | $output .= "labels[$i] = '" . $this->argumentArray["labels"][$i] . "';"; |
98 | 98 | } |
| 99 | + $output .= "fix_encoding( labels );"; |
99 | 100 | |
100 | 101 | // Run preprocessors |
101 | 102 | foreach ( $this->argumentArray["preprocessors"] as $preprocessor ) { |
102 | | - $output .= 'data = plotter_' . $preprocessor . '_process( data, labels, '; |
| 103 | + $output .= 'plotter_' . $preprocessor . '_process( data, labels, '; |
103 | 104 | foreach ( $this->argumentArray["preprocessorarguments"] as $argument ) { |
104 | 105 | $output .= $argument . ', '; |
105 | 106 | } |
— | — | @@ -126,9 +127,10 @@ |
127 | 128 | } |
128 | 129 | |
129 | 130 | static function setPlotterHeaders( &$outputPage ) { |
| 131 | + global $wgPlotterJavascriptPath; |
130 | 132 | global $wgPlotterExtensionPath; |
131 | 133 | |
132 | | - $extensionpath = $wgPlotterExtensionPath; |
| 134 | + $extensionpath = $wgPlotterJavascriptPath; |
133 | 135 | |
134 | 136 | // Add mochikit (required by PlotKit) |
135 | 137 | $outputPage->addScript( '<script src="' . $extensionpath . '/mochikit/MochiKit.js" type="text/javascript"></script>' ); |
— | — | @@ -139,6 +141,9 @@ |
140 | 142 | $outputPage->addScript( '<script src="' . $extensionpath . '/plotkit/Canvas.js" type="text/javascript"></script>' ); |
141 | 143 | $outputPage->addScript( '<script src="' . $extensionpath . '/plotkit/SweetCanvas.js" type="text/javascript"></script>' ); |
142 | 144 | |
| 145 | + // Add javascript to fix encoding |
| 146 | + $outputPage->addScript( '<script src="' . $wgPlotterExtensionPath . '/libs/fixencoding.js" type="text/javascript"></script>' ); |
| 147 | + |
143 | 148 | return true; |
144 | 149 | } |
145 | 150 | |
Index: trunk/extensions/Plotters/libs/fixencoding.js |
— | — | @@ -0,0 +1,232 @@ |
| 2 | +/* |
| 3 | + * More info at: http://kevin.vanzonneveld.net/techblog/category/php2js |
| 4 | + * |
| 5 | + * php.js is copyright 2008 Kevin van Zonneveld. |
| 6 | + * |
| 7 | + * Portions copyright Ates Goral (http://magnetiq.com), Legaev Andrey, |
| 8 | + * _argos, Jonas Raoni Soares Silva (http://www.jsfromhell.com), |
| 9 | + * Webtoolkit.info (http://www.webtoolkit.info/), Carlos R. L. Rodrigues, Ash |
| 10 | + * Searle (http://hexmen.com/blog/), Tyler Akins (http://rumkin.com), mdsjack |
| 11 | + * (http://www.mdsjack.bo.it), Alexander Ermolaev |
| 12 | + * (http://snippets.dzone.com/user/AlexanderErmolaev), Andrea Giammarchi |
| 13 | + * (http://webreflection.blogspot.com), Bayron Guevara, Cord, David, Karol |
| 14 | + * Kowalski, Leslie Hoare, Lincoln Ramsay, Mick@el, Nick Callen, Peter-Paul |
| 15 | + * Koch (http://www.quirksmode.org/js/beat.html), Philippe Baumann, Steve |
| 16 | + * Clay, booeyOH |
| 17 | + * |
| 18 | + * Licensed under the MIT (MIT-LICENSE.txt) license. |
| 19 | + * |
| 20 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 21 | + * copy of this software and associated documentation files (the |
| 22 | + * "Software"), to deal in the Software without restriction, including |
| 23 | + * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | + * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | + * permit persons to whom the Software is furnished to do so, subject to |
| 26 | + * the following conditions: |
| 27 | + * |
| 28 | + * The above copyright notice and this permission notice shall be included |
| 29 | + * in all copies or substantial portions of the Software. |
| 30 | + * |
| 31 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 32 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 34 | + * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES |
| 35 | + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 36 | + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 37 | + * OTHER DEALINGS IN THE SOFTWARE. |
| 38 | + */ |
| 39 | + |
| 40 | +function get_html_translation_table(table, quote_style) { |
| 41 | + // http://kevin.vanzonneveld.net |
| 42 | + // + original by: Philip Peterson |
| 43 | + // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| 44 | + // + bugfixed by: noname |
| 45 | + // + bugfixed by: Alex |
| 46 | + // + bugfixed by: Marco |
| 47 | + // + bugfixed by: madipta |
| 48 | + // + improved by: KELAN |
| 49 | + // + improved by: Brett Zamir (http://brettz9.blogspot.com) |
| 50 | + // % note: It has been decided that we're not going to add global |
| 51 | + // % note: dependencies to php.js. Meaning the constants are not |
| 52 | + // % note: real constants, but strings instead. integers are also supported if someone |
| 53 | + // % note: chooses to create the constants themselves. |
| 54 | + // * example 1: get_html_translation_table('HTML_SPECIALCHARS'); |
| 55 | + // * returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'} |
| 56 | + |
| 57 | + var entities = {}, histogram = {}, decimal = 0, symbol = ''; |
| 58 | + var constMappingTable = {}, constMappingQuoteStyle = {}; |
| 59 | + var useTable = {}, useQuoteStyle = {}; |
| 60 | + |
| 61 | + // Translate arguments |
| 62 | + constMappingTable[0] = 'HTML_SPECIALCHARS'; |
| 63 | + constMappingTable[1] = 'HTML_ENTITIES'; |
| 64 | + constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; |
| 65 | + constMappingQuoteStyle[2] = 'ENT_COMPAT'; |
| 66 | + constMappingQuoteStyle[3] = 'ENT_QUOTES'; |
| 67 | + |
| 68 | + useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS'; |
| 69 | + useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT'; |
| 70 | + |
| 71 | + if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') { |
| 72 | + throw Error("Table: "+useTable+' not supported'); |
| 73 | + // return false; |
| 74 | + } |
| 75 | + |
| 76 | + // ascii decimals for better compatibility |
| 77 | + entities['38'] = '&'; |
| 78 | + if (useQuoteStyle !== 'ENT_NOQUOTES') { |
| 79 | + entities['34'] = '"'; |
| 80 | + } |
| 81 | + if (useQuoteStyle === 'ENT_QUOTES') { |
| 82 | + entities['39'] = '''; |
| 83 | + } |
| 84 | + entities['60'] = '<'; |
| 85 | + entities['62'] = '>'; |
| 86 | + |
| 87 | + if (useTable === 'HTML_ENTITIES') { |
| 88 | + entities['160'] = ' '; |
| 89 | + entities['161'] = '¡'; |
| 90 | + entities['162'] = '¢'; |
| 91 | + entities['163'] = '£'; |
| 92 | + entities['164'] = '¤'; |
| 93 | + entities['165'] = '¥'; |
| 94 | + entities['166'] = '¦'; |
| 95 | + entities['167'] = '§'; |
| 96 | + entities['168'] = '¨'; |
| 97 | + entities['169'] = '©'; |
| 98 | + entities['170'] = 'ª'; |
| 99 | + entities['171'] = '«'; |
| 100 | + entities['172'] = '¬'; |
| 101 | + entities['173'] = '­'; |
| 102 | + entities['174'] = '®'; |
| 103 | + entities['175'] = '¯'; |
| 104 | + entities['176'] = '°'; |
| 105 | + entities['177'] = '±'; |
| 106 | + entities['178'] = '²'; |
| 107 | + entities['179'] = '³'; |
| 108 | + entities['180'] = '´'; |
| 109 | + entities['181'] = 'µ'; |
| 110 | + entities['182'] = '¶'; |
| 111 | + entities['183'] = '·'; |
| 112 | + entities['184'] = '¸'; |
| 113 | + entities['185'] = '¹'; |
| 114 | + entities['186'] = 'º'; |
| 115 | + entities['187'] = '»'; |
| 116 | + entities['188'] = '¼'; |
| 117 | + entities['189'] = '½'; |
| 118 | + entities['190'] = '¾'; |
| 119 | + entities['191'] = '¿'; |
| 120 | + entities['192'] = 'À'; |
| 121 | + entities['193'] = 'Á'; |
| 122 | + entities['194'] = 'Â'; |
| 123 | + entities['195'] = 'Ã'; |
| 124 | + entities['196'] = 'Ä'; |
| 125 | + entities['197'] = 'Å'; |
| 126 | + entities['198'] = 'Æ'; |
| 127 | + entities['199'] = 'Ç'; |
| 128 | + entities['200'] = 'È'; |
| 129 | + entities['201'] = 'É'; |
| 130 | + entities['202'] = 'Ê'; |
| 131 | + entities['203'] = 'Ë'; |
| 132 | + entities['204'] = 'Ì'; |
| 133 | + entities['205'] = 'Í'; |
| 134 | + entities['206'] = 'Î'; |
| 135 | + entities['207'] = 'Ï'; |
| 136 | + entities['208'] = 'Ð'; |
| 137 | + entities['209'] = 'Ñ'; |
| 138 | + entities['210'] = 'Ò'; |
| 139 | + entities['211'] = 'Ó'; |
| 140 | + entities['212'] = 'Ô'; |
| 141 | + entities['213'] = 'Õ'; |
| 142 | + entities['214'] = 'Ö'; |
| 143 | + entities['215'] = '×'; |
| 144 | + entities['216'] = 'Ø'; |
| 145 | + entities['217'] = 'Ù'; |
| 146 | + entities['218'] = 'Ú'; |
| 147 | + entities['219'] = 'Û'; |
| 148 | + entities['220'] = 'Ü'; |
| 149 | + entities['221'] = 'Ý'; |
| 150 | + entities['222'] = 'Þ'; |
| 151 | + entities['223'] = 'ß'; |
| 152 | + entities['224'] = 'à'; |
| 153 | + entities['225'] = 'á'; |
| 154 | + entities['226'] = 'â'; |
| 155 | + entities['227'] = 'ã'; |
| 156 | + entities['228'] = 'ä'; |
| 157 | + entities['229'] = 'å'; |
| 158 | + entities['230'] = 'æ'; |
| 159 | + entities['231'] = 'ç'; |
| 160 | + entities['232'] = 'è'; |
| 161 | + entities['233'] = 'é'; |
| 162 | + entities['234'] = 'ê'; |
| 163 | + entities['235'] = 'ë'; |
| 164 | + entities['236'] = 'ì'; |
| 165 | + entities['237'] = 'í'; |
| 166 | + entities['238'] = 'î'; |
| 167 | + entities['239'] = 'ï'; |
| 168 | + entities['240'] = 'ð'; |
| 169 | + entities['241'] = 'ñ'; |
| 170 | + entities['242'] = 'ò'; |
| 171 | + entities['243'] = 'ó'; |
| 172 | + entities['244'] = 'ô'; |
| 173 | + entities['245'] = 'õ'; |
| 174 | + entities['246'] = 'ö'; |
| 175 | + entities['247'] = '÷'; |
| 176 | + entities['248'] = 'ø'; |
| 177 | + entities['249'] = 'ù'; |
| 178 | + entities['250'] = 'ú'; |
| 179 | + entities['251'] = 'û'; |
| 180 | + entities['252'] = 'ü'; |
| 181 | + entities['253'] = 'ý'; |
| 182 | + entities['254'] = 'þ'; |
| 183 | + entities['255'] = 'ÿ'; |
| 184 | + } |
| 185 | + |
| 186 | + // ascii decimals to real symbols |
| 187 | + for (decimal in entities) { |
| 188 | + symbol = String.fromCharCode(decimal); |
| 189 | + histogram[symbol] = entities[decimal]; |
| 190 | + } |
| 191 | + |
| 192 | + return histogram; |
| 193 | +} |
| 194 | + |
| 195 | +function html_entity_decode( string, quote_style ) { |
| 196 | + // http://kevin.vanzonneveld.net |
| 197 | + // + original by: john (http://www.jd-tech.net) |
| 198 | + // + input by: ger |
| 199 | + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| 200 | + // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| 201 | + // + bugfixed by: Onno Marsman |
| 202 | + // + improved by: marc andreu |
| 203 | + // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) |
| 204 | + // - depends on: get_html_translation_table |
| 205 | + // * example 1: html_entity_decode('Kevin & van Zonneveld'); |
| 206 | + // * returns 1: 'Kevin & van Zonneveld' |
| 207 | + // * example 2: html_entity_decode('&lt;'); |
| 208 | + // * returns 2: '<' |
| 209 | + |
| 210 | + var histogram = {}, symbol = '', tmp_str = '', entity = ''; |
| 211 | + tmp_str = string.toString(); |
| 212 | + |
| 213 | + if (false === (histogram = get_html_translation_table('HTML_ENTITIES', quote_style))) { |
| 214 | + return false; |
| 215 | + } |
| 216 | + |
| 217 | + // & must be the last character when decoding! |
| 218 | + delete(histogram['&']); |
| 219 | + histogram['&'] = '&'; |
| 220 | + |
| 221 | + for (symbol in histogram) { |
| 222 | + entity = histogram[symbol]; |
| 223 | + tmp_str = tmp_str.split(entity).join(symbol); |
| 224 | + } |
| 225 | + |
| 226 | + return tmp_str; |
| 227 | +} |
| 228 | + |
| 229 | +function fix_encoding( data_arr ) { |
| 230 | + for ( var i = 0; i < data_arr.length; ++i ) { |
| 231 | + data_arr[i] = html_entity_decode( data_arr[i], 'ENT_QUOTES' ); |
| 232 | + } |
| 233 | +} |
Property changes on: trunk/extensions/Plotters/libs/fixencoding.js |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 234 | + native |