MediaWiki r110861 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r110860‎ | r110861 (on ViewVC)‎ | r110862 >
Date:18:26, 7 February 2012
Author:jeroendedauw
Status:deferred
Tags:educationprogram, nodeploy 
Comment:
some initial work on having proper logging of all actions with meta data such as comment and minor edit
Modified paths:

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -194,4 +194,71 @@
195195 return $success;
196196 }
197197
 198+ public static function deleteAndLog( EPRevisionAction $revAction, array $conditions ) {
 199+ $success = static::delete( $conditions );
 200+
 201+ if ( $success ) {
 202+ $revAction->setDelete( true );
 203+
 204+ // TODO
 205+ //static::log();
 206+ }
 207+
 208+ return $success;
 209+ }
 210+
198211 }
 212+
 213+class EPRevisionAction {
 214+
 215+ protected $user;
 216+ protected $isMinor = false;
 217+ protected $isDelete = false;
 218+ protected $comment = false;
 219+ protected $time = false;
 220+
 221+ public function __construct() {
 222+
 223+ }
 224+
 225+ public function isMinor() {
 226+ return $this->isMinor;
 227+ }
 228+
 229+ public function isDelete() {
 230+ return $this->isDelete;
 231+ }
 232+
 233+ public function getComment() {
 234+ return $this->comment;
 235+ }
 236+
 237+ public function getUser() {
 238+ return $this->user;
 239+ }
 240+
 241+ public function getTime() {
 242+ return $this->time;
 243+ }
 244+
 245+ public function setUser( User $user ) {
 246+ $this->user = $user;
 247+ }
 248+
 249+ public function setComment( $comment ) {
 250+ $this->comment = $comment;
 251+ }
 252+
 253+ public function setDelete( $isDelete ) {
 254+ $this->isDelete = $isDelete;
 255+ }
 256+
 257+ public function setMinor( $isMinor ) {
 258+ $this->isMinor = $isMinor;
 259+ }
 260+
 261+ public function setTime( $time ) {
 262+ $this->time = $time;
 263+ }
 264+
 265+}
Index: trunk/extensions/EducationProgram/includes/EPUtils.php
@@ -24,23 +24,21 @@
2525 public static function log( array $info ) {
2626 $user = array_key_exists( 'user', $info ) ? $info['user'] : $GLOBALS['wgUser'];
2727
28 - if ( $info !== false ) {
29 - $logEntry = new ManualLogEntry( $info['type'], $info['subtype'] );
 28+ $logEntry = new ManualLogEntry( $info['type'], $info['subtype'] );
3029
31 - $logEntry->setPerformer( $user );
32 - $logEntry->setTarget( $info['title'] );
33 -
34 - if ( array_key_exists( 'comment', $info ) ) {
35 - $logEntry->setComment( $info['comment'] );
36 - }
37 -
38 - if ( array_key_exists( 'parameters', $info ) ) {
39 - $logEntry->setParameters( $info['parameters'] );
40 - }
41 -
42 - $logid = $logEntry->insert();
43 - $logEntry->publish( $logid );
 30+ $logEntry->setPerformer( $user );
 31+ $logEntry->setTarget( $info['title'] );
 32+
 33+ if ( array_key_exists( 'comment', $info ) ) {
 34+ $logEntry->setComment( $info['comment'] );
4435 }
 36+
 37+ if ( array_key_exists( 'parameters', $info ) ) {
 38+ $logEntry->setParameters( $info['parameters'] );
 39+ }
 40+
 41+ $logid = $logEntry->insert();
 42+ $logEntry->publish( $logid );
4543 }
4644
4745 /**
Index: trunk/extensions/EducationProgram/api/ApiDeleteEducation.php
@@ -54,12 +54,23 @@
5555
5656 $everythingOk = true;
5757
58 - foreach ( $params['ids'] as $id ) {
59 - // $instance->remove is used instead of Class::delete,
60 - // so that linked data also gets deleted.
61 - $c = self::$typeMap[$params['type']];
62 - $object = new $c( array( 'id' => $id ) );
63 - $everythingOk = $object->remove() && $everythingOk;
 58+// foreach ( $params['ids'] as $id ) {
 59+// // $instance->remove is used instead of Class::delete,
 60+// // so that linked data also gets deleted.
 61+// $c = self::$typeMap[$params['type']];
 62+// $object = new $c( array( 'id' => $id ) );
 63+// $everythingOk = $object->remove() && $everythingOk;
 64+// }
 65+
 66+ $class = self::$typeMap[$params['type']];
 67+
 68+ if ( count( $params['ids'] ) > 0 ) {
 69+ $revAction = new EPRevisionAction();
 70+
 71+ $revAction->setUser( $this->getUser() );
 72+ $revAction->setComment( $params['comment'] );
 73+
 74+ $objects = $class::deleteAndLog( $revAction, array( 'id' => $params['ids'] ) );
6475 }
6576
6677 $this->getResult()->addValue(
@@ -115,6 +126,11 @@
116127 ApiBase::PARAM_REQUIRED => true,
117128 ApiBase::PARAM_ISMULTI => false,
118129 ),
 130+ 'comment' => array(
 131+ ApiBase::PARAM_TYPE => 'string',
 132+ ApiBase::PARAM_REQUIRED => false,
 133+ ApiBase::PARAM_DFLT => '',
 134+ ),
119135 'token' => null,
120136 );
121137 }
@@ -124,6 +140,7 @@
125141 'ids' => 'The IDs of the reviews to delete',
126142 'token' => 'Edit token. You can get one of these through prop=info.',
127143 'type' => 'Type of object to delete.',
 144+ 'comment' => 'Message with the reason for this change for the log',
128145 );
129146 }
130147
Index: trunk/extensions/EducationProgram/resources/ep.pager.js
@@ -20,7 +20,8 @@
2121 } );
2222
2323 var $dialog = undefined,
24 - $remove = undefined;
 24+ $remove = undefined,
 25+ $summaryInput = undefined;
2526
2627 var showConfirmDialog = function( args, onConfirm ) {
2728 var args = $.extend( {
@@ -71,7 +72,7 @@
7273 'for': 'epsummaryinput'
7374 } ).msg( 'ep-pager-summary-message-' + args.type ).append( ' ' );
7475
75 - var summaryInput = $( '<input>' ).attr( {
 76+ summaryInput = $( '<input>' ).attr( {
7677 'type': 'text',
7778 'size': 60,
7879 'maxlength': 250,
@@ -102,7 +103,8 @@
103104 args = {
104105 'type': $this.attr( 'data-type' ),
105106 'ids': [ $this.attr( 'data-id' ) ],
106 - 'names': [ $this.attr( 'data-name' ) ]
 107+ 'names': [ $this.attr( 'data-name' ) ],
 108+ 'comment': $summaryInput
107109 };
108110
109111 showConfirmDialog(
@@ -156,7 +158,8 @@
157159 args = {
158160 'type': $( this ).attr( 'data-type' ),
159161 'ids': ids,
160 - 'names': names
 162+ 'names': names,
 163+ 'comment': $summaryInput
161164 };
162165
163166 showConfirmDialog(

Status & tagging log

  • 18:02, 8 February 2012 ^demon (Talk | contribs) changed the status of r110861 [removed: new added: deferred]
  • 22:58, 7 February 2012 MarkAHershberger (Talk | contribs) changed the tags for r110861 [added: educationprogram,nodeploy]
Personal tools
Namespaces

Variants
Views
Actions
Navigation
Support
Download
Development
Communication
Toolbox