Index: trunk/extensions/CharInsert/CharInsert.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | -# Copyright (C) 2004 Brion Vibber <brion@pobox.com> |
| 3 | +# Copyright (C) 2004,2006 Brion Vibber <brion@pobox.com> |
4 | 4 | # http://www.mediawiki.org/ |
5 | 5 | # |
6 | 6 | # This program is free software; you can redistribute it and/or modify |
— | — | @@ -51,11 +51,25 @@ |
52 | 52 | function charInsertLine( $data ) { |
53 | 53 | return implode( "\n", |
54 | 54 | array_map( 'charInsertItem', |
55 | | - preg_split( '/\\s+/', $data ) ) ); |
| 55 | + preg_split( '/\\s+/', charInsertArmor( $data ) ) ) ); |
56 | 56 | } |
57 | 57 | |
| 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( '	', '', ' ' ), |
| 69 | + $matches[1] ); |
| 70 | +} |
| 71 | + |
58 | 72 | function charInsertItem( $data ) { |
59 | | - $chars = array_map( 'charInsertCleanChar', explode( '+', $data ) ); |
| 73 | + $chars = explode( '+', $data ); |
60 | 74 | if( count( $chars ) > 1 ) { |
61 | 75 | return charInsertChar( $chars[0], $chars[1], 'Click the character while selecting a text' ); |
62 | 76 | } elseif( count( $chars ) == 1 ) { |
— | — | @@ -65,21 +79,9 @@ |
66 | 80 | } |
67 | 81 | } |
68 | 82 | |
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 | | - |
81 | 83 | function charInsertChar( $start, $end = '', $title = null ) { |
82 | | - $estart = htmlspecialchars( charInsertJsString( $start ) ); |
83 | | - $eend = htmlspecialchars( charInsertJsString( $end ) ); |
| 84 | + $estart = charInsertJsString( $start ); |
| 85 | + $eend = charInsertJsString( $end ); |
84 | 86 | if( $eend == '' ) { |
85 | 87 | $inline = charInsertDisplay( $start ); |
86 | 88 | } else { |
— | — | @@ -90,12 +92,16 @@ |
91 | 93 | } else { |
92 | 94 | $extra = ''; |
93 | 95 | } |
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 ); |
95 | 101 | } |
96 | 102 | |
97 | 103 | function charInsertJsString( $text ) { |
98 | 104 | return strtr( |
99 | | - $text, |
| 105 | + charInsertDisplay( $text ), |
100 | 106 | array( |
101 | 107 | "\\" => "\\\\", |
102 | 108 | "\"" => "\\\"", |
— | — | @@ -109,7 +115,8 @@ |
110 | 116 | function charInsertDisplay( $text ) { |
111 | 117 | static $invisibles = array( ' ', ' ' ); |
112 | 118 | static $visibles = array( '&nbsp;', '&#160;' ); |
113 | | - return str_replace( $invisibles, $visibles, $text ); |
| 119 | + return Sanitizer::decodeCharReferences( |
| 120 | + str_replace( $invisibles, $visibles, $text ) ); |
114 | 121 | } |
115 | 122 | |
116 | 123 | ?> |