r98259 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98258‎ | r98259 | r98260 >
Date:21:19, 27 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added deletion stuff
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)
  • /trunk/extensions/Contest/resources/contest.special.contests.js (added) (history)
  • /trunk/extensions/Contest/specials/SpecialContests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/Contest.i18n.php
@@ -50,6 +50,9 @@
5151 'contest-special-edit' => 'Edit',
5252 'contest-special-delete' => 'Delete',
5353
 54+ 'contest-special-confirm-delete' => 'Are you sure you want to delete this contest?',
 55+ 'contest-special-delete-failed' => 'Failed to delete the contest.',
 56+
5457 // Special:EditContest
5558 'editcontest-text' => 'You are editing a contest.',
5659 'editcontest-legend' => 'Contest',
Index: trunk/extensions/Contest/specials/SpecialContests.php
@@ -201,6 +201,8 @@
202202
203203 $out->addHTML( '</tbody>' );
204204 $out->addHTML( '</table>' );
 205+
 206+ $out->addModules( 'contest.special.contests' );
205207 }
206208
207209 }
Index: trunk/extensions/Contest/Contest.php
@@ -114,10 +114,14 @@
115115 'remoteExtPath' => 'Contest/resources'
116116 );
117117
118 -$wgResourceModules[''] = $moduleTemplate + array(
 118+$wgResourceModules['contest.special.contests'] = $moduleTemplate + array(
119119 'scripts' => array(
120 - ''
 120+ 'contest.special.contests.js'
121121 ),
 122+ 'messages' => array(
 123+ 'contest-special-confirm-delete',
 124+ 'contest-special-delete-failed',
 125+ )
122126 );
123127
124128 unset( $moduleTemplate );
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -276,13 +276,8 @@
277277 * @return boolean Success indicator
278278 */
279279 public function removeFromDB() {
280 - $dbw = wfGetDB( DB_MASTER );
 280+ $sucecss = $this->delete( array( 'id' => $this->getId() ) );
281281
282 - $sucecss = $dbw->delete(
283 - $this->getDBTable(),
284 - array( $this->getFieldPrefix() . 'id' => $this->getId() )
285 - );
286 -
287282 if ( $sucecss ) {
288283 $this->setField( 'id', null );
289284 }
@@ -481,6 +476,22 @@
482477 }
483478
484479 /**
 480+ * Removes the object from the database.
 481+ *
 482+ * @since 0.1
 483+ *
 484+ * @param array $conditions
 485+ *
 486+ * @return boolean Success indicator
 487+ */
 488+ public function delete( array $conditions ) {
 489+ return wfGetDB( DB_MASTER )->delete(
 490+ $this->getDBTable(),
 491+ $this->getPrefixedValues( $conditions )
 492+ );
 493+ }
 494+
 495+ /**
485496 * Selects the the specified fields of the records matching the provided
486497 * conditions. Field names get prefixed.
487498 *
Index: trunk/extensions/Contest/resources/contest.special.contests.js
@@ -0,0 +1,50 @@
 2+/**
 3+ * JavasSript for the Contest MediaWiki extension.
 4+ * @see https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:Contest
 5+ *
 6+ * @licence GNU GPL v3 or later
 7+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 8+ */
 9+
 10+(function( $, mw ) { $( document ).ready( function() {
 11+
 12+ function deleteSurvey( options, successCallback, failCallback ) {
 13+ $.post(
 14+ wgScriptPath + '/api.php',
 15+ {
 16+ 'action': 'deletecontest',
 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( 'contest-special-delete-failed' ) );
 26+ }
 27+ }
 28+ );
 29+ }
 30+
 31+ $( '.contest-delete' ).click( function() {
 32+ $this = $( this );
 33+
 34+ if ( confirm( mw.msg( 'contest-special-confirm-delete' ) ) ) {
 35+ deleteSurvey(
 36+ {
 37+ id: $this.attr( 'data-contest-id' ),
 38+ token: $this.attr( 'data-contest-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+} ); })( window.jQuery, window.mediaWiki );
\ No newline at end of file
Property changes on: trunk/extensions/Contest/resources/contest.special.contests.js
___________________________________________________________________
Added: svn:eol-style
152 + native

Status & tagging log