Author: gregab
Description:
Hello, all,
I was recently installing MW at a site after a long time again.
Platform: CentOS
MediaWiki: 1.15.1
Database: PostgreSQL 8.1.11
While configuring it, it choke when I set $wgMaxCredits to 3 in LocalSettings.php. The exact error is attached below.
The PostgreSQL error message made it apparent immediately that GROUP BY was not going to be the thing to solve what getCredits() was supposed to do, so I fixed the query to use DISTINCT ON. Here's the patch:
$hideBit = Revision::DELETED_USER; // username hidden?
- $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp
+ $sql = "SELECT
+ DISTINCT ON (user_id)
+ {$userTable}.*,
+ rev_timestamp as timestamp
FROM $revTable LEFT JOIN $userTable ON rev_user = user_id WHERE rev_page = $pageId AND rev_user != $user AND rev_deleted & $hideBit = 0
- GROUP BY rev_user, rev_user_text, user_real_name
- ORDER BY timestamp DESC";
+ ORDER BY user_id, timestamp DESC";
if($limit > 0) { $sql .= ' LIMIT '.$limit; } if($offset > 0) { $sql .= ' OFFSET '.$offset; }
The sad thing is, it won't work with MySQL, of course, and I have no idea on how you MW guys circumvent such stuff.
This is the original error message:
A database error has occurred
Query: SELECT mwuser.*, MAX(rev_timestamp) as timestamp
FROM revision LEFT JOIN mwuser ON rev_user = user_id
WHERE rev_page = 6
AND rev_user != 2
AND rev_deleted & 4 = 0
GROUP BY rev_user, rev_user_text, user_real_name
ORDER BY timestamp DESC
Function: Article::getContributors
Error: 1 ERROR: column "mwuser.user_id" must appear in the GROUP BY clause or be used in an aggregate function
Backtrace:
#0 /var/www/wiki/includes/db/Database.php(616): DatabasePostgres->reportQueryError('ERROR: column ...', 1, 'SELECT mwuser.*...', 'Article::getCon...', false)
#1 /var/www/wiki/includes/Article.php(715): Database->query('SELECT mwuser.*...', 'Article::getCon...')
#2 /var/www/wiki/includes/Credits.php(103): Article->getContributors()
#3 /var/www/wiki/includes/Credits.php(65): Credits::getContributors(Object(Article), 2, true)
#4 /var/www/wiki/includes/SkinTemplate.php(371): Credits::getCredits(Object(Article), 3, true)
#5 /var/www/wiki/includes/OutputPage.php(968): SkinTemplate->outputPage(Object(OutputPage))
#6 /var/www/wiki/includes/Wiki.php(345): OutputPage->output()
#7 /var/www/wiki/index.php(117): MediaWiki->finalCleanup(Array, Object(OutputPage))
#8 {main}
Version: 1.20.x
Severity: major