mediawiki-extensions-Cite/CiteDataModule.php
Ed Sanders 18f616b9b8 VisualEditor: Move code for Cite into this repo
This code has been developed over three years now in the repo of MediaWiki's
integration of VisualEditor. It has grown and developed significantly during
that time, but now is pretty stable. A number of hacks inside the MediaWiki-
VisualEditor code base have been used to prevent this code from being loaded
on wikis where the Cite extension is not deployed, but this state of affairs
is and always was meant to be temporary.

This code is under the MIT licence which is a tad messy, but not impossible.
It's clearly labelled as such. The list of authors has been updated to take
into account the influx of new functionality.

Bug: T41621
Bug: T104928
Change-Id: I39936ed83d5a60471a0a75da753f498e80aef234
2016-02-04 08:41:54 -08:00

62 lines
1.5 KiB
PHP

<?php
/**
* Resource loader module providing extra data from the server to Cite.
*
* Temporary hack for T93800
*
* @file
* @ingroup Extensions
* @copyright 2011-2016 Cite VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see MIT-LICENSE.txt
*/
class CiteDataModule extends ResourceLoaderModule {
/* Protected Members */
protected $origin = self::ORIGIN_USER_SITEWIDE;
protected $targets = array( 'desktop', 'mobile' );
/* Methods */
public function getScript( ResourceLoaderContext $context ) {
$citationDefinition = json_decode(
wfMessage( 'visualeditor-cite-tool-definition.json' )->plain()
);
$citationTools = array();
if ( is_array( $citationDefinition ) ) {
foreach ( $citationDefinition as $tool ) {
if ( !isset( $tool->title ) ) {
$tool->title =
wfMessage( 'visualeditor-cite-tool-name-' . $tool->name )->text();
}
$citationTools[] = $tool;
}
}
return
've.init.platform.addMessages(' . FormatJson::encode(
array(
'visualeditor-cite-tool-definition.json' => json_encode( $citationTools )
),
ResourceLoader::inDebugMode()
) . ');';
}
public function getDependencies( ResourceLoaderContext $context = null ) {
return array(
'ext.visualEditor.base',
'ext.visualEditor.mediawiki',
);
}
public function getDefinitionSummary( ResourceLoaderContext $context ) {
$summary = parent::getDefinitionSummary( $context );
$summary[] = array(
'script' => $this->getScript( $context ),
);
return $summary;
}
}