From: Aryeh Gregor Date: Wed, 25 Jul 2018 18:36:56 +0000 (+0300) Subject: Use array_merge() for OutputPage::$mLanguageLinks, not + X-Git-Tag: 1.34.0-rc.0~4631^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;h=8a1bc59d114f2d2cf637db7754a41f409ce102c7;p=lhc%2Fweb%2Fwiklou.git Use array_merge() for OutputPage::$mLanguageLinks, not + Based on documentation together with inspection of some callers, the intent seems to be that this is an indexed array, not associative. + will therefore do totally the wrong thing, ignoring any new values that have the same key as an existing item (e.g., '0' or '1'). Even if it was an associative array, + keeps the values on the left-hand side, which means you normally want to do $foo = $bar + $foo instead of $foo += $bar if you want to overwrite old values with the new ones. Before this change, calling addLanguageLinks() or addParserOutputMetadata() would generally not add all of the links it was supposed to if there were already links defined. (It could still work if the arrays' keys didn't conflict for some reason, e.g., something passed an associative array or an indexed array with a hole.) I don't know if anything actually hits this bug, because it's likely that callers usually add all their links at once. I find no uses of addLanguageLinks() at all. I found this bug while working on adding more tests for OutputPage, and the tests for this change will be submitted later in Icdc0288c04b8c4ba841f9fbb3e05a0cdc8a20fa5. Change-Id: I53f6e7ea94417b0034371e56e733e8c86af21658 --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 4e7c0bbe83..25571a6aad 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1262,7 +1262,7 @@ class OutputPage extends ContextSource { * (e.g. 'fr:Test page') */ public function addLanguageLinks( array $newLinkArray ) { - $this->mLanguageLinks += $newLinkArray; + $this->mLanguageLinks = array_merge( $this->mLanguageLinks, $newLinkArray ); } /** @@ -1800,7 +1800,8 @@ class OutputPage extends ContextSource { * @param ParserOutput $parserOutput */ public function addParserOutputMetadata( $parserOutput ) { - $this->mLanguageLinks += $parserOutput->getLanguageLinks(); + $this->mLanguageLinks = + array_merge( $this->mLanguageLinks, $parserOutput->getLanguageLinks() ); $this->addCategoryLinks( $parserOutput->getCategories() ); $this->setIndicators( $parserOutput->getIndicators() ); $this->mNewSectionLink = $parserOutput->getNewSection();