|
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
|
|
|
// Set to true to notify users when they are unassigned from a task |
|
49
|
|
|
global $wgSemanticTasksNotifyIfUnassigned; |
|
50
|
|
|
$wgSemanticTasksNotifyIfUnassigned = false; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @since 1.0 |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function onExtensionFunction() { |
|
57
|
|
|
|
|
58
|
|
|
// Check requirements after LocalSetting.php has been processed |
|
59
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
|
60
|
|
|
if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
|
61
|
|
|
die( "\nThe 'Semantic Tasks' extension requires the 'Semantic MediaWiki' extension to be installed and enabled.\n" ); |
|
62
|
|
|
} else { |
|
63
|
|
|
die( |
|
64
|
|
|
'<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticTasks">Semantic Tasks</a> extension' . |
|
65
|
|
|
' requires the <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> extension to be installed and enabled.<br />' |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$assignees = new \ST\Assignees(); |
|
71
|
|
|
|
|
72
|
|
|
// Register extension hooks. |
|
73
|
|
|
global $wgHooks; |
|
74
|
|
|
$wgHooks['PageContentSave'][] = [ $assignees, 'saveAssignees' ]; |
|
75
|
|
|
$wgHooks['PageContentSaveComplete'][] = function(WikiPage $article, User $current_user, Content $text, |
|
76
|
|
|
$summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision) use ($assignees) { |
|
77
|
|
|
SemanticTasksMailer::mailAssigneesUpdatedTask( |
|
78
|
|
|
$assignees, $article, $current_user, $text, |
|
79
|
|
|
$summary, $minoredit, $watchthis, $sectionanchor, $flags, $revision |
|
80
|
|
|
); |
|
81
|
|
|
}; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
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
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.