Page MenuHomePhabricator

CategoryPage.php miscalculates number of articles in a three-column list
Closed, ResolvedPublic

Description

Author: rtsanev

Description:
Screenshot

I noticed that the Category Page miscalculates the number of articles when creating a three-column list. Here is an example (By the time I got it there were 9 pages in this category):
http://www.mediawiki.org/wiki/Category:ArticleDelete_extensions
Attached is also a screenshot.
I noticed that this only happens when then number of articles divided by 3 has no remainder - like 9, 12, 27 and etc. I guess when we have 9 articles we expect to have 3 in each column. Instead in the example you can see that we have 3 in column 1, 4 in column 2 and 2 in column 3.
When number of articles divided by 3 return a remainder the columns appears to be created proportionally.
I looked in to the code and will suggest the following code change:
Page - includes/CategoryPage.php, line 374:

// loop through the chunks
for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;

$chunkIndex < 3;
$chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1)

to be changed to (the last line only is different)
// loop through the chunks
for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;

$chunkIndex < 3;
$chunkIndex++, $startChunk = $endChunk, $endChunk += count($articles) % 3 == 0 ? $chunk : $chunk + 1)

I've did some testing and the patch appears to be working. Not sure however if this code change can have other implications.

Thanks
Rado Tsanev


Version: unspecified
Severity: enhancement

Attached:

category.png (484×1 px, 14 KB)

Details

Reference
bz18449

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:35 PM
bzimport set Reference to bz18449.
bzimport added a subscriber: Unknown Object (MLST).