r92261 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92260‎ | r92261 | r92262 >
Date:18:10, 15 July 2011
Author:krinkle
Status:reverted (Comments)
Tags:
Comment:
Add boolean inArray utility
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.util.js
@@ -109,6 +109,17 @@
110110 /* Main body */
111111
112112 /**
 113+ * Wether a value is in an array. Using jQuery's inArray cross-browser utility,
 114+ * (for browsers without Array indexOf support).
 115+ * @param val {Mixed} Needle
 116+ * @param arr {Array} Haystack
 117+ * @return Boolean
 118+ */
 119+ 'inArray' : function( val, arr ) {
 120+ return $.inArray( val, arr ) !== -1;
 121+ },
 122+
 123+ /**
113124 * Encode the string like PHP's rawurlencode
114125 *
115126 * @param str string String to be encoded

Follow-up revisions

RevisionCommit summaryAuthorDate
r92752Remove mw.util.inArray...krinkle16:41, 21 July 2011

Comments

#Comment by Yair rand (talk | contribs)   12:37, 17 July 2011

(I'm not sure if this is the right place to add this comment, but...) I really think this function is a bad idea. mw.util.inArray() is not shorter than $.inArray()!=-1, and including a function with the same name as one in a well-known Javascript library that does something different is very likely to cause confusion.

#Comment by Platonides (talk | contribs)   12:52, 17 July 2011

This mimics PHP in_array() function, but Yair is right in that mw.util.inArray() looks ugly. If the goal is to have the same interface as php, we could place it on a different namespace, such as having mw.php.rawurlencode() and mw.php.in_array()

PS: The comment should read 'Whether'

Status & tagging log