summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticResultFormats/SemanticResultFormats.utils.php
blob: 0093c000366f78f3109c9268ea6ecda588e9a439 (plain)
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
<?php

/**
 * Common libray of independent functions that are shared among different printers
 * @licence GNU GPL v2 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 boolean $isHtml
	 *
	 * @since 1.8
	 */
	public static function htmlProcessingElement( $isHtml = true ) {
		SMWOutputs::requireResource( 'ext.srf' );

		return Html::rawElement(
			'div',
			[ 'class' => 'srf-spinner mw-small-spinner' ],
			Html::element(
				'span',
				[ 'class' => 'srf-processing-text' ],
				wfMessage( 'srf-module-loading' )->inContentLanguage()->text()
			)
		);
	}

	/**
	 * 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', Skin::makeVariablesScript( $requireHeadItem, false ) );
	}

	/**
	 * @brief 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 );
	}

}