Requests for comment/Accessing page properties from wiki pages
This is a request for comments regarding accessing page properties from wiki pages.
Accessing page properties from wiki pages | |
---|---|
Component | General |
Creation date | |
Author(s) | MZMcBride, Legoktm, Jackmcbarn, Matma Rex |
Document status | in discussion See Phabricator. |
Background
editMediaWiki has a page_props database table where certain attributes and values are stored on a per-page basis. For example:
MariaDB [enwiki_p]> select page_title, pp_propname, pp_value from page join page_props on pp_page = page_id where page_namespace = 0 and page_title = 'Barack_Obama';
+--------------+--------------------------+----------------------------+
| page_title | pp_propname | pp_value |
+--------------+--------------------------+----------------------------+
| Barack_Obama | defaultsort | Obama, Barack |
| Barack_Obama | page_image_free | President_Barack_Obama.jpg |
| Barack_Obama | wikibase-badge-Q17437796 | 1 |
| Barack_Obama | wikibase_item | Q76 |
+--------------+--------------------------+----------------------------+
4 rows in set (0.00 sec)
MariaDB [enwiki_p]> select page_title, pp_propname, pp_value from page join page_props on pp_page = page_id where page_namespace = 0 and page_title = 'Obama_(disambiguation)';
+------------------------+----------------+----------+
| page_title | pp_propname | pp_value |
+------------------------+----------------+----------+
| Obama_(disambiguation) | disambiguation | |
| Obama_(disambiguation) | wikibase_item | Q223850 |
+------------------------+----------------+----------+
2 rows in set (0.00 sec)
MediaWiki stores whether a page is a disambiguation page, what its default category sort key is, and what its page image is, each being determined by different means: __DISAMBIG__
, {{DEFAULTSORT:Obama, Barack}}
, and a heuristic (cf. Extension:PageImages#Image choice).
Problem
editUsers cannot access a page's properties from other local wiki pages.
Potential use-cases:
- phabricator:T71441: Feature request: add detection for disambiguation pages to Scribunto
- phabricator:T131911: Allow retrieving/getting page image file name from wikitext using Scribunto/Lua or parser function or something
- phabricator:T154346: Provide "wikitext" means of accessing arbitrary wiki page's default category sort key
Complications
editThis makes wikitext more volatile. We already have features such as {{#ifexist:Page name}}
and {{CURRENTTIMESTAMP}}
, which can be combined in weird and potentially abusive ways. For example: {{DEFAULTSORT:{{CURRENTTIMESTAMP}}}}
.
If we added the ability to get page properties, we could end up with cases such as these:
{{DEFAULTSORT:{{#getdefaultsort:{{FULLPAGENAME}}}}}}
{{#if:{{#invoke:IsThisADabPage|main|{{FULLPAGENAME}}}}||__DISAMBIG__}}
While we could try to restrict page property retrieval to pages other than the current page, you could end up with trivial loops: page A tries to get page B's category sort key, page B tries to get category A's category sort key. These types of problems have been solved by templates.
It's also currently possible to do things like this: w:en:User:Sgeo/null-edit-detector.
You also have a problem that's basically the opposite of volatility: if a page's default category sort key changes, how do know to update the pages, such as its talk page, that are also using this sort key?
Proposal
editOption 1
editModify Scribunto/Lua to expose these properties as functions or Title object attributes.
We need to track these usages. Would using templatelinks be acceptable?
Option 2
editAdd parser functions to MediaWiki core or to extensions such as PageImages. For example:
{{#getdefaultsort:Page name}}
{{#getpageimage:Page name}}
We need to track these usages. Would using templatelinks be acceptable?
Option 3
editFor two of the use-cases, the focus is talk pages. So we could add:
{{ISSUBJECTSPACEPAGEADISAMBIGUATIONPAGE}}
{{SUBJECTPAGEDEFAULTCATEGORYSORTKEY}}
But this is kind of obnoxious and it boxes us in a bit. We may want to break out of the subject space page–talk page binary at some point (RfC: Associated namespaces (talk)), supporting groupings of three or four or more pages. On a related point, we may want to use this functionality on non-talk pages, which is the case for properties such as page images.
Option 4
editDo nothing. Don't allow access to these page properties. :-(
Option 5
editHere's a dumb idea: use the existing templates/transclusion system, either by creating a template for every page and property or by using Extension:LabeledSectionTransclusion to extract parts of a subject-space page.
This would be pretty terrible, but would save making a new links table and would require almost no development effort.
Option 6
editDon't store these properties in wikitext. A lot of complications described above go away if you don't use wikitext as the storage/input mechanism. But in exchange, you get new complications regarding tracking changes, preventing abuse/misuse, etc. We'd be in violation of everything is a wiki page, but perhaps with something like multi-content revisions, this would be possible. This option would delay any implementation significantly.
A different version of this option would be to store properties in a centralized repository such as Wikidata or in a local repository using the Wikibase Repository extension.