mediawiki-extensions-Templa.../TemplateData.php
Timo Tijhof b7080c5f90 Initial TemplateData commit
Registers a parser tag <templatedata> that should have a JSON
blob as content. The blob is then validated and normalised when
MediaWiki parses the page (e.g. during save and preview).

If there are validation errors, the save is aborted from the
extension hook and an error is displayed.

If all goes well, the normalised blob is stored in the database
(which can be retrieved through the API). And an HTML
representation of the template parameters is returned to the
wikitext parser to show where the <templatedata> was in the page.

The blob format is specified in spec.templatedata.json and
is validated in TemplateDataBlob::parse.

Bug: 44444
Change-Id: Icf305892a9512545a63f5a5280cc0d340c61585f
2013-03-14 19:19:55 +00:00

49 lines
1.4 KiB
PHP

<?php
/**
* TemplateInfo extension.
*
* @file
* @ingroup Extensions
*/
if ( version_compare( $wgVersion, '1.20', '<' ) ) {
echo "Extension:TemplateInfo requires MediaWiki 1.20 or higher.\n";
exit( 1 );
}
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'TemplateData',
'author' => array( 'Timo Tijhof' ),
'version' => '0.1.0',
'url' => 'https://www.mediawiki.org/wiki/Extension:TemplateData',
'descriptionmsg' => 'templatedata-desc',
);
/* Setup */
$dir = __DIR__;
// Register files
$wgExtensionMessagesFiles['TemplateData'] = $dir . '/TemplateData.i18n.php';
$wgAutoloadClasses['TemplateDataHooks'] = $dir . '/TemplateData.hooks.php';
$wgAutoloadClasses['TemplateDataBlob'] = $dir . '/TemplateDataBlob.php';
$wgAutoloadClasses['ApiQueryTemplateData'] = $dir . '/api/ApiQueryTemplateData.php';
// Register hooks
$wgHooks['ParserFirstCallInit'][] = 'TemplateDataHooks::onParserFirstCallInit';
$wgHooks['PageContentSave'][] = 'TemplateDataHooks::onPageContentSave';
// Register API actions
$wgAPIPropModules['templatedata'] = 'ApiQueryTemplateData';
// Register page_props
$wgPageProps['templatedata'] = 'Content of &lt;templatedata&gt; tag';
// Register modules
$wgResourceModules['ext.templateData'] = array(
'styles' => 'resources/ext.templateData.css',
'localBasePath' => $dir,
'remoteExtPath' => 'TemplateData',
);