Completed
Push — master ( e11051...f173c0 )
by mw
10s
created

SummaryCards.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use SUC\HookRegistry;
4
use SUC\Options;
5
6
/**
7
 * @see https://github.com/SemanticMediaWiki/SummaryCards/
8
 *
9
 * @defgroup SummaryCards Summary Cards
10
 */
11
if ( !defined( 'MEDIAWIKI' ) ) {
12
	die( 'This file is part of the SummaryCards extension, it is not a valid entry point.' );
13
}
14
15
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.24', 'lt' ) ) {
16
	die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SummaryCards/">SummaryCards</a> is only compatible with MediaWiki 1.24 or above. You need to upgrade MediaWiki first.' );
17
}
18
19
if ( defined( 'SUC_VERSION' ) ) {
20
	// Do not initialize more than once.
21
	return 1;
22
}
23
24
SummaryCards::initExtension();
25
26
$GLOBALS['wgExtensionFunctions'][] = function() {
27
	SummaryCards::onExtensionFunction();
28
};
29
30
/**
31
 * @codeCoverageIgnore
32
 */
33
class SummaryCards {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
35
	/**
36
	 * @since 1.0
37
	 */
38
	public static function initExtension() {
0 ignored issues
show
initExtension uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
39
40
		// Load DefaultSettings
41
		require_once __DIR__ . '/DefaultSettings.php';
42
43
		define( 'SUC_VERSION', '1.0.0-alpha' );
44
45
		// Register the extension
46
		$GLOBALS['wgExtensionCredits']['others'][ ] = array(
47
			'path'           => __DIR__,
48
			'name'           => 'Summary Cards',
49
			'author'         => array(
50
				'James Hong Kong'
51
			),
52
			'url'            => 'https://github.com/SemanticMediaWiki/SummaryCards/',
53
			'descriptionmsg' => 'suc-desc',
54
			'version'        => SUC_VERSION,
55
			'license-name'   => 'GPL-2.0+',
56
		);
57
58
		// Register message files
59
		$GLOBALS['wgMessagesDirs']['SummaryCards'] = __DIR__ . '/i18n';
60
61
		$GLOBALS['wgAPIModules']['ctparse'] = '\SUC\ApiCacheableTemplateParse';
62
63
		$GLOBALS['wgResourceModules']['ext.summary.cards.styles'] = array(
64
			'styles'  => 'res/ext.suc.styles.css',
65
			'localBasePath' => __DIR__ ,
66
			'remoteExtPath' => 'SummaryCards',
67
			'position' => 'top',
68
			'targets' => array(
69
				'mobile',
70
				'desktop'
71
			)
72
		);
73
74
		$GLOBALS['wgResourceModules']['ext.summary.cards.tooltip'] = array(
75
			'localBasePath' => __DIR__ ,
76
			'remoteExtPath' => 'SummaryCards',
77
			'position' => 'bottom',
78
			'dependencies'  => array(
79
				'onoi.qtip',
80
				'onoi.md5',
81
				'onoi.blobstore',
82
				'onoi.util'
83
			),
84
			'targets' => array(
85
				'mobile',
86
				'desktop'
87
			)
88
		);
89
90
		$GLOBALS['wgResourceModules']['ext.summary.cards'] = array(
91
			'scripts' => array(
92
				'res/ext.suc.cards.js'
93
			),
94
			'localBasePath' => __DIR__ ,
95
			'remoteExtPath' => 'SummaryCards',
96
			'position' => 'bottom',
97
			'dependencies'  => array(
98
				'mediawiki.api',
99
				'mediawiki.api.parse',
100
				'ext.summary.cards.styles',
101
				'ext.summary.cards.tooltip',
102
			),
103
			'messages' => array(
104
				'suc-tooltip-title',
105
				'suc-tooltip-error'
106
			),
107
			'targets' => array(
108
				'mobile',
109
				'desktop'
110
			)
111
		);
112
	}
113
114
	/**
115
	 * @since 1.0
116
	 */
117
	public static function onExtensionFunction() {
118
119
		$hookRegistry = new HookRegistry(
120
			Options::newFromGlobals()
121
		);
122
123
		$hookRegistry->register();
124
	}
125
126
	/**
127
	 * @since 1.0
128
	 *
129
	 * @return string|null
130
	 */
131
	public static function getVersion() {
132
		return SUC_VERSION;
133
	}
134
135
}
136