r69196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69195‎ | r69196 | r69197 >
Date:19:25, 8 July 2010
Author:jdpond
Status:deferred
Tags:
Comment:
Version 1.0.1 - Added #stripnewlines and corrected formatting
Modified paths:
  • /trunk/extensions/StringFunctionsEscaped/README (modified) (history)
  • /trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php (modified) (history)

Diff [purge]

Index: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php
@@ -46,7 +46,12 @@
4747 counting from the beginning. The last piece is at position -1.
4848 See: http://php.net/manual/function.explode.php
4949
 50+ {{#stripnewlines:value}}
5051
 52+ Remove multiple newlines. Any time there is more than one newline in "value",
 53+ they are changed to a single newline.
 54+
 55+
5156 Copyright (c) 2009 Jack D. Pond
5257 Licensed under GNU version 2
5358 */
@@ -54,7 +59,7 @@
5560 $wgExtensionCredits['parserhook'][] = array(
5661 'path' => __FILE__,
5762 'name' => 'StringFunctionsEscaped',
58 - 'version' => '1.0.0', // Sept 7, 2009
 63+ 'version' => '1.0.1', // July 7, 2010
5964 'descriptionmsg' => 'pfunc_desc',
6065 'author' => array('Jack D. Pond'),
6166 'license' => 'GNU Version 2',
@@ -74,21 +79,23 @@
7580
7681 $wgExtStringFunctionsEscaped = new ExtStringFunctionsEscaped ( );
7782
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' ));
8389 }
8490
8591 function wfStringFunctionsEscapedLanguageGetMagic( &$magicWords, $langCode = "en" ) {
8692 switch ( $langCode ) {
8793 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' );
93100 }
94101 return true;
95102 }
@@ -103,9 +110,9 @@
104111 */
105112 function runPos_e ( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) {
106113 global $wgParser;
107 - list($callback,$flags) = $wgParser->mFunctionHooks['pos'];
 114+ list( $callback, $flags ) = $wgParser->mFunctionHooks['pos'];
108115 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 ) ) );
110117 }
111118
112119 /**
@@ -114,11 +121,11 @@
115122 * Note: If the needle is not found, -1 is returned.
116123 * Note: The needle is limited to specific length.
117124 */
118 - function runRPos_e( &$parser, $inStr = '', $inNeedle = '' ) {
 125+ function runRPos_e( &$parser , $inStr = '', $inNeedle = '' ) {
119126 global $wgParser;
120 - list($callback,$flags) = $wgParser->mFunctionHooks['rpos'];
 127+ list( $callback, $flags ) = $wgParser->mFunctionHooks['rpos'];
121128 return @call_user_func_array( $callback,
122 - array_merge(array($parser),array($inStr,stripcslashes($inNeedle)) ));
 129+ array_merge( array( $parser ), array( $inStr, stripcslashes( $inNeedle ) ) ) );
123130 }
124131
125132 /**
@@ -127,9 +134,9 @@
128135 */
129136 function runPad_e( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) {
130137 global $wgParser;
131 - list($callback,$flags) = $wgParser->mFunctionHooks['pad'];
 138+ list( $callback , $flags ) = $wgParser->mFunctionHooks['pad'];
132139 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 ) ) );
134141 }
135142
136143 /**
@@ -138,11 +145,11 @@
139146 * Note: The needle is limited to specific length.
140147 * Note: The product is limited to specific length.
141148 */
142 - function runReplace_e( $parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) {
 149+ function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) {
143150 global $wgParser;
144 - list($callback,$flags) = $wgParser->mFunctionHooks['replace'];
 151+ list( $callback, $flags ) = $wgParser->mFunctionHooks['replace'];
145152 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 ) ) ) );
147154 }
148155
149156 /**
@@ -152,11 +159,18 @@
153160 * Note: The divider is limited to specific length.
154161 * Note: Empty string is returned, if there is not enough exploded chunks.
155162 */
156 - function runExplode_e ( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) {
 163+ function runExplode_e( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) {
157164 global $wgParser;
158 - list($callback,$flags) = $wgParser->mFunctionHooks['explode'];
 165+ list( $callback, $flags ) = $wgParser->mFunctionHooks['explode'];
159166 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 ) ));
161168 }
162169
 170+ /**
 171+ * {{#stripnewlines:value}}
 172+ */
 173+ function runStrip_nl( &$parser , $inStr = '' ) {
 174+ return preg_replace( stripcslashes( '/\n\n+/' ), stripcslashes( '\n' ), $inStr );
 175+ }
 176+
163177 }
Index: trunk/extensions/StringFunctionsEscaped/README
@@ -1,27 +1,27 @@
22 {{Extension|templatemode=
33 |name = StringFunctionsEscaped
4 -|status = beta
 4+|status = stable
55 |type1 = parser function
66 |type2 =
77 |hook1 = LanguageGetMagic
88 |hook2 =
9 -|username = [[user:jpond | Jack D. Pond ]]
10 -|author =
 9+|username = jpond
 10+|author = Jack D. Pond
1111 |description = Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments.
1212 |image =
1313 |imagesize =
14 -|version = 1.0.0
15 -|update = 2009-09-11
 14+|version = 1.0.1
 15+|update = 2010-06-07
1616 |mediawiki = Tested with 1.14,1.15,1.16A, Should work with all
1717 |php =
1818 |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]
2121 |changelog =
2222 |parameters = $wgPFEnableStringFunctions
2323 |tags =
2424 |rights =
25 -|example =
 25+|example = [[#Examples | examples]]
2626 |compatibility =
2727 }}
2828
@@ -29,13 +29,13 @@
3030
3131 ==What can this extension do?==
3232
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.
3434
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.
3636
3737 ==Usage==
3838
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.
4040
4141 === pos_e: (string position)===
4242
@@ -48,6 +48,7 @@
4949
5050 === rpos_e: (string position, reverse) ===
5151 <nowiki>{{#rpos_e:value|key}}</nowiki>
 52+
5253 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.
5354
5455 See: http://php.net/manual/function.strrpos.php
@@ -78,9 +79,15 @@
7980
8081 See: http://php.net/manual/function.explode.php
8182
 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+
8289 ==Download instructions==
8390 <!-- 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]]''.
8592
8693 ==Installation==
8794 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 @@
179186 Line 2
180187
181188 </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+
182211 ==See also==
183212
184213 * [[Extension:ParserFunctions]]

Status & tagging log