Last modified: 2011-11-12 10:22:44 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T33829, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 31829 - New format "count".
New format "count".
Status: VERIFIED FIXED
Product: MediaWiki extensions
Classification: Unclassified
SubPageList (Other open bugs)
unspecified
All All
: Unprioritized enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-reviewed
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-19 20:17 UTC by Van de Bugger
Modified: 2011-11-12 10:22 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
A patch, implementation of format `count'. (2.46 KB, patch)
2011-10-19 20:17 UTC, Van de Bugger
Details
Version 2, not yet production. (13.18 KB, patch)
2011-10-21 19:23 UTC, Van de Bugger
Details
Version 3. (11.67 KB, patch)
2011-10-21 21:09 UTC, Van de Bugger
Details
Version 3, all the files. (38.19 KB, application/x-tar)
2011-10-21 22:13 UTC, Van de Bugger
Details

Description Van de Bugger 2011-10-19 20:17:58 UTC
Created attachment 9254 [details]
A patch, implementation of format `count'.

This is an implementation of format "count" for extension SubPageList:

{{ #subpages: Page | format = count }}

returns number of subpages as a plain text, suitable for using in `#ifeq' and `#ifexpr' functions, for example:

{{ #ifexpr: {{ #subpages: Page | format = count }} > 0 
| <!-- There are subpages. -->
| <!-- There is no subpages. -->
}}

Note that tricks with other formats will *not* work:

{{ #if: {{ #subpages: Page | format = list }} 
| <!-- Always occurs. -->
| <!-- Never occurs. -->
}}

Result of `#subpages' (with non-`count' format) is never empty, even if there are no subpages.

Another example: Let us assume template `x' unconditionally returns `x', so 

{{ #subpages: Page | format = template | template = x }}

we hope result of construct will be character `x' repeated as many times as subpages we have. But this does not work. Result of `#subpages' looks like `x...x' but it cannot be used in function `#if': 

{{ #ifeq: {{ #subpages: Page | format = template | template = x }} | x
| <!-- Never occurs. -->
| <!-- Always occurs. -->
}}

Format `count' is inspired by extension SemanticMediaWiki.

Possible improvements: 

Currently `intro', `outro' and other parameters are ignored if format is `count'. They could be implemented (later).
Comment 1 Jeroen De Dauw 2011-10-19 20:44:10 UTC
Well, I agree it's nice to just get the number of pages, but that's not what this parser functions is intended for, so I don't think it's a good idea to go hack it in like this. A new parser function, such as #subpagecount or whatever would be more appropriate, and could make use of just doing a count query rather then selecting pages without introducing some very ugly format dependent handling.

Let me know if you need more pointers on how to do that :)

You have commit access right?
Comment 2 Van de Bugger 2011-10-19 21:34:29 UTC
Hmmm... I said the function is inspired by `{{ #ask: … | format=count }}'. Why `ask' is intended for counting but `#subpages' is not? I see some advantages of format `count':

1. It utilizes similarity with the function `#ask': both functions recognize  `intro', `outro', `default', `format' parameters.

2. No need on one more class => file, couple of hooks, etc. 

Regarding the db query… There is a comment in the code:

    // TODO: Can `getSubPages' be optimized for format `count'?"

I think one more `if' in `getSubPages' is better than duplicating much of the infrastructure, including content of `getSubPages'.

However, I will not insist on this approach. You are the master, you decide.

> You have commit access right?

Not yet. I requested it and received an answer, but something does not work. I need some time to get it really working.
Comment 3 Jeroen De Dauw 2011-10-19 21:49:29 UTC
I'm actually not convinced that having format=count in ask is the best thing to do either. There is more reason to do that in ask then in subpages though, since the query parsing part of the code is significant and the same in both situations.

For subpages, getting the count just needs a count query which gets directly returned. If you want a list, the query needs to select the actual pages with some limit, which then need to be formatted in some way. So you have not only a different query, but also something different that's returned (a number vs a list). Furthermore I think you do not need the intro and outro params for numbers, you can just put them in between whatever you want.

So in my eyes it's completely different code, not the same.
Comment 4 Van de Bugger 2011-10-21 19:23:32 UTC
Created attachment 9265 [details]
Version 2, not yet production.

Ok, this is the attempt № 2.

1. Function `#subpagecount' is implemented.

2. Common code of `#subpages' and `#subpagecount' are moved to class `SubPageBase'. (BTW, probably we have to use a prefix for class names, like 'splSubPageList', `splSubPageCount', `splSubPageBase'.)

3. Implemented correct handling of namespaces where subpages are not enabled.

4. There is a problem: My original though was that $dbr->estimateRowCount is the right way to go. However, in my local MediaWiki server it produces strange results. It returns bigger count than I expect. Looks like it always returns number of subpages, direct and indirect, regardless of parameter `kidsonly'. However, code borrowed from `Database.php', works well, while code borrowed from `DatabaseNysql.php', returns that wrong result. (My server runs MySQL, so I think `wfGetDB' returns an instance of class `DatabaseMysql'.) Please look. Implementation of the query may be selected by parameter `method':

{{ #subpagecount: page | method=mysql }}
Comment 5 Van de Bugger 2011-10-21 19:30:43 UTC
BTW, class `Title' contains method `getSubpages' which returns list of all subpages. Don't you think to tune it for SubPageList's needs? It seems parameters `sort' and `kidsonly' can be easily added...
Comment 6 Jeroen De Dauw 2011-10-21 19:40:38 UTC
estimateRowCount is not accurate, it's just an estimation that can be off a lot. The code you copied with COUNT(*) is the way to go, and ought to work with most SQL DBs. I think having a method param that switched the db code is very odd. If you need different behavior for different types of DBs, switch on $wgDBtype.

An prefix is best yes. I don't think it ought to be SPL though. 'SubPage' also works, and results in nicer class names. Well, you'd not even need to change them I guess :p
Comment 7 Jeroen De Dauw 2011-10-21 19:41:28 UTC
(In reply to comment #5)
> BTW, class `Title' contains method `getSubpages' which returns list of all
> subpages. Don't you think to tune it for SubPageList's needs? It seems
> parameters `sort' and `kidsonly' can be easily added...

Then SubPageList would require the new MW, which would be 1.19. Better to just have an extended copy of the code in the extension itself.
Comment 8 Van de Bugger 2011-10-21 20:46:12 UTC
> estimateRowCount is not accurate,
> The code you copied with COUNT(*) is the way to go,

?? Do not understand. The code I copied *is* the code of `estimateRowCount' from class `Database'.

> I think having a method param that switched the db code is very
odd.

I wrote in the comments that it is not a production code. I added it just to see the difference between different implementations. Of course parameter should be removed, and only one implementation should remain.

So, you think code

$res = $dbr->select( 'page', 'COUNT(*) AS rowcount', $conds, __METHOD__ );

will work everywhere? I will drop other variants then.
Comment 9 Van de Bugger 2011-10-21 21:09:24 UTC
Created attachment 9267 [details]
Version 3.

The third version. Temporary code removed.
Comment 10 Jeroen De Dauw 2011-10-21 21:54:14 UTC
Ok, looks fine. Can you just provide a copy of the modified files (ie trunk with this patch applied)? Merge is not going smoothly for me :/
Comment 11 Van de Bugger 2011-10-21 22:13:28 UTC
Created attachment 9268 [details]
Version 3, all the files.

Sure.
Comment 12 Mark A. Hershberger 2011-10-26 01:41:27 UTC
-need-review, +reviewed
Comment 13 Jeroen De Dauw 2011-10-26 01:47:53 UTC
Applied in r100468
Comment 14 Van de Bugger 2011-11-12 10:22:44 UTC
Verified on r102853.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links