2010-07-23 21:11:09 +08:00
|
|
|
<?php
|
|
|
|
|
2023-10-25 00:16:41 +08:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2010-07-23 21:11:09 +08:00
|
|
|
/**
|
2017-05-13 20:00:41 +08:00
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticResultFormats/
|
2012-07-16 21:57:52 +08:00
|
|
|
*
|
2017-05-13 20:00:41 +08:00
|
|
|
* @defgroup SRF Semantic Result Formats
|
2010-07-23 21:11:09 +08:00
|
|
|
*/
|
2013-11-30 10:52:50 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
SemanticResultFormats::load();
|
2011-10-15 17:40:32 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
|
|
|
class SemanticResultFormats {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.5
|
|
|
|
*
|
|
|
|
* @note It is expected that this function is loaded before LocalSettings.php
|
|
|
|
* to ensure that settings and global functions are available by the time
|
|
|
|
* the extension is activated.
|
|
|
|
*/
|
|
|
|
public static function load() {
|
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
|
|
|
|
include_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
}
|
2011-09-25 05:58:43 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
// Load DefaultSettings
|
|
|
|
require_once __DIR__ . '/DefaultSettings.php';
|
|
|
|
}
|
2012-11-18 18:57:02 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
/**
|
|
|
|
* @since 2.5
|
|
|
|
*/
|
2018-10-10 20:16:37 +08:00
|
|
|
public static function initExtension( $credits = [] ) {
|
2018-10-10 15:36:08 +08:00
|
|
|
// See https://phabricator.wikimedia.org/T151136
|
|
|
|
define( 'SRF_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
|
2017-05-13 20:00:41 +08:00
|
|
|
|
|
|
|
// Register message files
|
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticResultFormats'] = __DIR__ . '/i18n';
|
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticResultFormats'] = __DIR__ . '/SemanticResultFormats.i18n.php';
|
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['SemanticResultFormatsMagic'] = __DIR__ . '/SemanticResultFormats.i18n.magic.php';
|
|
|
|
|
|
|
|
$GLOBALS['srfgIP'] = __DIR__;
|
2022-01-13 08:27:51 +08:00
|
|
|
$GLOBALS['wgResourceModules'] = array_merge( $GLOBALS['wgResourceModules'], include __DIR__ . "/Resources.php" );
|
2017-05-13 20:00:41 +08:00
|
|
|
}
|
2012-11-18 18:57:02 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
/**
|
|
|
|
* @since 2.5
|
|
|
|
*/
|
|
|
|
public static function registerHooks() {
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
|
2011-11-17 00:03:39 +08:00
|
|
|
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'ParserFirstCallInit', 'SRFParserFunctions::registerFunctions' );
|
|
|
|
$hookContainer->register( 'UnitTestsList', 'SRFHooks::registerUnitTests' );
|
2011-11-17 00:03:39 +08:00
|
|
|
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'ResourceLoaderGetConfigVars', 'SRFHooks::onResourceLoaderGetConfigVars' );
|
2013-11-30 10:06:28 +08:00
|
|
|
|
2017-06-12 20:48:50 +08:00
|
|
|
// Format hooks
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'OutputPageParserOutput', 'SRF\Filtered\Hooks::onOutputPageParserOutput' );
|
|
|
|
$hookContainer->register( 'MakeGlobalVariablesScript', 'SRF\Filtered\Hooks::onMakeGlobalVariablesScript' );
|
2017-06-12 20:48:50 +08:00
|
|
|
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'SMW::Store::BeforeQueryResultLookupComplete', 'SRF\DataTables\Hooks::onSMWStoreBeforeQueryResultLookupComplete' );
|
2023-03-19 00:17:10 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
// register API modules
|
|
|
|
$GLOBALS['wgAPIModules']['ext.srf.slideshow.show'] = 'SRFSlideShowApi';
|
2023-03-19 00:17:10 +08:00
|
|
|
$GLOBALS['wgAPIModules']['ext.srf.datatables.api'] = 'SRF\DataTables\Api';
|
2014-01-03 08:22:20 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
// User preference
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'SMW::GetPreferences', 'SRFHooks::onGetPreferences' );
|
2017-10-01 12:18:04 +08:00
|
|
|
|
|
|
|
// Allows last minute changes to the output page, e.g. adding of CSS or JavaScript by extensions
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'BeforePageDisplay', 'SRFHooks::onBeforePageDisplay' );
|
2017-05-13 20:00:41 +08:00
|
|
|
}
|
2011-11-17 00:03:39 +08:00
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
/**
|
|
|
|
* @since 2.5
|
|
|
|
*/
|
2018-10-10 15:36:08 +08:00
|
|
|
public static function onExtensionFunction() {
|
2017-05-13 20:00:41 +08:00
|
|
|
if ( !defined( 'SMW_VERSION' ) ) {
|
2012-10-16 05:43:17 +08:00
|
|
|
|
2018-10-10 15:36:08 +08:00
|
|
|
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
|
|
|
|
die( "\nThe 'Semantic Result Formats' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" );
|
|
|
|
} else {
|
|
|
|
die(
|
|
|
|
'<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticResultFormats/">Semantic Result Formats</a> ' .
|
|
|
|
'extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be ' .
|
|
|
|
'installed and enabled.<br />'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-12-22 21:45:04 +08:00
|
|
|
self::registerHooks();
|
|
|
|
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
|
2017-05-13 20:00:41 +08:00
|
|
|
|
|
|
|
// Admin Links hook needs to be called in a delayed way so that it
|
|
|
|
// will always be called after SMW's Admin Links addition; as of
|
|
|
|
// SMW 1.9, SMW delays calling all its hook functions.
|
2023-10-25 00:16:41 +08:00
|
|
|
$hookContainer->register( 'AdminLinks', 'SRFHooks::addToAdminLinks' );
|
2017-05-13 20:00:41 +08:00
|
|
|
|
|
|
|
$GLOBALS['srfgScriptPath'] = ( $GLOBALS['wgExtensionAssetsPath'] === false ? $GLOBALS['wgScriptPath'] . '/extensions' : $GLOBALS['wgExtensionAssetsPath'] ) . '/SemanticResultFormats';
|
|
|
|
|
2017-05-26 02:51:17 +08:00
|
|
|
$formatClasses = [
|
2017-05-13 20:00:41 +08:00
|
|
|
// Assign the Boilerplate class to a format identifier
|
|
|
|
// 'boilerplate' => 'SRFBoilerplate',
|
|
|
|
'timeline' => 'SRFTimeline',
|
|
|
|
'eventline' => 'SRFTimeline',
|
2017-11-04 18:36:16 +08:00
|
|
|
'vcard' => 'SRF\vCard\vCardFileExportPrinter',
|
2017-11-04 17:47:07 +08:00
|
|
|
'icalendar' => 'SRF\iCalendar\iCalendarFileExportPrinter',
|
2019-07-27 22:09:32 +08:00
|
|
|
'bibtex' => 'SRF\BibTex\BibTexFileExportPrinter',
|
2017-05-13 20:00:41 +08:00
|
|
|
'calendar' => 'SRFCalendar',
|
|
|
|
'eventcalendar' => 'SRF\EventCalendar',
|
2019-07-28 00:40:52 +08:00
|
|
|
'outline' => 'SRF\Outline\OutlineResultPrinter',
|
2017-05-13 20:00:41 +08:00
|
|
|
'sum' => 'SRFMath',
|
|
|
|
'product' => 'SRFMath',
|
|
|
|
'average' => 'SRFMath',
|
|
|
|
'min' => 'SRFMath',
|
|
|
|
'max' => 'SRFMath',
|
|
|
|
'median' => 'SRFMath',
|
2020-07-16 23:07:14 +08:00
|
|
|
'samplevariance' => 'SRFMath',
|
|
|
|
'variance' => 'SRFMath',
|
|
|
|
'standarddeviation' => 'SRFMath',
|
|
|
|
'samplestandarddeviation' => 'SRFMath',
|
2020-07-17 19:09:45 +08:00
|
|
|
'range' => 'SRFMath',
|
2020-07-27 21:30:25 +08:00
|
|
|
'quartillower' => 'SRFMath',
|
|
|
|
'quartilupper' => 'SRFMath',
|
|
|
|
'quartillower.exc' => 'SRFMath',
|
|
|
|
'quartilupper.exc' => 'SRFMath',
|
|
|
|
'interquartilerange' => 'SRFMath',
|
|
|
|
'interquartilerange.exc' => 'SRFMath',
|
|
|
|
'mode' => 'SRFMath',
|
|
|
|
'interquartilemean' => 'SRFMath',
|
2017-05-13 20:00:41 +08:00
|
|
|
'exhibit' => 'SRFExhibit',
|
|
|
|
'googlebar' => 'SRFGoogleBar',
|
|
|
|
'googlepie' => 'SRFGooglePie',
|
|
|
|
'jitgraph' => 'SRFJitGraph',
|
|
|
|
'jqplotchart' => 'SRFjqPlotChart',
|
|
|
|
'jqplotseries' => 'SRFjqPlotSeries',
|
2019-07-23 23:33:12 +08:00
|
|
|
'graph' => 'SRF\Graph\GraphPrinter',
|
2017-05-13 20:00:41 +08:00
|
|
|
'process' => 'SRFProcess',
|
|
|
|
'gallery' => 'SRF\Gallery',
|
|
|
|
'tagcloud' => 'SRF\TagCloud',
|
|
|
|
'valuerank' => 'SRFValueRank',
|
|
|
|
'array' => 'SRFArray',
|
|
|
|
'hash' => 'SRFHash',
|
|
|
|
'd3chart' => 'SRFD3Chart',
|
2017-06-12 20:29:50 +08:00
|
|
|
'tree' => 'SRF\Formats\Tree\TreeResultPrinter',
|
|
|
|
'ultree' => 'SRF\Formats\Tree\TreeResultPrinter',
|
|
|
|
'oltree' => 'SRF\Formats\Tree\TreeResultPrinter',
|
2017-06-12 20:48:50 +08:00
|
|
|
'filtered' => 'SRF\Filtered\Filtered',
|
2017-05-13 20:00:41 +08:00
|
|
|
'latest' => 'SRFTime',
|
|
|
|
'earliest' => 'SRFTime',
|
|
|
|
'slideshow' => 'SRFSlideShow',
|
|
|
|
'timeseries' => 'SRFTimeseries',
|
|
|
|
'sparkline' => 'SRFSparkline',
|
|
|
|
'listwidget' => 'SRFListWidget',
|
|
|
|
'pagewidget' => 'SRFPageWidget',
|
|
|
|
'dygraphs' => 'SRFDygraphs',
|
|
|
|
'incoming' => 'SRFIncoming',
|
|
|
|
'media' => 'SRF\MediaPlayer',
|
Provide "gantt" format (#467)
* Implement new mermaid format with chart type "gantt"
* Change format naming to "gantt". Bugfix in GanttTask.php. Include format in DefaultSettings.php
* Add gantt test case for prioritymapping/statusmapping
* Rework on unit tests. Change Namespaces and format name / Delete unit tests of core classes
* add missing i18n keys in qqq.json / rename i18n keys
* Change printername
* remove sortkey, consistency on quotes, change equality operators to identity operators
* push arrays in a faster way
* set type on params, rework mapping validation
* set dependency on ext.mermaid
* remove modules that are loaded manually instead handle it with dependency
* remove member var mParams
* uses certain selector to replace <esc>35</esc> in svg
* Add credits on forceTextWrappingOn() (https://gist.github.com/jkappers/3892971)
* minimize looping through title elements
* calculate height of label text
* This check is not needed. Should $sections be empty, the next check on array_key_exists( $sectionID, $sections ) will fail.
* No need to loop over all sections! Instead use array key if exists
* Remove sort functionality, this can be done with inline query standard sort and order property
* remove loop over all tasks. Call Task Obj directly based on its Task id
* Refactor "setTaskParams"
* change printer name in qqq.json
* Validate Theme
* Outsource validation of status and priority mapping.
* add build/travis/install-mermaid.sh, extend JsonTestCaseScriptRunnerTest.php
* removed "bash ./build/travis/install-mermaid.sh"
* Add "install-mermaid.sh"
* remove env for php <= 7
* add travis environment for php 5.6
* remove runTestCaseFile(), rewrite checkMermaidDependency
* Add MERMAID var to travis CI
* add mermaid as composer requirement, rework on JsonTestCaseScriptRunnerTest
* bugfix in installMermaidWithComposer, change mermaid version in composer settings
* comment installMermaidWithComposer, use mermaid in composer.json
* add "lost" composer command to install semantic-result-formats
* install mermaid-master if no version is specified
* use mermaid just in travis env with MW > 1.29+
* Add new test environment to travis matrix
* change   to regualr spaces
* remove "to-be-valid-html": 1 in gantt-01.json
* added html_entity_decode to output of getResultText()
* Added Mermaid environment vars for Travis CI
* Remove Travis CI environment for Mermaid ext in MW <= 1.30.0
* Change line seperators from CR to LF
* Remove Mermaid from test environment in MW > 1.32
2019-05-06 22:27:12 +08:00
|
|
|
'datatables' => 'SRF\DataTables',
|
2024-05-04 15:44:28 +08:00
|
|
|
'carousel' => 'SRF\Carousel',
|
|
|
|
'gantt' => 'SRF\Gantt\GanttPrinter',
|
|
|
|
'prolog' => 'SRF\Prolog\PrologPrinter',
|
|
|
|
'dataframe' => 'SRF\dataframe\DataframePrinter',
|
2017-05-26 02:51:17 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
$formatAliases = [
|
|
|
|
'tagcloud' => [ 'tag cloud' ],
|
|
|
|
'datatables' => [ 'datatable' ],
|
|
|
|
'valuerank' => [ 'value rank' ],
|
|
|
|
'd3chart' => [ 'd3 chart' ],
|
2022-01-13 08:34:48 +08:00
|
|
|
'timeseries' => [ 'time series' ],
|
2017-05-26 02:51:17 +08:00
|
|
|
'jqplotchart' => [ 'jqplot chart', 'jqplotpie', 'jqplotbar' ],
|
|
|
|
'jqplotseries' => [ 'jqplot series' ],
|
|
|
|
];
|
2017-05-13 20:00:41 +08:00
|
|
|
|
2019-08-01 16:26:07 +08:00
|
|
|
if ( class_exists( '\PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) {
|
|
|
|
$formatClasses['spreadsheet'] = 'SRF\SpreadsheetPrinter';
|
|
|
|
$formatAliases['spreadsheet'] = [ 'excel' ];
|
|
|
|
}
|
|
|
|
|
2017-05-13 20:00:41 +08:00
|
|
|
foreach ( $GLOBALS['srfgFormats'] as $format ) {
|
|
|
|
if ( array_key_exists( $format, $formatClasses ) ) {
|
|
|
|
$GLOBALS['smwgResultFormats'][$format] = $formatClasses[$format];
|
|
|
|
|
|
|
|
if ( isset( $GLOBALS['smwgResultAliases'] ) && array_key_exists( $format, $formatAliases ) ) {
|
|
|
|
$GLOBALS['smwgResultAliases'][$format] = $formatAliases[$format];
|
|
|
|
}
|
2011-02-09 06:35:21 +08:00
|
|
|
}
|
2011-03-02 02:31:23 +08:00
|
|
|
}
|
2012-11-18 18:57:02 +08:00
|
|
|
}
|
2017-05-13 20:00:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.5
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return SRF_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|