summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Hooks/GetPreferences.php
blob: e9af0f4182f83bb53797c4b286e6551bf8c11214 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

namespace SMW\MediaWiki\Hooks;

use Hooks;
use User;
use Xml;

/**
 * Hook: GetPreferences adds user preference
 *
 * @see https://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
 *
 * @license GNU GPL v2+
 * @since 2.0
 *
 * @author mwjames
 */
class GetPreferences extends HookHandler {

	/**
	 * @var User
	 */
	private $user;

	/**
	 * @since  2.0
	 *
	 * @param User $user
	 */
	public function __construct( User $user ) {
		$this->user = $user;
	}

	/**
	 * @since 2.0
	 *
	 * @param array &$preferences
	 *
	 * @return true
	 */
	public function process( array &$preferences ) {

		// Intro text
		$preferences['smw-prefs-intro'] =
			[
				'type' => 'info',
				'label' => '&#160;',
				'default' => Xml::tags( 'tr', [ 'class' => 'plainlinks' ],
					Xml::tags( 'td', [ 'colspan' => 2 ],
						wfMessage(  'smw-prefs-intro-text' )->parseAsBlock() ) ),
				'section' => 'smw',
				'raw' => 1,
				'rawrow' => 1,
			];

		// Preference to allow time correction
		$preferences['smw-prefs-general-options-time-correction'] = [
			'type' => 'toggle',
			'label-message' => 'smw-prefs-general-options-time-correction',
			'section' => 'smw/general-options',
		];

		$preferences['smw-prefs-general-options-disable-editpage-info'] = [
			'type' => 'toggle',
			'label-message' => 'smw-prefs-general-options-disable-editpage-info',
			'section' => 'smw/general-options',
			'disabled' => !$this->getOption( 'smwgEnabledEditPageHelp', false )
		];

		$preferences['smw-prefs-general-options-disable-search-info'] = [
			'type' => 'toggle',
			'label-message' => 'smw-prefs-general-options-disable-search-info',
			'section' => 'smw/general-options',
			'disabled' => $this->getOption( 'wgSearchType' ) !== 'SMWSearch'
		];

		$preferences['smw-prefs-general-options-jobqueue-watchlist'] = [
			'type' => 'toggle',
			'label-message' => 'smw-prefs-general-options-jobqueue-watchlist',
			'help-message' => 'smw-prefs-help-general-options-jobqueue-watchlist',
			'section' => 'smw/general-options',
			'disabled' => $this->getOption( 'smwgJobQueueWatchlist', [] ) === []
		];

		// Option to enable input assistance
		$preferences['smw-prefs-general-options-suggester-textinput'] = [
			'type' => 'toggle',
			'label-message' => 'smw-prefs-general-options-suggester-textinput',
			'help-message' => 'smw-prefs-help-general-options-suggester-textinput',
			'section' => 'smw/general-options',
		];

		// Option to enable tooltip info
		$preferences['smw-prefs-ask-options-tooltip-display'] = [
			'type' => 'toggle',
			'label-message' => 'smw-prefs-ask-options-tooltip-display',
			'section' => 'smw/ask-options',
		];

		Hooks::run( 'SMW::GetPreferences', [ $this->user, &$preferences ] );

		return true;
	}

}