r44712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44711‎ | r44712 | r44713 >
Date:08:56, 17 December 2008
Author:nikerabbit
Status:ok (Comments)
Tags:
Comment:
* This can't be right
Modified paths:
  • /trunk/extensions/SelectCategory/SelectCategoryFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SelectCategory/SelectCategoryFunctions.php
@@ -107,7 +107,7 @@
108108
109109 # default sort key is page name with stripped namespace name,
110110 # otherwise sorting is ugly.
111 - if ($wgTitle->getNamespace() == "NS_MAIN") {
 111+ if ($wgTitle->getNamespace() == NS_MAIN) {
112112 $default_sortkey = "";
113113 } else {
114114 $default_sortkey = "|{{PAGENAME}}";

Comments

#Comment by Simetrical (talk | contribs)   21:02, 17 December 2008

Actually, I'm pretty sure they're equivalent, because of the magic of PHP type casting . . .

#Comment by Nikerabbit (talk | contribs)   07:32, 18 December 2008

Isn't non-empty string evaluated to true, while NS_MAIN is zero and thus false?

#Comment by Simetrical (talk | contribs)   15:51, 18 December 2008

When strings are compared to integers, the string is cast to an integer, and strings not starting with an integer evaluate to 0.

$ php -r 'var_dump( "NS_MAIN" == 0 );' bool(true)

The full gory details are in the PHP manual. Of course, (bool)"NS_MAIN" != (bool)0, but that doesn't affect "NS_MAIN" == 0. PHP doesn't care much for transitivity in this kind of thing:

$ php -r 'var_dump( "0" == false && false == "" && "" != "0" );' bool(true)

#Comment by Voice of All (talk | contribs)   22:38, 18 December 2008

Either way, the previous code was wrong and only worked by chance. "NS_CATEGORY" wouldn't far so well.

#Comment by Simetrical (talk | contribs)   23:10, 18 December 2008

Yup.

Status & tagging log