Author: carlb613
Description:
patch to allow template to override default Wikivoyage listing format
The format of a Wikivoyage listing tag, as generated by [[mw:extension:listings]], is hard-coded and rather inflexible. A mechanism is needed to allow the parameters or presentation style to be changed without editing the PHP code each time.
The listings are tags (eat, drink, see, do, buy, sleep) for historical reasons. All behave identically; the parameters are fed into Listings.body.php where private static function listingsTag( $aType, $input, $args, $parser ) is effectively a template written in hard-coded PHP.
There has already been at least one request on [[voy:Wikivoyage_talk:Listings]] to change this hard-coded format but that can't be done if there's no way to override the listingsTag() function.
I propose, simply, to change listingsTag() to look for a plain, standard template. If one exists, call it and let it deal with formatting the listing; if not, proceed as before.
The change requires inserting the following code into Listings.body.php at the start of the listingsTag() function:
private static function listingsTag( $aType, $input, $args, $parser ) {
/* * if a {{listings}} template exists, feed tag name and parameter list to template verbatim and exit */ $ltemplate=''; if ( !wfMessage( 'listings-template' )->inContentLanguage()->isDisabled() ) $ltemplate = wfMessage( 'listings-template' )->inContentLanguage()->text(); if ( $ltemplate != '' ) { $inputtext = '{{' . $ltemplate . '|type=' . $aType; foreach ($args as $key => $value) $inputtext .= '|' . $key . '=' . $value; $inputtext .= '|' . $input . '}}'; $out .= $parser->internalParse( $inputtext ); return $out; } /* * if no pre-defined template exists, generate listing from parameters normally */
Version: master
Severity: normal
Attached: