FactoryJoe recently asked me about theming the pager. Looking at the code, I decided it was way too much uncommented voodoo. So here's the cleanup patch.
The biggest change is that before this patch, the pager would count items. When there are 5 items per page, the urls would go from=0, from=5, from=10, etc. The code also handled in between values, e.g. from=2 or from=13. IMO this 'in between' feature is useless (you can only use it by typing in the url yourself, and once you do the pager remembers the in-page offset) and it complicates the code.
Instead of this, I made the pager count page numbers. 'from' is simply an integer per pager: 0, 1, 2, 3... This makes the code simpler. I also commented it some more, and cleaned up some inconsistencies in the code. Finally, the code had a lot of (int) casts in it. Most of these were unnecessary as the variable was either the result of a calculation, or used in a calculation. I got rid of those that had no effect.
Functionally, nothing changes except the meaning of "from" in the pager URLs. I hardly think anyone would link to a specific pager page.
Comment | File | Size | Author |
---|---|---|---|
pager_1.patch | 20.22 KB | Steven | |
Comments
Comment #1
kbahey CreditAttribution: kbahey commentedNot humans perhaps, but search engines would for sure.
Now this will cause 404.
This does not mean I am against the change. It makes sense. Just pointing out a potential consequence.
Comment #2
Steven CreditAttribution: Steven commentedI'm not sure what you mean... a search engine can simply spider out the new indices like any other page change.
In fact, now the from numbers are sequential, a really smart search engine might take advantage of that ;).
Comment #3
kbahey CreditAttribution: kbahey commentedWhat I mean is that sites will already have from=25, from=50, ...etc. indexed in Google and other search engines. So these pages are bookmarked in a way, though not by humans.
These will now give a 404 (at least some of them) if someone clicks on the old links.
Comment #4
Eric Scouten CreditAttribution: Eric Scouten commentedThat's probably not a major concern. Such search links are pretty fragile anyway, since new items will invariably get posted and push older items down the list and onto the next ?from= batch.
I wonder if there's a way to discourage Google from scanning the search pages, but still following the links on those pages.
Comment #5
Steven CreditAttribution: Steven commentedActually, old links will continue to work partially. Part of my cleanup patch was ensuring you cannot go beyond the last or before the first page due to such bad links. If you use a value of from= that is too large, you end up on the last page.
Comment #6
Bèr Kessels CreditAttribution: Bèr Kessels commentedcan we not add a few lines to legacy.module?
I suggtest something like: if the from value is larger then the amount of pages, then translate it yo a new version.
in psuedocode:
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedSteven - I have noticed that the pager will issue a query if if its COUNT query found 0 rows. Seems like we could optimize out the 2nd query, no? This is a long standing issue, unrelated to your patch. But as long as you are there ...
Comment #8
Dries CreditAttribution: Dries commentedIMO, we don't need a legacy handler for this. You can't install one in the legacy.module because the from-parameter is not part of $_GET['q']. Because most (if not all) pages with pagers show content in reverse chronological order, it is very unlikely that they are used as permanent links.
Additional comments:
from
means 'page number', why don't we rename it topage
? It makes for a better URL scheme and improves readability of the code. Something to consider.UnConeD: I'm not committing this patch because you might want to respond, and revise it once more based on people's comments. Either way, I'm OK with the patch as is so feel free to commit once you think it is ready.
Comment #9
Junyor CreditAttribution: Junyor commentedCouldn't 'from' be from the first post, rather than the latest? I thought that was one of the problems with the existing pager. And it would once and for all solve problems with search engine results.
Comment #10
Steven CreditAttribution: Steven commentedJunyor: adding such logic to the pager would complicate the code a lot. The goal of this patch was to simplify the code.
As has been pointed out, there are no real problems with renumbering the pager. Search engines will spider them out, manual links can be corrected (but they will continue to point to the last page if they go beyond the end).
+1 on this patch going in as is.
Comment #11
Steven CreditAttribution: Steven commentedDries: fixed the comments and used page instead of from, it makes more sense indeed ;).
Committed to HEAD.
Comment #12
Steven CreditAttribution: Steven commentedBy the way moshe: I couldn't get rid of the useless query when there are 0 items, because pager_query() has to return a vaild result. Perhaps we could replace it with a dummy query which has no rows? Not sure how that would be done though.
Comment #13
(not verified) CreditAttribution: commented