Extension:ArticleProperties

From Organic Design wiki
Revision as of 12:51, 2 March 2012 by Nad (talk | contribs) (Development notes)

Template:Project MediaWiki has a page properties table which is used to store and manipulate named property lists for articles. The parser includes the required hooks to integrate with this properties system in an event-driven way so that other functionality that depends on these values can be prompted to update their state when changes occur.

Since template parameters play such an important role in wiki based data structures, it makes sense that the named parameters of the template should be stored in the properties table, so that templates can effectively become objects that have both properties and methods.

It also allows much more efficient querying of properties defined in template syntax since these queries can be carried out directly on the properties table rather than having to convert wikitext which is much more expensive even with caching.

The first useful application would be to change the #recordtable parser-function to use the properties table instead of referring to the wikitext. The RA extension has methods for converting to and from value-arrays and wikitext template syntax, so this could be implemented easily be effectively using the properties table as a "live" cache tied into those two methods. But also the queries in the parser-function should be updated too since they no longer need to refer to the text field of the articles.

Development notes

I've started an extensions called ArticleProperties which creates a new ArticleProperties class that is a sub-class of Article. It main purpose is to add a properties method allowing named properties to be read from and written to an articles page_prop entries.

It also provides a query method which allows conditions and options to be sent in the same format used by the SQL Database::select method, and it returns a list of Title objects for matching articles.

And finally it also provides a table method that allows a list of titles to be rendered as an HTML table. The method takes three parameters, the second two are optional. The first is the title-list, the second an array of HTML attributes such as class and id that the resulting table should have. And the third parameter is an array of columns that the table should use. If the columns are not provided, they will be extracted from the properties of the first article from the title list.