Index: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php |
— | — | @@ -46,7 +46,12 @@ |
47 | 47 | counting from the beginning. The last piece is at position -1. |
48 | 48 | See: http://php.net/manual/function.explode.php |
49 | 49 | |
| 50 | + {{#stripnewlines:value}} |
50 | 51 | |
| 52 | + Remove multiple newlines. Any time there is more than one newline in "value", |
| 53 | + they are changed to a single newline. |
| 54 | + |
| 55 | + |
51 | 56 | Copyright (c) 2009 Jack D. Pond |
52 | 57 | Licensed under GNU version 2 |
53 | 58 | */ |
— | — | @@ -54,7 +59,7 @@ |
55 | 60 | $wgExtensionCredits['parserhook'][] = array( |
56 | 61 | 'path' => __FILE__, |
57 | 62 | 'name' => 'StringFunctionsEscaped', |
58 | | - 'version' => '1.0.0', // Sept 7, 2009 |
| 63 | + 'version' => '1.0.1', // July 7, 2010 |
59 | 64 | 'descriptionmsg' => 'pfunc_desc', |
60 | 65 | 'author' => array('Jack D. Pond'), |
61 | 66 | 'license' => 'GNU Version 2', |
— | — | @@ -74,21 +79,23 @@ |
75 | 80 | |
76 | 81 | $wgExtStringFunctionsEscaped = new ExtStringFunctionsEscaped ( ); |
77 | 82 | |
78 | | - $wgParser->setFunctionHook('pos_e', array(&$wgExtStringFunctionsEscaped,'runPos_e' )); |
79 | | - $wgParser->setFunctionHook('rpos_e', array(&$wgExtStringFunctionsEscaped,'runRPos_e' )); |
80 | | - $wgParser->setFunctionHook('pad_e', array(&$wgExtStringFunctionsEscaped,'runPad_e' )); |
81 | | - $wgParser->setFunctionHook('replace_e', array(&$wgExtStringFunctionsEscaped,'runReplace_e' )); |
82 | | - $wgParser->setFunctionHook('explode_e', array(&$wgExtStringFunctionsEscaped,'runExplode_e' )); |
| 83 | + $wgParser->setFunctionHook('pos_e', array( &$wgExtStringFunctionsEscaped, 'runPos_e' )); |
| 84 | + $wgParser->setFunctionHook('rpos_e', array( &$wgExtStringFunctionsEscaped, 'runRPos_e' )); |
| 85 | + $wgParser->setFunctionHook('pad_e', array( &$wgExtStringFunctionsEscaped, 'runPad_e' )); |
| 86 | + $wgParser->setFunctionHook('replace_e', array( &$wgExtStringFunctionsEscaped, 'runReplace_e' )); |
| 87 | + $wgParser->setFunctionHook('explode_e', array( &$wgExtStringFunctionsEscaped, 'runExplode_e' )); |
| 88 | + $wgParser->setFunctionHook('stripnewlines', array( &$wgExtStringFunctionsEscaped, 'runStrip_nl' )); |
83 | 89 | } |
84 | 90 | |
85 | 91 | function wfStringFunctionsEscapedLanguageGetMagic( &$magicWords, $langCode = "en" ) { |
86 | 92 | switch ( $langCode ) { |
87 | 93 | default: |
88 | | - $magicWords['pos_e'] = array ( 0, 'pos_e' ); |
89 | | - $magicWords['rpos_e'] = array ( 0, 'rpos_e' ); |
90 | | - $magicWords['pad_e'] = array ( 0, 'pad_e' ); |
91 | | - $magicWords['replace_e'] = array ( 0, 'replace_e' ); |
92 | | - $magicWords['explode_e'] = array ( 0, 'explode_e' ); |
| 94 | + $magicWords['pos_e'] = array ( 0, 'pos_e' ); |
| 95 | + $magicWords['rpos_e'] = array ( 0, 'rpos_e' ); |
| 96 | + $magicWords['pad_e'] = array ( 0, 'pad_e' ); |
| 97 | + $magicWords['replace_e'] = array ( 0, 'replace_e' ); |
| 98 | + $magicWords['explode_e'] = array ( 0, 'explode_e' ); |
| 99 | + $magicWords['stripnewlines'] = array ( 0, 'stripnewlines' ); |
93 | 100 | } |
94 | 101 | return true; |
95 | 102 | } |
— | — | @@ -103,9 +110,9 @@ |
104 | 111 | */ |
105 | 112 | function runPos_e ( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
106 | 113 | global $wgParser; |
107 | | - list($callback,$flags) = $wgParser->mFunctionHooks['pos']; |
| 114 | + list( $callback, $flags ) = $wgParser->mFunctionHooks['pos']; |
108 | 115 | return @call_user_func_array( $callback, |
109 | | - array_merge(array($parser),array($inStr,stripcslashes($inNeedle),$inOffset) )); |
| 116 | + array_merge( array( $parser ), array( $inStr, stripcslashes( $inNeedle ), $inOffset ) ) ); |
110 | 117 | } |
111 | 118 | |
112 | 119 | /** |
— | — | @@ -114,11 +121,11 @@ |
115 | 122 | * Note: If the needle is not found, -1 is returned. |
116 | 123 | * Note: The needle is limited to specific length. |
117 | 124 | */ |
118 | | - function runRPos_e( &$parser, $inStr = '', $inNeedle = '' ) { |
| 125 | + function runRPos_e( &$parser , $inStr = '', $inNeedle = '' ) { |
119 | 126 | global $wgParser; |
120 | | - list($callback,$flags) = $wgParser->mFunctionHooks['rpos']; |
| 127 | + list( $callback, $flags ) = $wgParser->mFunctionHooks['rpos']; |
121 | 128 | return @call_user_func_array( $callback, |
122 | | - array_merge(array($parser),array($inStr,stripcslashes($inNeedle)) )); |
| 129 | + array_merge( array( $parser ), array( $inStr, stripcslashes( $inNeedle ) ) ) ); |
123 | 130 | } |
124 | 131 | |
125 | 132 | /** |
— | — | @@ -127,9 +134,9 @@ |
128 | 135 | */ |
129 | 136 | function runPad_e( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) { |
130 | 137 | global $wgParser; |
131 | | - list($callback,$flags) = $wgParser->mFunctionHooks['pad']; |
| 138 | + list( $callback , $flags ) = $wgParser->mFunctionHooks['pad']; |
132 | 139 | return @call_user_func_array( $callback, |
133 | | - array_merge(array($parser),array($inStr, $inLen , stripcslashes($inWith), $inDirection) )); |
| 140 | + array_merge( array( $parser ), array( $inStr, $inLen, stripcslashes( $inWith ), $inDirection ) ) ); |
134 | 141 | } |
135 | 142 | |
136 | 143 | /** |
— | — | @@ -138,11 +145,11 @@ |
139 | 146 | * Note: The needle is limited to specific length. |
140 | 147 | * Note: The product is limited to specific length. |
141 | 148 | */ |
142 | | - function runReplace_e( $parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
| 149 | + function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
143 | 150 | global $wgParser; |
144 | | - list($callback,$flags) = $wgParser->mFunctionHooks['replace']; |
| 151 | + list( $callback, $flags ) = $wgParser->mFunctionHooks['replace']; |
145 | 152 | return @call_user_func_array( $callback, |
146 | | - array_merge(array($parser),array($inStr, stripcslashes($inReplaceFrom), stripcslashes($inReplaceTo)) )); |
| 153 | + array_merge( array( $parser ), array( $inStr, stripcslashes( $inReplaceFrom ), stripcslashes( $inReplaceTo ) ) ) ); |
147 | 154 | } |
148 | 155 | |
149 | 156 | /** |
— | — | @@ -152,11 +159,18 @@ |
153 | 160 | * Note: The divider is limited to specific length. |
154 | 161 | * Note: Empty string is returned, if there is not enough exploded chunks. |
155 | 162 | */ |
156 | | - function runExplode_e ( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
| 163 | + function runExplode_e( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
157 | 164 | global $wgParser; |
158 | | - list($callback,$flags) = $wgParser->mFunctionHooks['explode']; |
| 165 | + list( $callback, $flags ) = $wgParser->mFunctionHooks['explode']; |
159 | 166 | return @call_user_func_array( $callback, |
160 | | - array_merge(array($parser),array($inStr, stripcslashes($inDiv), $inPos) )); |
| 167 | + array_merge(array( $parser ), array( $inStr, stripcslashes( $inDiv ), $inPos ) )); |
161 | 168 | } |
162 | 169 | |
| 170 | + /** |
| 171 | + * {{#stripnewlines:value}} |
| 172 | + */ |
| 173 | + function runStrip_nl( &$parser , $inStr = '' ) { |
| 174 | + return preg_replace( stripcslashes( '/\n\n+/' ), stripcslashes( '\n' ), $inStr ); |
| 175 | + } |
| 176 | + |
163 | 177 | } |
Index: trunk/extensions/StringFunctionsEscaped/README |
— | — | @@ -1,27 +1,27 @@ |
2 | 2 | {{Extension|templatemode= |
3 | 3 | |name = StringFunctionsEscaped |
4 | | -|status = beta |
| 4 | +|status = stable |
5 | 5 | |type1 = parser function |
6 | 6 | |type2 = |
7 | 7 | |hook1 = LanguageGetMagic |
8 | 8 | |hook2 = |
9 | | -|username = [[user:jpond | Jack D. Pond ]] |
10 | | -|author = |
| 9 | +|username = jpond |
| 10 | +|author = Jack D. Pond |
11 | 11 | |description = Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments. |
12 | 12 | |image = |
13 | 13 | |imagesize = |
14 | | -|version = 1.0.0 |
15 | | -|update = 2009-09-11 |
| 14 | +|version = 1.0.1 |
| 15 | +|update = 2010-06-07 |
16 | 16 | |mediawiki = Tested with 1.14,1.15,1.16A, Should work with all |
17 | 17 | |php = |
18 | 18 | |license = GNU Version 2 |
19 | | -|download = |
20 | | -|readme = |
| 19 | +|download = {{WikimediaDownload|StringFunctionsEscaped}} |
| 20 | +|readme = [http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/StringFunctionsEscaped/README README] |
21 | 21 | |changelog = |
22 | 22 | |parameters = $wgPFEnableStringFunctions |
23 | 23 | |tags = |
24 | 24 | |rights = |
25 | | -|example = |
| 25 | +|example = [[#Examples | examples]] |
26 | 26 | |compatibility = |
27 | 27 | }} |
28 | 28 | |
— | — | @@ -29,13 +29,13 @@ |
30 | 30 | |
31 | 31 | ==What can this extension do?== |
32 | 32 | |
33 | | -Wikitext allows the imbedding of certain control characters (newline, tab, etc.). These parser functions allow them to be identified and used with standard c-type escape character sequence (/n,/t, etc.). |
| 33 | +Wikitext allows the imbedding of certain control characters (newline, tab, etc.). These parser functions allows the developer to find and manipulate standard c-type escape character sequence (<nowiki>\n,\t</nowiki>, etc.) within wikitext. |
34 | 34 | |
35 | | -These can be used (among other things) to make infoblox-type templates much more WYSIWIG (see Examples) for novice/non-technical users. |
| 35 | +These parser functions can be used to make infoblox-type templates and/or forms much more WYSIWIG (see [[#Examples | examples]]) for novice/non-technical users. |
36 | 36 | |
37 | 37 | ==Usage== |
38 | 38 | |
39 | | -These functions are all invoked exactly as their string parser functions would be (except with the '_e' appended to distinguish). |
| 39 | +All parser functions are invoked exactly as their string parser functions would be (except with the '_e' appended). They can be used exactly as their counterparts are, even if there are no embedded special characters. |
40 | 40 | |
41 | 41 | === pos_e: (string position)=== |
42 | 42 | |
— | — | @@ -48,6 +48,7 @@ |
49 | 49 | |
50 | 50 | === rpos_e: (string position, reverse) === |
51 | 51 | <nowiki>{{#rpos_e:value|key}}</nowiki> |
| 52 | + |
52 | 53 | Returns the last position of key inside the given value, or -1 if the key is not found. When using this to search for the last delimiter, add +1 to the result to retreive position after the last delimiter. This also works when the delimiter is not found, because "-1 + 1" is zero, which is the beginning of the given value. |
53 | 54 | |
54 | 55 | See: http://php.net/manual/function.strrpos.php |
— | — | @@ -78,9 +79,15 @@ |
79 | 80 | |
80 | 81 | See: http://php.net/manual/function.explode.php |
81 | 82 | |
| 83 | +=== stripnewlines: (remove multiple newlines) === |
| 84 | + |
| 85 | +<nowiki>{{#stripnewlines:value}}</nowiki> |
| 86 | + |
| 87 | +Any time there is more than one newline in "value", they are changed to a single newline. |
| 88 | + |
82 | 89 | ==Download instructions== |
83 | 90 | <!-- revise these instructions if code is available via a download site --> |
84 | | -Please cut and paste the code found [[#Code|below]] and place it in <code>$IP/extensions/ExtensionName/ExtensionName.php</code>. ''Note: [[Manual:$IP|$IP]] stands for the root directory of your MediaWiki installation, the same directory that holds [[Manual:LocalSettings.php|LocalSettings.php]]''. |
| 91 | +Download the extension from [http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php SVN] and place it in <code>$IP/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php</code>. ''Note: [[Manual:$IP|$IP]] stands for the root directory of your MediaWiki installation, the same directory that holds [[Manual:LocalSettings.php|LocalSettings.php]]''. |
85 | 92 | |
86 | 93 | ==Installation== |
87 | 94 | String functions were integrated into [[Extension:ParserFunctions]] extension as of [[Special:Code/MediaWiki/50997|r50997]]. This revision of [[Extension:ParserFunctions]] is designed for MediaWiki 1.16, but updating to the trunk version may work on previous versions. If you are using a prior version of [[Extension:ParserFunctions]], you will also have to include [[Extension:StringFunctions]]. |
— | — | @@ -178,6 +185,28 @@ |
179 | 186 | Line 2 |
180 | 187 | |
181 | 188 | </pre> |
| 189 | + |
| 190 | +=== stripnewlines === |
| 191 | +<pre> |
| 192 | +{{#stripnewlines:Line 1 |
| 193 | + |
| 194 | +Line 2 |
| 195 | + |
| 196 | + |
| 197 | +Line 3}} |
| 198 | + |
| 199 | +Returns: |
| 200 | + |
| 201 | +Line 1 |
| 202 | +Line 2 |
| 203 | +Line 3 |
| 204 | + |
| 205 | +Printed version: |
| 206 | + |
| 207 | +Line 1 Line 2 Line 3 |
| 208 | + |
| 209 | +</pre> |
| 210 | + |
182 | 211 | ==See also== |
183 | 212 | |
184 | 213 | * [[Extension:ParserFunctions]] |