Using PHP and MySQL, I am integrating a site with a wiki based on MediaWiki, so that profiles of users in the site have some stats about their contributions in the wiki.
I want to show the last 3 edited articles of a user in a namespace (the main one, id 0), without repeating, and the links to them.
In order to do that, I do more or less the following:
// getting the article IDs
$db->query("SELECT DISTINCT rev_page
FROM revision r, page p
WHERE r.rev_page = p.page_id
AND p.page_namespace = 0
AND rev_user = {$userId}
ORDER BY r.rev_timestamp DESC
LIMIT 3");
// then the IDs are stored in $last_edited_ids...
// getting the names of the articles
$db->query("SELECT page_title
FROM page WHERE page_id
IN (" . implode($last_edited_ids, ',') . ")");
The problem is that I am not sure it is correct, although it works most of the time: for some users, an old article shows as the last edited, but the 2nd and 3rd result are correct. That makes me thing I must be doing something wrong, but SQL is not my strong point...
Tip: if you don't know the MediaWiki database scheme (it is rather autoexplicative), you can have a look to it here.