r113531 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113530‎ | r113531 | r113532 >
Date:22:10, 9 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some minor cleanup
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EPHistoryAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevision.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php
@@ -70,14 +70,8 @@
7171 * @param EPPageObject $object
7272 */
7373 protected function displayRevisions( EPPageObject $object ) {
74 - $conditions = array(
75 - 'type' => get_class( $object ),
76 - );
 74+ $conditions = $object->getRevisionIdentifiers();
7775
78 - if ( $object->hasIdField() ) {
79 - $conditions['object_id'] = $object->getId();
80 - }
81 -
8276 $action = htmlspecialchars( $GLOBALS['wgScript'] );
8377
8478 $request = $this->getRequest();
Index: trunk/extensions/EducationProgram/includes/EPRevisions.php
@@ -78,17 +78,15 @@
7979 * @return EPRevision
8080 */
8181 public function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) {
82 - $fields = array(
83 - 'object_id' => $object->getId(),
 82+ $fields = array_merge( $object->getRevisionIdentifiers(), array(
8483 'user_id' => $revAction->getUser()->getID(),
8584 'user_text' => $revAction->getUser()->getName(),
86 - 'type' => get_class( $object ),
8785 'comment' => $revAction->getComment(),
8886 'minor_edit' => $revAction->isMinor(),
8987 'time' => $revAction->getTime(),
9088 'deleted' => $revAction->isDelete(),
9189 'data' => serialize( $object->toArray() )
92 - );
 90+ ) );
9391
9492 $identifier = $object->getIdentifier();
9593
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -276,14 +276,23 @@
277277 */
278278 public function getRevisions( array $conditions = array(), array $options = array() ) {
279279 return EPRevisions::singleton()->select( null, array_merge(
280 - array(
281 - 'type' => get_called_class(),
282 - 'object_id' => $this->getId(),
283 - ),
 280+ $this->getRevisionIdentifiers(),
284281 $conditions
285282 ), $options );
286283 }
287284
 285+ public function getRevisionIdentifiers() {
 286+ $identifiers = array(
 287+ 'type' => get_class( $this->table )
 288+ );
 289+
 290+ if ( $this->hasIdField() ) {
 291+ $identifiers['object_id'] = $this->getId();
 292+ }
 293+
 294+ return $identifiers;
 295+ }
 296+
288297 /**
289298 * Returns the most recently stored revision for this object
290299 * matching the provided contions or false if there is none.
@@ -299,10 +308,7 @@
300309 $options['ORDER BY'] = EPRevisions::singleton()->getPrefixedField( 'id' ) . ' DESC';
301310
302311 return EPRevisions::singleton()->selectRow( null, array_merge(
303 - array(
304 - 'type' => get_called_class(),
305 - 'object_id' => $this->getId(),
306 - ),
 312+ $this->getRevisionIdentifiers(),
307313 $conditions
308314 ), $options );
309315 }
@@ -430,5 +436,5 @@
431437 $revision = $this->getRevisionById( $revId );
432438 return $revision === false ? false : $this->undoRevision( $revision, $fields );
433439 }
434 -
 440+
435441 }
Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -22,6 +22,14 @@
2323 protected $user = false;
2424
2525 /**
 26+ * (non-PHPdoc)
 27+ * @see DBDataObject::getTable()
 28+ */
 29+ public function getTable() {
 30+ return EPRevisions::singleton();
 31+ }
 32+
 33+ /**
2634 * Return the object as it was at this revision.
2735 *
2836 * @since 0,1
@@ -29,8 +37,8 @@
3038 * @return EPRevisionedObject
3139 */
3240 public function getObject() {
33 - $class = $this->getField( 'type' ) . 's'; // TODO: refactor made this suck a lot
34 - return $class::singleton()->newFromArray( $this->getField( 'data' ), true );
 41+ $tableClass = $this->getField( 'type' );
 42+ return $tableClass::singleton()->newFromArray( $this->getField( 'data' ), true );
3543 }
3644
3745 /**
@@ -53,13 +61,13 @@
5462 $conditions['object_id'] = $objectId;
5563 }
5664
57 - $rev = EPRevision::selectRow( array( 'type', 'data' ), $conditions );
 65+ $rev = EPRevisions::singleton()->selectRow( array( 'type', 'data' ), $conditions );
5866
5967 if ( $rev === false ) {
6068 return false;
6169 }
6270 else {
63 - return $rev->getDataObject();
 71+ return $rev->getObject();
6472 }
6573 }
6674

Status & tagging log