Open main menu

It would be nice to be able to dynamically link through the list of images in a category, rather than backing up to the category page itself. (This would make mediawiki a viable gallery program!)

Below are some implemenation ideas. No PHP work has been done on this topic, but a mediawiki template in conjunction with a bot can get a decent working version.

Example categoryEdit

The category "foo" used in the examples on this page contains ten images (a, b, c, ... j) and three articles (1, 2, 3).

Example syntaxEdit

Like a namespaceEdit

[[Pager:foo]]

This syntax allows parameters, so we could say [[Pager:foo|images]] to only page between images, and [[Pager:foo|articles]] for only articles (plus "all" and perhaps other restrictions on what gets paged). A big con is that it is not actually a namespace; it is one-to-one with the Category: namespace. A fix to this could be along the lines of [[Special:Pager]].

Like a templateEdit

{{pager|foo}}

This acts almost identically to the namespace suggestion, allowing further parameters.

Like a tagEdit

This syntax would allow multiple categories to be stringed together in one pager:

<pager>[[Category:foo]]</pager>

This would create a simple pager which notes the order of the articles and images listed in the category view. It presents a link to the first, previous, current, next, and last article/image in the list, perhaps looking like this:

Example pagerEdit

This is the pager that Adam Katz uses; it is positioned at the top of this document.

Implementation w/out a patchEdit

This is up live in a functional form; see http://people.ics.com/wiki/Template_talk:Pager. It uses two templates; one for pagers overall and one for each category:

Template:PagerEdit

<!-- pager template syntax: {{pager|category|first|prev|next|last}} -->
<div style="background:white;color:black;border:dashed thin gray;padding:0 1em 0 1em;position:absolute;top:1em;right:1em">
[[{{{2}}}|&lt;&lt;]]
[[{{{3}}}|&lt;]]
[[:Category:{{{1}}}|<b>{{{1}}} pager</b>]]
[[{{{4}}}|&gt;]]
[[{{{5}}}|&gt;&gt;]]
</div>

Template:Pager-fooEdit

{{pager|foo|1|{{{1}}}|{{{2}}}|:Image:J}}

UsageEdit

With my hacks, you could call this with:

{{pager-foo|:Image:C|:Image:E}}

Creating the pagers w/out a patchEdit

Creating the pager for each image is tedious; the Pywikipediabot can help, but even that is quite messy. Here's my implemenation:

echo "y" >yes     # (I don't like the 'yes' command)
export f=current
links -dump-width 300 -dump "http://wiki.bar.com/wiki/Category:foo" \
  |sed -e '/http:/!d' -e 's/^.*http.*wiki\///' |uniq >$f

# now manually edit the file
vim $f
# - remove all lines before the first entry and after the last entry
# - duplicate the first and last entries
#   (so {a, b, c} would be {a, a, b, c, c}, with each entry on its own line)

export n=2
# loop through each entry (excluding first and last)
while [ $n -lt `sed -n '$=' $f` ]
  do python replace.py \
    -page:`sed -n ${n}p $f` \
    -regex "(\]\])$" \
    "\1\n{{pager-foo|:`sed -n $((n-1))p $f`|:`sed -n $((n+1))p $f`}}" \
    <yes
  # increment counter for loop
  export n=$((n+1))
done

The python pywikipediabot replace script:

  • -page... will modify the current page (line n of our list)
  • -regex... best way I know of to only replace once (how do we just match the EOF? That would be ideal.) ... This is the stupid part; it needs exactly one link at the end of a line in the entire description.
  • "\1\n{{pager-foo|... this inserts the template on a new line, pulling the previous and next lines from our list
  • <yes... we're prompted to accept the changes. I don't like the yes command, so we created a file to feed it earlier.