meta/LPAR

Thinking inside the Big Blue box.

WordPress OpenID problems

Scenario:

You are using WordPress with OpenID, using the openid plugin.

Symptom:

You get an error page looking something like

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/meta/public_html/lpar/wp-includes/formatting.php on line 2822

when users try to log in.

Diagnosis:

You can patch the appropriate code in formatting.php so that it actually reports the error:

function wp_strip_all_tags($string, $remove_breaks = false) {
$string = preg_replace( '@<(script|style)[^>]*?>.*?@si', '', $string );
$string = strip_tags($string);
if ( $remove_breaks )
$string = preg_replace('/[\r\n\t ]+/', ' ', $string);
return trim($string);
}

You then get a useful error in error_log:

[28-Apr-2011 08:54:18] [OpenID] User was created fine, but wp_login() for the new user failed. This is probably a bug.

No, really?

Anyhow, it turns out that the problem is caused by previous OpenID plugins or user registrations resulting in user entries with no e-mail address. For whatever reason, WordPress now seems to require one, and user creation and login falls over if there are any users without one. I discovered this by reading a topic at the WordPress support forums.

The obvious fix is to delete all the users who have no e-mail address, using the standard WordPress interface. However, what if you have users with no e-mail address whose comments you want to keep? Well, my suggestion in that case would be to insert a dummy e-mail address in the appropriate records:

UPDATE wp_users SET user_email = 'suckweasel@example.com' WHERE user_email = ''

It’s probably possible to patch the appropriate WordPress code to not fall over on missing e-mail addresses, but since there could be any number of other bits of WordPress code that are similarly lacking in resilience, it’s probably better to clean up the user database.

Posted by meta on 2011-04-28 | Posted in Standards | Tagged , | Comment

JavaScript modulus weirdness

I just became aware of an interesting JavaScript ‘feature’. The code

y = x % 1;

is equivalent to

y = x - Math.floor(x);

because ECMA-262 says:

