Index: trunk/extensions/ArrayExtension/ArrayExtension.i18n.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Internationalization file for the ArrayExtension extension. |
| 5 | + * Internationalization file for the 'ArrayExtension' extension. |
6 | 6 | * |
7 | 7 | * @since 1.3.4 |
8 | 8 | * |
— | — | @@ -81,7 +81,7 @@ |
82 | 82 | * @author Kghbln |
83 | 83 | */ |
84 | 84 | $messages['de'] = array( |
85 | | - 'arrayext-desc' => 'Ermöglicht das Speichern und Nutzen definierter Datenreihen', |
| 85 | + 'arrayext-desc' => 'Ermöglicht das Speichern und Nutzen definierter Datenreihen (Arrays)', |
86 | 86 | ); |
87 | 87 | |
88 | 88 | /** French (Français) |
Index: trunk/extensions/ArrayExtension/ArrayExtension.php |
— | — | @@ -3,9 +3,9 @@ |
4 | 4 | /** |
5 | 5 | * Initialization file for the ArrayExtension extension. |
6 | 6 | * |
7 | | - * Documentation: http://www.mediawiki.org/wiki/Extension:ArrayExtension |
8 | | - * Support http://www.mediawiki.org/wiki/Extension_talk:ArrayExtension |
9 | | - * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ArrayExtension |
| 7 | + * Documentation: http://www.mediawiki.org/wiki/Extension:ArrayExtension |
| 8 | + * Support: http://www.mediawiki.org/wiki/Extension_talk:ArrayExtension |
| 9 | + * Source code: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ArrayExtension |
10 | 10 | * |
11 | 11 | * @file ArrayExtension.php |
12 | 12 | * @ingroup ArrayExtension |
— | — | @@ -42,44 +42,58 @@ |
43 | 43 | die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
44 | 44 | } |
45 | 45 | |
46 | | -$wgHooks['ParserFirstCallInit'][] = 'efArrayExtensionParserFirstCallInit'; |
47 | | - |
48 | 46 | $wgExtensionCredits['parserhook'][] = array( |
49 | | - 'path' => __FILE__, |
50 | | - 'name' => 'ArrayExtension', |
51 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:ArrayExtension', |
52 | | - 'author' => array ( 'Li Ding', 'Jie Bao', 'Daniel Werner' ), |
| 47 | + 'path' => __FILE__, |
| 48 | + 'name' => 'ArrayExtension', |
| 49 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:ArrayExtension', |
| 50 | + 'author' => array ( 'Li Ding', 'Jie Bao', 'Daniel Werner' ), |
53 | 51 | 'descriptionmsg' => 'arrayext-desc', |
54 | | - 'version' => ArrayExtension::VERSION |
| 52 | + 'version' => ArrayExtension::VERSION |
55 | 53 | ); |
56 | 54 | |
| 55 | +$wgHooks['ParserFirstCallInit'][] = 'efArrayExtensionParserFirstCallInit'; |
| 56 | + |
57 | 57 | $dir = dirname( __FILE__ ); |
58 | 58 | |
59 | | -$wgExtensionMessagesFiles['ArrayExtension'] = $dir . '/ArrayExtension.i18n.php'; |
| 59 | +$wgExtensionMessagesFiles['ArrayExtension' ] = $dir . '/ArrayExtension.i18n.php'; |
60 | 60 | $wgExtensionMessagesFiles['ArrayExtensionMagic'] = $dir . '/ArrayExtension.i18n.magic.php'; |
61 | 61 | |
| 62 | +unset( $dir ); |
| 63 | + |
62 | 64 | /** |
63 | 65 | * named arrays - an array has a list of values, and could be set to a SET |
64 | 66 | */ |
65 | 67 | class ArrayExtension { |
66 | 68 | |
| 69 | + /** |
| 70 | + * Version of the ArrayExtension extension. |
| 71 | + * |
| 72 | + * @since 1.3.2 |
| 73 | + */ |
67 | 74 | const VERSION = '1.3.4 alpha'; |
68 | 75 | |
| 76 | + /** |
| 77 | + * Store for arrays. |
| 78 | + * |
| 79 | + * @var array |
| 80 | + * @private |
| 81 | + */ |
69 | 82 | var $mArrayExtension = array(); |
70 | 83 | |
71 | | - function ArrayExtension() { |
| 84 | + function __construct() { |
72 | 85 | global $wgHooks; |
73 | 86 | $wgHooks['ParserClearState'][] = &$this; |
74 | 87 | } |
75 | 88 | |
76 | 89 | function onParserClearState( &$parser ) { |
77 | | - $this->mArrayExtension = array(); // remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates |
| 90 | + // remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates |
| 91 | + $this->mArrayExtension = array(); |
78 | 92 | return true; |
79 | 93 | } |
80 | 94 | |
81 | | - ////////////////////////////////////////////////////////// / |
| 95 | + /////////////////////////////////////////////////////////// |
82 | 96 | // PART 1. constructor |
83 | | - ////////////////////////////////////////////////////////// / |
| 97 | + /////////////////////////////////////////////////////////// |
84 | 98 | |
85 | 99 | /** |
86 | 100 | * Define an array by a list of 'values' deliminated by 'delimiter', |
— | — | @@ -90,7 +104,17 @@ |
91 | 105 | * http://us2.php.net/manual/en/book.pcre.php |
92 | 106 | * see also: http://us2.php.net/manual/en/function.preg-split.php |
93 | 107 | */ |
94 | | - function arraydefine( &$parser, $arrayid, $value = '', $delimiter = '/\s*,\s*/', $options = '', $delimiter2 = ', ', $search = '@@@@', $subject = '@@@@', $frame = null ) { |
| 108 | + function arraydefine( |
| 109 | + &$parser, |
| 110 | + $arrayid, |
| 111 | + $value = '', |
| 112 | + $delimiter = '/\s*,\s*/', |
| 113 | + $options = '', |
| 114 | + $delimiter2 = ', ', |
| 115 | + $search = '@@@@', |
| 116 | + $subject = '@@@@', |
| 117 | + $frame = null |
| 118 | + ) { |
95 | 119 | if ( !isset( $arrayid ) ) { |
96 | 120 | return ''; |
97 | 121 | } |
— | — | @@ -148,9 +172,9 @@ |
149 | 173 | } |
150 | 174 | |
151 | 175 | |
152 | | - ////////////////////////////////////////////////////////// / |
| 176 | + /////////////////////////////////////////////////////////// |
153 | 177 | // PART 2. print |
154 | | - ////////////////////////////////////////////////////////// / |
| 178 | + /////////////////////////////////////////////////////////// |
155 | 179 | |
156 | 180 | |
157 | 181 | /** |
— | — | @@ -169,29 +193,59 @@ |
170 | 194 | * {{#arrayprint:b|<br/>|@@@|[[name::@@@]]}} -- make SMW links |
171 | 195 | */ |
172 | 196 | function arrayprint( &$parser, $arrayid , $delimiter = ', ', $search = '@@@@', $subject = '@@@@', $frame = null ) { |
173 | | - $ret = $this->validate_array_by_arrayid( $arrayid ); |
174 | | - if ( $ret !== true ) { |
175 | | - return $ret; |
176 | | - } |
| 197 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 198 | + if ( $ret !== true ) { |
| 199 | + return $ret; |
| 200 | + } |
177 | 201 | |
178 | | - $values = $this->mArrayExtension[$arrayid]; |
179 | | - $rendered_values = array(); |
180 | | - foreach ( $values as $v ) { |
181 | | - $temp_result_value = str_replace( $search, $v, $subject ); |
182 | | - if ( isset( $frame ) ) { |
183 | | - $temp_result_value = $parser->preprocessToDom( $temp_result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
184 | | - $temp_result_value = trim( $frame->expand( $temp_result_value ) ); |
185 | | - } |
186 | | - $rendered_values[] = $temp_result_value ; |
187 | | - } |
188 | | - return array( implode( $delimiter, $rendered_values ) , 'noparse' => false, 'isHTML' => false ); |
189 | | - } |
| 202 | + $values = $this->mArrayExtension[$arrayid]; |
| 203 | + $rendered_values = array(); |
| 204 | + foreach ( $values as $v ) { |
| 205 | + $temp_result_value = str_replace( $search, $v, $subject ); |
| 206 | + // frame is only available in newer MW versions |
| 207 | + if ( isset( $frame ) ) { |
| 208 | + /* |
| 209 | + * in case frame is given (new MW versions) the $subjectd still is un-expanded (this allows to use |
| 210 | + * some parser functions like {{FULLPAGENAME:@@@@}} directly without getting parsed before @@@@ is replaced. |
| 211 | + * Expand it so we replace templates like {{!}} which we need for the final parse. |
| 212 | + */ |
| 213 | + $temp_result_value = $parser->preprocessToDom( $temp_result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
| 214 | + $temp_result_value = trim( $frame->expand( $temp_result_value ) ); |
| 215 | + } |
| 216 | + $rendered_values[] = $temp_result_value ; |
| 217 | + } |
| 218 | + |
| 219 | + $output = implode( $delimiter, $rendered_values ); |
| 220 | + $noparse = false; |
| 221 | + |
| 222 | + if ( isset( $frame ) ) { |
| 223 | + /* |
| 224 | + * don't leave the final parse to Parser::braceSubstitution() since there are some special cases where it |
| 225 | + * would produce unexpected output (it uses a new child frame and ignores whether the frame is a template!) |
| 226 | + */ |
| 227 | + $noparse = true; |
190 | 228 | |
191 | | - function arrayprintObj( &$parser, $frame, $args ) { |
| 229 | + $output = $parser->preprocessToDom( $output, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
| 230 | + $output = trim( $frame->expand( $output ) ); |
| 231 | + } |
| 232 | + |
| 233 | + return array( |
| 234 | + $output, |
| 235 | + 'noparse' => $noparse, |
| 236 | + 'isHTML' => false |
| 237 | + ); |
| 238 | + } |
| 239 | + |
| 240 | + function arrayprintObj( &$parser, $frame, $args ) { |
192 | 241 | // Set variables |
193 | | - $arrayid = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
| 242 | + $arrayid = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
194 | 243 | $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', '; |
195 | | - $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
| 244 | + /* |
| 245 | + * PPFrame::NO_ARGS and PPFrame::NO_TEMPLATES for expansion make a lot of sense here since the patterns getting replaced |
| 246 | + * in $subject before $subject is being parsed. So any template or argument influence in the patterns wouldn't make any |
| 247 | + * sense in any sane scenario. |
| 248 | + */ |
| 249 | + $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
196 | 250 | $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
197 | 251 | |
198 | 252 | return $this->arrayprint( $parser, $arrayid, $delimiter, $search, $subject, $frame ); |
— | — | @@ -261,7 +315,7 @@ |
262 | 316 | if ( !$ret ) |
263 | 317 | return $no; |
264 | 318 | |
265 | | - if ( !$this->isValidRegEx( $needle ) ) |
| 319 | + if ( ! $this->isValidRegEx( $needle ) ) |
266 | 320 | $needle = '/^\s*' . preg_quote( $needle, '/' ) . '\s*$/'; |
267 | 321 | |
268 | 322 | // search for a match inside the array: |
— | — | @@ -337,9 +391,9 @@ |
338 | 392 | |
339 | 393 | |
340 | 394 | |
341 | | - ////////////////////////////////////////////////////////// / |
| 395 | + /////////////////////////////////////////////////////////// |
342 | 396 | // PART 3. alter an array |
343 | | - ////////////////////////////////////////////////////////// / |
| 397 | + /////////////////////////////////////////////////////////// |
344 | 398 | |
345 | 399 | /** |
346 | 400 | * reset some or all defined arrayes |
— | — | @@ -425,9 +479,9 @@ |
426 | 480 | } |
427 | 481 | |
428 | 482 | |
429 | | - ////////////////////////////////////////////////////////// / |
| 483 | + /////////////////////////////////////////////////////////// |
430 | 484 | // PART 4. create an array |
431 | | - ////////////////////////////////////////////////////////// / |
| 485 | + /////////////////////////////////////////////////////////// |
432 | 486 | |
433 | 487 | /** |
434 | 488 | * merge two arrays, keep duplicated values |
— | — | @@ -702,39 +756,51 @@ |
703 | 757 | else |
704 | 758 | return null; |
705 | 759 | } |
706 | | - |
| 760 | + |
| 761 | + /** |
| 762 | + * Returns whether a certain array is defined within the page scope. |
| 763 | + * |
| 764 | + * @param string $arrayId |
| 765 | + * @return boolean |
| 766 | + */ |
707 | 767 | function arrayExists( $arrayId = '' ) { |
708 | | - if ( array_key_exists( trim( $arrayId ), $this->mArrayExtension ) ) |
709 | | - |
710 | | - |
711 | | - |
712 | | - return true; |
713 | | - else |
714 | | - return false; |
| 768 | + return array_key_exists( trim( $arrayId ), $this->mArrayExtension ); |
715 | 769 | } |
716 | 770 | |
717 | | - // add a new array or overwrite existing one. Values delivered as real array. |
718 | | - function createArray( $arrayId = '', $arr = array() ) { |
| 771 | + /** |
| 772 | + * Adds a new array or overwrites an existing one. |
| 773 | + * |
| 774 | + * @param string $arrayId |
| 775 | + * @param array $arr the new array, should contain string values. |
| 776 | + */ |
| 777 | + public function createArray( $arrayId = '', $arr = array() ) { |
719 | 778 | $arr = $this->reorganizeArrayKeys( $arr ); |
720 | 779 | $this->mArrayExtension[ trim( $arrayId ) ] = $arr; |
721 | 780 | } |
722 | 781 | |
723 | 782 | |
724 | | - // remove an existing array. If array doesn't exist this will return false, otherwise true. |
725 | | - function removeArray( $arrayId = '' ) { |
| 783 | + /** |
| 784 | + * Removes an existing array. If array doesn't exist this will return false, otherwise true. |
| 785 | + * |
| 786 | + * @param string $arrayId |
| 787 | + * @return boolean whether the array existed and has been removed |
| 788 | + */ |
| 789 | + public function removeArray( $arrayId = '' ) { |
726 | 790 | $arrayId = trim( $arrayId ); |
727 | 791 | if ( $this->arrayExists( $arrayId ) ) { |
728 | 792 | unset( $this->mArrayExtension[ $arrayId ] ); |
729 | 793 | return true; |
730 | | - } else { |
731 | | - return false; |
732 | 794 | } |
733 | | - |
734 | | - |
| 795 | + return false; |
735 | 796 | } |
736 | 797 | |
737 | | - // Rebuild the array and reorganize all keys. This means all gaps between array items will be closed. |
738 | | - function reorganizeArrayKeys( $arr = array() ) { |
| 798 | + /** |
| 799 | + * Rebuild the array and reorganize all keys. This means all gaps between array items will be closed. |
| 800 | + * |
| 801 | + * @param array $arr array to be reorganized |
| 802 | + * @return array |
| 803 | + */ |
| 804 | + public function reorganizeArrayKeys( $arr = array() ) { |
739 | 805 | $newArray = array(); |
740 | 806 | foreach ( $arr as $val ) { |
741 | 807 | $newArray[] = trim( $val ); |
— | — | @@ -742,16 +808,22 @@ |
743 | 809 | return $newArray; |
744 | 810 | } |
745 | 811 | |
746 | | - // Decide for the given $pattern if its a valid regular expression or not |
747 | | - function isValidRegEx( $pattern ) { |
748 | | - return preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ); |
| 812 | + /** |
| 813 | + * Decides for the given $pattern whether its a valid regular expression acceptable for |
| 814 | + * ArrayExtension parser functions or not. |
| 815 | + * |
| 816 | + * @param string $pattern regular expression including delimiters and optional flags |
| 817 | + * @return boolean |
| 818 | + */ |
| 819 | + function isValidRegEx( $pattern ) { |
| 820 | + return (bool)preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ); |
749 | 821 | } |
750 | 822 | } |
751 | 823 | |
752 | | -function efArrayExtensionParserFirstCallInit( $parser ) { |
| 824 | +function efArrayExtensionParserFirstCallInit( &$parser ) { |
753 | 825 | global $wgArrayExtension; |
754 | 826 | |
755 | | - $wgArrayExtension = new ArrayExtension; |
| 827 | + $wgArrayExtension = new ArrayExtension(); |
756 | 828 | $parser->setFunctionHook( 'arraydefine', array( &$wgArrayExtension, 'arraydefine' ) ); |
757 | 829 | |
758 | 830 | if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) { |
Index: trunk/extensions/ArrayExtension/INSTALL |
— | — | @@ -1,12 +1,12 @@ |
2 | | -These is the install file for the ArrayExtension extension. |
| 2 | +This is the install file for the 'ArrayExtension' extension. |
3 | 3 | |
4 | 4 | Extension page on mediawiki.org: http://www.mediawiki.org/wiki/Extension:ArrayExtension |
5 | | -Latest version of the install file: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ArrayExtension/INSTALL?view=co |
| 5 | +Latest version of this install file: http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ArrayExtension/INSTALL?view=co |
6 | 6 | |
7 | 7 | |
8 | 8 | == Download == |
9 | 9 | |
10 | | -You can download a snapshot of the ArrayExtension via the Wikimedia extension distributor at |
| 10 | +You can download a snapshot of 'ArrayExtension' via the Wikimedia extension distributor at |
11 | 11 | https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Special:ExtensionDistributor/ArrayExtension |
12 | 12 | |
13 | 13 | You can also get the code directly from SVN. Tags can be obtained via |
— | — | @@ -18,10 +18,11 @@ |
19 | 19 | |
20 | 20 | svn checkout <nowiki>http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/ArrayExtension/</nowiki> |
21 | 21 | |
| 22 | + |
22 | 23 | == Installation == |
23 | 24 | |
24 | | -Once you have downloaded the code, place the ''ArrayExtension'' directory within your |
| 25 | +Once you have downloaded the code, place the 'ArrayExtension' directory within your |
25 | 26 | MediaWiki 'extensions' directory. Then add the following code to your [[Manual:LocalSettings.php|LocalSettings.php]] file: |
26 | 27 | |
27 | | -# ArrayExtension |
28 | | -require_once( "$IP/extensions/ArrayExtension/ArrayExtension.php" ); |
| 28 | + # ArrayExtension |
| 29 | + require_once( "$IP/extensions/ArrayExtension/ArrayExtension.php" ); |
Index: trunk/extensions/ArrayExtension/RELEASE-NOTES |
— | — | @@ -1,5 +1,9 @@ |
2 | 2 | Changelog: |
3 | 3 | ========== |
| 4 | + * (trunk) version 1.3.4 |
| 5 | + - arrayprint will handle <includeonly>/<noinclude> correct in case its used in a template. |
| 6 | + - moved into mediawiki.org SVN |
| 7 | + |
4 | 8 | * January 24, 2011 version 1.3.2 |
5 | 9 | - New public class methods for creating and removing arrays. Good for use by other extensions. |
6 | 10 | - VERSION constant added to ArrayExtension class |
Index: trunk/extensions/ArrayExtension/ArrayExtension.i18n.magic.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Internationalization file for magic words in the ArrayExtension extension. |
| 5 | + * Internationalization file for magic words in the 'ArrayExtension' extension. |
6 | 6 | * |
7 | 7 | * @file ArrayExtension.i18n.magic.php |
8 | 8 | * @ingroup ArrayExtension |