* Two callers of wfArrayMerge() were bugs, both assuming strange and complex behaviour in wfArrayMerge() which has never been present or documented.
* Introduced wfMergeErrorArrays() to remove duplicates from merged error arrays, e.g. from getUserPermissionsErrors().
* Rewrote the remaining callers of wfArrayMerge() to use array plus. It makes the code clearer, assuming the reader knows more about basic PHP operators than GlobalFunctions.php. Considering the two bugs discussed above, this seems like a fair assumption. If you don't know PHP, you shouldn't be writing MediaWiki code.
*/
function wfEscapeWikiText( $text ) {
$text = str_replace(
- array( '[', '|', ']', '\'', 'ISBN ', 'RFC ', '://', "\n=", '{{' ),
+ array( '[', '|', ']', '\'', 'ISBN ', 'RFC ', '://', "\n=", '{{' ), # }}
array( '[', '|', ']', ''', 'ISBN ', 'RFC ', '://', "\n=", '{{' ),
htmlspecialchars($text) );
return $text;
}
/**
- * Like array_merge(), but always applying the behavior for string
- * keys. array_merge() has inconsistent behavior when your string
- * indexes happen to look like integers, which is undesireable
- * for arbitrary input.
- *
- * This is roughly equivalent to $array1 + $array2 + $array3...
- * but has different behavior when there are conflicts.
- *
- * array_merge() and wfArrayMerge() take the right-hand value,
- * whereas the + operator takes the left-hand value.
+ * Backwards array plus for people who haven't bothered to read the PHP manual
+ * XXX: will not darn your socks for you.
*
* @param array $array1, [$array2, [...]]
* @return array
*/
function wfArrayMerge( $array1/* ... */ ) {
- $out = $array1;
- for( $i = 1; $i < func_num_args(); $i++ ) {
- foreach( func_get_arg( $i ) as $key => $value ) {
- $out[$key] = $value;
- }
+ $args = func_get_args();
+ $args = array_reverse( $args, true );
+ $out = array();
+ foreach ( $args as $arg ) {
+ $out += $arg;
}
return $out;
}
+/**
+ * Merge arrays in the style of getUserPermissionsErrors, with duplicate removal
+ * e.g.
+ * wfMergeErrorArrays(
+ * array( array( 'x' ) ),
+ * array( array( 'x', '2' ) ),
+ * array( array( 'x' ) ),
+ * array( array( 'y') )
+ * );
+ * returns:
+ * array(
+ * array( 'x', '2' ),
+ * array( 'x' ),
+ * array( 'y' )
+ * )
+ */
+function wfMergeErrorArrays(/*...*/) {
+ $args = func_get_args();
+ $out = array();
+ foreach ( $args as $errors ) {
+ foreach ( $errors as $params ) {
+ $spec = implode( "\t", $params );
+ $out[$spec] = $params;
+ }
+ }
+ return array_values( $out );
+}
+
/**
* Make a URL index, appropriate for the el_index field of externallinks.
*/
$this->mNoGallery = $parserOutput->getNoGallery();
$this->mHeadItems = array_merge( $this->mHeadItems, (array)$parserOutput->mHeadItems );
// Versioning...
- $this->mTemplateIds = wfArrayMerge( $this->mTemplateIds, (array)$parserOutput->mTemplateIds );
-
+ foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
+ if ( isset( $this->mTemplateIds[$ns] ) ) {
+ $this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
+ } else {
+ $this->mTemplateIds[$ns] = $dbks;
+ }
+ }
// Display title
if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
$this->setPageTitle( $dt );
}
if ( $auth ) {
- $errors = wfArrayMerge($errors,
- $this->getUserPermissionsErrors('move', $wgUser),
- $this->getUserPermissionsErrors('edit', $wgUser),
- $nt->getUserPermissionsErrors('move-target', $wgUser),
- $nt->getUserPermissionsErrors('edit', $wgUser));
+ $errors = wfMergeErrorArrays( $errors,
+ $this->getUserPermissionsErrors('move', $wgUser),
+ $this->getUserPermissionsErrors('edit', $wgUser),
+ $nt->getUserPermissionsErrors('move-target', $wgUser),
+ $nt->getUserPermissionsErrors('edit', $wgUser) );
}
$match = EditPage::matchSpamRegex( $reason );
// POST overrides GET data
// We don't use $_REQUEST here to avoid interference from cookies...
- $this->data = wfArrayMerge( $_GET, $_POST );
+ $this->data = $_POST + $_GET;
}
/**
function makeOptionsLink( $title, $override, $options, $active = false ) {
global $wgUser;
$sk = $wgUser->getSkin();
- $params = wfArrayMerge( $options, $override );
+ $params = $options + $override;
$ipblocklist = SpecialPage::getTitleFor( 'IPBlockList' );
return $sk->link( $ipblocklist, htmlspecialchars( $title ),
( $active ? array( 'style'=>'font-weight: bold;' ) : array() ), $params, array( 'known' ) );
function makeOptionsLink( $title, $override, $options, $active = false ) {
global $wgUser;
$sk = $wgUser->getSkin();
- $params = wfArrayMerge( $options, $override );
+ $params = $override + $options;
return $sk->link( $this->getTitle(), htmlspecialchars( $title ),
( $active ? array( 'style'=>'font-weight: bold;' ) : array() ), $params, array( 'known' ) );
}
$aliases[$code] = $this->fixSpecialPageAliases( $aliases[$code] );
/* Merge the aliases, THIS will break if there is special page name
* which looks like a numerical key, thanks to PHP...
- * See the comments for wfArrayMerge in GlobalSettings.php. */
+ * See the array_merge_recursive manual entry */
$this->mExtendedSpecialPageAliases = array_merge_recursive(
$this->mExtendedSpecialPageAliases, $aliases[$code] );