User "Krinkle" posted a comment on MediaWiki.r96188.

Full URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96188#c21854
Commit summary:

Expand r96170's support for space separated attributes with support for boolean 
keys such as array( 'class' => array( 'selected' => true ) ) to match our 
array( 'checked' => false ) support.
As per discussion with Krinkle make sure that in array( 'foo', 'foo' => false, 
'foo' ) the 'foo' key is authoritive.

Comment:

So, to repeat the example Dantman gave on IRC:
<pre>
$isSelected = someFunc();
Html::element( 'input', array(
  'selected' => $isSelected
) );

Html::element( 'div', array(
  'id' => 'mw-foo-wrapper',
  'class' => array( 'foo', 'bar', 'baz' =>hasBar()
) );
</pre>

And another great use case:
<pre>
public function getFooAttr(){
 return array(
  'class' => array( 'foo', 'bar', baz' )
 );
}

public function getFooAttr(){
 $attribs = parent::getFooAttr();
 $attribs['id'] = 'mw-my-foo';
 $attribs['class'][] = 'my-foo';
 $attribs['class']['foo'] = false;
 return $attribs;
}
</pre>
being able to set to false like that makes code a lot more readable and easy. 
No need to do multiple array_search'es followed by unset to remove all 
occurences of value 'foo', just set foo to false and it will not be outputted.

We'll need unit tests for this functionality

_______________________________________________
MediaWiki-CodeReview mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview

Reply via email to