summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Site.php
blob: c2bd32813d33662e55a0c38df041d081e6b3a01c (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php

namespace SMW;

use SiteStats;

/**
 * @license GNU GPL v2+
 * @since 3.0
 *
 * @author mwjames
 */
class Site {

	/**
	 * Check whether the wiki is in read-only mode.
	 *
	 * @since 3.0
	 *
	 * @return boolean
	 */
	public static function isReadOnly() {

		// MediaWiki\Services\ServiceDisabledException from line 340 of
		// ...\ServiceContainer.php: Service disabled: DBLoadBalancer
		try {
			$isReadOnly = wfReadOnly();
		} catch( \MediaWiki\Services\ServiceDisabledException $e ) {
			$isReadOnly = true;
		}

		return $isReadOnly;
	}

	/**
	 * @since 3.0
	 *
	 * @return boolean
	 */
	public static function isBlocked() {
		return defined( 'MEDIAWIKI_INSTALL' ) && MEDIAWIKI_INSTALL;
	}

	/**
	 * @since 3.0
	 *
	 * @return string
	 */
	public static function name() {
		return $GLOBALS['wgSitename'];
	}

	/**
	 * @since 3.0
	 *
	 * @return string
	 */
	public static function wikiurl() {
		return $GLOBALS['wgServer'] . str_replace( '$1', '', $GLOBALS['wgArticlePath'] );
	}

	/**
	 * @since 3.0
	 *
	 * @return string
	 */
	public static function languageCode() {
		return $GLOBALS['wgLanguageCode'];
	}

	/**
	 * @since 3.0
	 *
	 * @return boolean
	 */
	public static function isCommandLineMode() {

		// MW 1.27 wgCommandLineMode isn't set correctly
		if ( ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) ) {
			return true;
		}

		return $GLOBALS['wgCommandLineMode'];
	}

	/**
	 * @since 3.0
	 *
	 * @return boolean
	 */
	public static function isCapitalLinks() {
		return $GLOBALS['wgCapitalLinks'];
	}

	/**
	 * @since 3.0
	 *
	 * @param $affix string
	 *
	 * @return string
	 */
	public static function id( $affix = '' ) {

		if ( $affix !== '' && $affix{0} !== ':' ) {
			$affix = ':' . $affix;
		}

		return wfWikiID() . $affix;
	}

	/**
	 * @since 3.0
	 *
	 * @return []
	 */
	public static function stats() {
		return [
			'pageCount' => SiteStats::pages(),
			'contentPageCount' => SiteStats::articles(),
			'mediaCount' => SiteStats::images(),
			'editCount' => SiteStats::edits(),
			'userCount' => SiteStats::users(),
			'adminCount' => SiteStats::numberingroup( 'sysop' )
		];
	}

	/**
	 * @since 3.0
	 *
	 * @param string $typeFilter
	 *
	 * @return array
	 */
	public static function getJobClasses( $typeFilter = '' ) {

		if ( $typeFilter === 'SMW' ) {
			$typeFilter = 'smw.';
		}

		$jobList = $GLOBALS['wgJobClasses'];

		foreach ( $jobList as $type => $class ) {

			if ( $typeFilter === '' ) {
				continue;
			}

			if ( strpos( $type, $typeFilter ) === false ) {
				unset( $jobList[$type] );
			}
		}

		return $jobList;
	}

}