r105871 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105870‎ | r105871 | r105872 >
Date:13:03, 12 December 2011
Author:danwe
Status:deferred
Tags:
Comment:
'#hashtotemplate' parameter 3 depreciated, using the '$egHashTablesExpansionEscapeTemplates' escaping system now.
Modified paths:
  • /trunk/extensions/HashTables/HashTables.php (modified) (history)
  • /trunk/extensions/HashTables/RELEASE-NOTES (modified) (history)

Diff [purge]

Index: trunk/extensions/HashTables/HashTables.php
@@ -588,22 +588,39 @@
589589 return '';
590590 }
591591
 592+ global $egHashTablesExpansionEscapeTemplates;
592593 $store = self::get( $parser );
593594
594595 $template = trim( $frame->expand($args[0] ) );
595596 $hashId = trim( $frame->expand($args[1] ) );
596 - $pipeReplacer = isset($args[2]) ? trim( $frame->expand( $args[2] ) ) : '|';
 597+ if( $egHashTablesExpansionEscapeTemplates === null ) {
 598+ // COMPATIBILITY-MODE
 599+ // third parameter is depreciated since 1.0 in case we can auto-escape
 600+ $pipeReplacer = isset($args[2]) ? trim( $frame->expand( $args[2] ) ) : '|';
 601+ }
597602
598603 if( ! $store->hashExists( $hashId ) ) {
599604 return '';
600605 }
601606
602607 $params = $store->getHash( $hashId );
603 - $templateCall = '{{' . $template;
 608+ $templateCall = '{{' . $template;
604609
605 - foreach ($params as $paramKey => $paramValue){
606 - // replace '{', '}' and '|' to avoid template call manipulation
607 - $paramValue = str_replace( array( '{', '}', '|' ), array( '{', '}', $pipeReplacer ), $paramValue );
 610+ foreach( $params as $paramKey => $paramValue ){
 611+ if( $egHashTablesExpansionEscapeTemplates !== null ) {
 612+ // escape all special chars so template call won't get destroyed by user values
 613+ $paramKey = self::escapeForExpansion( $paramKey );
 614+ $paramValue = self::escapeForExpansion( $paramValue );
 615+ } else {
 616+ // COMPATIBILITY-MODE
 617+ $replacedValues = str_replace(
 618+ array( '{', '}', '|' ),
 619+ array( '{', '}', $pipeReplacer ),
 620+ array( $paramKey, $paramValue )
 621+ );
 622+ $paramKey = $replacedValues[0];
 623+ $paramValue = $replacedValues[1];
 624+ }
608625 $templateCall .= "|$paramKey=$paramValue";
609626 }
610627 $templateCall .= '}}';
Index: trunk/extensions/HashTables/RELEASE-NOTES
@@ -1,21 +1,24 @@
22 Changelog:
33 ==========
44
5 - * (trunk) Version 1.0
 5+ * (trunk) Version 1.0 alpha
66 This release has lots of internal changes in it. All functions representing a parser funcdtions now
77 use a 'pf_' or 'pfObj_' prefix, are declared static and there are new/changed public functions for
88 interaction with 'HashTables' extension.
99 - Compatbility with other extensions increased by using one hash tables store per Parser instance.
1010 - Inclusion of special pages in the middle of the page won't reset all defined hash tables anymore.
11 - - '#hashprint' will handle <includeonly>/<noinclude> correct in case it's used in a template.
 11+ - '#hashprint' will handle '<includeonly>' and '<noinclude>' correct in case it's used in a template.
1212 - '#hashprint' will use the languages default comma separator instead of hard-coded ', ' as default.
1313 - '#hashprint' will no longer expand the given wiki markup twice. Instead, it will escape special
1414 characters of hash values before they will be inserted into the markup. This way it won't be
1515 possible anymore that hash values can break the functions output. '$egHashTablesExpansionEscapeTemplates'
1616 defines which special characters should be escaped by which template/parser function. It can also
1717 be set to null to keep the old behavior as some kind of compatibility mode.
 18+ - '#hashtotemplate' uses the new escaping mechanism (except '$egHashTablesExpansionEscapeTemplates'
 19+ is set to null). Therefore '#hashtotemplate' parameter three is depreciated.
1820 - '#hashvalue' will only expand its default when required.
1921
 22+
2023 * November 4, 2011 -- Version 0.7
2124 - buggy behavior in 'hashkeyexists' which led to expanding both arguments 'yes' and 'no' in
2225 case custom arguments were given is solved. Now only the one actual case is being expanded.
@@ -27,8 +30,8 @@
2831 - some gernal cleanup done.
2932 - put into wikimedia.org svn (http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/HashTables/)
3033 - distributed under ISC license.
31 -
3234
 35+
3336 * August 3, 2011 -- Version 0.6.3
3437 - minor bug in 'parameterstohash' function solved.
3538
@@ -42,8 +45,8 @@
4346 * January 19, 2011 -- Version 0.6
4447 - New public class methods for creating and removing hash tables. Good for use by other extensions.
4548 - New experimental function 'hashtotemplate'.
46 -
47 -
 49+
 50+
4851 * August 3, 2010 -- Version 0.5.1
4952 - Hashinclude didn't trim key and value so keys with ending space ' ' and values with leading
5053 space were possible when defining something like {{#hashinclude: a | a = 1}}
@@ -58,19 +61,19 @@
5962 * July 20, 2010 -- Version 0.4
6063 - Removed critical bug. Some kind of "Superglobal" HashTables on page imports and job queue jobs.
6164 Values were passed from one page to another page.
62 -
63 -
 65+
 66+
6467 * June 11, 2010 -- Version 0.3
6568 - Third parameter for 'arraytohash' allows to set a key array.
6669 - New function 'hashkeyexists'.
67 -
68 -
 70+
 71+
6972 * June 6, 2010 -- Version 0.2
7073 - New functions 'hashmerge', 'hashmix', 'hashdiff', 'hashinclude' and 'hashexclude'.
7174 - New functions if 'ArrayExtension' is available in the wiki: 'hashtoarray' and 'arraytohash'.
7275 - New parameter for 'hashprint' which allows to define the print order thru an array.
73 -
74 -
 76+
 77+
7578 * Mai 30, 2010 -- Version 0.1
7679 - First version of HashTables featuring the functions 'hashdefine', 'hashvalue', 'hashsize',
7780 'hashprint', 'hashreset' and 'parameterstohash'.

Status & tagging log