r110945 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110944‎ | r110945 | r110946 >
Date:17:51, 8 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on revision comments and logging
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiDeleteEducation.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPageObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionAction.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -100,6 +100,7 @@
101101 $wgAutoloadClasses['EPArticle'] = dirname( __FILE__ ) . '/includes/EPArticle.php';
102102 $wgAutoloadClasses['EPArticlePager'] = dirname( __FILE__ ) . '/includes/EPArticlePager.php';
103103 $wgAutoloadClasses['EPArticleTable'] = dirname( __FILE__ ) . '/includes/EPArticleTable.php';
 104+$wgAutoloadClasses['EPRevisionAction'] = dirname( __FILE__ ) . '/includes/EPRevisionAction.php';
104105
105106 $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php';
106107 $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php';
Index: trunk/extensions/EducationProgram/includes/EPRevisionAction.php
@@ -0,0 +1,58 @@
 2+<?php
 3+
 4+class EPRevisionAction {
 5+
 6+ protected $user;
 7+ protected $isMinor = false;
 8+ protected $isDelete = false;
 9+ protected $comment = '';
 10+ protected $time = false;
 11+
 12+ public function __construct() {
 13+
 14+ }
 15+
 16+ public function isMinor() {
 17+ return $this->isMinor;
 18+ }
 19+
 20+ public function isDelete() {
 21+ return $this->isDelete;
 22+ }
 23+
 24+ public function getComment() {
 25+ return $this->comment;
 26+ }
 27+
 28+ /**
 29+ * @return User
 30+ */
 31+ public function getUser() {
 32+ return $this->user;
 33+ }
 34+
 35+ public function getTime() {
 36+ return $this->time === false ? wfTimestampNow() : $this->time;
 37+ }
 38+
 39+ public function setUser( User $user ) {
 40+ $this->user = $user;
 41+ }
 42+
 43+ public function setComment( $comment ) {
 44+ $this->comment = $comment;
 45+ }
 46+
 47+ public function setDelete( $isDelete ) {
 48+ $this->isDelete = $isDelete;
 49+ }
 50+
 51+ public function setMinor( $isMinor ) {
 52+ $this->isMinor = $isMinor;
 53+ }
 54+
 55+ public function setTime( $time ) {
 56+ $this->time = $time;
 57+ }
 58+
 59+}
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -29,8 +29,26 @@
3030 * @var bool
3131 */
3232 protected $storeRevisions = true;
33 -
 33+
3434 /**
 35+ *
 36+ * @since 0.1
 37+ * @var EPRevisionAction|false
 38+ */
 39+ protected $revAction = false;
 40+
 41+ /**
 42+ *
 43+ *
 44+ * @since 0.1
 45+ *
 46+ * @param EPRevisionAction $revAction
 47+ */
 48+ protected function setRevisionAction( EPRevisionAction $revAction ) {
 49+ $this->revAction = $revAction;
 50+ }
 51+
 52+ /**
3553 * Sets the value for the @see $storeRevisions field.
3654 *
3755 * @since 0.1
@@ -79,12 +97,22 @@
8098 * @since 0.1
8199 *
82100 * @param EPRevision $revision
83 - * @param bool $isDelete
84101 *
85102 * @return boolean Success indicator
86103 */
87 - protected function storeRevision( EPRevision $revision, $isDelete = false ) {
 104+ protected function storeRevision( EPRevision $revision ) {
88105 if ( $this->storeRevisions ) {
 106+ if ( $this->revAction !== false ) {
 107+ $revision->setFields( array(
 108+ 'minor_edit' => $this->revAction->isMinor(),
 109+ 'deleted' => $this->revAction->deleted(),
 110+ 'time' => $this->revAction->getTime(),
 111+ 'comment' => $this->revAction->getComment(),
 112+ 'user_id' => $this->revAction->getUser()->getId(),
 113+ 'user_text' => $this->revAction->getUser()->getName(),
 114+ ) );
 115+ }
 116+
89117 return $revision->save();
90118 }
91119
@@ -101,8 +129,12 @@
102130 protected function log( $subType ) {
103131 if ( $this->log ) {
104132 $info = $this->getLogInfo( $subType );
105 -
 133+
106134 if ( $info !== false ) {
 135+ if ( $this->revAction !== false ) {
 136+ $info['user'] = $this->revAction->getUser();
 137+ }
 138+
107139 $info['subtype'] = $subType;
108140 EPUtils::log( $info );
109141 }
@@ -193,72 +225,9 @@
194226
195227 return $success;
196228 }
197 -
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 -
211 -}
212229
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 -
 230+ public function logRmove() {
 231+ $this->log( 'remove' );
223232 }
224 -
225 - public function isMinor() {
226 - return $this->isMinor;
227 - }
228233
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 -}
 234+}
\ No newline at end of file
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php
@@ -100,4 +100,37 @@
101101 return self::$info[get_called_class()]['list'];
102102 }
103103
 104+ /**
 105+ *
 106+ *
 107+ * @since 0.1
 108+ *
 109+ * @param EPRevisionAction $revAction
 110+ * @param array $conditions
 111+ *
 112+ * @return boolean
 113+ */
 114+ public static function deleteAndLog( EPRevisionAction $revAction, array $conditions ) {
 115+ $objects = static::select(
 116+ null,
 117+ $conditions
 118+ );
 119+
 120+ $success = true;
 121+
 122+ if ( count( $objects ) > 0 ) {
 123+ $success = static::delete( $conditions );
 124+
 125+ if ( $success ) {
 126+ $revAction->setDelete( true );
 127+
 128+ foreach ( $objects as /* EPPageObject */ $object ) {
 129+ $object->logRemove();
 130+ }
 131+ }
 132+ }
 133+
 134+ return $success;
 135+ }
 136+
104137 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/api/ApiDeleteEducation.php
@@ -70,7 +70,7 @@
7171 $revAction->setUser( $this->getUser() );
7272 $revAction->setComment( $params['comment'] );
7373
74 - $objects = $class::deleteAndLog( $revAction, array( 'id' => $params['ids'] ) );
 74+ $class::deleteAndLog( $revAction, array( 'id' => $params['ids'] ) );
7575 }
7676
7777 $this->getResult()->addValue(
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -175,7 +175,7 @@
176176 */
177177 public static function onPageTabs( SkinTemplate &$sktemplate, array &$links ) {
178178 self::displayTabs( $sktemplate, $links, $sktemplate->getTitle() );
179 -
 179+
180180 return false;
181181 }
182182

Status & tagging log