1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticTasks |
5
|
|
|
* |
6
|
|
|
* @defgroup SemanticTasks Semantic Tasks |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use ST\SemanticTasksMailer; |
10
|
|
|
|
11
|
|
|
SemanticTasks::load(); |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @codeCoverageIgnore |
15
|
|
|
*/ |
16
|
|
|
class SemanticTasks { |
17
|
|
|
|
18
|
|
|
public static function load() { |
19
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
20
|
|
|
include_once __DIR__ . '/vendor/autoload.php'; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @global boolean $wgSemanticTasksNotifyIfUnassigned |
26
|
|
|
* @since 1.0 |
27
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Extension.json/Schema#callback |
28
|
|
|
*/ |
29
|
|
|
public static function initExtension( $credits = [] ) { |
30
|
|
|
|
31
|
|
|
$version = 'UNKNOWN' ; |
32
|
|
|
|
33
|
|
|
// See https://phabricator.wikimedia.org/T151136 |
34
|
|
|
if ( isset( $credits['version'] ) ) { |
35
|
|
|
$version = $credits['version']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
define( 'SEMANTIC_TASKS', $version ); |
39
|
|
|
|
40
|
|
|
// https://phabricator.wikimedia.org/T212738 |
41
|
|
|
if ( !defined( 'MW_VERSION' ) ) { |
42
|
|
|
define( 'MW_VERSION', $GLOBALS['wgVersion'] ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Register extension messages and other localisation. |
46
|
|
|
$wgMessagesDirs['SemanticTasks'] = __DIR__ . '/i18n'; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @since 1.0 |
51
|
|
|
*/ |
52
|
|
|
public static function onExtensionFunction() { |
53
|
|
|
|
54
|
|
|
// Check requirements after LocalSetting.php has been processed |
55
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
56
|
|
|
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
57
|
|
|
die( "\nThe 'Semantic Tasks' extension requires the 'Semantic MediaWiki' extension to be installed and enabled.\n" ); |
58
|
|
|
} else { |
59
|
|
|
die( |
60
|
|
|
'<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticTasks">Semantic Tasks</a> extension' . |
61
|
|
|
' requires the <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> extension to be installed and enabled.<br />' |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$assignees = new \ST\Assignees(); |
67
|
|
|
|
68
|
|
|
// Register extension hooks. |
69
|
|
|
global $wgHooks; |
70
|
|
|
$wgHooks['PageContentSave'][] = [ $assignees, 'saveAssignees' ]; |
71
|
|
|
$wgHooks['PageContentSaveComplete'][] = function(WikiPage $article, User $current_user, Content $text, |
72
|
|
|
$summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision) use ($assignees) { |
73
|
|
|
SemanticTasksMailer::mailAssigneesUpdatedTask( |
74
|
|
|
$assignees, $article, $current_user, $text, |
75
|
|
|
$summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision |
76
|
|
|
); |
77
|
|
|
}; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.