-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSciFileHandler.hooks.php
More file actions
66 lines (54 loc) · 1.86 KB
/
SciFileHandler.hooks.php
File metadata and controls
66 lines (54 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Hooks for SciFileHandler extension
*
* @file
* @ingroup Extensions
*/
class SciFileHandlerHooks {
public static function onParserFirstCallInit( Parser &$parser ) {
// important: This needs
// "ExtensionMessagesFiles": { "SciFileHandlerMagic": "SciFileHandler.i18n.magic.php" }
// in extension.json
$parser->setFunctionHook( 'hdf', 'SciFileHandlerHooks::doSomething' );
#$parser->setFunctionHook( 'hdf', [ 'SciFileHandlerHooks', 'doSomething' ] );
}
/**
* @param Parser &$parser
* @param string &$text
* @return true
*/
public static function doSomething( &$parser, &$text ) {
// Called in MW text like this: {{#hdf: }}
// For named parameters like {{#hdf: foo=bar | apple=orange | banana }}
// See: https://www.mediawiki.org/wiki/Manual:Parser_functions#Named_parameters
return "This text will be shown when calling this in MW text.";
}
public static function onMimeMagicInit( $mime ) {
$mime->addExtraTypes( 'chemical/x-jcamp-dx dx jdx jcm' );
}
public static function onMimeMagicImproveFromExtension( $mimeAnalyzer, $ext, &$mime ) {
if ( in_array( $ext, ['hdf', 'h4', 'hdf4', 'he2']) ) {
$mime = 'application/x-hdf';
}
if ( in_array( $ext, ['h5', 'hdf5', 'he5']) ) {
$mime = 'application/x-hdf5';
}
if ( in_array( $ext, ['dx', 'jdx', 'jcm'] ) ) {
$mime = 'chemical/x-jcamp-dx';
}
if ( in_array( $ext, ['mpr', 'mpt', 'mps'] ) ) {
#.mpr : Raw binary file containing the data
#.mpt : .mpr into Text file
#.mps : experiment Settings text file.
#$mime = 'application/octet-stream'
$mime = 'application/x-biologic';
}
}
public static function onMimeMagicGuessFromContent( $mimeAnalyzer, &$head, &$tail, $file, &$mime ) {
#if ( str_contains( $head, '##JCAMP' ) ) {
# $mime = 'chemical/x-jcamp-dx';
#}
return;
}
}