Index: trunk/extensions/UploadWizard/UploadWizard.php |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | foreach ( array( |
39 | 39 | 'UploadWizardMessages' => $wgUpwizDir, |
40 | 40 | 'UploadWizardHooks' => $wgUpwizDir, |
| 41 | + 'ApiDeleteUploadCampaign' => $wgUpwizDir . '/api', |
41 | 42 | 'UploadWizardConfig' => $wgUpwizDir . '/includes', |
42 | 43 | 'UploadWizardTutorial' => $wgUpwizDir . '/includes', |
43 | 44 | 'UploadWizardCampaign' => $wgUpwizDir . '/includes', |
— | — | @@ -60,6 +61,8 @@ |
61 | 62 | $wgSpecialPages['UploadCampaign'] = 'SpecialUploadCampaign'; |
62 | 63 | $wgSpecialPageGroups['UploadCampaign'] = 'media'; |
63 | 64 | |
| 65 | +$wgAPIModules['deleteuploadcampaign'] = 'ApiDeleteUploadCampaign'; |
| 66 | + |
64 | 67 | // Disable ResourceLoader support by default, it's currently broken |
65 | 68 | // $wgUploadWizardDisableResourceLoader = true; |
66 | 69 | |
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -389,6 +389,15 @@ |
390 | 390 | 'resources/mw.MockUploadHandler.js' |
391 | 391 | ), |
392 | 392 | ), |
| 393 | + 'ext.uploadWizard.campaigns' => array( |
| 394 | + 'scripts' => array( |
| 395 | + 'resources/ext.upwiz.campaigns.js' |
| 396 | + ), |
| 397 | + 'messages' => array( |
| 398 | + 'mwe-upwiz-campaigns-delete-failed', |
| 399 | + 'mwe-upwiz-campaigns-confirm-delete', |
| 400 | + ), |
| 401 | + ), |
393 | 402 | ); |
394 | 403 | |
395 | 404 | /* |
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php |
— | — | @@ -57,7 +57,6 @@ |
58 | 58 | |
59 | 59 | $this->setHeaders(); |
60 | 60 | $this->outputHeader(); |
61 | | - $subPage = explode( '/', $subPage, 4 ); |
62 | 61 | |
63 | 62 | // If the user is authorized, display the page, if not, show an error. |
64 | 63 | if ( $this->userCanExecute( $wgUser ) ) { |
— | — | @@ -66,12 +65,6 @@ |
67 | 66 | && $wgRequest->getCheck( 'newcampaign' ) ) { |
68 | 67 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() ); |
69 | 68 | } |
70 | | - elseif ( count( $subPage ) == 4 && $subPage[0] == 'del' |
71 | | - && $wgUser->matchEditToken( $subPage[3], serialize( array( $subPage[1], $subPage[2] ) ) ) ) { |
72 | | - $campaign = UploadWizardCampaign::newFromId( $subPage[1], false ); |
73 | | - $campaign->deleteFromDB(); |
74 | | - $this->getOutput()->redirect( $this->getTitle()->getLocalURL() ); |
75 | | - } |
76 | 69 | else { |
77 | 70 | $this->displayUploadCamaigns(); |
78 | 71 | } |
— | — | @@ -175,11 +168,6 @@ |
176 | 169 | global $wgUser; |
177 | 170 | |
178 | 171 | foreach ( $campaigns as $campaign ) { |
179 | | - $editToken = $wgUser->editToken( serialize( array( |
180 | | - $campaign->campaign_id, |
181 | | - $campaign->campaign_name |
182 | | - ) ) ); |
183 | | - |
184 | 172 | $out->addHTML( |
185 | 173 | '<tr>' . |
186 | 174 | '<td>' . |
— | — | @@ -205,10 +193,10 @@ |
206 | 194 | Html::element( |
207 | 195 | 'a', |
208 | 196 | array( |
209 | | - 'href' => $this->getTitle( |
210 | | - implode( '/', array( 'del', $campaign->campaign_id, $campaign->campaign_name, $editToken ) ) |
211 | | - )->getLocalURL(), |
212 | | - 'onclick' => 'return confirm( "' . wfMsg( 'mwe-upwiz-campaigns-confdel' ) . '" )' |
| 197 | + 'href' => '#', |
| 198 | + 'class' => 'campaign-delete', |
| 199 | + 'data-campaign-id' => $campaign->campaign_id, |
| 200 | + 'data-campaign-token' => $wgUser->editToken( 'deletecampaign' . $campaign->campaign_id ) |
213 | 201 | ), |
214 | 202 | wfMsg( 'mwe-upwiz-campaigns-delete' ) |
215 | 203 | ) . |
— | — | @@ -219,6 +207,8 @@ |
220 | 208 | |
221 | 209 | $out->addHTML( '</tbody>' ); |
222 | 210 | $out->addHTML( '</table>' ); |
| 211 | + |
| 212 | + $out->addModules( 'ext.uploadWizard.campaigns' ); |
223 | 213 | } |
224 | 214 | |
225 | 215 | } |
Index: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | * @param boolean $isEnabled |
67 | 67 | * @param array $config |
68 | 68 | */ |
69 | | - public function __construct( $id, $name, $isEnabled, array $config ) { |
| 69 | + public function __construct( $id, $name = '', $isEnabled = false, array $config = array() ) { |
70 | 70 | $this->id = $id; |
71 | 71 | $this->name = $name; |
72 | 72 | $this->isEnabled = $isEnabled; |
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -314,6 +314,8 @@ |
315 | 315 | 'mwe-upwiz-campaigns-editing' => 'Upload campaign configuration', |
316 | 316 | 'mwe-upwiz-campaigns-delete' => 'Delete', |
317 | 317 | 'mwe-upwiz-campaigns-confdel' => 'Are you sure you want to delete this campaign?', |
| 318 | + 'mwe-upwiz-campaigns-delete-failed' => 'Could not delete the campaign.', |
| 319 | + 'mwe-upwiz-campaigns-confirm-delete' => 'Are you sure you want to delete this campaign?', |
318 | 320 | |
319 | 321 | // Special:UploadCampaign |
320 | 322 | 'uploadcampaign-legend' => 'Upload campaign configuration', |
Index: trunk/extensions/UploadWizard/api/ApiDeleteUploadCampaign.php |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to delete upload wizard campaigns. |
| 6 | + * |
| 7 | + * @since 1.2 |
| 8 | + * |
| 9 | + * @file ApiDeleteUploadCampaign.php |
| 10 | + * @ingroup Upload |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiDeleteUploadCampaign extends ApiBase { |
| 17 | + |
| 18 | + public function __construct( $main, $action ) { |
| 19 | + parent::__construct( $main, $action ); |
| 20 | + } |
| 21 | + |
| 22 | + public function execute() { |
| 23 | + global $wgUser; |
| 24 | + |
| 25 | + if ( !$wgUser->isAllowed( 'upwizcampaigns' ) || $wgUser->isBlocked() ) { |
| 26 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 27 | + } |
| 28 | + |
| 29 | + $params = $this->extractRequestParams(); |
| 30 | + |
| 31 | + $everythingOk = true; |
| 32 | + |
| 33 | + foreach ( $params['ids'] as $id ) { |
| 34 | + $campaign = new UploadWizardCampaign( $id ); |
| 35 | + $everythingOk = $campaign->deleteFromDB() && $everythingOk; |
| 36 | + } |
| 37 | + |
| 38 | + $this->getResult()->addValue( |
| 39 | + null, |
| 40 | + 'success', |
| 41 | + $everythingOk |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + public function needsToken() { |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + public function getTokenSalt() { |
| 50 | + $params = $this->extractRequestParams(); |
| 51 | + return 'deletecampaign' . implode( '|', $params['ids'] ); |
| 52 | + } |
| 53 | + |
| 54 | + public function mustBePosted() { |
| 55 | + return true; |
| 56 | + } |
| 57 | + |
| 58 | + public function getAllowedParams() { |
| 59 | + return array( |
| 60 | + 'ids' => array( |
| 61 | + ApiBase::PARAM_TYPE => 'integer', |
| 62 | + ApiBase::PARAM_REQUIRED => true, |
| 63 | + ApiBase::PARAM_ISMULTI => true, |
| 64 | + ), |
| 65 | + 'token' => null, |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + public function getParamDescription() { |
| 70 | + return array( |
| 71 | + 'ids' => 'The IDs of the campaigns to delete', |
| 72 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public function getDescription() { |
| 77 | + return array( |
| 78 | + 'API module for deleting surveys.' |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + public function getPossibleErrors() { |
| 83 | + return array_merge( parent::getPossibleErrors(), array( |
| 84 | + array( 'missingparam', 'ids' ), |
| 85 | + ) ); |
| 86 | + } |
| 87 | + |
| 88 | + protected function getExamples() { |
| 89 | + return array( |
| 90 | + 'api.php?action=deleteuploadcampaign&ids=42', |
| 91 | + 'api.php?action=deleteuploadcampaign&ids=4|2', |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | + public function getVersion() { |
| 96 | + return __CLASS__ . ': $Id: $'; |
| 97 | + } |
| 98 | + |
| 99 | +} |
Property changes on: trunk/extensions/UploadWizard/api/ApiDeleteUploadCampaign.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 100 | + native |
Index: trunk/extensions/UploadWizard/resources/ext.upwiz.campaigns.js |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Special:UploadCampaigns of the UploadWizard MediaWiki extension. |
| 4 | + * @see https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:UploadWizard |
| 5 | + * |
| 6 | + * @licence GNU GPL v3 or later |
| 7 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 8 | + */ |
| 9 | + |
| 10 | +(function( $ ) { $( document ).ready( function() { |
| 11 | + |
| 12 | + function deleteCampaign( options, successCallback, failCallback ) { |
| 13 | + $.post( |
| 14 | + wgScriptPath + '/api.php', |
| 15 | + { |
| 16 | + 'action': 'deleteuploadcampaign', |
| 17 | + 'format': 'json', |
| 18 | + 'ids': options.id, |
| 19 | + 'token': options.token |
| 20 | + }, |
| 21 | + function( data ) { |
| 22 | + if ( data.success ) { |
| 23 | + successCallback(); |
| 24 | + } else { |
| 25 | + failCallback( mw.msg( 'mwe-upwiz-campaigns-delete-failed' ) ); |
| 26 | + } |
| 27 | + } |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + $( '.campaign-delete' ).click( function() { |
| 32 | + $this = $( this ); |
| 33 | + |
| 34 | + if ( confirm( mw.msg( 'mwe-upwiz-campaigns-confirm-delete' ) ) ) { |
| 35 | + deleteCampaign( |
| 36 | + { |
| 37 | + id: $this.attr( 'data-campaign-id' ), |
| 38 | + token: $this.attr( 'data-campaign-token' ) |
| 39 | + }, |
| 40 | + function() { |
| 41 | + $this.closest( 'tr' ).slideUp( 'slow', function() { $( this ).remove(); } ); |
| 42 | + }, |
| 43 | + function( error ) { |
| 44 | + alert( error ); |
| 45 | + } |
| 46 | + ); |
| 47 | + } |
| 48 | + return false; |
| 49 | + } ); |
| 50 | + |
| 51 | +} ); })( jQuery ); |
\ No newline at end of file |
Property changes on: trunk/extensions/UploadWizard/resources/ext.upwiz.campaigns.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 52 | + native |