Index: trunk/extensions/Arrays/RELEASE-NOTES |
— | — | @@ -15,6 +15,8 @@ |
16 | 16 | + '#arraymerge', '#arrayunion', '#arraydiff' and '#arrayintersect' with only one array for |
17 | 17 | the operation will make a copy of that array instead of creating no array at all. |
18 | 18 | + See 1.4 alpha for previous changes |
| 19 | + - '#arraydefine' option 'print' no longer supports 'print=print' and parameters beyond options. |
| 20 | + This functionality never worked reliably anyways. 'print=list' still works. |
19 | 21 | - If 'Regex Fun' extension is installed, '#arraysearcharray' can use Regex Funs 'e' flag feature |
20 | 22 | for transforming the result and at the same time parsing them after each back-reference inclusion. |
21 | 23 | - 1.4 alpha bug solved, '#arraysearcharray' with empty string as start index was interpreted as 0 |
Index: trunk/extensions/Arrays/Arrays.php |
— | — | @@ -154,11 +154,7 @@ |
155 | 155 | $arrayId, |
156 | 156 | $value = null, |
157 | 157 | $delimiter = '/\s*,\s*/', |
158 | | - $options = '', |
159 | | - $delimiter2 = ', ', |
160 | | - $search = '@@@@', |
161 | | - $subject = '@@@@', |
162 | | - $frame = null |
| 158 | + $options = '' |
163 | 159 | ) { |
164 | 160 | if ( !isset( $arrayId ) ) { |
165 | 161 | return ''; |
— | — | @@ -230,17 +226,17 @@ |
231 | 227 | */ |
232 | 228 | |
233 | 229 | // sort array if the option is set |
234 | | - self::pf_arraysort( $parser, $arrayId, self::array_value( $arrayOptions, 'sort' ) ); |
| 230 | + if( array_key_exists( 'sort', $arrayOptions ) ) { |
| 231 | + $array = self::arraySort( $array, self::array_value( $arrayOptions, 'sort' ) ); |
| 232 | + } |
235 | 233 | |
236 | 234 | // print the array upon request |
237 | 235 | switch( self::array_value( $arrayOptions, 'print' ) ) { |
238 | 236 | case 'list': |
239 | | - $out = self::pf_arrayprint( $parser, $arrayId ); |
| 237 | + global $wgLang; |
| 238 | + // simple list output |
| 239 | + $out = implode( ', ', $array ); |
240 | 240 | break; |
241 | | - |
242 | | - case 'print': |
243 | | - $out = self::pf_arrayprint( $parser, $arrayId, $delimiter2, $search, $subject, $frame ); |
244 | | - break; |
245 | 241 | } |
246 | 242 | } |
247 | 243 | |
— | — | @@ -668,32 +664,16 @@ |
669 | 665 | static function pf_arraysort( Parser &$parser, $arrayId , $sort = 'none' ) { |
670 | 666 | $store = self::get( $parser ); |
671 | 667 | |
672 | | - if( ! $store->arrayExists( $arrayId ) ) { |
| 668 | + $array = $store->getArray( $arrayId ); |
| 669 | + |
| 670 | + if( $array === null ) { |
673 | 671 | return ''; |
674 | 672 | } |
675 | 673 | |
676 | | - // do the requested sorting of the given array: |
677 | | - switch( $sort ) { |
678 | | - case 'asc': |
679 | | - case 'asce': |
680 | | - case 'ascending': |
681 | | - sort( $store->mArrays[ $arrayId ] ); |
682 | | - break; |
683 | | - |
684 | | - case 'desc': |
685 | | - case 'descending': |
686 | | - rsort( $store->mArrays[ $arrayId ] ); |
687 | | - break; |
688 | | - |
689 | | - case 'random': |
690 | | - shuffle( $store->mArrays[ $arrayId ] ); |
691 | | - break; |
692 | | - |
693 | | - case 'reverse': |
694 | | - $reverse = array_reverse( $store->getArray( $arrayId ) ); |
695 | | - $store->setArray( $arrayId, $reverse ); |
696 | | - break; |
697 | | - } ; |
| 674 | + // sort array and store it |
| 675 | + $array = self::arraySort( $array, $sort ); |
| 676 | + $store->setArray( $arrayId, $array ); |
| 677 | + return ''; |
698 | 678 | } |
699 | 679 | |
700 | 680 | |
— | — | @@ -921,9 +901,11 @@ |
922 | 902 | /** |
923 | 903 | * Convenience function to get a value from an array. Returns '' in case the |
924 | 904 | * value doesn't exist or no array was given |
| 905 | + * |
| 906 | + * @return string |
925 | 907 | */ |
926 | 908 | protected static function array_value( $array, $field ) { |
927 | | - if ( is_array( $array ) && array_key_exists( $field, $array ) ) { |
| 909 | + if ( is_array( $array ) && array_key_exists( $field, $array ) ) { |
928 | 910 | return $array[ $field ]; |
929 | 911 | } |
930 | 912 | return ''; |
— | — | @@ -1124,7 +1106,7 @@ |
1125 | 1107 | |
1126 | 1108 | /** |
1127 | 1109 | * Removes duplicate values and all empty elements from an array just like the |
1128 | | - * arrayunique parser function would do it. The array will be sanitized internally. |
| 1110 | + * '#arrayunique' parser function would do it. The array will be sanitized internally. |
1129 | 1111 | * |
1130 | 1112 | * @since 2.0 |
1131 | 1113 | * |
— | — | @@ -1136,7 +1118,44 @@ |
1137 | 1119 | $arr = $this->sanitizeArray( $arr ); |
1138 | 1120 | $array = self::array_unique( $array ); |
1139 | 1121 | } |
| 1122 | + |
| 1123 | + /** |
| 1124 | + * Sorts an array just like parser function '#arraysort' would do it and allows the |
| 1125 | + * same sort modes. |
| 1126 | + * |
| 1127 | + * @since 2.0 |
| 1128 | + * |
| 1129 | + * @param array $array |
| 1130 | + * @param string $sortMode |
| 1131 | + * |
| 1132 | + * @return array |
| 1133 | + */ |
| 1134 | + public static function arraySort( array $array, $sortMode ) { |
| 1135 | + // do the requested sorting of the given array: |
| 1136 | + switch( $sortMode ) { |
| 1137 | + case 'asc': |
| 1138 | + case 'asce': |
| 1139 | + case 'ascending': |
| 1140 | + sort( $array ); |
| 1141 | + break; |
1140 | 1142 | |
| 1143 | + case 'desc': |
| 1144 | + case 'descending': |
| 1145 | + rsort( $array ); |
| 1146 | + break; |
| 1147 | + |
| 1148 | + case 'rand': |
| 1149 | + case 'random': |
| 1150 | + shuffle( $array ); |
| 1151 | + break; |
| 1152 | + |
| 1153 | + case 'reverse': |
| 1154 | + $array = array_reverse( $array ); |
| 1155 | + break; |
| 1156 | + } ; |
| 1157 | + return $array; |
| 1158 | + } |
| 1159 | + |
1141 | 1160 | /** |
1142 | 1161 | * Decides for the given $pattern whether its a valid regular expression acceptable for |
1143 | 1162 | * Arrays parser functions or not. |