r96575 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96574‎ | r96575 | r96576 >
Date:15:15, 8 September 2011
Author:jeroendedauw
Status:ok (Comments)
Tags:
Comment:
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizard.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/api (added) (history)
  • /trunk/extensions/UploadWizard/api/ApiDeleteUploadCampaign.php (added) (history)
  • /trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php (modified) (history)
  • /trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/ext.upwiz.campaigns.js (added) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizard.php
@@ -37,6 +37,7 @@
3838 foreach ( array(
3939 'UploadWizardMessages' => $wgUpwizDir,
4040 'UploadWizardHooks' => $wgUpwizDir,
 41+ 'ApiDeleteUploadCampaign' => $wgUpwizDir . '/api',
4142 'UploadWizardConfig' => $wgUpwizDir . '/includes',
4243 'UploadWizardTutorial' => $wgUpwizDir . '/includes',
4344 'UploadWizardCampaign' => $wgUpwizDir . '/includes',
@@ -60,6 +61,8 @@
6162 $wgSpecialPages['UploadCampaign'] = 'SpecialUploadCampaign';
6263 $wgSpecialPageGroups['UploadCampaign'] = 'media';
6364
 65+$wgAPIModules['deleteuploadcampaign'] = 'ApiDeleteUploadCampaign';
 66+
6467 // Disable ResourceLoader support by default, it's currently broken
6568 // $wgUploadWizardDisableResourceLoader = true;
6669
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -389,6 +389,15 @@
390390 'resources/mw.MockUploadHandler.js'
391391 ),
392392 ),
 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+ ),
393402 );
394403
395404 /*
Index: trunk/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php
@@ -57,7 +57,6 @@
5858
5959 $this->setHeaders();
6060 $this->outputHeader();
61 - $subPage = explode( '/', $subPage, 4 );
6261
6362 // If the user is authorized, display the page, if not, show an error.
6463 if ( $this->userCanExecute( $wgUser ) ) {
@@ -66,12 +65,6 @@
6766 && $wgRequest->getCheck( 'newcampaign' ) ) {
6867 $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() );
6968 }
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 - }
7669 else {
7770 $this->displayUploadCamaigns();
7871 }
@@ -175,11 +168,6 @@
176169 global $wgUser;
177170
178171 foreach ( $campaigns as $campaign ) {
179 - $editToken = $wgUser->editToken( serialize( array(
180 - $campaign->campaign_id,
181 - $campaign->campaign_name
182 - ) ) );
183 -
184172 $out->addHTML(
185173 '<tr>' .
186174 '<td>' .
@@ -205,10 +193,10 @@
206194 Html::element(
207195 'a',
208196 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 )
213201 ),
214202 wfMsg( 'mwe-upwiz-campaigns-delete' )
215203 ) .
@@ -219,6 +207,8 @@
220208
221209 $out->addHTML( '</tbody>' );
222210 $out->addHTML( '</table>' );
 211+
 212+ $out->addModules( 'ext.uploadWizard.campaigns' );
223213 }
224214
225215 }
Index: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
@@ -65,7 +65,7 @@
6666 * @param boolean $isEnabled
6767 * @param array $config
6868 */
69 - public function __construct( $id, $name, $isEnabled, array $config ) {
 69+ public function __construct( $id, $name = '', $isEnabled = false, array $config = array() ) {
7070 $this->id = $id;
7171 $this->name = $name;
7272 $this->isEnabled = $isEnabled;
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -314,6 +314,8 @@
315315 'mwe-upwiz-campaigns-editing' => 'Upload campaign configuration',
316316 'mwe-upwiz-campaigns-delete' => 'Delete',
317317 '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?',
318320
319321 // Special:UploadCampaign
320322 '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
1100 + 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
152 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r96576follow up to r96575; added svn:keywords Idjeroendedauw15:16, 8 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95880address bug 30644jeroendedauw16:14, 31 August 2011
r95976use id and name in token salt; bug 30644jeroendedauw13:04, 1 September 2011

Comments

#Comment by NeilK (talk | contribs)   18:06, 12 September 2011

I don't understand this -- why is an API method necessary? There is no equivalent API method to create Upload Campaigns.

Are you trying to fix the POST issue? https://bugzilla.wikimedia.org/show_bug.cgi?id=30644

This seems like a very roundabout way of doing that.

#Comment by NeilK (talk | contribs)   18:27, 12 September 2011

I'm okaying this because it fixes a bug and we need it deployed asap for WikiLovesMonuments, but I think it was a bad choice to make an API module -- we will discuss redesign it by next deploy. See bug #30877

Status & tagging log