Page MenuHomePhabricator

BaseTemplate does not unset 'copyright' footer array properly
Closed, ResolvedPublic

Description

If you pass "nocopyright" then MediaWiki's copyright icon will not be included
in the list of footer icons. This is mostly useful for skins which only
display the text from footericons instead of the images and don't want a
duplicate copyright statement because footerlinks already rendered one.

But even after using BaseTemplate::getFooterIcons( 'nocopyright' ), the copyright icon will still be included.
and BaseTemplate::getFooterIcons( 'nocopyright' ) === BaseTemplate::getFooterIcons() is true. This will lead to duplicate rights text that is ought to be avoided, and may raise undefined 'alt' index PHP notice if $wgRightsIcon and $wgRightsText are falsey. They're by default and will be set to empty string if "no license footer" is set during installation.

Screen Shot 2020-10-31 at 7.57.29 AM.png (140×1 px, 174 KB)

...
} elseif ( $option == 'nocopyright' ) {
   unset( $footericons['copyright']['copyright'] ); 
   if ( $footericons['copyright'] === [] ) { 
	unset( $footericons['copyright'] );
   }
}

Event Timeline

$footericons got the array from template data:

protected function getFooterIcons( $option = null ) {
   // Generate additional footer icons
   $footericons = $this->get( 'footericons' );
   ...

The template data array is set by SkinTemplate::getFooterIcons which takes no args. It produces the following array (assuming $wgFooterIcons has not been overridden locally and license has been selected during install):

[
     "copyright" => [
       [
         "url" => "https://creativecommons.org/licenses/by-sa/4.0/",
         "src" => "/core/resources/assets/licenses/cc-by-sa.png",
         "alt" => "Creative Commons Attribution-ShareAlike",
         "width" => 88,
         "height" => 31,
       ],
     ],
     "poweredby" => [
       [
         "src" => "/core/resources/assets/poweredby_mediawiki_88x31.png",
         "url" => "https://www.mediawiki.org/",
         "alt" => "Powered by MediaWiki",
         "srcset" => "/core/resources/assets/poweredby_mediawiki_132x47.png 1.5x, /core/resources/assets/poweredby_mediawiki_176x62.png 2x",
         "width" => 88,
         "height" => 31,
       ],
     ],
   ]

There's no inner 'copyright' index on the outer one. Basically $footericons['copyright']['copyright'] is null. But unset() will not raise any warning/notice on that by design.
$footericons['copyright'] === [] will evaluate to false. Because the actual value of $footericons['copyright'] is an array with a single element (empty array) [ [] ] when license footer is not selected or both $wgRightsText and $wgRightsIcon are falsey. Otherwise, it's an array of arrays with content.

Change 639318 had a related patch set uploaded (by Ammarpad; owner: Ammarpad):
[mediawiki/core@master] Fix unsetting of copyright icon in FooterIcons

https://gerrit.wikimedia.org/r/639318

Change 639318 merged by jenkins-bot:
[mediawiki/core@master] Fix unsetting of copyright icon in FooterIcons

https://gerrit.wikimedia.org/r/639318

Change 639662 had a related patch set uploaded (by Ammarpad; owner: Ammarpad):
[mediawiki/core@REL1_35] Fix unsetting of copyright icon in FooterIcons

https://gerrit.wikimedia.org/r/639662

Change 639662 merged by jenkins-bot:
[mediawiki/core@REL1_35] Fix unsetting of copyright icon in FooterIcons

https://gerrit.wikimedia.org/r/639662

Ammarpad claimed this task.
Ammarpad moved this task from Blocker to Done on the MW-1.35-release board.