… the floating-point remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n − (d * q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d.

So if d is 1 then q is the largest integer that’s smaller than n/1, so r = n – Math.floor(n).

I will not be using this feature in my code.

Posted by meta on 2011-04-27 | Posted in JavaScript | Tagged | 2 Comments

Why TeX?

Recently someone on Stack Exchange asked Why are there no alternatives to TeX, or, why is TeX still used?

Here are some reasons.

  • It works.

    It sounds trite, but TeX has a robustness and reliability that other software lacks. Recently, there was a discussion of a bug in LuaTeX triggered when a document hits 3,987 pages. I can’t imagine creating a document with over 1,000 complex pages using something like Microsoft Word or OpenOffice Writer.

  • It’s predictable.

    If you’ve ever wondered why your word processor is formatting something a particular way, well, sometimes there’s really no way to answer the question. Microsoft’s OOXML spec resorted to defining many aspects of formatting by saying that they had to be the same as particular versions of Word; even Microsoft couldn’t specify what that behavior actually was. Pro typesetting software like Adobe InDesign isn’t much better when it comes to maintaining compatibility between versions.

    With TeX, there are fewer ghosts in the machine. Even if the details underneath are pretty scary, at least you can always see exactly what macros you are applying to a piece of text and what parameters you have tweaked. Nothing is hidden, and there’s more of a feeling of being in control.

  • It keeps working.

    I’ve used a lot of word processors over the years. Wordwise, View, LocoScript, 1st Word Plus, MacWrite, WordStar, WordPerfect, AppleWorks, DisplayWrite, Word Pro, ClarisWorks… They’re all dead and gone now. Good luck reading any files you still have stored in their special file formats. In fact, there have been discussions on Macintouch recently about the problems of converting a large number of legacy ClarisWorks documents into something readable, and that product was only declared end-of-life in 2007. Yet if I still had a copy of my dissertation, I could typeset and print it today, because I wrote it in TeX.

    ConTeXt is the newest and most rapidly changing TeX macro package. Even so, switching from a 2 year old version to today’s bleeding-edge beta is mostly a non-event.

  • It runs everywhere.

    Using TeX, I can produce finished documents on Mac, Windows, Linux, or any Unix-like OS. I don’t need a high-end CPU, I don’t even need a high resolution display.

  • You can edit it using whatever tool you prefer.

    TeX files are just UTF-8 text files. Edit them with TextWrangler, vim, Emacs, jEdit, pretty much any text editor you want. It helps to have syntax highlighting, but it’s not essential.

    Edit on your laptop, on someone else’s laptop, on a tablet, on your phone. Anywhere there’s a text editor.

    Put your documents in version control. They’re just text, so you can diff them. They’re small and compress really well, so you can keep every version forever and not run out of space. Store them on a remote server and edit via SSH. Transfer them in a fraction of a second across a modern network connection.

  • It’s cheap.

    I use the word ‘cheap’ rather than ‘free’ because really, I’m not at all averse to paying for software. However, my budget is limited.

    There are some solid proprietary page layout systems that can deal robustly with large documents. Adobe FrameMaker, for example. MSRP for that is $999. If you want something a bit cheaper, there’s InDesign, for $699. Both are a bit pricey for my liking.

    Or there’s TeX, which is where FrameMaker got its typesetting algorithms from anyway. Cost: $0. I think it’s something of a bargain.

  • It gets out of the way.

    Recently, a lot of writers have been discovering the joy of ultra-minimalistic tools which get out of the way and let you focus on the actual writing. There are programs like WriteRoom, DarkRoom, jDarkRoom, Byword, OmmWriter, and so on, which attempt to remove distractions and give you just text on an otherwise empty screen. Then there are tools like Markdown, reStructuredText and wiki syntax, markup languages which allow you to edit plain text with minimal annotations and convert it into something with pretty formatting later on.

    All of these tools are rediscovering something that was lost when we moved from word processors like WordPerfect, which used plain text with embedded formatting commands, and entered the WYSIWYG world of the 90s with its endless buttons, sliders, ribbons and rulers.

    Being a markup language, TeX has that minimalist essence. It’s just text.

  • It’s extensible, on the fly.

    Sometimes I’m writing some documentation, and I suddenly realize I’ll have to repeatedly refer to some kind of thing–a set of menu entries, say–and format them in a special way throughout the text.

    In a normal word processor, I stop writing. I decide whether I need a paragraph style or a text style. I decide what existing style it needs to be based on. I click around to create my new style and give it a name. I adjust its formatting to be distinctive so I can see what I’m editing. I map it to a key. And then I try to remember what I was about to write before my multi-minute jaunt into wordprocessorland.

    In TeX, I make up an imaginary macro off the top of my head–{\Menu File – Quit}–and keep on writing. After I’m done writing whatever was in my head, then I worry about extraneous details such as how it’ll look on the page and whether it needs to be based on the look of anything else. Even if I decide I need a more elaborate calling pattern–say, if the macro needs some arguments–it doesn’t matter, because the plain text nature of my made-up-on-the-spot macro makes it easy to find and replace.

  • Obviously, actually applying the formatting is harder than with a word processor. But once I’ve done it once, I can re-use that magic incantation endlessly.

  • It handles vector art properly.

    One place a surprising number of word processors fall down is incorporating images into the text. Somehow it seems to be acceptable to offer fonts that are infinitely scalable vectors, and then fail to offer any reliable way to insert and adjust a vector diagram. Want to bring your process diagram into OpenOffice? Sorry, can’t read the SVG, why don’t you just draw it again with the horrible OpenOffice Draw?

    In business, it’s not at all unusual to receive documents that have diagrams as horrible resized bitmaps, or tables as embedded objects that look like crap, for pretty much this reason.

    With TeX, I can use any vector graphics tool I like, and there’s almost always a way to get PDF out–either directly, or via a print-to-PDF driver. Once I have PDF, it’s painless to place it onto the page as vectors. So like everything else, it scales correctly for the display. The only things in my documents that end up as ugly bitmaps are the screen captures, and that’s the way it should be.

    There are more reasons if you’re a mathematician or scientist. I’m just listing reasons why a person who wants to write ordinary everyday business and personal documents might choose to use TeX to do so.

    Nevertheless, I would absolutely use something more modern that met the same basic requirements. If you know of a word processor that runs on any modern computer, can deal with 5,000 page documents, imports vector art in standard formats and handles it in vector form, writes to tagged PDF with working hyperlinks, is guaranteed to be around and supported for the next 40 years, will let me edit without having to learn a new user interface or have anything but my text on the screen, has output the quality of FrameMaker or InDesign, is arbitrarily extensible, and costs under $100, do please let me know.

  • Posted by meta on 2011-04-05 | Posted in Business, Standards | Comment

    The Google Event Horizon

    Yesterday I ran into a familiar SSL problem. I learned that a Sun engineer named Andreas Sterbenz had written a handy utility to solve the problem, and posted it on his Sun blog.

    I looked to see what else he had posted. The last entry mentioned that he had jumped ship to Google, and pointed at his new Google blog. Go look at it, it’s pretty typical of a Google employee blog.

    Not every new employee takes the hint. Sometimes they get fired as a result.

    It’s known as the Google Vortex or Google Black Hole, and it affects products as well as people. Things pass through the event horizon in Mountain View, and you never hear from them again.

    There’s something deeply ironic about it. Google is, after all, a company that just got slapped by the FTC and fined in France for not protecting privacy. If it’s your information, well, information wants to be free, right? But if it’s information about what the Google cafeteria is like or what the working hours are at Google, ironclad secrecy applies. You can’t even tell people that you’ve signed an NDA saying you can’t tell them anything.

    Microsoft has a reputation for paranoia, but you see far more open commentary from Microsoft developers than you do from Google employees. Can you imagine a Google developer writing publicly about the internal limits of Google algorithms? Microsoft lets developers write that kind of stuff. Apple is notoriously secretive too, but get on the developer mailing lists and you’ll find helpful Apple employees actually answering questions. The only other Google-like situation I can think of was the person I knew who got a job at GCHQ, the UK’s equivalent of the NSA. Obviously that’s all I ever learned about that. But speaking of the NSA, I wonder if they have cheese and wine parties with their Google friends and laugh about who has the more restrictive employment contract?

    Obviously IBM is rather different from Google as well. I actually started this work blog because IBM encouraged me to do so. Big Blue has some guidelines for public blogging, of course; if you want, you can go and read them, because they’re public too. How weird is that, eh? Obviously IBM got on the cluetrain. Google has not yet done so.

    I can’t help thinking about the USA vs the Soviet Union during the Cold War. It’s widely viewed that the culture of secrecy in the USSR held back their scientific progress. So far Google has managed to entice enough smart people to move behind the iron curtain that they’ve kept ahead–but then, the Soviet Union managed to entice a few defectors in the early days too. Ted Nelson’s “Computer Lib” contained this anonymous quote:

    “IBM is run by and for people who really believe in authority. IBM is, to my way of thinking, the way the Soviet Union would be if the Soviet Union worked.”

    If there’s ever a third revised edition of Computer Lib, I can’t wait to see what it says about Google.

    (Oh, and Ted, if you ever happen to see this: I’d love to help you put together a complete web edition of Computer Lib. I know you’re not keen on the web because of its limitations, but Computer Lib and Dream Machines are important historical documents that ought to be preserved and made available to the public, and even a read-only hypertext copy would be a good start. People could at least easily link to it and comment on it then, and spread the ideas.)

    Posted by meta on 2011-04-01 | Posted in Business, Culture | Comment