Drupal Pagination

I've put my Pagination (Node) module up on drupal, and am looking to tackle two issues/features associated with it.

1 based paging

Currently, drupal pagination is 0 based, in that the URL will show "?page=1" for the link to page 2, "?page=2" for page 3, and etc. In the greater scheme of life, liberty, apple pie, and hockey, it's a pretty minor point, but it seems odd that the paging scheme ends up being "incorrect".

Drupal provides a number of hooks to access the data, and the trick is figuring out the best way handle it. The main stumbling block is that the paging functions include a number of random globals, and it's difficult to insert and alter the data at key points to ensure the pagination is calculated properly, and becomes 1 based at the end.

I'm currently leaning towards taking the data at a point after the internal pagination functions have dealt with it.

The other issue is, although the module relies on drupal pagination, it does not alter how other pagers work. In that sense, you could end up with the default pagination (ie, a list of blog entries) being 0 based, and the pagination provided by Pagination (Node) being 1 based.

It seems the choices we have are:

  • Leave it alone, maybe drupal 7 will update to 1 based pagination
  • Alter pagination for this module, making inconsistent paging schemes (0 based for pagination not related to this module)
  • Have an option to convert all pagination to 1 based

At first I was leaning towards option #3, but I have a feeling most people would be happy enough with option #2, and not too worried about the inconsistency.

Clean URL's

You may have noticed that, despite your clean URL's setting, pagination still uses the query string "/node/25?page=2", instead of something like "/node/25/2" There is a module that will convert pagination, however it's still a dev release, and drupal 5.

I took a brief look at how it works, but I don't think it will be easy to duplicate the functionality in this module.

The other major issue is sites which use drupal's Path module, which allows users to declare URL aliases for their content (ie "/node/25" becomes "/much-friendlier-name". Clean pagination fails on these resources (drupal can't map "/much-friendlier-name/2", and returns a 404 not found instead).

The potential solution I'm looking at is to use hashes in the URL, such that "/node/25?page2" becomes "/node/25/#page2" or similar. This method works (as the hash is not considered part of the URL to parse for drupal), however, introduces another problem, being the misuse of the hash.

Ultimately, it's a semantics issue, but despite my reservations, I think it may be the best way to offer this functionality. For those who are interested in the more esoteric arguments for or against hashes, w3c has an ongoing draft analyzing it's use.

The options for clean URL's seem to be:

  • Wait for drupal to see if there's a better solution
  • Respect drupal clean URL settings (will break Path aliased nodes)
  • Use a hash in the URL

Right now I'm leaning towards option #3, it seems like the w3c is realizing people use the hash in a manner inconsistent with it's original intent. It's unlikely that the naming scheme "#page2" will interfere with markers in a page.

I'd appreciate your feedback on the choices, please leave a comment here or on the project page.