r100432 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100431‎ | r100432 | r100433 >
Date:17:37, 21 October 2011
Author:reedy
Status:resolved
Tags:
Comment:
1st attempt at disabling deletion

Let's see how far this gets me
Modified paths:
  • /trunk/extensions/Contest/Contest.php (modified) (history)
  • /trunk/extensions/Contest/api/ApiDeleteContest.php (modified) (history)
  • /trunk/extensions/Contest/includes/Contest.class.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestDBObject.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContests.php
@@ -216,17 +216,19 @@
217217 ),
218218 wfMsg( 'contest-special-edit' )
219219 );
220 -
221 - $links[] = Html::element(
222 - 'a',
223 - array(
224 - 'href' => '#',
225 - 'class' => 'contest-delete',
226 - 'data-contest-id' => $contest->getId(),
227 - 'data-contest-token' => $this->getUser()->editToken( 'deletecontest' . $contest->getId() )
228 - ),
229 - wfMsg( 'contest-special-delete' )
230 - );
 220+ global $wgContestDeletionEnabled;
 221+ if ( $wgContestDeletionEnabled ) {
 222+ $links[] = Html::element(
 223+ 'a',
 224+ array(
 225+ 'href' => '#',
 226+ 'class' => 'contest-delete',
 227+ 'data-contest-id' => $contest->getId(),
 228+ 'data-contest-token' => $this->getUser()->editToken( 'deletecontest' . $contest->getId() )
 229+ ),
 230+ wfMsg( 'contest-special-delete' )
 231+ );
 232+ }
231233 }
232234
233235 $links[] = Html::element(
Index: trunk/extensions/Contest/Contest.php
@@ -301,3 +301,5 @@
302302
303303 $wgContestMailSender = $wgPasswordSender;
304304 $wgContestMailSenderName = $wgPasswordSenderName;
 305+
 306+$wgContestDeletionEnabled = true;
Index: trunk/extensions/Contest/includes/ContestDBObject.php
@@ -23,15 +23,15 @@
2424 * @var array
2525 */
2626 protected $fields = array( 'id' => null );
27 -
 27+
2828 /**
2929 * The database connection to use for read operations.
30 - *
 30+ *
3131 * @since 0.2
3232 * @var integer DB_ enum
3333 */
3434 protected static $readDb = DB_SLAVE;
35 -
 35+
3636 /**
3737 * Constructor.
3838 *
@@ -281,7 +281,7 @@
282282 return $this->insertIntoDB();
283283 }
284284 }
285 -
 285+
286286 /**
287287 * Updates the object in the database.
288288 *
@@ -330,13 +330,13 @@
331331 * @return boolean Success indicator
332332 */
333333 public function removeFromDB() {
334 - $sucecss = $this->delete( array( 'id' => $this->getId() ) );
 334+ $success = $this->delete( array( 'id' => $this->getId() ) );
335335
336 - if ( $sucecss ) {
 336+ if ( $success ) {
337337 $this->setField( 'id', null );
338338 }
339339
340 - return $sucecss;
 340+ return $success;
341341 }
342342
343343 /**
@@ -461,25 +461,25 @@
462462
463463 /**
464464 * Get the database type used for read operations.
465 - *
 465+ *
466466 * @since 0.2
467467 * @return integer DB_ enum
468468 */
469469 public function getReadDb() {
470470 return self::$readDb;
471471 }
472 -
 472+
473473 /**
474474 * Set the database type to use for read operations.
475 - *
 475+ *
476476 * @param integer $db
477 - *
 477+ *
478478 * @since 0.2
479479 */
480480 public function setReadDb( $db ) {
481481 self::$readDb = $db;
482482 }
483 -
 483+
484484 /**
485485 * Gets if the object can take a certain field.
486486 *
Index: trunk/extensions/Contest/includes/Contest.class.php
@@ -412,6 +412,11 @@
413413 * @return boolean Success indicator
414414 */
415415 public function removeAllFromDB() {
 416+ global $wgContestDeletionEnabled;
 417+ if ( !$wgContestDeletionEnabled ) {
 418+ // Shouldn't get here (UI should prevent it)
 419+ throw new MWException( 'Contest deletion is disabled', 'contestdeletiondisabled' );
 420+ }
416421 $condition = array( 'contest_id' => $this->getId() );
417422
418423 $success = ContestChallenge::s()->delete( $condition );
Index: trunk/extensions/Contest/api/ApiDeleteContest.php
@@ -19,6 +19,10 @@
2020 }
2121
2222 public function execute() {
 23+ global $wgContestDeletionEnabled;
 24+ if ( !$wgContestDeletionEnabled ) {
 25+ $this->dieUsage( 'Contest deletion is disabled', 'contestdeletiondisabled' );
 26+ }
2327 global $wgUser;
2428
2529 if ( !$wgUser->isAllowed( 'contestadmin' ) || $wgUser->isBlocked() ) {
@@ -80,7 +84,7 @@
8185
8286 public function getPossibleErrors() {
8387 return array_merge( parent::getPossibleErrors(), array(
84 - array( 'missingparam', 'ids' ),
 88+ array( 'code' => 'contestdeletiondisabled', 'info' => 'Contest deletion is disabled' ),
8589 ) );
8690 }
8791

Follow-up revisions

RevisionCommit summaryAuthorDate
r100436Followup r100432...reedy18:47, 21 October 2011
r1004401.18wmf1 REL r100402, r100405, r100419, r100427, r100432, r100433, r100435, r...reedy19:22, 21 October 2011

Status & tagging log