You have two problems. The first is that you forgot to specify that \WWW takes an optional argument, for which you'd need [2][] rather than just [2] (with the second [] specifying the empty default); the second problem is that you need to group \ifthenelse, but not its arguments. (I think the problem is that when \ifthenelse expands, it doesn't introduce a group, and so the wrong token is being grabbed.) Also, on the "just my opinion" side of things, if this is just for Wikipedia links, I'd probably call it \wiki instead. Anyway, putting that together yields
\documentclass{article}
\usepackage{ifthen}
\usepackage{hyperref}
\newcommand*{\wiki}[2][]{\href{http://en.wikipedia.org/wiki/#2}%
{\ifthenelse{\equal{#1}{}}{#2}{#1}}}
\begin{document}
The Wikipedia article about \wiki[the metasyntactic variable foobar]{Foobar}
is shorter than the one about \wiki{Einstein}.
\end{document}
(Also, note that this doesn't necessarily play well with Wikipedia's underscore-for-space convention, though that's certainly fixable.)
Edit 1: Actually, if you use the xstring package, it's very easy to take care of underscores automatically. This revised command will automatically replace all spaces in its argument with underscores, so you don't have to. If you still want a different title, you can provide it. So
\documentclass{article}
\usepackage{ifthen}
\usepackage{hyperref}
\usepackage{xstring}
\makeatletter
\newcommand*{\wiki}[2][]{%
\StrSubstitute{#2}{ }{_}[\wiki@article]%
\href{http://en.wikipedia.org/wiki/\wiki@article}%
{\ifthenelse{\equal{#1}{}}{#2}{#1}}}
\makeatother
\begin{document}
The Wikipedia article about \wiki[the metasyntactic variable foobar]{Foobar}
is shorter than the one about \wiki{Albert Einstein} or the one about \wiki[the
creator of \TeX]{Donald Knuth}.
\end{document}
renders as
The Wikipedia article about the metasyntactic variable foobar is shorter than the one about Albert Einstein or the one about the creator of TeX.
xstringpackage; see my edit. And most other special characters aren't problematic: if you specify e.g.\wiki{Boyle's law}, then you'll get linked to http://en.wikipedia.org/wiki/Boyle's_law, which is a perfectly valid URL. – Antal Spector-Zabusky Oct 15 '10 at 17:58xstringseems to do exactly the job I want it to do. Thanks a lot for your answer. – qbi Oct 15 '10 at 18:11