forked from SemanticMediaWiki/SemanticResultFormats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SemanticResultFormats.utils.php
87 lines (76 loc) · 1.89 KB
/
SemanticResultFormats.utils.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Common libray of independent functions that are shared among different printers
* @license GPL-2.0-or-later
*
* @since 1.8
*
* @author mwjames
*/
final class SRFUtils {
/**
* Helper function that generates a html element, representing a
* processing/loading image as long as jquery is inactive
*
* @param bool $isHtml
*
* @since 1.8
*/
public static function htmlProcessingElement( $isHtml = true ) {
SMWOutputs::requireResource( 'ext.smw.styles' );
return Html::rawElement(
'div',
[ 'class' => 'srf-loading-dots' ]
);
}
/**
* Add JavaScript variables to the output
*
* @since 1.8
*/
public static function addGlobalJSVariables() {
$options = [
'srfgScriptPath' => $GLOBALS['srfgScriptPath'],
'srfVersion' => SRF_VERSION
];
$requireHeadItem = [ 'srf.options' => $options ];
SMWOutputs::requireHeadItem( 'srf.options', self::makeVariablesScript( $requireHeadItem ) );
}
/**
* Returns semantic search link for the current query
*
* Generate a link to access the current ask query
*
* @since 1.8
*
* @param string $link
*
* @return $link
*/
public static function htmlQueryResultLink( $link ) {
// Get linker instance
$linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
// Set caption
$link->setCaption( '[+]' );
// Set parameters
$link->setParameter( '', 'class' );
$link->setParameter( '', 'searchlabel' );
return $link->getText( SMW_OUTPUT_HTML, $linker );
}
/**
* @since 3.2.0
*
* @param array $data
*
* @param string|null|bool $nonce
*
* @return string|WrappedString HTML
*/
public static function makeVariablesScript( $data, $nonce = null ) {
$script = ResourceLoader::makeConfigSetScript( $data );
if ( $nonce === null ) {
$nonce = RequestContext::getMain()->getOutput()->getCSP()->getNonce();
}
return ResourceLoader::makeInlineScript( $script, $nonce );
}
}