On Fri, Sep 24, 2010 at 2:12 PM, David Raison wrote:
I've been working on this extension that generates
qrcode bitmaps and
displays them on a wiki page [0].
Hi David! I've actually been peeking at this extension as I'd like to use
something like this to generate scannable QR codes with Android software
download links for other projects. :)
1. QrCodes are generated for pages that do not have or
transclude a
{{#qrcode:}} function call, in this case properties [2,3,4].
I haven't fully traced out the execution, but I do notice a few things in
the code that look suspicious.
It looks like you're naming the destination file based on the wiki page that
has the {{#qrcode}} in it by pulling $wgTitle:
// Use this page's title as part of the filename (Also regenerates
qrcodes when the label changes).
$this->_dstFileName =
'QR-'.$wgTitle->getDBKey().$append.'.png';
This might be the cause of some of your problems here... background jobs may
run re-parses of other seemingly unconnected wiki pages during a request,
and other fun things where $wgTitle isn't what you expect, and that might be
one cause of it triggering with an unexpected title. You may find that it's
more reliable to use $parser->getTitle(), which should definitely return the
title for the page being actively parsed.
More generally, using the calling page's title means that you can't easily
put multiple codes on a single page, and the same code used on different
pages will get copied unnecessarily.
I'd recommend naming the file using a hash of the properties used to
generate the image, instead of naming it for the using page. This will make
your code a bit more independent of where it gets called from, and will let
you both put multiple code images on one page and let common images be
shared among multiple pages.
One potential problem is garbage collection: a code that gets generated and
used, then removed and not used again will still have been loaded into the
system. This is an existing problem with things like the texvc math system,
but is a bit more visible here because the images appear in the local
uploads area within the wiki. (However they'll be deletable by admins, so
not too awful!)
6. Looking at the database, the mixup hypothesis is confirmed:
SELECT page_id,page_title,cl_sortkey FROM `page` INNER JOIN
`categorylinks` FORCE INDEX (cl_sortkey) ON ((cl_from = page_id)) LEFT
JOIN `category` ON ((cat_title = page_title AND page_namespace = 14))
WHERE (1 = 1) AND cl_to = 'Project' ORDER BY cl_sortkey
gives (among other data):
page_id page_title cl_sortkey
1403 SMS2Space File:QR-Ask.png
1244 Syn2Sat File:QR-LetzHack.png
1251 ChillyChill File:QR-Syn2cat-radio-ara.png.png
It's possible that the internal uploading process interferes with global
parsing state when it generates and saves the description page for the wiki;
if so, fixing that may require jumping through some interesting hoops. :)
-- brion