I'm interested in adding the ability to generate files via Scribunto. The first major decision that we need to make is how we'd use these files from a wiki page. I talked with TimStarling and Carmela on IRC about this, and here's some of the ideas we came up with:
1. [[File:Module:Foo|bar=baz|width=200px]] - Module:Foo gets called to generate the file 2. [[DynamicFile:Foo|bar=baz|width=200px]] - Module:DynamicFile/Foo gets called to generate the file 3. [[File:Any file that doesn't exist.svg|bar=baz|width=200px]] - Module:FileHandlers/Any file that doesn't exist.svg gets called to generate the file 4. {{#invokefile:Foo|main|bar=baz}} Module:Foo's main function gets called to generate the file 5. No use directly from wikitext. A Lua function mw.makeFile() would take file content as a parameter and emit (stripped) HTML to display it.
Advantages: 1. Works everywhere that normal files work without any modifications. 2. As #1, but not quite everywhere. No clashes with existing files. 3. Works everywhere, and no clashes. 4. Consistency with {{#invoke:}} and doesn't cause confusion with "real" files. 5. Simple.
Disadvantages: 1. Clashes with existing files already named File:Module:Foo. 2. Adding a second namespace that works like File is pretty much impossible. 3. Can't think of any right now. 4. Incompatible with things that expect filenames, which is a lot of on-wiki templates, and things like Extension:ImageMap 5. Wikis would probably build a wrapper module around it, making it equivalent to #4
At the moment, I'm leaning towards option 3.
Are there any other thoughts on these, or any additional ideas?
Jackmcbarn
On (1): "File:Module:Foo" may not be invalid* but UploadWizard and others automatically strip the ':' in File titles, so it's not really a supported title and I count few hundreds in Commons. It would be ok to make such titles illegal and rename existing files: in fact, I see it was proposed already by John Vandenberg in https://www.mediawiki.org/wiki/Requests_for_comment/Associated_namespaces#Automatically_moving_pages_on_namespace_creation.
Nemo
(*) https://www.mediawiki.org/wiki/Help:Bad_title (and friends) would use some editing.
Jackmcbarn wrote:
I'm interested in adding the ability to generate files via Scribunto. The first major decision that we need to make is how we'd use these files from a wiki page. [...]
- [[File:Module:Foo|bar=baz|width=200px]] - Module:Foo gets called to
generate the file 2. [[DynamicFile:Foo|bar=baz|width=200px]] - Module:DynamicFile/Foo gets called to generate the file 3. [[File:Any file that doesn't exist.svg|bar=baz|width=200px]] - Module:FileHandlers/Any file that doesn't exist.svg gets called to generate the file
As discussed on IRC, my biggest concern here is that file inclusion syntax is pretty awkward and awful and I'm very wary of duplicating it. Current file inclusion syntax requires parsing magic keywords that may change in the future ("thumb", "left", etc.), there are unnamed parameters, there are parameters that only activate if the software thinks that the user wanted a size specification, and so on.
If we use file inclusion syntax as a model, we would need to do what you're suggesting here: be much more explicit about parameter names (i.e., "|width=200px" instead of just "|200px").
- {{#invokefile:Foo|main|bar=baz}} Module:Foo's main function gets called
to generate the file
I think this is my current favorite. It has parity with {{#invoke:}}. And more fundamentally, if we rewrote MediaWiki from scratch, I would strongly recommend {{#file:}} and {{#category:}} over the re-use of [[link syntax]]. I think this option puts us in a better position for the future.
- No use directly from wikitext. A Lua function mw.makeFile() would take
file content as a parameter and emit (stripped) HTML to display it.
Eh, I'm not hot on this idea. Though maybe there would be benefits to forcing everyone to use wrapper templates (particularly built-in usage tracking and existing familiarity with the syntax).
Thanks for starting this thread. I'm excited to see work in this area.
MZMcBride
On Tue, Sep 16, 2014 at 10:40 PM, Jackmcbarn jackmcbarn@gmail.com wrote:
- [[File:Module:Foo|bar=baz|width=200px]] - Module:Foo gets called to
generate the file 3. [[File:Any file that doesn't exist.svg|bar=baz|width=200px]] - Module:FileHandlers/Any file that doesn't exist.svg gets called to generate the file
I like either of these. I don't see any files on enwiki[1] or Commons[2] with names beginning "Module:", so I doubt collisions are much of a concern.
IMO, the disadvantages for option 4 (not being usable for anything that wants filenames rather than the full image link syntax) outweigh the advantage of the similar syntax.
I note that neither of the syntax examples given allows you to specify which method in the module to invoke. I don't think we should try to provide one, we should just define that it always invokes "renderFile" (feel free to bikeshed the name).
We should be able to use the same code path on the image page that is used for Commons images, although the default text of the relevant messages might need work. If we go that route, we should also define that "extraDescription" returns wikitext to include in the image page (like how the description page from Commons is shown).
We should probably also require that a file extension be included on the module name, and use the existing code that's used on upload to validate that the file content matches the extension.
As for image syntax parameter handling, the current flow for parsing the syntax seems to be something along these lines:
* A 'File' object is fetched for the named image. * The file's media handler is asked for a list of parameters it recognizes, which can even override a core parameter. * Each pipe-separated parameter gets checked for matching one of these magic words. Handler-specified parameters get passed to a callback on the handler, although if it's named 'width' it gets special pre-parsing. * If the parameter is valid, it gets collected in an assoc (grouped by type, e.g. 'frame' or 'handler'); otherwise it's used as the caption. * Eventually, the file gets asked to generate a thumbnail object (and gets passed all the "handler" parameters from above). And then the thumbnail object gets asked to generate the HTML.
We'd probably have to add a new media handler method called to preprocess each option so we can collect them to pass to Lua later.
One other issue to consider is how the rendered files will be cached and purged, especially considering that people almost certainly will do stuff like have [[File:GraphMyData.svg]] use mw.title:getContent() to load data off of a wiki page of some sort and we'd ideally like to purge the rendered file when that wiki page gets changed.
[1]: https://en.wikipedia.org/w/api.php?action=query&list=allimages%7Callpage... : [2]: https://commons.wikimedia.org/w/api.php?action=query&list=allimages%7Cal... :
wikitech-l@lists.wikimedia.org