SemanticResultFormats/SemanticResultFormats.php

206 行
6.9 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* @see https://github.com/SemanticMediaWiki/SemanticResultFormats/
*
* @defgroup SRF Semantic Result Formats
*/
SemanticResultFormats::load();
/**
* @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
// Load DefaultSettings
require_once __DIR__ . '/DefaultSettings.php';
}
/**
* @since 2.5
*/
2018-10-10 20:16:37 +08:00
public static function initExtension( $credits = [] ) {
// See https://phabricator.wikimedia.org/T151136
define( 'SRF_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' );
// 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" );
}
/**
* @since 2.5
*/
public static function registerHooks() {
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
2011-11-17 00:03:39 +08:00
$hookContainer->register( 'ParserFirstCallInit', 'SRFParserFunctions::registerFunctions' );
$hookContainer->register( 'UnitTestsList', 'SRFHooks::registerUnitTests' );
2011-11-17 00:03:39 +08:00
$hookContainer->register( 'ResourceLoaderGetConfigVars', 'SRFHooks::onResourceLoaderGetConfigVars' );
// Format hooks
$hookContainer->register( 'OutputPageParserOutput', 'SRF\Filtered\Hooks::onOutputPageParserOutput' );
$hookContainer->register( 'MakeGlobalVariablesScript', 'SRF\Filtered\Hooks::onMakeGlobalVariablesScript' );
$hookContainer->register( 'SMW::Store::BeforeQueryResultLookupComplete', 'SRF\DataTables\Hooks::onSMWStoreBeforeQueryResultLookupComplete' );
Datatable v2 (rebased) (#771) * fix sorting with $wgCachePages * fix sorting with $wgCachePages * fix datatable collation * added datatable hook * hook + datatables v2 * datatable v2 * datatable v2 (fixed comment error) * datatables modules * datatables richer features * datatables native options * datatables native options * datatables v2 revised * datatables v2 api * datatables v2 ajax * datatables v2 ajax * datatables messages * datatables v2 merge with old design * datatables ajax loading * updated max length * updated sliced result * fixed mainlabel * fixed mainlabel * datatables v2 search * datatables v2 search * fix pageLength * fix pagelength * fix pagelength * fix pagelength * fix space * added parser * pageLength and style * fix parser * fix load datatables extra * Rename resources/jquery/datatables/jquery.dataTables.bootstrap.css to resources/jquery/datatables-legacy/jquery.dataTables.bootstrap.css * Rename resources/jquery/datatables/jquery.dataTables.bootstrap.js to resources/jquery/datatables-legacy/jquery.dataTables.bootstrap.js * Rename resources/jquery/datatables/jquery.dataTables.extras.js to resources/jquery/datatables-legacy/jquery.dataTables.extras.js * Rename resources/jquery/datatables/jquery.dataTables_themeroller.css to resources/jquery/datatables-legacy/jquery.dataTables_themeroller.css * datatables extra v2 * datatables fix sort * datatables fix sort * datatable native options messages * added options * added options * fix class * fix margin * added options, license notice * added options, license notice * added license notice * remove console.log * moved files to legacy folder * datatables v2 (sorting - printouts parameters) * datatables v2 (sorting - printouts parameters) * datatables v2 + legacy version * datatables v2 messages * datatables legacy * Rename formats/DataTablesLegacy.php to formats/datatables-legacy/DataTablesLegacy.php * datatables legacy js * Rename formats/datatables-legacy/ext.srf.formats.datatables.js to formats/datatables-legacy/resources/ext.srf.formats.datatables.js * datatables legacy css * datatables legacy js * fix show Panes * fix cache * datatables notice * datatables notice * datatables notice * datatables notice * update cookieKey * comment labelsCount * fix template printout label * fix nested printouts parameters * fix console log * added tests * added tests * added tests * js tests * fix module * Rename ext.srf.formats.datatables.js to ext.srf.formats.datatablesLegacy.js * updated class name * added comment * datatables comment * update class vars * add type case * add type cast * fix hook BeforeQueryResultLookupComplete not called * added scrollY auto unit --------- Co-authored-by: Bernhard Krabina <bernhard.krabina@km-a.net>
2023-03-19 00:17:10 +08:00
// register API modules
$GLOBALS['wgAPIModules']['ext.srf.slideshow.show'] = 'SRFSlideShowApi';
Datatable v2 (rebased) (#771) * fix sorting with $wgCachePages * fix sorting with $wgCachePages * fix datatable collation * added datatable hook * hook + datatables v2 * datatable v2 * datatable v2 (fixed comment error) * datatables modules * datatables richer features * datatables native options * datatables native options * datatables v2 revised * datatables v2 api * datatables v2 ajax * datatables v2 ajax * datatables messages * datatables v2 merge with old design * datatables ajax loading * updated max length * updated sliced result * fixed mainlabel * fixed mainlabel * datatables v2 search * datatables v2 search * fix pageLength * fix pagelength * fix pagelength * fix pagelength * fix space * added parser * pageLength and style * fix parser * fix load datatables extra * Rename resources/jquery/datatables/jquery.dataTables.bootstrap.css to resources/jquery/datatables-legacy/jquery.dataTables.bootstrap.css * Rename resources/jquery/datatables/jquery.dataTables.bootstrap.js to resources/jquery/datatables-legacy/jquery.dataTables.bootstrap.js * Rename resources/jquery/datatables/jquery.dataTables.extras.js to resources/jquery/datatables-legacy/jquery.dataTables.extras.js * Rename resources/jquery/datatables/jquery.dataTables_themeroller.css to resources/jquery/datatables-legacy/jquery.dataTables_themeroller.css * datatables extra v2 * datatables fix sort * datatables fix sort * datatable native options messages * added options * added options * fix class * fix margin * added options, license notice * added options, license notice * added license notice * remove console.log * moved files to legacy folder * datatables v2 (sorting - printouts parameters) * datatables v2 (sorting - printouts parameters) * datatables v2 + legacy version * datatables v2 messages * datatables legacy * Rename formats/DataTablesLegacy.php to formats/datatables-legacy/DataTablesLegacy.php * datatables legacy js * Rename formats/datatables-legacy/ext.srf.formats.datatables.js to formats/datatables-legacy/resources/ext.srf.formats.datatables.js * datatables legacy css * datatables legacy js * fix show Panes * fix cache * datatables notice * datatables notice * datatables notice * datatables notice * update cookieKey * comment labelsCount * fix template printout label * fix nested printouts parameters * fix console log * added tests * added tests * added tests * js tests * fix module * Rename ext.srf.formats.datatables.js to ext.srf.formats.datatablesLegacy.js * updated class name * added comment * datatables comment * update class vars * add type case * add type cast * fix hook BeforeQueryResultLookupComplete not called * added scrollY auto unit --------- Co-authored-by: Bernhard Krabina <bernhard.krabina@km-a.net>
2023-03-19 00:17:10 +08:00
$GLOBALS['wgAPIModules']['ext.srf.datatables.api'] = 'SRF\DataTables\Api';
// User preference
$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
$hookContainer->register( 'BeforePageDisplay', 'SRFHooks::onBeforePageDisplay' );
}
2011-11-17 00:03:39 +08:00
/**
* @since 2.5
*/
public static function onExtensionFunction() {
if ( !defined( 'SMW_VERSION' ) ) {
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 />'
);
}
}
self::registerHooks();
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
// 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.
$hookContainer->register( 'AdminLinks', 'SRFHooks::addToAdminLinks' );
$GLOBALS['srfgScriptPath'] = ( $GLOBALS['wgExtensionAssetsPath'] === false ? $GLOBALS['wgScriptPath'] . '/extensions' : $GLOBALS['wgExtensionAssetsPath'] ) . '/SemanticResultFormats';
$formatClasses = [
// 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',
'icalendar' => 'SRF\iCalendar\iCalendarFileExportPrinter',
2019-07-27 22:09:32 +08:00
'bibtex' => 'SRF\BibTex\BibTexFileExportPrinter',
'calendar' => 'SRFCalendar',
'eventcalendar' => 'SRF\EventCalendar',
2019-07-28 00:40:52 +08:00
'outline' => 'SRF\Outline\OutlineResultPrinter',
'sum' => 'SRFMath',
'product' => 'SRFMath',
'average' => 'SRFMath',
'min' => 'SRFMath',
'max' => 'SRFMath',
'median' => 'SRFMath',
'samplevariance' => 'SRFMath',
'variance' => 'SRFMath',
'standarddeviation' => 'SRFMath',
'samplestandarddeviation' => 'SRFMath',
2020-07-17 19:09:45 +08:00
'range' => 'SRFMath',
'quartillower' => 'SRFMath',
'quartilupper' => 'SRFMath',
'quartillower.exc' => 'SRFMath',
'quartilupper.exc' => 'SRFMath',
'interquartilerange' => 'SRFMath',
'interquartilerange.exc' => 'SRFMath',
'mode' => 'SRFMath',
'interquartilemean' => 'SRFMath',
'exhibit' => 'SRFExhibit',
'googlebar' => 'SRFGoogleBar',
'googlepie' => 'SRFGooglePie',
'jitgraph' => 'SRFJitGraph',
'jqplotchart' => 'SRFjqPlotChart',
'jqplotseries' => 'SRFjqPlotSeries',
'graph' => 'SRF\Graph\GraphPrinter',
'process' => 'SRFProcess',
'gallery' => 'SRF\Gallery',
'tagcloud' => 'SRF\TagCloud',
'valuerank' => 'SRFValueRank',
'array' => 'SRFArray',
'hash' => 'SRFHash',
'd3chart' => 'SRFD3Chart',
'tree' => 'SRF\Formats\Tree\TreeResultPrinter',
'ultree' => 'SRF\Formats\Tree\TreeResultPrinter',
'oltree' => 'SRF\Formats\Tree\TreeResultPrinter',
'filtered' => 'SRF\Filtered\Filtered',
'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 &#160; 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',
'carousel' => 'SRF\Carousel',
'gantt' => 'SRF\Gantt\GanttPrinter',
'prolog' => 'SRF\Prolog\PrologPrinter',
'dataframe' => 'SRF\dataframe\DataframePrinter',
];
$formatAliases = [
'tagcloud' => [ 'tag cloud' ],
'datatables' => [ 'datatable' ],
'valuerank' => [ 'value rank' ],
'd3chart' => [ 'd3 chart' ],
2022-01-13 08:34:48 +08:00
'timeseries' => [ 'time series' ],
'jqplotchart' => [ 'jqplot chart', 'jqplotpie', 'jqplotbar' ],
'jqplotseries' => [ 'jqplot series' ],
];
if ( class_exists( '\PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) {
$formatClasses['spreadsheet'] = 'SRF\SpreadsheetPrinter';
$formatAliases['spreadsheet'] = [ 'excel' ];
}
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
}
}
/**
* @since 2.5
*
* @return string|null
*/
public static function getVersion() {
return SRF_VERSION;
}
}