Index: trunk/extensions/UploadWizard/UploadWizardTutorial.php |
— | — | @@ -1,127 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Class to encapsulate all the html generation associated with the UploadWizard tutorial. |
6 | | - * Might be a start for a subclass of UploadWizard, if we ever free it of its WMF-oriented features |
7 | | - * So that non-WMF'ers can use it |
8 | | - */ |
9 | | -class UploadWizardTutorial { |
10 | | - |
11 | | - // name of the tutorial on Wikimedia Commons. The $1 is replaced with the language desired |
12 | | - const NAME_TEMPLATE = 'Licensing_tutorial_$1.svg'; |
13 | | - |
14 | | - // the width we want to scale the tutorial to, for our interface |
15 | | - const WIDTH_PX = 720; |
16 | | - |
17 | | - // imagemap coordinates of the "helpdesk" button at the bottom, which is supposed to be clickable. |
18 | | - const HELPDESK_BUTTON_COORDS = "27, 1319, 691, 1384"; |
19 | | - |
20 | | - // id of imagemap used in tutorial |
21 | | - const IMAGEMAP_ID = 'tutorialMap'; |
22 | | - |
23 | | - /** |
24 | | - * Fetches appropriate HTML for the tutorial portion of the wizard. |
25 | | - * Looks up an image on the current wiki. This will work as is on Commons, and will also work |
26 | | - * on test wikis that enable instantCommons. |
27 | | - * @param {String} $langCode language code as used by MediaWiki, similar but not identical to ISO 639-1. |
28 | | - * @return {String} html that will display the tutorial. |
29 | | - */ |
30 | | - public static function getHtml() { |
31 | | - global $wgLang; |
32 | | - |
33 | | - $error = null; |
34 | | - $errorHtml = ''; |
35 | | - $tutorialHtml = ''; |
36 | | - |
37 | | - $langCode = $wgLang->getCode(); |
38 | | - |
39 | | - $tutorialFile = false; |
40 | | - // getFile returns false if it can't find the right file |
41 | | - if ( ! $tutorialFile = self::getFile( $langCode ) ) { |
42 | | - $error = 'localized-file-missing'; |
43 | | - if ( $langCode !== 'en' ) { |
44 | | - $tutorialFile = self::getFile( 'en' ); |
45 | | - } |
46 | | - } |
47 | | - |
48 | | - // at this point, we have one of the following situations: |
49 | | - // $error is null, and tutorialFile is the right one for this language |
50 | | - // $error notes we couldn't find the tutorialFile for your language, and $tutorialFile is the english one |
51 | | - // $error notes we couldn't find the tutorialFile for your language, and $tutorialFile is still false (major file failure) |
52 | | - |
53 | | - if ( $tutorialFile ) { |
54 | | - // XXX TODO if the client can handle SVG, we could also just send it the unscaled thumb, client-scaled into a DIV or something. |
55 | | - // if ( client can handle SVG ) { |
56 | | - // $tutorialThumbnailImage->getUnscaledThumb(); |
57 | | - // } |
58 | | - // put it into a div of appropriate dimensions. |
59 | | - |
60 | | - // n.b. File::transform() returns false if failed, MediaTransformOutput otherwise |
61 | | - $thumbnailImage = $tutorialFile->transform( array( 'width' => self::WIDTH_PX ) ); |
62 | | - if ( $thumbnailImage ) { |
63 | | - $tutorialHtml = self::getImageHtml( $thumbnailImage ); |
64 | | - } else { |
65 | | - $error = 'cannot-transform'; |
66 | | - } |
67 | | - } else { |
68 | | - $error = 'file-missing'; |
69 | | - } |
70 | | - |
71 | | - if ( $error !== null ) { |
72 | | - $errorHtml = Html::element( 'p', array( 'class' => 'errorbox', 'style' => 'float: none;' ), wfMsg( 'mwe-upwiz-tutorial-error-' . $error ) ); |
73 | | - } |
74 | | - |
75 | | - return $errorHtml . $tutorialHtml; |
76 | | - |
77 | | - } |
78 | | - |
79 | | - /** |
80 | | - * Get tutorial file for a particular language, or false if not available. |
81 | | - * @param {String} $langCode: language Code |
82 | | - * @return {File|false} |
83 | | - */ |
84 | | - public static function getFile( $langCode ) { |
85 | | - $tutorialName = str_replace( '$1', $langCode, self::NAME_TEMPLATE ); |
86 | | - $tutorialTitle = Title::newFromText( $tutorialName, NS_FILE ); |
87 | | - return wfFindFile( $tutorialTitle ); |
88 | | - } |
89 | | - |
90 | | - /** |
91 | | - * Constructs HTML for the tutorial (laboriously), including an imagemap for the clickable "Help desk" button. |
92 | | - * @param {ThumbnailImage} $thumb |
93 | | - * @return {String} HTML representing the image, with clickable helpdesk button |
94 | | - */ |
95 | | - public static function getImageHtml( $thumb ) { |
96 | | - |
97 | | - $helpDeskUrl = wfMsg( 'mwe-upwiz-help-desk-url' ); |
98 | | - |
99 | | - // Per convention, we may be either using an absolute URL or a wiki page title in this UI message |
100 | | - if( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $helpDeskUrl )) { |
101 | | - $helpDeskHref = $helpDeskUrl; |
102 | | - } else { |
103 | | - $helpDeskTitle = Title::newFromText( $helpDeskUrl ); |
104 | | - $helpDeskHref = $helpDeskTitle ? $helpDeskTitle->getLocalURL() : '#'; |
105 | | - } |
106 | | - |
107 | | - // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image. |
108 | | - // we could do more special effects with hovers and images and such, not to mention SVG scripting, |
109 | | - // but we aren't sure what we want yet... |
110 | | - $img = Html::element( 'img', array( |
111 | | - 'src' => $thumb->getUrl(), |
112 | | - 'width' => $thumb->getWidth(), |
113 | | - 'height' => $thumb->getHeight(), |
114 | | - 'usemap' => '#' . self::IMAGEMAP_ID |
115 | | - ) ); |
116 | | - $areaAltText = wfMsg( 'mwe-upwiz-help-desk' ); |
117 | | - $area = Html::element( 'area', array( |
118 | | - 'shape' => 'rect', |
119 | | - 'coords' => self::HELPDESK_BUTTON_COORDS, |
120 | | - 'href' => $helpDeskHref, |
121 | | - 'alt' => $areaAltText, |
122 | | - 'title' => $areaAltText |
123 | | - ) ); |
124 | | - $map = Html::rawElement( 'map', array( 'id' => self::IMAGEMAP_ID, 'name' => self::IMAGEMAP_ID ), $area ); |
125 | | - return $map . $img; |
126 | | - } |
127 | | - |
128 | | -} |
Index: trunk/extensions/UploadWizard/UploadWizardConfig.php |
— | — | @@ -1,76 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Static class with methods for interacting with the Upload Wizards configuration. |
6 | | - * |
7 | | - * @file |
8 | | - * @ingroup Upload |
9 | | - * |
10 | | - * @since 1.2 |
11 | | - * |
12 | | - * @licence GNU GPL v3+ |
13 | | - * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | | - */ |
15 | | -class UploadWizardConfig { |
16 | | - |
17 | | - /** |
18 | | - * Returns the globally configuration, optionaly combined with campaign sepcific |
19 | | - * configuration. |
20 | | - * |
21 | | - * @since 1.2 |
22 | | - * |
23 | | - * @param string|null $campaignName |
24 | | - * |
25 | | - * @return array |
26 | | - */ |
27 | | - public static function getConfig( $campaignName = null ) { |
28 | | - global $wgUploadWizardConfig; |
29 | | - static $mergedConfig = false; |
30 | | - |
31 | | - if ( !$mergedConfig ) { |
32 | | - $wgUploadWizardConfig = array_merge( self::getDefaultConfig(), $wgUploadWizardConfig ); |
33 | | - } |
34 | | - |
35 | | - if ( !is_null( $campaignName ) ) { |
36 | | - $wgUploadWizardConfig = array_merge( $wgUploadWizardConfig, self::getCampaignConfig( $campaignName ) ); |
37 | | - } |
38 | | - |
39 | | - return $wgUploadWizardConfig; |
40 | | - } |
41 | | - |
42 | | - /** |
43 | | - * Returns the default global config, from UploadWizard.config.php. |
44 | | - * |
45 | | - * @since 1.2 |
46 | | - * |
47 | | - * @return array |
48 | | - */ |
49 | | - protected static function getDefaultConfig() { |
50 | | - global $wgUpwizDir; |
51 | | - $configPath = $wgUpwizDir . '/UploadWizard.config.php'; |
52 | | - return is_file( $configPath ) ? include( $configPath ) : array(); |
53 | | - } |
54 | | - |
55 | | - /** |
56 | | - * Returns the configuration of the specified campaign, |
57 | | - * or an empty array when the campaign is not found or not enabled. |
58 | | - * |
59 | | - * @since 1.2 |
60 | | - * |
61 | | - * @param string $campaignName |
62 | | - * |
63 | | - * @return array |
64 | | - */ |
65 | | - protected static function getCampaignConfig( $campaignName ) { |
66 | | - $capmaignSettings = array(); |
67 | | - |
68 | | - $capaign = UploadWizardCampaign::newFromName( $campaignName ); |
69 | | - |
70 | | - if ( $capaign !== false && $capaign->getIsEnabled() ) { |
71 | | - return $capaign->getConfig(); |
72 | | - } |
73 | | - |
74 | | - return array(); |
75 | | - } |
76 | | - |
77 | | -} |
Index: trunk/extensions/UploadWizard/UploadWizardCampaign.php |
— | — | @@ -1,452 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Class that represents a single upload campaign. |
6 | | - * |
7 | | - * @file |
8 | | - * @ingroup Upload |
9 | | - * |
10 | | - * @since 1.2 |
11 | | - * |
12 | | - * @licence GNU GPL v3+ |
13 | | - * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | | - */ |
15 | | -class UploadWizardCampaign { |
16 | | - |
17 | | - /** |
18 | | - * If the ID of the campaign. |
19 | | - * Either this matched a record in the uw_campaigns table or is null. |
20 | | - * |
21 | | - * @since 1.2 |
22 | | - * @var integer or null |
23 | | - */ |
24 | | - protected $id; |
25 | | - |
26 | | - /** |
27 | | - * If the name of the campaign. |
28 | | - * This name is the string used to invoke the campaign via campaign=name. |
29 | | - * |
30 | | - * @since 1.2 |
31 | | - * @var string |
32 | | - */ |
33 | | - protected $name; |
34 | | - |
35 | | - /** |
36 | | - * If the campaign is enabled or not. |
37 | | - * |
38 | | - * @since 1.2 |
39 | | - * @var boolean |
40 | | - */ |
41 | | - protected $isEnabled; |
42 | | - |
43 | | - /** |
44 | | - * The campaign configuration. |
45 | | - * |
46 | | - * @since 1.2 |
47 | | - * @var array |
48 | | - */ |
49 | | - protected $config; |
50 | | - |
51 | | - /** |
52 | | - * If the campaign config has been loaded or not. |
53 | | - * |
54 | | - * @since 1.2 |
55 | | - * @var boolean |
56 | | - */ |
57 | | - protected $loadedConfig = false; |
58 | | - |
59 | | - /** |
60 | | - * Create a new instance of $campaignName. |
61 | | - * |
62 | | - * @since 1.2 |
63 | | - * |
64 | | - * @param integer $id |
65 | | - * @param string $name |
66 | | - * @param boolean $isEnabled |
67 | | - * @param array $config |
68 | | - */ |
69 | | - public function __construct( $id, $name, $isEnabled, array $config ) { |
70 | | - $this->id = $id; |
71 | | - $this->name = $name; |
72 | | - $this->isEnabled = $isEnabled; |
73 | | - $this->config = $config; |
74 | | - |
75 | | - $this->loadedConfig = count( $this->config ) > 0; |
76 | | - } |
77 | | - |
78 | | - /** |
79 | | - * Returns the UploadWizardCampaign with specified name, or false if there is no such campaign. |
80 | | - * |
81 | | - * @since 1.2 |
82 | | - * |
83 | | - * @param string $campaignName |
84 | | - * @param boolean $loadConfig |
85 | | - * |
86 | | - * @return UploadWizardCampaign or false |
87 | | - */ |
88 | | - public static function newFromName( $campaignName, $loadConfig = true ) { |
89 | | - return self::newFromDB( array( 'campaign_name' => $campaignName ), $loadConfig ); |
90 | | - } |
91 | | - |
92 | | - /** |
93 | | - * Returns the UploadWizardCampaign with specified ID, or false if there is no such campaign. |
94 | | - * |
95 | | - * @since 1.2 |
96 | | - * |
97 | | - * @param integer $campaignId |
98 | | - * @param boolean $loadConfig |
99 | | - * |
100 | | - * @return UploadWizardCampaign or false |
101 | | - */ |
102 | | - public static function newFromId( $campaignId, $loadConfig = true ) { |
103 | | - return self::newFromDB( array( 'campaign_id' => $campaignId ), $loadConfig ); |
104 | | - } |
105 | | - |
106 | | - /** |
107 | | - * Returns a new instance of UploadWizardCampaign build from a database result |
108 | | - * obtained by doing a select with the porvided conditions on the uw_campaigns table. |
109 | | - * If no campaign matches the conditions, false will be returned. |
110 | | - * |
111 | | - * @since 1.2 |
112 | | - * |
113 | | - * @param array $conditions |
114 | | - * @param boolean $loadConfig |
115 | | - * |
116 | | - * @return UploadWizardCampaign or false |
117 | | - */ |
118 | | - protected static function newFromDB( array $conditions, $loadConfig = true ) { |
119 | | - $dbr = wfGetDB( DB_SLAVE ); |
120 | | - |
121 | | - $campaign = $dbr->selectRow( |
122 | | - 'uw_campaigns', |
123 | | - array( |
124 | | - 'campaign_id', |
125 | | - 'campaign_name', |
126 | | - 'campaign_enabled', |
127 | | - ), |
128 | | - $conditions |
129 | | - ); |
130 | | - |
131 | | - if ( !$campaign ) { |
132 | | - return false; |
133 | | - } |
134 | | - |
135 | | - $config = $loadConfig ? self::getPropsFromDB( $dbr, $campaign->campaign_id ) : array(); |
136 | | - |
137 | | - return new self( |
138 | | - $campaign->campaign_id, |
139 | | - $campaign->campaign_name, |
140 | | - $campaign->campaign_enabled, |
141 | | - $config |
142 | | - ); |
143 | | - } |
144 | | - |
145 | | - /** |
146 | | - * Returns the list of configuration settings that can be modified by campaigns, |
147 | | - * and the HTMLForm input type that can be used to represent their value. |
148 | | - * Property name => HTMLForm input type |
149 | | - * |
150 | | - * @since 1.2 |
151 | | - * |
152 | | - * @return array |
153 | | - */ |
154 | | - public static function getConfigTypes() { |
155 | | - return array( |
156 | | - 'skipTutorial' => 'check' |
157 | | - ); |
158 | | - } |
159 | | - |
160 | | - /** |
161 | | - * Returns the default configuration values. |
162 | | - * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
163 | | - * |
164 | | - * @since 1.2 |
165 | | - * |
166 | | - * @return array |
167 | | - */ |
168 | | - public static function getDefaultConfig() { |
169 | | - static $config = false; |
170 | | - |
171 | | - if ( $config === false ) { |
172 | | - $config = array(); |
173 | | - $globalConf = UploadWizardConfig::getConfig(); |
174 | | - |
175 | | - foreach ( self::getConfigTypes() as $setting => $type ) { |
176 | | - if ( array_key_exists( $setting, $globalConf ) ) { |
177 | | - $config[$setting] = array( 'type' => $type, 'default' => $globalConf[$setting] ); |
178 | | - } |
179 | | - else { |
180 | | - wfWarn( "Nonexiting Upload Wizard configuration setting '$setting' will be ignored." ); |
181 | | - } |
182 | | - } |
183 | | - } |
184 | | - |
185 | | - return $config; |
186 | | - } |
187 | | - |
188 | | - /** |
189 | | - * Returns the id of the campaign. |
190 | | - * |
191 | | - * @since 1.2 |
192 | | - * |
193 | | - * @return intgere |
194 | | - */ |
195 | | - public function getId() { |
196 | | - return $this->id; |
197 | | - } |
198 | | - |
199 | | - /** |
200 | | - * Returns the name of the campaign. |
201 | | - * |
202 | | - * @since 1.2 |
203 | | - * |
204 | | - * @return string |
205 | | - */ |
206 | | - public function getName() { |
207 | | - return $this->name; |
208 | | - } |
209 | | - |
210 | | - /** |
211 | | - * Returns if the campaign is enabled. |
212 | | - * |
213 | | - * @since 1.2 |
214 | | - * |
215 | | - * @return boolean |
216 | | - */ |
217 | | - public function getIsEnabled() { |
218 | | - return $this->isEnabled; |
219 | | - } |
220 | | - |
221 | | - /** |
222 | | - * Sets all config properties. |
223 | | - * |
224 | | - * @since 1.2 |
225 | | - * |
226 | | - * @param array $config |
227 | | - */ |
228 | | - public function setConfig( array $config ) { |
229 | | - $this->config = $config; |
230 | | - $this->loadedConfig = true; |
231 | | - } |
232 | | - |
233 | | - /** |
234 | | - * Returns all set config properties. |
235 | | - * Property name => property value |
236 | | - * |
237 | | - * @since 1.2 |
238 | | - * |
239 | | - * @return array |
240 | | - */ |
241 | | - public function getConfig() { |
242 | | - if ( !$this->loadedConfig ) { |
243 | | - if ( !is_null( $this->id ) ) { |
244 | | - $this->config = self::getPropsFromDB( wfGetDB( DB_SLAVE ), $this->id ); |
245 | | - } |
246 | | - |
247 | | - $this->loadedConfig = true; |
248 | | - } |
249 | | - |
250 | | - return $this->config; |
251 | | - } |
252 | | - |
253 | | - /** |
254 | | - * Returns all config properties by merging the set ones with a list of default ones. |
255 | | - * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
256 | | - * |
257 | | - * @since 1.2 |
258 | | - * |
259 | | - * @return array |
260 | | - */ |
261 | | - public function getAllConfig() { |
262 | | - $setConfig = $this->getConfig(); |
263 | | - $config = array(); |
264 | | - |
265 | | - foreach ( self::getDefaultConfig() as $name => $data ) { |
266 | | - if ( array_key_exists( $name, $setConfig ) ) { |
267 | | - $data['default'] = $setConfig[$name]; |
268 | | - } |
269 | | - |
270 | | - $config[$name] = $data; |
271 | | - } |
272 | | - |
273 | | - return $config; |
274 | | - } |
275 | | - |
276 | | - /** |
277 | | - * Returns the value of the specified config property. |
278 | | - * |
279 | | - * @since 1.2 |
280 | | - * |
281 | | - * @param string $property |
282 | | - * |
283 | | - * @return mixed |
284 | | - */ |
285 | | - public function getProperty( $property ) { |
286 | | - global $wgUploadWizardConfig; |
287 | | - |
288 | | - if ( array_key_exists( $property, $this->config ) ) { |
289 | | - return $this->config[$property]; |
290 | | - } |
291 | | - elseif ( array_key_exists( $property, $wgUploadWizardConfig['campaignDefaults'] ) ) { |
292 | | - return $wgUploadWizardConfig['campaignDefaults'][$property]; |
293 | | - } |
294 | | - else { |
295 | | - return null; |
296 | | - } |
297 | | - } |
298 | | - |
299 | | - /** |
300 | | - * Write the campaign to the DB. |
301 | | - * If it's already there, it'll be updated, else it'll be inserted. |
302 | | - * |
303 | | - * @since 1.2 |
304 | | - * |
305 | | - * @return boolean Success indicator |
306 | | - */ |
307 | | - public function writeToDB() { |
308 | | - if ( is_null( $this->id ) ) { |
309 | | - return $this->insertIntoDB(); |
310 | | - } |
311 | | - else { |
312 | | - return $this->updateInDB(); |
313 | | - } |
314 | | - } |
315 | | - |
316 | | - /** |
317 | | - * Insert the campaign into the DB. |
318 | | - * |
319 | | - * @since 1.2 |
320 | | - * |
321 | | - * @return boolean Success indicator |
322 | | - */ |
323 | | - protected function insertIntoDB() { |
324 | | - $dbw = wfGetDB( DB_MASTER ); |
325 | | - |
326 | | - $success = $dbw->insert( |
327 | | - 'uw_campaigns', |
328 | | - array( |
329 | | - 'campaign_name' => $this->name, |
330 | | - 'campaign_enabled' => $this->isEnabled, |
331 | | - ), |
332 | | - array( 'campaign_id' => $this->id ) |
333 | | - ); |
334 | | - |
335 | | - if ( $success ) { |
336 | | - $this->id = $dbw->insertId(); |
337 | | - $success &= $this->writePropsToDB( $dbw ); |
338 | | - } |
339 | | - |
340 | | - return $success; |
341 | | - } |
342 | | - |
343 | | - /** |
344 | | - * Update the campaign in the DB. |
345 | | - * |
346 | | - * @since 1.2 |
347 | | - * |
348 | | - * @return boolean Success indicator |
349 | | - */ |
350 | | - protected function updateInDB() { |
351 | | - $dbw = wfGetDB( DB_MASTER ); |
352 | | - |
353 | | - $success = $dbw->update( |
354 | | - 'uw_campaigns', |
355 | | - array( |
356 | | - 'campaign_name' => $this->name, |
357 | | - 'campaign_enabled' => $this->isEnabled, |
358 | | - ), |
359 | | - array( 'campaign_id' => $this->id ) |
360 | | - ); |
361 | | - |
362 | | - // Delete and insert instead of update. |
363 | | - // This will not result into dead-data when config vars are removed. |
364 | | - $success &= $dbw->delete( |
365 | | - 'uw_campaign_conf', |
366 | | - array( 'cc_campaign_id' => $this->id ) |
367 | | - ); |
368 | | - |
369 | | - $success &= $this->writePropsToDB( $dbw ); |
370 | | - |
371 | | - return $success; |
372 | | - } |
373 | | - |
374 | | - /** |
375 | | - * Write (insert) the properties into the DB. |
376 | | - * |
377 | | - * @since 1.2 |
378 | | - * |
379 | | - * @param Database $dbw |
380 | | - * |
381 | | - * @return boolean Success indicator |
382 | | - */ |
383 | | - protected function writePropsToDB( DatabaseBase $dbw ) { |
384 | | - $success = true; |
385 | | - |
386 | | - foreach ( $this->config as $prop => $value ) { |
387 | | - $success &= $dbw->insert( |
388 | | - 'uw_campaign_conf', |
389 | | - array( |
390 | | - 'cc_campaign_id' => $this->id, |
391 | | - 'cc_property' => $prop, |
392 | | - 'cc_value' => $value |
393 | | - ) |
394 | | - ); |
395 | | - } |
396 | | - |
397 | | - return $success; |
398 | | - } |
399 | | - |
400 | | - /** |
401 | | - * Get the configuration properties from the DB. |
402 | | - * |
403 | | - * @since 1.2 |
404 | | - * |
405 | | - * @param Database $dbr |
406 | | - * @param integer $campaignId |
407 | | - * |
408 | | - * @return array |
409 | | - */ |
410 | | - protected static function getPropsFromDB( DatabaseBase $dbr, $campaignId ) { |
411 | | - $config = array(); |
412 | | - |
413 | | - $confProps = $dbr->select( |
414 | | - 'uw_campaign_conf', |
415 | | - array( 'cc_property', 'cc_value' ), |
416 | | - array( 'cc_campaign_id' => $campaignId ) |
417 | | - ); |
418 | | - |
419 | | - foreach ( $confProps as $confProp ) { |
420 | | - $config[$confProp->cc_property] = $confProp->cc_value; |
421 | | - } |
422 | | - |
423 | | - return $config; |
424 | | - } |
425 | | - |
426 | | - /** |
427 | | - * Delete the campaign from the DB (when present). |
428 | | - * |
429 | | - * @since 1.2 |
430 | | - * |
431 | | - * @return boolean Success indicator |
432 | | - */ |
433 | | - public function deleteFromDB() { |
434 | | - if ( is_null( $this->id ) ) { |
435 | | - return true; |
436 | | - } |
437 | | - |
438 | | - $dbw = wfGetDB( DB_MASTER ); |
439 | | - |
440 | | - $d1 = $dbw->delete( |
441 | | - 'uw_campaigns', |
442 | | - array( 'campaign_id' => $this->id ) |
443 | | - ); |
444 | | - |
445 | | - $d2 = $dbw->delete( |
446 | | - 'uw_campaign_conf', |
447 | | - array( 'cc_campaign_id' => $this->id ) |
448 | | - ); |
449 | | - |
450 | | - return $d1 && $d2; |
451 | | - } |
452 | | - |
453 | | -} |
Index: trunk/extensions/UploadWizard/SpecialUploadWizard.php |
— | — | @@ -1,332 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Special:UploadWizard |
5 | | - * |
6 | | - * Easy to use multi-file upload page. |
7 | | - * |
8 | | - * @file |
9 | | - * @ingroup SpecialPage |
10 | | - * @ingroup Upload |
11 | | - */ |
12 | | - |
13 | | -class SpecialUploadWizard extends SpecialPage { |
14 | | - // the HTML form without javascript |
15 | | - private $simpleForm; |
16 | | - |
17 | | - // $request is the request (usually wgRequest) |
18 | | - // $par is everything in the URL after Special:UploadWizard. Not sure what we can use it for |
19 | | - public function __construct( $request = null, $par = null ) { |
20 | | - global $wgRequest; |
21 | | - // here we would configure ourselves based on stuff in $request and $wgRequest, but so far, we |
22 | | - // don't have such things |
23 | | - |
24 | | - parent::__construct( 'UploadWizard', 'upload' ); |
25 | | - |
26 | | - // create a simple form for non-JS fallback, which targets the old Special:Upload page. |
27 | | - // at some point, if we completely subsume its functionality, change that to point here again, |
28 | | - // but then we'll need to process non-JS uploads in the same way Special:Upload does. |
29 | | - $this->simpleForm = new UploadWizardSimpleForm(); |
30 | | - $this->simpleForm->setTitle( |
31 | | - SpecialPage::getTitleFor( 'Upload' ) |
32 | | - ); |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * Replaces default execute method |
37 | | - * Checks whether uploading enabled, user permissions okay, |
38 | | - * @param $subPage, e.g. the "foo" in Special:UploadWizard/foo. |
39 | | - */ |
40 | | - public function execute( $subPage ) { |
41 | | - global $wgRequest, $wgLang, $wgUser, $wgOut, $wgExtensionAssetsPath, |
42 | | - $wgUploadWizardDisableResourceLoader, $wgUploadWizardConfig; |
43 | | - |
44 | | - // side effects: if we can't upload, will print error page to wgOut |
45 | | - // and return false |
46 | | - if ( !( $this->isUploadAllowed() && $this->isUserUploadAllowed( $wgUser ) ) ) { |
47 | | - return; |
48 | | - } |
49 | | - |
50 | | - $this->setHeaders(); |
51 | | - $this->outputHeader(); |
52 | | - |
53 | | - // if query string includes 'skiptutorial=true' set config variable to true |
54 | | - if ( $wgRequest->getText( 'skiptutorial' ) ) { |
55 | | - $wgUploadWizardConfig['skipTutorial'] = true; |
56 | | - } |
57 | | - |
58 | | - // fallback for non-JS |
59 | | - $wgOut->addHTML( '<noscript>' ); |
60 | | - $wgOut->addHTML( '<p class="errorbox">' . htmlspecialchars( wfMsg( 'mwe-upwiz-js-off' ) ) . '</p>' ); |
61 | | - $this->simpleForm->show(); |
62 | | - $wgOut->addHTML( '</noscript>' ); |
63 | | - |
64 | | - |
65 | | - // global javascript variables |
66 | | - $this->addJsVars( $subPage ); |
67 | | - |
68 | | - // dependencies (css, js) |
69 | | - if ( !$wgUploadWizardDisableResourceLoader && class_exists( 'ResourceLoader' ) ) { |
70 | | - $wgOut->addModules( 'ext.uploadWizard' ); |
71 | | - } else { |
72 | | - $basepath = "$wgExtensionAssetsPath/UploadWizard"; |
73 | | - $dependencyLoader = new UploadWizardDependencyLoader( $wgLang->getCode() ); |
74 | | - if ( $wgUploadWizardConfig['debug'] ) { |
75 | | - // each file as an individual script or style |
76 | | - $dependencyLoader->outputHtmlDebug( $wgOut, $basepath ); |
77 | | - } else { |
78 | | - // combined & minified |
79 | | - $dependencyLoader->outputHtml( $wgOut, $basepath ); |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - // where the uploadwizard will go |
84 | | - // TODO import more from UploadWizard's createInterface call. |
85 | | - $wgOut->addHTML( self::getWizardHtml() ); |
86 | | - } |
87 | | - |
88 | | - /** |
89 | | - * Adds some global variables for our use, as well as initializes the UploadWizard |
90 | | - * |
91 | | - * TODO once bug https://bugzilla.wikimedia.org/show_bug.cgi?id=26901 |
92 | | - * is fixed we should package configuration with the upload wizard instead of |
93 | | - * in uploadWizard output page. |
94 | | - * |
95 | | - * @param subpage, e.g. the "foo" in Special:UploadWizard/foo |
96 | | - */ |
97 | | - public function addJsVars( $subPage ) { |
98 | | - global $wgOut, $wgSitename, $wgRequest; |
99 | | - |
100 | | - $wgOut->addScript( |
101 | | - Skin::makeVariablesScript( |
102 | | - array( |
103 | | - 'UploadWizardConfig' => UploadWizardConfig::getConfig( $wgRequest->getVal( 'campaign' ) ) |
104 | | - ) + |
105 | | - // Site name is a true global not specific to Upload Wizard |
106 | | - array( |
107 | | - 'wgSiteName' => $wgSitename |
108 | | - ) |
109 | | - ) |
110 | | - ); |
111 | | - |
112 | | - } |
113 | | - |
114 | | - /** |
115 | | - * Check if anyone can upload (or if other sitewide config prevents this) |
116 | | - * Side effect: will print error page to wgOut if cannot upload. |
117 | | - * @return boolean -- true if can upload |
118 | | - */ |
119 | | - private function isUploadAllowed() { |
120 | | - global $wgOut, $wgEnableAPI; |
121 | | - |
122 | | - // Check uploading enabled |
123 | | - if ( !UploadBase::isEnabled() ) { |
124 | | - $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); |
125 | | - return false; |
126 | | - } |
127 | | - |
128 | | - // XXX does wgEnableAPI affect all uploads too? |
129 | | - |
130 | | - // Check whether we actually want to allow changing stuff |
131 | | - if ( wfReadOnly() ) { |
132 | | - $wgOut->readOnlyPage(); |
133 | | - return false; |
134 | | - } |
135 | | - |
136 | | - // we got all the way here, so it must be okay to upload |
137 | | - return true; |
138 | | - } |
139 | | - |
140 | | - /** |
141 | | - * Check if the user can upload |
142 | | - * Side effect: will print error page to wgOut if cannot upload. |
143 | | - * @param User |
144 | | - * @return boolean -- true if can upload |
145 | | - */ |
146 | | - private function isUserUploadAllowed( $user ) { |
147 | | - global $wgOut, $wgGroupPermissions; |
148 | | - |
149 | | - if ( !$user->isAllowed( 'upload' ) ) { |
150 | | - if ( !$user->isLoggedIn() && ( $wgGroupPermissions['user']['upload'] |
151 | | - || $wgGroupPermissions['autoconfirmed']['upload'] ) ) { |
152 | | - // Custom message if logged-in users without any special rights can upload |
153 | | - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); |
154 | | - } else { |
155 | | - $wgOut->permissionRequired( 'upload' ); |
156 | | - } |
157 | | - return false; |
158 | | - } |
159 | | - |
160 | | - // Check blocks |
161 | | - if ( $user->isBlocked() ) { |
162 | | - $wgOut->blockedPage(); |
163 | | - return false; |
164 | | - } |
165 | | - |
166 | | - // we got all the way here, so it must be okay to upload |
167 | | - return true; |
168 | | - } |
169 | | - |
170 | | - /** |
171 | | - * Return the basic HTML structure for the entire page |
172 | | - * Will be enhanced by the javascript to actually do stuff |
173 | | - * @return {String} html |
174 | | - */ |
175 | | - function getWizardHtml() { |
176 | | - global $wgUploadWizardConfig, $wgExtensionAssetsPath; |
177 | | - |
178 | | - if ( array_key_exists( 'fallbackToAltUploadForm', $wgUploadWizardConfig ) |
179 | | - && array_key_exists( 'altUploadForm', $wgUploadWizardConfig ) |
180 | | - && $wgUploadWizardConfig['altUploadForm'] != '' |
181 | | - && $wgUploadWizardConfig[ 'fallbackToAltUploadForm' ] ) { |
182 | | - |
183 | | - $linkHtml = ''; |
184 | | - $altUploadForm = Title::newFromText( $wgUploadWizardConfig[ 'altUploadForm' ] ); |
185 | | - if ( $altUploadForm instanceof Title ) { |
186 | | - $linkHtml = Html::rawElement( 'p', array( 'style' => 'text-align: center;' ), |
187 | | - Html::rawElement( 'a', array( 'href' => $altUploadForm->getLocalURL() ), |
188 | | - $wgUploadWizardConfig['altUploadForm'] |
189 | | - ) |
190 | | - ); |
191 | | - } |
192 | | - |
193 | | - return |
194 | | - Html::rawElement( 'div', array( 'id' => 'upload-wizard', 'class' => 'upload-section' ), |
195 | | - Html::rawElement( 'p', array( 'style' => 'text-align: center' ), wfMsg( 'mwe-upwiz-extension-disabled' ) ) |
196 | | - . $linkHtml |
197 | | - ); |
198 | | - |
199 | | - } |
200 | | - |
201 | | - $tutorialHtml = ''; |
202 | | - // only load the tutorial HTML if we aren't skipping the first step |
203 | | - // TODO should use user preference not a cookie ( so the user does not have to skip it for every browser ) |
204 | | - if ( !isset( $_COOKIE['skiptutorial'] ) && !$wgUploadWizardConfig['skipTutorial'] ) { |
205 | | - $tutorialHtml = UploadWizardTutorial::getHtml(); |
206 | | - } |
207 | | - // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard |
208 | | - // can be dynamically included ( for example the add media wizard ) |
209 | | - return |
210 | | - '<div id="upload-wizard" class="upload-section">' |
211 | | - |
212 | | - // if loading takes > 2 seconds display spinner. Note we are evading Resource Loader here, and linking directly. Because we want an image to appear if RL's package is late. |
213 | | - // using some 's which is a bit of superstition, to make sure jQuery will hide this (it seems that it doesn't sometimes, when it has no content) |
214 | | - // the min-width & max-width is copied from the #uploadWizard properties, so in nice browsers the spinner is right where the button will go. |
215 | | - . '<div id="mwe-first-spinner" style="min-width:750px; max-width:900px; height:200px; line-height:200px; text-align:center;">' |
216 | | - . ' <img src="' . $wgExtensionAssetsPath . '/UploadWizard/resources/images/24px-spinner-0645ad.gif" width="24" height="24" /> ' |
217 | | - . '</div>' |
218 | | - |
219 | | - // the arrow steps - hide until styled |
220 | | - . '<ul id="mwe-upwiz-steps" style="display:none;">' |
221 | | - . '<li id="mwe-upwiz-step-tutorial"><div>' . wfMsg( 'mwe-upwiz-step-tutorial' ) . '</div></li>' |
222 | | - . '<li id="mwe-upwiz-step-file"><div>' . wfMsg( 'mwe-upwiz-step-file' ) . '</div></li>' |
223 | | - . '<li id="mwe-upwiz-step-deeds"><div>' . wfMsg( 'mwe-upwiz-step-deeds' ) . '</div></li>' |
224 | | - . '<li id="mwe-upwiz-step-details"><div>' . wfMsg( 'mwe-upwiz-step-details' ) . '</div></li>' |
225 | | - . '<li id="mwe-upwiz-step-thanks"><div>' . wfMsg( 'mwe-upwiz-step-thanks' ) . '</div></li>' |
226 | | - . '</ul>' |
227 | | - |
228 | | - // the individual steps, all at once - hide until needed |
229 | | - . '<div id="mwe-upwiz-content">' |
230 | | - |
231 | | - . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-tutorial" style="display:none;">' |
232 | | - . '<div id="mwe-upwiz-tutorial">' |
233 | | - . $tutorialHtml |
234 | | - . '</div>' |
235 | | - . '<div class="mwe-upwiz-buttons">' |
236 | | - . '<input type="checkbox" id="mwe-upwiz-skip" value="1" name="skip">' |
237 | | - . '<label for="mwe-upwiz-skip">' . wfMsg('mwe-upwiz-skip-tutorial-future') . '</label>' |
238 | | - . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next" ) . '</button>' |
239 | | - . '</div>' |
240 | | - . '</div>' |
241 | | - |
242 | | - . '<div class="mwe-upwiz-stepdiv ui-helper-clearfix" id="mwe-upwiz-stepdiv-file" style="display:none;">' |
243 | | - . '<div id="mwe-upwiz-files">' |
244 | | - . '<div id="mwe-upwiz-filelist" class="ui-corner-all"></div>' |
245 | | - . '<div id="mwe-upwiz-upload-ctrls" class="mwe-upwiz-file ui-helper-clearfix">' |
246 | | - . '<div id="mwe-upwiz-add-file-container" class="mwe-upwiz-add-files-0">' |
247 | | - . '<button id="mwe-upwiz-add-file">' . wfMsg( "mwe-upwiz-add-file-0-free" ) . '</button>' |
248 | | - . '</div>' |
249 | | - . '<div id="mwe-upwiz-upload-ctrl-container">' |
250 | | - . '<button id="mwe-upwiz-upload-ctrl">' . wfMsg( "mwe-upwiz-upload" ) . '</button>' |
251 | | - . '</div>' |
252 | | - . '</div>' |
253 | | - . '<div id="mwe-upwiz-progress" class="ui-helper-clearfix"></div>' |
254 | | - . '<div id="mwe-upwiz-continue" class="ui-helper-clearfix"></div>' |
255 | | - . '</div>' |
256 | | - . '<div class="mwe-upwiz-buttons">' |
257 | | - . '<div class="mwe-upwiz-file-next-all-ok mwe-upwiz-file-endchoice">' |
258 | | - . wfMsg( "mwe-upwiz-file-all-ok" ) |
259 | | - . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-file" ) . '</button>' |
260 | | - . '</div>' |
261 | | - . '<div class="mwe-upwiz-file-next-some-failed mwe-upwiz-file-endchoice">' |
262 | | - . wfMsg( "mwe-upwiz-file-some-failed" ) |
263 | | - . '<button class="mwe-upwiz-button-retry">' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
264 | | - . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-file-despite-failures" ) . '</button>' |
265 | | - . '</div>' |
266 | | - . '<div class="mwe-upwiz-file-next-all-failed mwe-upwiz-file-endchoice">' |
267 | | - . wfMsg( "mwe-upwiz-file-all-failed" ) |
268 | | - . '<button class="mwe-upwiz-button-retry"> ' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
269 | | - . '</div>' |
270 | | - . '</div>' |
271 | | - . '</div>' |
272 | | - |
273 | | - . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-deeds" style="display:none;">' |
274 | | - . '<div id="mwe-upwiz-deeds-thumbnails" class="ui-helper-clearfix"></div>' |
275 | | - . '<div id="mwe-upwiz-deeds" class="ui-helper-clearfix"></div>' |
276 | | - . '<div id="mwe-upwiz-deeds-custom" class="ui-helper-clearfix"></div>' |
277 | | - . '<div class="mwe-upwiz-buttons">' |
278 | | - . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-deeds" ) . '</button>' |
279 | | - . '</div>' |
280 | | - . '</div>' |
281 | | - |
282 | | - . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-details" style="display:none;">' |
283 | | - . '<div id="mwe-upwiz-macro-files" class="mwe-upwiz-filled-filelist ui-corner-all"></div>' |
284 | | - . '<div class="mwe-upwiz-buttons">' |
285 | | - . '<div id="mwe-upwiz-details-error-count" class="mwe-upwiz-file-endchoice mwe-error"></div>' |
286 | | - . '<div class="mwe-upwiz-start-next mwe-upwiz-file-endchoice">' |
287 | | - . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-details" ) . '</button>' |
288 | | - . '</div>' |
289 | | - . '<div class="mwe-upwiz-file-next-some-failed mwe-upwiz-file-endchoice">' |
290 | | - . wfMsg( "mwe-upwiz-file-some-failed" ) |
291 | | - . '<button class="mwe-upwiz-button-retry">' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
292 | | - . '<button class="mwe-upwiz-button-next-despite-failures">' . wfMsg( "mwe-upwiz-next-file-despite-failures" ) . '</button>' |
293 | | - . '</div>' |
294 | | - . '<div class="mwe-upwiz-file-next-all-failed mwe-upwiz-file-endchoice">' |
295 | | - . wfMsg( "mwe-upwiz-file-all-failed" ) |
296 | | - . '<button class="mwe-upwiz-button-retry"> ' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
297 | | - . '</div>' |
298 | | - . '</div>' |
299 | | - . '</div>' |
300 | | - |
301 | | - . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-thanks" style="display:none;">' |
302 | | - . '<div id="mwe-upwiz-thanks"></div>' |
303 | | - . '<div class="mwe-upwiz-buttons">' |
304 | | - . '<button class="mwe-upwiz-button-home">' . wfMsg( "mwe-upwiz-home" ) . '</button>' |
305 | | - . '<button class="mwe-upwiz-button-begin">' . wfMsg( "mwe-upwiz-upload-another" ) . '</button>' |
306 | | - . '</div>' |
307 | | - . '</div>' |
308 | | - |
309 | | - . '</div>' |
310 | | - |
311 | | - . '<div class="mwe-upwiz-clearing"></div>' |
312 | | - |
313 | | - . '</div>'; |
314 | | - } |
315 | | - |
316 | | -} |
317 | | - |
318 | | - |
319 | | -/** |
320 | | - * This is a hack on UploadForm, to make one that works from UploadWizard when JS is not available. |
321 | | - */ |
322 | | -class UploadWizardSimpleForm extends UploadForm { |
323 | | - |
324 | | - /* |
325 | | - * Normally, UploadForm adds its own Javascript. |
326 | | - * We wish to prevent this, because we want to control the case where we have Javascript. |
327 | | - * So, we make the addUploadJS a no-op. |
328 | | - */ |
329 | | - protected function addUploadJS( ) { } |
330 | | - |
331 | | -} |
332 | | - |
333 | | - |
Index: trunk/extensions/UploadWizard/SpecialUploadCampaigns.php |
— | — | @@ -1,188 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Special:UploadCampaigns |
6 | | - * |
7 | | - * Lists the upload campaigns. |
8 | | - * |
9 | | - * @file |
10 | | - * @ingroup SpecialPage |
11 | | - * @ingroup Upload |
12 | | - * |
13 | | - * @since 1.2 |
14 | | - * |
15 | | - * @licence GNU GPL v3+ |
16 | | - * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
17 | | - */ |
18 | | -class SpecialUploadCampaigns extends SpecialPage { |
19 | | - |
20 | | - /** |
21 | | - * Constructor. |
22 | | - * |
23 | | - * @param $request is the request (usually wgRequest) |
24 | | - * @param $par is everything in the URL after Special:UploadCampaigns. Not sure what we can use it for |
25 | | - */ |
26 | | - public function __construct( $request = null, $par = null ) { |
27 | | - parent::__construct( 'UploadCampaigns', 'upwizcampaigns' ); |
28 | | - } |
29 | | - |
30 | | - /** |
31 | | - * (non-PHPdoc) |
32 | | - * @see SpecialPage::getDescription() |
33 | | - */ |
34 | | - public function getDescription() { |
35 | | - return wfMsg( 'mwe-upwiz-' . strtolower( $this->mName ) ); |
36 | | - } |
37 | | - |
38 | | - /** |
39 | | - * Main method. |
40 | | - * |
41 | | - * @param string $subPage, e.g. the "foo" in Special:UploadCampaigns/foo. |
42 | | - */ |
43 | | - public function execute( $subPage ) { |
44 | | - global $wgRequest, $wgUser; |
45 | | - |
46 | | - $this->setHeaders(); |
47 | | - $this->outputHeader(); |
48 | | - $subPage = explode( '/', $subPage, 2 ); |
49 | | - |
50 | | - // If the user is authorized, display the page, if not, show an error. |
51 | | - if ( $this->userCanExecute( $wgUser ) ) { |
52 | | - if ( $wgRequest->wasPosted() |
53 | | - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) |
54 | | - && $wgRequest->getCheck( 'newcampaign' ) ) { |
55 | | - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() ); |
56 | | - } |
57 | | - elseif ( count( $subPage ) == 2 && $subPage[0] == 'del' ) { |
58 | | - $campaign = UploadWizardCampaign::newFromName( $subPage[1], false ); |
59 | | - $campaign->deleteFromDB(); |
60 | | - $this->getOutput()->redirect( $this->getTitle()->getLocalURL() ); |
61 | | - } |
62 | | - else { |
63 | | - $this->displayUploadCamaigns(); |
64 | | - } |
65 | | - } else { |
66 | | - $this->displayRestrictionError(); |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Displays the pages regular output. |
72 | | - * |
73 | | - * @since 1.2 |
74 | | - */ |
75 | | - protected function displayUploadCamaigns() { |
76 | | - $this->displayAddNewControl(); |
77 | | - |
78 | | - $dbr = wfGetDB( DB_SLAVE ); |
79 | | - |
80 | | - $campaigns = $dbr->select( |
81 | | - 'uw_campaigns', |
82 | | - array( |
83 | | - 'campaign_id', |
84 | | - 'campaign_name', |
85 | | - 'campaign_enabled', |
86 | | - ) |
87 | | - ); |
88 | | - |
89 | | - if ( $campaigns->numRows() > 0 ) { |
90 | | - $this->displayCampaignTable( $campaigns ); |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - /** |
95 | | - * Displays a small form to add a new campaign. |
96 | | - * |
97 | | - * @since 1.2 |
98 | | - */ |
99 | | - protected function displayAddNewControl() { |
100 | | - $out = $this->getOutput(); |
101 | | - |
102 | | - $out->addHTML( Html::openElement( |
103 | | - 'form', |
104 | | - array( |
105 | | - 'method' => 'post', |
106 | | - 'action' => $this->getTitle()->getLocalURL(), |
107 | | - ) |
108 | | - ) ); |
109 | | - |
110 | | - $out->addHTML( '<fieldset>' ); |
111 | | - |
112 | | - $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'mwe-upwiz-campaigns-addnew' ) ) . '</legend>' ); |
113 | | - |
114 | | - $out->addHTML( Html::element( 'p', array(), wfMsg( 'mwe-upwiz-campaigns-namedoc' ) ) ); |
115 | | - |
116 | | - $out->addHTML( Html::element( 'label', array( 'for' => 'newcampaign' ), wfMsg( 'mwe-upwiz-campaigns-newname' ) ) ); |
117 | | - |
118 | | - $out->addHTML( Html::input( 'newcampaign' ) . ' ' ); |
119 | | - |
120 | | - $out->addHTML( Html::input( |
121 | | - 'addnewcampaign', |
122 | | - wfMsg( 'mwe-upwiz-campaigns-add' ), |
123 | | - 'submit' |
124 | | - ) ); |
125 | | - |
126 | | - global $wgUser; |
127 | | - $out->addHTML( Html::hidden( 'wpEditToken', $wgUser->editToken() ) ); |
128 | | - |
129 | | - $out->addHTML( '</fieldset></form>' ); |
130 | | - } |
131 | | - |
132 | | - /** |
133 | | - * Displays a list of all campaigns. |
134 | | - * |
135 | | - * @since 1.2 |
136 | | - * |
137 | | - * @param ResultWrapper $campaigns |
138 | | - */ |
139 | | - protected function displayCampaignTable( ResultWrapper $campaigns ) { |
140 | | - $out = $this->getOutput(); |
141 | | - |
142 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) ); |
143 | | - |
144 | | - $out->addHTML( Xml::openElement( |
145 | | - 'table', |
146 | | - array( 'class' => 'wikitable', 'style' => 'width:400px' ) |
147 | | - ) ); |
148 | | - |
149 | | - $out->addHTML( |
150 | | - '<tr>' . |
151 | | - Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-name' ) ) . |
152 | | - Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-status' ) ) . |
153 | | - Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-edit' ) ) . |
154 | | - Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-delete' ) ) . |
155 | | - '</tr>' |
156 | | - ); |
157 | | - |
158 | | - foreach ( $campaigns as $campaign ) { |
159 | | - $out->addHTML( |
160 | | - '<tr>' . |
161 | | - Html::element( 'td', array(), $campaign->campaign_name ) . |
162 | | - Html::element( 'td', array(), wfMsg( 'mwe-upwiz-campaigns-' . ( $campaign->campaign_enabled ? 'enabled' : 'disabled' ) ) ) . |
163 | | - '<td>' . |
164 | | - Html::element( |
165 | | - 'a', |
166 | | - array( |
167 | | - 'href' => SpecialPage::getTitleFor( 'UploadCampaign', $campaign->campaign_name )->getLocalURL() |
168 | | - ), |
169 | | - wfMsg( 'mwe-upwiz-campaigns-edit' ) |
170 | | - ) . |
171 | | - '</td>' . |
172 | | - '<td>' . |
173 | | - Html::element( |
174 | | - 'a', |
175 | | - array( |
176 | | - 'href' => SpecialPage::getTitleFor( 'UploadCampaigns', 'del/' . $campaign->campaign_name )->getLocalURL(), |
177 | | - 'onclick' => 'return confirm( "' . wfMsg( 'mwe-upwiz-campaigns-confdel' ) . '" )' |
178 | | - ), |
179 | | - wfMsg( 'mwe-upwiz-campaigns-delete' ) |
180 | | - ) . |
181 | | - '</td>' . |
182 | | - '</tr>' |
183 | | - ); |
184 | | - } |
185 | | - |
186 | | - $out->addHTML( '</table>' ); |
187 | | - } |
188 | | - |
189 | | -} |
Index: trunk/extensions/UploadWizard/SpecialUploadCampaign.php |
— | — | @@ -1,107 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Special:UploadCampaign |
6 | | - * |
7 | | - * Configuration interface for an upload wizard campaign. |
8 | | - * |
9 | | - * @file |
10 | | - * @ingroup SpecialPage |
11 | | - * @ingroup Upload |
12 | | - * |
13 | | - * @since 1.2 |
14 | | - * |
15 | | - * @licence GNU GPL v3+ |
16 | | - * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
17 | | - */ |
18 | | -class SpecialUploadCampaign extends FormSpecialPage { |
19 | | - |
20 | | - protected $subPage; |
21 | | - |
22 | | - /** |
23 | | - * Constructor. |
24 | | - * |
25 | | - * @param $request is the request (usually wgRequest) |
26 | | - * @param $par is everything in the URL after Special:UploadCampaign. Not sure what we can use it for |
27 | | - */ |
28 | | - public function __construct($request = null, $par = null) { |
29 | | - parent::__construct ( 'UploadCampaign', 'upwizcampaigns', false ); |
30 | | - } |
31 | | - |
32 | | - /** |
33 | | - * (non-PHPdoc) |
34 | | - * @see SpecialPage::getDescription() |
35 | | - */ |
36 | | - public function getDescription() { |
37 | | - return wfMsg( 'mwe-upwiz-' . strtolower( $this->mName ) ); |
38 | | - } |
39 | | - |
40 | | - /** |
41 | | - * (non-PHPdoc) |
42 | | - * @see FormSpecialPage::setParameter() |
43 | | - */ |
44 | | - protected function setParameter( $par ){ |
45 | | - $this->subPage = $par; |
46 | | - } |
47 | | - |
48 | | - /** |
49 | | - * (non-PHPdoc) |
50 | | - * @see FormSpecialPage::getFormFields() |
51 | | - */ |
52 | | - protected function getFormFields() { |
53 | | - $dbr = wfGetDB( DB_SLAVE ); |
54 | | - |
55 | | - $campaign = UploadWizardCampaign::newFromName( $this->subPage ); |
56 | | - |
57 | | - $id = $campaign ? $campaign->getId() : null; |
58 | | - $enabled = $campaign ? $campaign->getIsEnabled() : false; |
59 | | - $configFields = $campaign ? $campaign->getAllConfig() : UploadWizardCampaign::getDefaultConfig(); |
60 | | - |
61 | | - $fields = array (); |
62 | | - |
63 | | - $fields['Campaignid'] = array ( 'type' => 'hidden', 'default' => $id ); |
64 | | - $fields['Campaignname'] = array ( 'type' => 'text', 'default' => $this->subPage, 'label-message' => 'mwe-upwiz-campaign-name' ); |
65 | | - $fields['Campaignenabled'] = array ( 'type' => 'check', 'default' => $enabled, 'label-message' => 'mwe-upwiz-campaign-enabled' ); |
66 | | - |
67 | | - foreach ( $configFields as $name => $data ) { |
68 | | - $data['label-message'] = 'mwe-upwiz-campaign-conf-' . $name; |
69 | | - $fields[$name] = $data; |
70 | | - } |
71 | | - |
72 | | - return $fields; |
73 | | - } |
74 | | - |
75 | | - /** |
76 | | - * Process the form. At this point we know that the user passes all the criteria in |
77 | | - * userCanExecute(), and if the data array contains 'Username', etc, then Username |
78 | | - * resets are allowed. |
79 | | - * @param $data array |
80 | | - * @return Bool|Array |
81 | | - */ |
82 | | - public function onSubmit( array $data ) { |
83 | | - $id = $data['Campaignid'] == '' ? null : $data['Campaignid']; |
84 | | - unset( $data['Campaignid'] ); |
85 | | - |
86 | | - $name = $data['Campaignname']; |
87 | | - unset( $data['Campaignname'] ); |
88 | | - |
89 | | - $enabled = $data['Campaignenabled']; |
90 | | - unset( $data['Campaignenabled'] ); |
91 | | - |
92 | | - $campaign = new UploadWizardCampaign( $id, $name, $enabled, $data ); |
93 | | - |
94 | | - $success = $campaign->writeToDB(); |
95 | | - |
96 | | - if ( $success ) { |
97 | | - return true; |
98 | | - } |
99 | | - else { |
100 | | - return array(); // TODO |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - public function onSuccess() { |
105 | | - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() ); |
106 | | - } |
107 | | - |
108 | | -} |
\ No newline at end of file |
Index: trunk/extensions/UploadWizard/includes/UploadWizardTutorial.php |
— | — | @@ -0,0 +1,127 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class to encapsulate all the html generation associated with the UploadWizard tutorial. |
| 6 | + * Might be a start for a subclass of UploadWizard, if we ever free it of its WMF-oriented features |
| 7 | + * So that non-WMF'ers can use it |
| 8 | + */ |
| 9 | +class UploadWizardTutorial { |
| 10 | + |
| 11 | + // name of the tutorial on Wikimedia Commons. The $1 is replaced with the language desired |
| 12 | + const NAME_TEMPLATE = 'Licensing_tutorial_$1.svg'; |
| 13 | + |
| 14 | + // the width we want to scale the tutorial to, for our interface |
| 15 | + const WIDTH_PX = 720; |
| 16 | + |
| 17 | + // imagemap coordinates of the "helpdesk" button at the bottom, which is supposed to be clickable. |
| 18 | + const HELPDESK_BUTTON_COORDS = "27, 1319, 691, 1384"; |
| 19 | + |
| 20 | + // id of imagemap used in tutorial |
| 21 | + const IMAGEMAP_ID = 'tutorialMap'; |
| 22 | + |
| 23 | + /** |
| 24 | + * Fetches appropriate HTML for the tutorial portion of the wizard. |
| 25 | + * Looks up an image on the current wiki. This will work as is on Commons, and will also work |
| 26 | + * on test wikis that enable instantCommons. |
| 27 | + * @param {String} $langCode language code as used by MediaWiki, similar but not identical to ISO 639-1. |
| 28 | + * @return {String} html that will display the tutorial. |
| 29 | + */ |
| 30 | + public static function getHtml() { |
| 31 | + global $wgLang; |
| 32 | + |
| 33 | + $error = null; |
| 34 | + $errorHtml = ''; |
| 35 | + $tutorialHtml = ''; |
| 36 | + |
| 37 | + $langCode = $wgLang->getCode(); |
| 38 | + |
| 39 | + $tutorialFile = false; |
| 40 | + // getFile returns false if it can't find the right file |
| 41 | + if ( ! $tutorialFile = self::getFile( $langCode ) ) { |
| 42 | + $error = 'localized-file-missing'; |
| 43 | + if ( $langCode !== 'en' ) { |
| 44 | + $tutorialFile = self::getFile( 'en' ); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // at this point, we have one of the following situations: |
| 49 | + // $error is null, and tutorialFile is the right one for this language |
| 50 | + // $error notes we couldn't find the tutorialFile for your language, and $tutorialFile is the english one |
| 51 | + // $error notes we couldn't find the tutorialFile for your language, and $tutorialFile is still false (major file failure) |
| 52 | + |
| 53 | + if ( $tutorialFile ) { |
| 54 | + // XXX TODO if the client can handle SVG, we could also just send it the unscaled thumb, client-scaled into a DIV or something. |
| 55 | + // if ( client can handle SVG ) { |
| 56 | + // $tutorialThumbnailImage->getUnscaledThumb(); |
| 57 | + // } |
| 58 | + // put it into a div of appropriate dimensions. |
| 59 | + |
| 60 | + // n.b. File::transform() returns false if failed, MediaTransformOutput otherwise |
| 61 | + $thumbnailImage = $tutorialFile->transform( array( 'width' => self::WIDTH_PX ) ); |
| 62 | + if ( $thumbnailImage ) { |
| 63 | + $tutorialHtml = self::getImageHtml( $thumbnailImage ); |
| 64 | + } else { |
| 65 | + $error = 'cannot-transform'; |
| 66 | + } |
| 67 | + } else { |
| 68 | + $error = 'file-missing'; |
| 69 | + } |
| 70 | + |
| 71 | + if ( $error !== null ) { |
| 72 | + $errorHtml = Html::element( 'p', array( 'class' => 'errorbox', 'style' => 'float: none;' ), wfMsg( 'mwe-upwiz-tutorial-error-' . $error ) ); |
| 73 | + } |
| 74 | + |
| 75 | + return $errorHtml . $tutorialHtml; |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Get tutorial file for a particular language, or false if not available. |
| 81 | + * @param {String} $langCode: language Code |
| 82 | + * @return {File|false} |
| 83 | + */ |
| 84 | + public static function getFile( $langCode ) { |
| 85 | + $tutorialName = str_replace( '$1', $langCode, self::NAME_TEMPLATE ); |
| 86 | + $tutorialTitle = Title::newFromText( $tutorialName, NS_FILE ); |
| 87 | + return wfFindFile( $tutorialTitle ); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Constructs HTML for the tutorial (laboriously), including an imagemap for the clickable "Help desk" button. |
| 92 | + * @param {ThumbnailImage} $thumb |
| 93 | + * @return {String} HTML representing the image, with clickable helpdesk button |
| 94 | + */ |
| 95 | + public static function getImageHtml( $thumb ) { |
| 96 | + |
| 97 | + $helpDeskUrl = wfMsg( 'mwe-upwiz-help-desk-url' ); |
| 98 | + |
| 99 | + // Per convention, we may be either using an absolute URL or a wiki page title in this UI message |
| 100 | + if( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $helpDeskUrl )) { |
| 101 | + $helpDeskHref = $helpDeskUrl; |
| 102 | + } else { |
| 103 | + $helpDeskTitle = Title::newFromText( $helpDeskUrl ); |
| 104 | + $helpDeskHref = $helpDeskTitle ? $helpDeskTitle->getLocalURL() : '#'; |
| 105 | + } |
| 106 | + |
| 107 | + // here we use the not-yet-forgotten HTML imagemap to add a clickable area to the tutorial image. |
| 108 | + // we could do more special effects with hovers and images and such, not to mention SVG scripting, |
| 109 | + // but we aren't sure what we want yet... |
| 110 | + $img = Html::element( 'img', array( |
| 111 | + 'src' => $thumb->getUrl(), |
| 112 | + 'width' => $thumb->getWidth(), |
| 113 | + 'height' => $thumb->getHeight(), |
| 114 | + 'usemap' => '#' . self::IMAGEMAP_ID |
| 115 | + ) ); |
| 116 | + $areaAltText = wfMsg( 'mwe-upwiz-help-desk' ); |
| 117 | + $area = Html::element( 'area', array( |
| 118 | + 'shape' => 'rect', |
| 119 | + 'coords' => self::HELPDESK_BUTTON_COORDS, |
| 120 | + 'href' => $helpDeskHref, |
| 121 | + 'alt' => $areaAltText, |
| 122 | + 'title' => $areaAltText |
| 123 | + ) ); |
| 124 | + $map = Html::rawElement( 'map', array( 'id' => self::IMAGEMAP_ID, 'name' => self::IMAGEMAP_ID ), $area ); |
| 125 | + return $map . $img; |
| 126 | + } |
| 127 | + |
| 128 | +} |
Property changes on: trunk/extensions/UploadWizard/includes/UploadWizardTutorial.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 129 | + native |
Index: trunk/extensions/UploadWizard/includes/UploadWizardConfig.php |
— | — | @@ -0,0 +1,76 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Static class with methods for interacting with the Upload Wizards configuration. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Upload |
| 9 | + * |
| 10 | + * @since 1.2 |
| 11 | + * |
| 12 | + * @licence GNU GPL v3+ |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class UploadWizardConfig { |
| 16 | + |
| 17 | + /** |
| 18 | + * Returns the globally configuration, optionaly combined with campaign sepcific |
| 19 | + * configuration. |
| 20 | + * |
| 21 | + * @since 1.2 |
| 22 | + * |
| 23 | + * @param string|null $campaignName |
| 24 | + * |
| 25 | + * @return array |
| 26 | + */ |
| 27 | + public static function getConfig( $campaignName = null ) { |
| 28 | + global $wgUploadWizardConfig; |
| 29 | + static $mergedConfig = false; |
| 30 | + |
| 31 | + if ( !$mergedConfig ) { |
| 32 | + $wgUploadWizardConfig = array_merge( self::getDefaultConfig(), $wgUploadWizardConfig ); |
| 33 | + } |
| 34 | + |
| 35 | + if ( !is_null( $campaignName ) ) { |
| 36 | + $wgUploadWizardConfig = array_merge( $wgUploadWizardConfig, self::getCampaignConfig( $campaignName ) ); |
| 37 | + } |
| 38 | + |
| 39 | + return $wgUploadWizardConfig; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Returns the default global config, from UploadWizard.config.php. |
| 44 | + * |
| 45 | + * @since 1.2 |
| 46 | + * |
| 47 | + * @return array |
| 48 | + */ |
| 49 | + protected static function getDefaultConfig() { |
| 50 | + global $wgUpwizDir; |
| 51 | + $configPath = $wgUpwizDir . '/UploadWizard.config.php'; |
| 52 | + return is_file( $configPath ) ? include( $configPath ) : array(); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Returns the configuration of the specified campaign, |
| 57 | + * or an empty array when the campaign is not found or not enabled. |
| 58 | + * |
| 59 | + * @since 1.2 |
| 60 | + * |
| 61 | + * @param string $campaignName |
| 62 | + * |
| 63 | + * @return array |
| 64 | + */ |
| 65 | + protected static function getCampaignConfig( $campaignName ) { |
| 66 | + $capmaignSettings = array(); |
| 67 | + |
| 68 | + $capaign = UploadWizardCampaign::newFromName( $campaignName ); |
| 69 | + |
| 70 | + if ( $capaign !== false && $capaign->getIsEnabled() ) { |
| 71 | + return $capaign->getConfig(); |
| 72 | + } |
| 73 | + |
| 74 | + return array(); |
| 75 | + } |
| 76 | + |
| 77 | +} |
Property changes on: trunk/extensions/UploadWizard/includes/UploadWizardConfig.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 78 | + native |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php |
— | — | @@ -0,0 +1,107 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Special:UploadCampaign |
| 6 | + * |
| 7 | + * Configuration interface for an upload wizard campaign. |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup SpecialPage |
| 11 | + * @ingroup Upload |
| 12 | + * |
| 13 | + * @since 1.2 |
| 14 | + * |
| 15 | + * @licence GNU GPL v3+ |
| 16 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 17 | + */ |
| 18 | +class SpecialUploadCampaign extends FormSpecialPage { |
| 19 | + |
| 20 | + protected $subPage; |
| 21 | + |
| 22 | + /** |
| 23 | + * Constructor. |
| 24 | + * |
| 25 | + * @param $request is the request (usually wgRequest) |
| 26 | + * @param $par is everything in the URL after Special:UploadCampaign. Not sure what we can use it for |
| 27 | + */ |
| 28 | + public function __construct($request = null, $par = null) { |
| 29 | + parent::__construct ( 'UploadCampaign', 'upwizcampaigns', false ); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * (non-PHPdoc) |
| 34 | + * @see SpecialPage::getDescription() |
| 35 | + */ |
| 36 | + public function getDescription() { |
| 37 | + return wfMsg( 'mwe-upwiz-' . strtolower( $this->mName ) ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * (non-PHPdoc) |
| 42 | + * @see FormSpecialPage::setParameter() |
| 43 | + */ |
| 44 | + protected function setParameter( $par ){ |
| 45 | + $this->subPage = $par; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * (non-PHPdoc) |
| 50 | + * @see FormSpecialPage::getFormFields() |
| 51 | + */ |
| 52 | + protected function getFormFields() { |
| 53 | + $dbr = wfGetDB( DB_SLAVE ); |
| 54 | + |
| 55 | + $campaign = UploadWizardCampaign::newFromName( $this->subPage ); |
| 56 | + |
| 57 | + $id = $campaign ? $campaign->getId() : null; |
| 58 | + $enabled = $campaign ? $campaign->getIsEnabled() : false; |
| 59 | + $configFields = $campaign ? $campaign->getAllConfig() : UploadWizardCampaign::getDefaultConfig(); |
| 60 | + |
| 61 | + $fields = array (); |
| 62 | + |
| 63 | + $fields['Campaignid'] = array ( 'type' => 'hidden', 'default' => $id ); |
| 64 | + $fields['Campaignname'] = array ( 'type' => 'text', 'default' => $this->subPage, 'label-message' => 'mwe-upwiz-campaign-name' ); |
| 65 | + $fields['Campaignenabled'] = array ( 'type' => 'check', 'default' => $enabled, 'label-message' => 'mwe-upwiz-campaign-enabled' ); |
| 66 | + |
| 67 | + foreach ( $configFields as $name => $data ) { |
| 68 | + $data['label-message'] = 'mwe-upwiz-campaign-conf-' . $name; |
| 69 | + $fields[$name] = $data; |
| 70 | + } |
| 71 | + |
| 72 | + return $fields; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Process the form. At this point we know that the user passes all the criteria in |
| 77 | + * userCanExecute(), and if the data array contains 'Username', etc, then Username |
| 78 | + * resets are allowed. |
| 79 | + * @param $data array |
| 80 | + * @return Bool|Array |
| 81 | + */ |
| 82 | + public function onSubmit( array $data ) { |
| 83 | + $id = $data['Campaignid'] == '' ? null : $data['Campaignid']; |
| 84 | + unset( $data['Campaignid'] ); |
| 85 | + |
| 86 | + $name = $data['Campaignname']; |
| 87 | + unset( $data['Campaignname'] ); |
| 88 | + |
| 89 | + $enabled = $data['Campaignenabled']; |
| 90 | + unset( $data['Campaignenabled'] ); |
| 91 | + |
| 92 | + $campaign = new UploadWizardCampaign( $id, $name, $enabled, $data ); |
| 93 | + |
| 94 | + $success = $campaign->writeToDB(); |
| 95 | + |
| 96 | + if ( $success ) { |
| 97 | + return true; |
| 98 | + } |
| 99 | + else { |
| 100 | + return array(); // TODO |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + public function onSuccess() { |
| 105 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() ); |
| 106 | + } |
| 107 | + |
| 108 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 109 | + native |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php |
— | — | @@ -0,0 +1,332 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special:UploadWizard |
| 5 | + * |
| 6 | + * Easy to use multi-file upload page. |
| 7 | + * |
| 8 | + * @file |
| 9 | + * @ingroup SpecialPage |
| 10 | + * @ingroup Upload |
| 11 | + */ |
| 12 | + |
| 13 | +class SpecialUploadWizard extends SpecialPage { |
| 14 | + // the HTML form without javascript |
| 15 | + private $simpleForm; |
| 16 | + |
| 17 | + // $request is the request (usually wgRequest) |
| 18 | + // $par is everything in the URL after Special:UploadWizard. Not sure what we can use it for |
| 19 | + public function __construct( $request = null, $par = null ) { |
| 20 | + global $wgRequest; |
| 21 | + // here we would configure ourselves based on stuff in $request and $wgRequest, but so far, we |
| 22 | + // don't have such things |
| 23 | + |
| 24 | + parent::__construct( 'UploadWizard', 'upload' ); |
| 25 | + |
| 26 | + // create a simple form for non-JS fallback, which targets the old Special:Upload page. |
| 27 | + // at some point, if we completely subsume its functionality, change that to point here again, |
| 28 | + // but then we'll need to process non-JS uploads in the same way Special:Upload does. |
| 29 | + $this->simpleForm = new UploadWizardSimpleForm(); |
| 30 | + $this->simpleForm->setTitle( |
| 31 | + SpecialPage::getTitleFor( 'Upload' ) |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Replaces default execute method |
| 37 | + * Checks whether uploading enabled, user permissions okay, |
| 38 | + * @param $subPage, e.g. the "foo" in Special:UploadWizard/foo. |
| 39 | + */ |
| 40 | + public function execute( $subPage ) { |
| 41 | + global $wgRequest, $wgLang, $wgUser, $wgOut, $wgExtensionAssetsPath, |
| 42 | + $wgUploadWizardDisableResourceLoader, $wgUploadWizardConfig; |
| 43 | + |
| 44 | + // side effects: if we can't upload, will print error page to wgOut |
| 45 | + // and return false |
| 46 | + if ( !( $this->isUploadAllowed() && $this->isUserUploadAllowed( $wgUser ) ) ) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + $this->setHeaders(); |
| 51 | + $this->outputHeader(); |
| 52 | + |
| 53 | + // if query string includes 'skiptutorial=true' set config variable to true |
| 54 | + if ( $wgRequest->getText( 'skiptutorial' ) ) { |
| 55 | + $wgUploadWizardConfig['skipTutorial'] = true; |
| 56 | + } |
| 57 | + |
| 58 | + // fallback for non-JS |
| 59 | + $wgOut->addHTML( '<noscript>' ); |
| 60 | + $wgOut->addHTML( '<p class="errorbox">' . htmlspecialchars( wfMsg( 'mwe-upwiz-js-off' ) ) . '</p>' ); |
| 61 | + $this->simpleForm->show(); |
| 62 | + $wgOut->addHTML( '</noscript>' ); |
| 63 | + |
| 64 | + |
| 65 | + // global javascript variables |
| 66 | + $this->addJsVars( $subPage ); |
| 67 | + |
| 68 | + // dependencies (css, js) |
| 69 | + if ( !$wgUploadWizardDisableResourceLoader && class_exists( 'ResourceLoader' ) ) { |
| 70 | + $wgOut->addModules( 'ext.uploadWizard' ); |
| 71 | + } else { |
| 72 | + $basepath = "$wgExtensionAssetsPath/UploadWizard"; |
| 73 | + $dependencyLoader = new UploadWizardDependencyLoader( $wgLang->getCode() ); |
| 74 | + if ( $wgUploadWizardConfig['debug'] ) { |
| 75 | + // each file as an individual script or style |
| 76 | + $dependencyLoader->outputHtmlDebug( $wgOut, $basepath ); |
| 77 | + } else { |
| 78 | + // combined & minified |
| 79 | + $dependencyLoader->outputHtml( $wgOut, $basepath ); |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + // where the uploadwizard will go |
| 84 | + // TODO import more from UploadWizard's createInterface call. |
| 85 | + $wgOut->addHTML( self::getWizardHtml() ); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Adds some global variables for our use, as well as initializes the UploadWizard |
| 90 | + * |
| 91 | + * TODO once bug https://bugzilla.wikimedia.org/show_bug.cgi?id=26901 |
| 92 | + * is fixed we should package configuration with the upload wizard instead of |
| 93 | + * in uploadWizard output page. |
| 94 | + * |
| 95 | + * @param subpage, e.g. the "foo" in Special:UploadWizard/foo |
| 96 | + */ |
| 97 | + public function addJsVars( $subPage ) { |
| 98 | + global $wgOut, $wgSitename, $wgRequest; |
| 99 | + |
| 100 | + $wgOut->addScript( |
| 101 | + Skin::makeVariablesScript( |
| 102 | + array( |
| 103 | + 'UploadWizardConfig' => UploadWizardConfig::getConfig( $wgRequest->getVal( 'campaign' ) ) |
| 104 | + ) + |
| 105 | + // Site name is a true global not specific to Upload Wizard |
| 106 | + array( |
| 107 | + 'wgSiteName' => $wgSitename |
| 108 | + ) |
| 109 | + ) |
| 110 | + ); |
| 111 | + |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Check if anyone can upload (or if other sitewide config prevents this) |
| 116 | + * Side effect: will print error page to wgOut if cannot upload. |
| 117 | + * @return boolean -- true if can upload |
| 118 | + */ |
| 119 | + private function isUploadAllowed() { |
| 120 | + global $wgOut, $wgEnableAPI; |
| 121 | + |
| 122 | + // Check uploading enabled |
| 123 | + if ( !UploadBase::isEnabled() ) { |
| 124 | + $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); |
| 125 | + return false; |
| 126 | + } |
| 127 | + |
| 128 | + // XXX does wgEnableAPI affect all uploads too? |
| 129 | + |
| 130 | + // Check whether we actually want to allow changing stuff |
| 131 | + if ( wfReadOnly() ) { |
| 132 | + $wgOut->readOnlyPage(); |
| 133 | + return false; |
| 134 | + } |
| 135 | + |
| 136 | + // we got all the way here, so it must be okay to upload |
| 137 | + return true; |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Check if the user can upload |
| 142 | + * Side effect: will print error page to wgOut if cannot upload. |
| 143 | + * @param User |
| 144 | + * @return boolean -- true if can upload |
| 145 | + */ |
| 146 | + private function isUserUploadAllowed( $user ) { |
| 147 | + global $wgOut, $wgGroupPermissions; |
| 148 | + |
| 149 | + if ( !$user->isAllowed( 'upload' ) ) { |
| 150 | + if ( !$user->isLoggedIn() && ( $wgGroupPermissions['user']['upload'] |
| 151 | + || $wgGroupPermissions['autoconfirmed']['upload'] ) ) { |
| 152 | + // Custom message if logged-in users without any special rights can upload |
| 153 | + $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); |
| 154 | + } else { |
| 155 | + $wgOut->permissionRequired( 'upload' ); |
| 156 | + } |
| 157 | + return false; |
| 158 | + } |
| 159 | + |
| 160 | + // Check blocks |
| 161 | + if ( $user->isBlocked() ) { |
| 162 | + $wgOut->blockedPage(); |
| 163 | + return false; |
| 164 | + } |
| 165 | + |
| 166 | + // we got all the way here, so it must be okay to upload |
| 167 | + return true; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Return the basic HTML structure for the entire page |
| 172 | + * Will be enhanced by the javascript to actually do stuff |
| 173 | + * @return {String} html |
| 174 | + */ |
| 175 | + function getWizardHtml() { |
| 176 | + global $wgUploadWizardConfig, $wgExtensionAssetsPath; |
| 177 | + |
| 178 | + if ( array_key_exists( 'fallbackToAltUploadForm', $wgUploadWizardConfig ) |
| 179 | + && array_key_exists( 'altUploadForm', $wgUploadWizardConfig ) |
| 180 | + && $wgUploadWizardConfig['altUploadForm'] != '' |
| 181 | + && $wgUploadWizardConfig[ 'fallbackToAltUploadForm' ] ) { |
| 182 | + |
| 183 | + $linkHtml = ''; |
| 184 | + $altUploadForm = Title::newFromText( $wgUploadWizardConfig[ 'altUploadForm' ] ); |
| 185 | + if ( $altUploadForm instanceof Title ) { |
| 186 | + $linkHtml = Html::rawElement( 'p', array( 'style' => 'text-align: center;' ), |
| 187 | + Html::rawElement( 'a', array( 'href' => $altUploadForm->getLocalURL() ), |
| 188 | + $wgUploadWizardConfig['altUploadForm'] |
| 189 | + ) |
| 190 | + ); |
| 191 | + } |
| 192 | + |
| 193 | + return |
| 194 | + Html::rawElement( 'div', array( 'id' => 'upload-wizard', 'class' => 'upload-section' ), |
| 195 | + Html::rawElement( 'p', array( 'style' => 'text-align: center' ), wfMsg( 'mwe-upwiz-extension-disabled' ) ) |
| 196 | + . $linkHtml |
| 197 | + ); |
| 198 | + |
| 199 | + } |
| 200 | + |
| 201 | + $tutorialHtml = ''; |
| 202 | + // only load the tutorial HTML if we aren't skipping the first step |
| 203 | + // TODO should use user preference not a cookie ( so the user does not have to skip it for every browser ) |
| 204 | + if ( !isset( $_COOKIE['skiptutorial'] ) && !$wgUploadWizardConfig['skipTutorial'] ) { |
| 205 | + $tutorialHtml = UploadWizardTutorial::getHtml(); |
| 206 | + } |
| 207 | + // TODO move this into UploadWizard.js or some other javascript resource so the upload wizard |
| 208 | + // can be dynamically included ( for example the add media wizard ) |
| 209 | + return |
| 210 | + '<div id="upload-wizard" class="upload-section">' |
| 211 | + |
| 212 | + // if loading takes > 2 seconds display spinner. Note we are evading Resource Loader here, and linking directly. Because we want an image to appear if RL's package is late. |
| 213 | + // using some 's which is a bit of superstition, to make sure jQuery will hide this (it seems that it doesn't sometimes, when it has no content) |
| 214 | + // the min-width & max-width is copied from the #uploadWizard properties, so in nice browsers the spinner is right where the button will go. |
| 215 | + . '<div id="mwe-first-spinner" style="min-width:750px; max-width:900px; height:200px; line-height:200px; text-align:center;">' |
| 216 | + . ' <img src="' . $wgExtensionAssetsPath . '/UploadWizard/resources/images/24px-spinner-0645ad.gif" width="24" height="24" /> ' |
| 217 | + . '</div>' |
| 218 | + |
| 219 | + // the arrow steps - hide until styled |
| 220 | + . '<ul id="mwe-upwiz-steps" style="display:none;">' |
| 221 | + . '<li id="mwe-upwiz-step-tutorial"><div>' . wfMsg( 'mwe-upwiz-step-tutorial' ) . '</div></li>' |
| 222 | + . '<li id="mwe-upwiz-step-file"><div>' . wfMsg( 'mwe-upwiz-step-file' ) . '</div></li>' |
| 223 | + . '<li id="mwe-upwiz-step-deeds"><div>' . wfMsg( 'mwe-upwiz-step-deeds' ) . '</div></li>' |
| 224 | + . '<li id="mwe-upwiz-step-details"><div>' . wfMsg( 'mwe-upwiz-step-details' ) . '</div></li>' |
| 225 | + . '<li id="mwe-upwiz-step-thanks"><div>' . wfMsg( 'mwe-upwiz-step-thanks' ) . '</div></li>' |
| 226 | + . '</ul>' |
| 227 | + |
| 228 | + // the individual steps, all at once - hide until needed |
| 229 | + . '<div id="mwe-upwiz-content">' |
| 230 | + |
| 231 | + . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-tutorial" style="display:none;">' |
| 232 | + . '<div id="mwe-upwiz-tutorial">' |
| 233 | + . $tutorialHtml |
| 234 | + . '</div>' |
| 235 | + . '<div class="mwe-upwiz-buttons">' |
| 236 | + . '<input type="checkbox" id="mwe-upwiz-skip" value="1" name="skip">' |
| 237 | + . '<label for="mwe-upwiz-skip">' . wfMsg('mwe-upwiz-skip-tutorial-future') . '</label>' |
| 238 | + . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next" ) . '</button>' |
| 239 | + . '</div>' |
| 240 | + . '</div>' |
| 241 | + |
| 242 | + . '<div class="mwe-upwiz-stepdiv ui-helper-clearfix" id="mwe-upwiz-stepdiv-file" style="display:none;">' |
| 243 | + . '<div id="mwe-upwiz-files">' |
| 244 | + . '<div id="mwe-upwiz-filelist" class="ui-corner-all"></div>' |
| 245 | + . '<div id="mwe-upwiz-upload-ctrls" class="mwe-upwiz-file ui-helper-clearfix">' |
| 246 | + . '<div id="mwe-upwiz-add-file-container" class="mwe-upwiz-add-files-0">' |
| 247 | + . '<button id="mwe-upwiz-add-file">' . wfMsg( "mwe-upwiz-add-file-0-free" ) . '</button>' |
| 248 | + . '</div>' |
| 249 | + . '<div id="mwe-upwiz-upload-ctrl-container">' |
| 250 | + . '<button id="mwe-upwiz-upload-ctrl">' . wfMsg( "mwe-upwiz-upload" ) . '</button>' |
| 251 | + . '</div>' |
| 252 | + . '</div>' |
| 253 | + . '<div id="mwe-upwiz-progress" class="ui-helper-clearfix"></div>' |
| 254 | + . '<div id="mwe-upwiz-continue" class="ui-helper-clearfix"></div>' |
| 255 | + . '</div>' |
| 256 | + . '<div class="mwe-upwiz-buttons">' |
| 257 | + . '<div class="mwe-upwiz-file-next-all-ok mwe-upwiz-file-endchoice">' |
| 258 | + . wfMsg( "mwe-upwiz-file-all-ok" ) |
| 259 | + . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-file" ) . '</button>' |
| 260 | + . '</div>' |
| 261 | + . '<div class="mwe-upwiz-file-next-some-failed mwe-upwiz-file-endchoice">' |
| 262 | + . wfMsg( "mwe-upwiz-file-some-failed" ) |
| 263 | + . '<button class="mwe-upwiz-button-retry">' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
| 264 | + . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-file-despite-failures" ) . '</button>' |
| 265 | + . '</div>' |
| 266 | + . '<div class="mwe-upwiz-file-next-all-failed mwe-upwiz-file-endchoice">' |
| 267 | + . wfMsg( "mwe-upwiz-file-all-failed" ) |
| 268 | + . '<button class="mwe-upwiz-button-retry"> ' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
| 269 | + . '</div>' |
| 270 | + . '</div>' |
| 271 | + . '</div>' |
| 272 | + |
| 273 | + . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-deeds" style="display:none;">' |
| 274 | + . '<div id="mwe-upwiz-deeds-thumbnails" class="ui-helper-clearfix"></div>' |
| 275 | + . '<div id="mwe-upwiz-deeds" class="ui-helper-clearfix"></div>' |
| 276 | + . '<div id="mwe-upwiz-deeds-custom" class="ui-helper-clearfix"></div>' |
| 277 | + . '<div class="mwe-upwiz-buttons">' |
| 278 | + . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-deeds" ) . '</button>' |
| 279 | + . '</div>' |
| 280 | + . '</div>' |
| 281 | + |
| 282 | + . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-details" style="display:none;">' |
| 283 | + . '<div id="mwe-upwiz-macro-files" class="mwe-upwiz-filled-filelist ui-corner-all"></div>' |
| 284 | + . '<div class="mwe-upwiz-buttons">' |
| 285 | + . '<div id="mwe-upwiz-details-error-count" class="mwe-upwiz-file-endchoice mwe-error"></div>' |
| 286 | + . '<div class="mwe-upwiz-start-next mwe-upwiz-file-endchoice">' |
| 287 | + . '<button class="mwe-upwiz-button-next">' . wfMsg( "mwe-upwiz-next-details" ) . '</button>' |
| 288 | + . '</div>' |
| 289 | + . '<div class="mwe-upwiz-file-next-some-failed mwe-upwiz-file-endchoice">' |
| 290 | + . wfMsg( "mwe-upwiz-file-some-failed" ) |
| 291 | + . '<button class="mwe-upwiz-button-retry">' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
| 292 | + . '<button class="mwe-upwiz-button-next-despite-failures">' . wfMsg( "mwe-upwiz-next-file-despite-failures" ) . '</button>' |
| 293 | + . '</div>' |
| 294 | + . '<div class="mwe-upwiz-file-next-all-failed mwe-upwiz-file-endchoice">' |
| 295 | + . wfMsg( "mwe-upwiz-file-all-failed" ) |
| 296 | + . '<button class="mwe-upwiz-button-retry"> ' . wfMsg( "mwe-upwiz-file-retry" ) . '</button>' |
| 297 | + . '</div>' |
| 298 | + . '</div>' |
| 299 | + . '</div>' |
| 300 | + |
| 301 | + . '<div class="mwe-upwiz-stepdiv" id="mwe-upwiz-stepdiv-thanks" style="display:none;">' |
| 302 | + . '<div id="mwe-upwiz-thanks"></div>' |
| 303 | + . '<div class="mwe-upwiz-buttons">' |
| 304 | + . '<button class="mwe-upwiz-button-home">' . wfMsg( "mwe-upwiz-home" ) . '</button>' |
| 305 | + . '<button class="mwe-upwiz-button-begin">' . wfMsg( "mwe-upwiz-upload-another" ) . '</button>' |
| 306 | + . '</div>' |
| 307 | + . '</div>' |
| 308 | + |
| 309 | + . '</div>' |
| 310 | + |
| 311 | + . '<div class="mwe-upwiz-clearing"></div>' |
| 312 | + |
| 313 | + . '</div>'; |
| 314 | + } |
| 315 | + |
| 316 | +} |
| 317 | + |
| 318 | + |
| 319 | +/** |
| 320 | + * This is a hack on UploadForm, to make one that works from UploadWizard when JS is not available. |
| 321 | + */ |
| 322 | +class UploadWizardSimpleForm extends UploadForm { |
| 323 | + |
| 324 | + /* |
| 325 | + * Normally, UploadForm adds its own Javascript. |
| 326 | + * We wish to prevent this, because we want to control the case where we have Javascript. |
| 327 | + * So, we make the addUploadJS a no-op. |
| 328 | + */ |
| 329 | + protected function addUploadJS( ) { } |
| 330 | + |
| 331 | +} |
| 332 | + |
| 333 | + |
Property changes on: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 334 | + native |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php |
— | — | @@ -0,0 +1,188 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Special:UploadCampaigns |
| 6 | + * |
| 7 | + * Lists the upload campaigns. |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup SpecialPage |
| 11 | + * @ingroup Upload |
| 12 | + * |
| 13 | + * @since 1.2 |
| 14 | + * |
| 15 | + * @licence GNU GPL v3+ |
| 16 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 17 | + */ |
| 18 | +class SpecialUploadCampaigns extends SpecialPage { |
| 19 | + |
| 20 | + /** |
| 21 | + * Constructor. |
| 22 | + * |
| 23 | + * @param $request is the request (usually wgRequest) |
| 24 | + * @param $par is everything in the URL after Special:UploadCampaigns. Not sure what we can use it for |
| 25 | + */ |
| 26 | + public function __construct( $request = null, $par = null ) { |
| 27 | + parent::__construct( 'UploadCampaigns', 'upwizcampaigns' ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * (non-PHPdoc) |
| 32 | + * @see SpecialPage::getDescription() |
| 33 | + */ |
| 34 | + public function getDescription() { |
| 35 | + return wfMsg( 'mwe-upwiz-' . strtolower( $this->mName ) ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Main method. |
| 40 | + * |
| 41 | + * @param string $subPage, e.g. the "foo" in Special:UploadCampaigns/foo. |
| 42 | + */ |
| 43 | + public function execute( $subPage ) { |
| 44 | + global $wgRequest, $wgUser; |
| 45 | + |
| 46 | + $this->setHeaders(); |
| 47 | + $this->outputHeader(); |
| 48 | + $subPage = explode( '/', $subPage, 2 ); |
| 49 | + |
| 50 | + // If the user is authorized, display the page, if not, show an error. |
| 51 | + if ( $this->userCanExecute( $wgUser ) ) { |
| 52 | + if ( $wgRequest->wasPosted() |
| 53 | + && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) |
| 54 | + && $wgRequest->getCheck( 'newcampaign' ) ) { |
| 55 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() ); |
| 56 | + } |
| 57 | + elseif ( count( $subPage ) == 2 && $subPage[0] == 'del' ) { |
| 58 | + $campaign = UploadWizardCampaign::newFromName( $subPage[1], false ); |
| 59 | + $campaign->deleteFromDB(); |
| 60 | + $this->getOutput()->redirect( $this->getTitle()->getLocalURL() ); |
| 61 | + } |
| 62 | + else { |
| 63 | + $this->displayUploadCamaigns(); |
| 64 | + } |
| 65 | + } else { |
| 66 | + $this->displayRestrictionError(); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Displays the pages regular output. |
| 72 | + * |
| 73 | + * @since 1.2 |
| 74 | + */ |
| 75 | + protected function displayUploadCamaigns() { |
| 76 | + $this->displayAddNewControl(); |
| 77 | + |
| 78 | + $dbr = wfGetDB( DB_SLAVE ); |
| 79 | + |
| 80 | + $campaigns = $dbr->select( |
| 81 | + 'uw_campaigns', |
| 82 | + array( |
| 83 | + 'campaign_id', |
| 84 | + 'campaign_name', |
| 85 | + 'campaign_enabled', |
| 86 | + ) |
| 87 | + ); |
| 88 | + |
| 89 | + if ( $campaigns->numRows() > 0 ) { |
| 90 | + $this->displayCampaignTable( $campaigns ); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Displays a small form to add a new campaign. |
| 96 | + * |
| 97 | + * @since 1.2 |
| 98 | + */ |
| 99 | + protected function displayAddNewControl() { |
| 100 | + $out = $this->getOutput(); |
| 101 | + |
| 102 | + $out->addHTML( Html::openElement( |
| 103 | + 'form', |
| 104 | + array( |
| 105 | + 'method' => 'post', |
| 106 | + 'action' => $this->getTitle()->getLocalURL(), |
| 107 | + ) |
| 108 | + ) ); |
| 109 | + |
| 110 | + $out->addHTML( '<fieldset>' ); |
| 111 | + |
| 112 | + $out->addHTML( '<legend>' . htmlspecialchars( wfMsg( 'mwe-upwiz-campaigns-addnew' ) ) . '</legend>' ); |
| 113 | + |
| 114 | + $out->addHTML( Html::element( 'p', array(), wfMsg( 'mwe-upwiz-campaigns-namedoc' ) ) ); |
| 115 | + |
| 116 | + $out->addHTML( Html::element( 'label', array( 'for' => 'newcampaign' ), wfMsg( 'mwe-upwiz-campaigns-newname' ) ) ); |
| 117 | + |
| 118 | + $out->addHTML( Html::input( 'newcampaign' ) . ' ' ); |
| 119 | + |
| 120 | + $out->addHTML( Html::input( |
| 121 | + 'addnewcampaign', |
| 122 | + wfMsg( 'mwe-upwiz-campaigns-add' ), |
| 123 | + 'submit' |
| 124 | + ) ); |
| 125 | + |
| 126 | + global $wgUser; |
| 127 | + $out->addHTML( Html::hidden( 'wpEditToken', $wgUser->editToken() ) ); |
| 128 | + |
| 129 | + $out->addHTML( '</fieldset></form>' ); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Displays a list of all campaigns. |
| 134 | + * |
| 135 | + * @since 1.2 |
| 136 | + * |
| 137 | + * @param ResultWrapper $campaigns |
| 138 | + */ |
| 139 | + protected function displayCampaignTable( ResultWrapper $campaigns ) { |
| 140 | + $out = $this->getOutput(); |
| 141 | + |
| 142 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) ); |
| 143 | + |
| 144 | + $out->addHTML( Xml::openElement( |
| 145 | + 'table', |
| 146 | + array( 'class' => 'wikitable', 'style' => 'width:400px' ) |
| 147 | + ) ); |
| 148 | + |
| 149 | + $out->addHTML( |
| 150 | + '<tr>' . |
| 151 | + Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-name' ) ) . |
| 152 | + Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-status' ) ) . |
| 153 | + Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-edit' ) ) . |
| 154 | + Html::element( 'th', array(), wfMsg( 'mwe-upwiz-campaigns-delete' ) ) . |
| 155 | + '</tr>' |
| 156 | + ); |
| 157 | + |
| 158 | + foreach ( $campaigns as $campaign ) { |
| 159 | + $out->addHTML( |
| 160 | + '<tr>' . |
| 161 | + Html::element( 'td', array(), $campaign->campaign_name ) . |
| 162 | + Html::element( 'td', array(), wfMsg( 'mwe-upwiz-campaigns-' . ( $campaign->campaign_enabled ? 'enabled' : 'disabled' ) ) ) . |
| 163 | + '<td>' . |
| 164 | + Html::element( |
| 165 | + 'a', |
| 166 | + array( |
| 167 | + 'href' => SpecialPage::getTitleFor( 'UploadCampaign', $campaign->campaign_name )->getLocalURL() |
| 168 | + ), |
| 169 | + wfMsg( 'mwe-upwiz-campaigns-edit' ) |
| 170 | + ) . |
| 171 | + '</td>' . |
| 172 | + '<td>' . |
| 173 | + Html::element( |
| 174 | + 'a', |
| 175 | + array( |
| 176 | + 'href' => SpecialPage::getTitleFor( 'UploadCampaigns', 'del/' . $campaign->campaign_name )->getLocalURL(), |
| 177 | + 'onclick' => 'return confirm( "' . wfMsg( 'mwe-upwiz-campaigns-confdel' ) . '" )' |
| 178 | + ), |
| 179 | + wfMsg( 'mwe-upwiz-campaigns-delete' ) |
| 180 | + ) . |
| 181 | + '</td>' . |
| 182 | + '</tr>' |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + $out->addHTML( '</table>' ); |
| 187 | + } |
| 188 | + |
| 189 | +} |
Property changes on: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 190 | + native |
Index: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php |
— | — | @@ -0,0 +1,452 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class that represents a single upload campaign. |
| 6 | + * |
| 7 | + * @file |
| 8 | + * @ingroup Upload |
| 9 | + * |
| 10 | + * @since 1.2 |
| 11 | + * |
| 12 | + * @licence GNU GPL v3+ |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class UploadWizardCampaign { |
| 16 | + |
| 17 | + /** |
| 18 | + * If the ID of the campaign. |
| 19 | + * Either this matched a record in the uw_campaigns table or is null. |
| 20 | + * |
| 21 | + * @since 1.2 |
| 22 | + * @var integer or null |
| 23 | + */ |
| 24 | + protected $id; |
| 25 | + |
| 26 | + /** |
| 27 | + * If the name of the campaign. |
| 28 | + * This name is the string used to invoke the campaign via campaign=name. |
| 29 | + * |
| 30 | + * @since 1.2 |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + protected $name; |
| 34 | + |
| 35 | + /** |
| 36 | + * If the campaign is enabled or not. |
| 37 | + * |
| 38 | + * @since 1.2 |
| 39 | + * @var boolean |
| 40 | + */ |
| 41 | + protected $isEnabled; |
| 42 | + |
| 43 | + /** |
| 44 | + * The campaign configuration. |
| 45 | + * |
| 46 | + * @since 1.2 |
| 47 | + * @var array |
| 48 | + */ |
| 49 | + protected $config; |
| 50 | + |
| 51 | + /** |
| 52 | + * If the campaign config has been loaded or not. |
| 53 | + * |
| 54 | + * @since 1.2 |
| 55 | + * @var boolean |
| 56 | + */ |
| 57 | + protected $loadedConfig = false; |
| 58 | + |
| 59 | + /** |
| 60 | + * Create a new instance of $campaignName. |
| 61 | + * |
| 62 | + * @since 1.2 |
| 63 | + * |
| 64 | + * @param integer $id |
| 65 | + * @param string $name |
| 66 | + * @param boolean $isEnabled |
| 67 | + * @param array $config |
| 68 | + */ |
| 69 | + public function __construct( $id, $name, $isEnabled, array $config ) { |
| 70 | + $this->id = $id; |
| 71 | + $this->name = $name; |
| 72 | + $this->isEnabled = $isEnabled; |
| 73 | + $this->config = $config; |
| 74 | + |
| 75 | + $this->loadedConfig = count( $this->config ) > 0; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Returns the UploadWizardCampaign with specified name, or false if there is no such campaign. |
| 80 | + * |
| 81 | + * @since 1.2 |
| 82 | + * |
| 83 | + * @param string $campaignName |
| 84 | + * @param boolean $loadConfig |
| 85 | + * |
| 86 | + * @return UploadWizardCampaign or false |
| 87 | + */ |
| 88 | + public static function newFromName( $campaignName, $loadConfig = true ) { |
| 89 | + return self::newFromDB( array( 'campaign_name' => $campaignName ), $loadConfig ); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Returns the UploadWizardCampaign with specified ID, or false if there is no such campaign. |
| 94 | + * |
| 95 | + * @since 1.2 |
| 96 | + * |
| 97 | + * @param integer $campaignId |
| 98 | + * @param boolean $loadConfig |
| 99 | + * |
| 100 | + * @return UploadWizardCampaign or false |
| 101 | + */ |
| 102 | + public static function newFromId( $campaignId, $loadConfig = true ) { |
| 103 | + return self::newFromDB( array( 'campaign_id' => $campaignId ), $loadConfig ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Returns a new instance of UploadWizardCampaign build from a database result |
| 108 | + * obtained by doing a select with the porvided conditions on the uw_campaigns table. |
| 109 | + * If no campaign matches the conditions, false will be returned. |
| 110 | + * |
| 111 | + * @since 1.2 |
| 112 | + * |
| 113 | + * @param array $conditions |
| 114 | + * @param boolean $loadConfig |
| 115 | + * |
| 116 | + * @return UploadWizardCampaign or false |
| 117 | + */ |
| 118 | + protected static function newFromDB( array $conditions, $loadConfig = true ) { |
| 119 | + $dbr = wfGetDB( DB_SLAVE ); |
| 120 | + |
| 121 | + $campaign = $dbr->selectRow( |
| 122 | + 'uw_campaigns', |
| 123 | + array( |
| 124 | + 'campaign_id', |
| 125 | + 'campaign_name', |
| 126 | + 'campaign_enabled', |
| 127 | + ), |
| 128 | + $conditions |
| 129 | + ); |
| 130 | + |
| 131 | + if ( !$campaign ) { |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + $config = $loadConfig ? self::getPropsFromDB( $dbr, $campaign->campaign_id ) : array(); |
| 136 | + |
| 137 | + return new self( |
| 138 | + $campaign->campaign_id, |
| 139 | + $campaign->campaign_name, |
| 140 | + $campaign->campaign_enabled, |
| 141 | + $config |
| 142 | + ); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Returns the list of configuration settings that can be modified by campaigns, |
| 147 | + * and the HTMLForm input type that can be used to represent their value. |
| 148 | + * Property name => HTMLForm input type |
| 149 | + * |
| 150 | + * @since 1.2 |
| 151 | + * |
| 152 | + * @return array |
| 153 | + */ |
| 154 | + public static function getConfigTypes() { |
| 155 | + return array( |
| 156 | + 'skipTutorial' => 'check' |
| 157 | + ); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Returns the default configuration values. |
| 162 | + * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
| 163 | + * |
| 164 | + * @since 1.2 |
| 165 | + * |
| 166 | + * @return array |
| 167 | + */ |
| 168 | + public static function getDefaultConfig() { |
| 169 | + static $config = false; |
| 170 | + |
| 171 | + if ( $config === false ) { |
| 172 | + $config = array(); |
| 173 | + $globalConf = UploadWizardConfig::getConfig(); |
| 174 | + |
| 175 | + foreach ( self::getConfigTypes() as $setting => $type ) { |
| 176 | + if ( array_key_exists( $setting, $globalConf ) ) { |
| 177 | + $config[$setting] = array( 'type' => $type, 'default' => $globalConf[$setting] ); |
| 178 | + } |
| 179 | + else { |
| 180 | + wfWarn( "Nonexiting Upload Wizard configuration setting '$setting' will be ignored." ); |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + return $config; |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * Returns the id of the campaign. |
| 190 | + * |
| 191 | + * @since 1.2 |
| 192 | + * |
| 193 | + * @return intgere |
| 194 | + */ |
| 195 | + public function getId() { |
| 196 | + return $this->id; |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * Returns the name of the campaign. |
| 201 | + * |
| 202 | + * @since 1.2 |
| 203 | + * |
| 204 | + * @return string |
| 205 | + */ |
| 206 | + public function getName() { |
| 207 | + return $this->name; |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * Returns if the campaign is enabled. |
| 212 | + * |
| 213 | + * @since 1.2 |
| 214 | + * |
| 215 | + * @return boolean |
| 216 | + */ |
| 217 | + public function getIsEnabled() { |
| 218 | + return $this->isEnabled; |
| 219 | + } |
| 220 | + |
| 221 | + /** |
| 222 | + * Sets all config properties. |
| 223 | + * |
| 224 | + * @since 1.2 |
| 225 | + * |
| 226 | + * @param array $config |
| 227 | + */ |
| 228 | + public function setConfig( array $config ) { |
| 229 | + $this->config = $config; |
| 230 | + $this->loadedConfig = true; |
| 231 | + } |
| 232 | + |
| 233 | + /** |
| 234 | + * Returns all set config properties. |
| 235 | + * Property name => property value |
| 236 | + * |
| 237 | + * @since 1.2 |
| 238 | + * |
| 239 | + * @return array |
| 240 | + */ |
| 241 | + public function getConfig() { |
| 242 | + if ( !$this->loadedConfig ) { |
| 243 | + if ( !is_null( $this->id ) ) { |
| 244 | + $this->config = self::getPropsFromDB( wfGetDB( DB_SLAVE ), $this->id ); |
| 245 | + } |
| 246 | + |
| 247 | + $this->loadedConfig = true; |
| 248 | + } |
| 249 | + |
| 250 | + return $this->config; |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * Returns all config properties by merging the set ones with a list of default ones. |
| 255 | + * Property name => array( 'default' => $value, 'type' => HTMLForm input type ) |
| 256 | + * |
| 257 | + * @since 1.2 |
| 258 | + * |
| 259 | + * @return array |
| 260 | + */ |
| 261 | + public function getAllConfig() { |
| 262 | + $setConfig = $this->getConfig(); |
| 263 | + $config = array(); |
| 264 | + |
| 265 | + foreach ( self::getDefaultConfig() as $name => $data ) { |
| 266 | + if ( array_key_exists( $name, $setConfig ) ) { |
| 267 | + $data['default'] = $setConfig[$name]; |
| 268 | + } |
| 269 | + |
| 270 | + $config[$name] = $data; |
| 271 | + } |
| 272 | + |
| 273 | + return $config; |
| 274 | + } |
| 275 | + |
| 276 | + /** |
| 277 | + * Returns the value of the specified config property. |
| 278 | + * |
| 279 | + * @since 1.2 |
| 280 | + * |
| 281 | + * @param string $property |
| 282 | + * |
| 283 | + * @return mixed |
| 284 | + */ |
| 285 | + public function getProperty( $property ) { |
| 286 | + global $wgUploadWizardConfig; |
| 287 | + |
| 288 | + if ( array_key_exists( $property, $this->config ) ) { |
| 289 | + return $this->config[$property]; |
| 290 | + } |
| 291 | + elseif ( array_key_exists( $property, $wgUploadWizardConfig['campaignDefaults'] ) ) { |
| 292 | + return $wgUploadWizardConfig['campaignDefaults'][$property]; |
| 293 | + } |
| 294 | + else { |
| 295 | + return null; |
| 296 | + } |
| 297 | + } |
| 298 | + |
| 299 | + /** |
| 300 | + * Write the campaign to the DB. |
| 301 | + * If it's already there, it'll be updated, else it'll be inserted. |
| 302 | + * |
| 303 | + * @since 1.2 |
| 304 | + * |
| 305 | + * @return boolean Success indicator |
| 306 | + */ |
| 307 | + public function writeToDB() { |
| 308 | + if ( is_null( $this->id ) ) { |
| 309 | + return $this->insertIntoDB(); |
| 310 | + } |
| 311 | + else { |
| 312 | + return $this->updateInDB(); |
| 313 | + } |
| 314 | + } |
| 315 | + |
| 316 | + /** |
| 317 | + * Insert the campaign into the DB. |
| 318 | + * |
| 319 | + * @since 1.2 |
| 320 | + * |
| 321 | + * @return boolean Success indicator |
| 322 | + */ |
| 323 | + protected function insertIntoDB() { |
| 324 | + $dbw = wfGetDB( DB_MASTER ); |
| 325 | + |
| 326 | + $success = $dbw->insert( |
| 327 | + 'uw_campaigns', |
| 328 | + array( |
| 329 | + 'campaign_name' => $this->name, |
| 330 | + 'campaign_enabled' => $this->isEnabled, |
| 331 | + ), |
| 332 | + array( 'campaign_id' => $this->id ) |
| 333 | + ); |
| 334 | + |
| 335 | + if ( $success ) { |
| 336 | + $this->id = $dbw->insertId(); |
| 337 | + $success &= $this->writePropsToDB( $dbw ); |
| 338 | + } |
| 339 | + |
| 340 | + return $success; |
| 341 | + } |
| 342 | + |
| 343 | + /** |
| 344 | + * Update the campaign in the DB. |
| 345 | + * |
| 346 | + * @since 1.2 |
| 347 | + * |
| 348 | + * @return boolean Success indicator |
| 349 | + */ |
| 350 | + protected function updateInDB() { |
| 351 | + $dbw = wfGetDB( DB_MASTER ); |
| 352 | + |
| 353 | + $success = $dbw->update( |
| 354 | + 'uw_campaigns', |
| 355 | + array( |
| 356 | + 'campaign_name' => $this->name, |
| 357 | + 'campaign_enabled' => $this->isEnabled, |
| 358 | + ), |
| 359 | + array( 'campaign_id' => $this->id ) |
| 360 | + ); |
| 361 | + |
| 362 | + // Delete and insert instead of update. |
| 363 | + // This will not result into dead-data when config vars are removed. |
| 364 | + $success &= $dbw->delete( |
| 365 | + 'uw_campaign_conf', |
| 366 | + array( 'cc_campaign_id' => $this->id ) |
| 367 | + ); |
| 368 | + |
| 369 | + $success &= $this->writePropsToDB( $dbw ); |
| 370 | + |
| 371 | + return $success; |
| 372 | + } |
| 373 | + |
| 374 | + /** |
| 375 | + * Write (insert) the properties into the DB. |
| 376 | + * |
| 377 | + * @since 1.2 |
| 378 | + * |
| 379 | + * @param Database $dbw |
| 380 | + * |
| 381 | + * @return boolean Success indicator |
| 382 | + */ |
| 383 | + protected function writePropsToDB( DatabaseBase $dbw ) { |
| 384 | + $success = true; |
| 385 | + |
| 386 | + foreach ( $this->config as $prop => $value ) { |
| 387 | + $success &= $dbw->insert( |
| 388 | + 'uw_campaign_conf', |
| 389 | + array( |
| 390 | + 'cc_campaign_id' => $this->id, |
| 391 | + 'cc_property' => $prop, |
| 392 | + 'cc_value' => $value |
| 393 | + ) |
| 394 | + ); |
| 395 | + } |
| 396 | + |
| 397 | + return $success; |
| 398 | + } |
| 399 | + |
| 400 | + /** |
| 401 | + * Get the configuration properties from the DB. |
| 402 | + * |
| 403 | + * @since 1.2 |
| 404 | + * |
| 405 | + * @param Database $dbr |
| 406 | + * @param integer $campaignId |
| 407 | + * |
| 408 | + * @return array |
| 409 | + */ |
| 410 | + protected static function getPropsFromDB( DatabaseBase $dbr, $campaignId ) { |
| 411 | + $config = array(); |
| 412 | + |
| 413 | + $confProps = $dbr->select( |
| 414 | + 'uw_campaign_conf', |
| 415 | + array( 'cc_property', 'cc_value' ), |
| 416 | + array( 'cc_campaign_id' => $campaignId ) |
| 417 | + ); |
| 418 | + |
| 419 | + foreach ( $confProps as $confProp ) { |
| 420 | + $config[$confProp->cc_property] = $confProp->cc_value; |
| 421 | + } |
| 422 | + |
| 423 | + return $config; |
| 424 | + } |
| 425 | + |
| 426 | + /** |
| 427 | + * Delete the campaign from the DB (when present). |
| 428 | + * |
| 429 | + * @since 1.2 |
| 430 | + * |
| 431 | + * @return boolean Success indicator |
| 432 | + */ |
| 433 | + public function deleteFromDB() { |
| 434 | + if ( is_null( $this->id ) ) { |
| 435 | + return true; |
| 436 | + } |
| 437 | + |
| 438 | + $dbw = wfGetDB( DB_MASTER ); |
| 439 | + |
| 440 | + $d1 = $dbw->delete( |
| 441 | + 'uw_campaigns', |
| 442 | + array( 'campaign_id' => $this->id ) |
| 443 | + ); |
| 444 | + |
| 445 | + $d2 = $dbw->delete( |
| 446 | + 'uw_campaign_conf', |
| 447 | + array( 'cc_campaign_id' => $this->id ) |
| 448 | + ); |
| 449 | + |
| 450 | + return $d1 && $d2; |
| 451 | + } |
| 452 | + |
| 453 | +} |
Property changes on: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 454 | + native |
Index: trunk/extensions/UploadWizard/UploadWizard.php |
— | — | @@ -37,16 +37,16 @@ |
38 | 38 | |
39 | 39 | # Require modules, including the special page |
40 | 40 | foreach ( array( |
41 | | - 'UploadWizardConfig', |
42 | | - 'SpecialUploadWizard', |
43 | | - 'SpecialUploadCampaigns', |
44 | | - 'SpecialUploadCampaign', |
45 | | - 'UploadWizardMessages', |
46 | | - 'UploadWizardHooks', |
47 | | - 'UploadWizardTutorial', |
48 | | - 'UploadWizardCampaign' |
49 | | - ) as $module ) { |
50 | | - $wgAutoloadLocalClasses[$module] = $wgUpwizDir . '/' . $module . '.php'; |
| 41 | + 'UploadWizardMessages' => $wgUpwizDir, |
| 42 | + 'UploadWizardHooks' => $wgUpwizDir, |
| 43 | + 'UploadWizardConfig' => $wgUpwizDir . '/includes', |
| 44 | + 'UploadWizardTutorial' => $wgUpwizDir . '/includes', |
| 45 | + 'UploadWizardCampaign' => $wgUpwizDir . '/includes', |
| 46 | + 'SpecialUploadWizard' => $wgUpwizDir . '/includes/specials', |
| 47 | + 'SpecialUploadCampaigns' => $wgUpwizDir . '/includes/specials', |
| 48 | + 'SpecialUploadCampaign' => $wgUpwizDir . '/includes/specials', |
| 49 | + ) as $module => $dir ) { |
| 50 | + $wgAutoloadLocalClasses[$module] = $dir . '/' . $module . '.php'; |
51 | 51 | } |
52 | 52 | |
53 | 53 | // $wgAPIModules['titlecheck'] = 'ApiTitleCheck'; |