1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\MediaWiki\Specials\Admin; |
4
|
|
|
|
5
|
|
|
use SMW\Message; |
6
|
|
|
use Html; |
7
|
|
|
use WebRequest; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @license GNU GPL v2+ |
11
|
|
|
* @since 3.0 |
12
|
|
|
* |
13
|
|
|
* @author mwjames |
14
|
|
|
*/ |
15
|
|
|
class DeprecationNoticeTaskHandler extends TaskHandler { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var OutputFormatter |
19
|
|
|
*/ |
20
|
|
|
private $outputFormatter; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private $deprecationNoticeList = array(); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @since 3.0 |
29
|
|
|
* |
30
|
|
|
* @param OutputFormatter $outputFormatter |
31
|
|
|
* @param array $deprecationNoticeList |
32
|
|
|
*/ |
33
|
|
|
public function __construct( OutputFormatter $outputFormatter, array $deprecationNoticeList = array() ) { |
34
|
|
|
$this->outputFormatter = $outputFormatter; |
35
|
|
|
$this->deprecationNoticeList = $deprecationNoticeList; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @since 3.0 |
40
|
|
|
* |
41
|
|
|
* {@inheritDoc} |
42
|
|
|
*/ |
43
|
|
|
public function getHtml() { |
44
|
|
|
|
45
|
|
|
$noticeConfigList = array(); |
46
|
|
|
$replacementConfigList = array(); |
47
|
|
|
$removedConfigList = array(); |
48
|
|
|
|
49
|
|
|
if ( isset( $this->deprecationNoticeList['notice'] ) ) { |
50
|
|
|
$noticeConfigList = $this->deprecationNoticeList['notice']; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ( isset( $this->deprecationNoticeList['replacement'] ) ) { |
54
|
|
|
$replacementConfigList = $this->deprecationNoticeList['replacement']; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ( isset( $this->deprecationNoticeList['removal'] ) ) { |
58
|
|
|
$removedConfigList = $this->deprecationNoticeList['removal']; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$noticeList = $this->detectOn( |
62
|
|
|
$noticeConfigList, |
63
|
|
|
$replacementConfigList, |
64
|
|
|
$removedConfigList |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
if ( $noticeList === array() ) { |
68
|
|
|
return ''; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return Html::rawElement( 'h2', array(), $this->getMessageAsString( 'smw-admin-deprecation-notice-title' ) ) . |
72
|
|
|
Html::rawElement( 'div', array( 'class' => 'smw-admin-deprecation-notice-section' ), |
73
|
|
|
Html::rawElement( 'p', array( 'class' => 'smw-admin-deprecation-notice-docu-section plainlinks' ), $this->getMessageAsString( 'smw-admin-deprecation-notice-docu' ) ) . |
74
|
|
|
Html::rawElement( 'div', array( 'class' => 'plainlinks' ), |
75
|
|
|
Html::rawElement( 'p', array(), implode( '', $noticeList ) ) |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @since 3.0 |
82
|
|
|
* |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function isTaskFor( $task ) {} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @since 3.0 |
89
|
|
|
* |
90
|
|
|
* {@inheritDoc} |
91
|
|
|
*/ |
92
|
|
|
public function handleRequest( WebRequest $webRequest ) {} |
93
|
|
|
|
94
|
|
|
private function detectOn( $noticeConfigList, $replacementConfigList, $removedConfigList ) { |
|
|
|
|
95
|
|
|
|
96
|
|
|
$noticeList = array(); |
97
|
|
|
$list = array(); |
98
|
|
|
|
99
|
|
|
foreach ( $noticeConfigList as $setting => $msg ) { |
100
|
|
|
if ( isset( $GLOBALS[$setting] ) ) { |
101
|
|
|
$list[] = $this->createListItem( array( 'smw-admin-deprecation-notice-config-msg', '$' . $setting, $msg ) ); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$this->createList( $noticeList, $list, 'smw-admin-deprecation-notice-title-notice' ); |
106
|
|
|
|
107
|
|
|
foreach ( $replacementConfigList as $old => $new ) { |
108
|
|
|
if ( isset( $GLOBALS[$old] ) ) { |
109
|
|
|
$list[] = $this->createListItem( array( 'smw-admin-deprecation-notice-config-replacement', '$' . $old, '$' . $new ) ); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$this->createList( $noticeList, $list, 'smw-admin-deprecation-notice-title-replacement' ); |
114
|
|
|
|
115
|
|
|
foreach ( $removedConfigList as $setting => $msg ) { |
116
|
|
|
if ( isset( $GLOBALS[$setting] ) ) { |
117
|
|
|
$list[] = $this->createListItem( array( 'smw-admin-deprecation-notice-config-msg', '$' . $setting, $msg ) ); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$this->createList( $noticeList, $list, 'smw-admin-deprecation-notice-title-removal' ); |
122
|
|
|
|
123
|
|
|
return $noticeList; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
private function createList( &$noticeList, &$list, $title ) { |
127
|
|
|
|
128
|
|
|
if ( $list === array() ) { |
129
|
|
|
return; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$noticeList[] = Html::rawElement( |
133
|
|
|
'h3', |
134
|
|
|
array(), |
135
|
|
|
$this->getMessageAsString( $title ) |
136
|
|
|
) . Html::rawElement( |
137
|
|
|
'ul', |
138
|
|
|
array(), |
139
|
|
|
implode( '', $list ) |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
$list = array(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
private function createListItem( $message ) { |
146
|
|
|
return Html::rawElement( 'li', array(), $this->getMessageAsString( $message, Message::PARSE ) ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
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: