r110987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110986‎ | r110987 | r110988 >
Date:00:06, 9 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on revisioning
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /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/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -46,6 +46,7 @@
4747 'id' => 'id',
4848
4949 'object_id' => 'int',
 50+ 'object_identifier' => 'str',
5051 'user_id' => 'int',
5152 'type' => 'str',
5253 'comment' => 'str',
@@ -58,28 +59,34 @@
5960 }
6061
6162 /**
62 - * Create a new revision object for the provided EPDBObject.
63 - * The EPDBObject should have all it's fields loaded.
 63+ * Create a new revision object for the provided EPRevisionedObject.
 64+ * The EPRevisionedObject should have all it's fields loaded.
6465 *
6566 * @since 0.1
6667 *
6768 * @param EPDBObject $object
68 - * @param boolean $deleted
 69+ * @param EPRevisionAction $revAction
6970 *
7071 * @return EPRevision
7172 */
72 - public static function newFromObject( EPDBObject $object, $deleted = false ) {
 73+ public static function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) {
7374 $fields = array(
7475 'object_id' => $object->getId(),
75 - 'user_id' => $GLOBALS['wgUser']->getID(), // TODO
76 - 'user_text' => $GLOBALS['wgUser']->getName(), // TODO
 76+ 'user_id' => $revAction->getUser()->getID(),
 77+ 'user_text' => $revAction->getUser()->getName(),
7778 'type' => get_class( $object ),
78 - 'comment' => '', // TODO
79 - 'minor_edit' => false, // TODO
80 - 'time' => wfTimestampNow(),
81 - 'deleted' => $deleted,
 79+ 'comment' => $revAction->getComment(),
 80+ 'minor_edit' => $revAction->isMinor(),
 81+ 'time' => $revAction->getTime(),
 82+ 'deleted' => $revAction->isDelete(),
8283 'data' => serialize( $object->toArray() )
8384 );
 85+
 86+ $identifier = $object->getIdentifier();
 87+
 88+ if ( !is_null( $identifier ) ) {
 89+ $fields['object_identifier'] = $identifier;
 90+ }
8491
8592 return new static( $fields );
8693 }
@@ -89,7 +96,7 @@
9097 *
9198 * @since 0,1
9299 *
93 - * @return EPDBObject
 100+ * @return EPRevisionedObject
94101 */
95102 public function getObject() {
96103 $class = $this->getField( 'type' );
@@ -105,7 +112,7 @@
106113 * @param integer $revId
107114 * @param integer|null $objectId
108115 *
109 - * @return EPDBObject|false
 116+ * @return EPRevisionedObject|false
110117 */
111118 public static function getObjectFromRevId( $revId, $objectId = null ) {
112119 $conditions = array(
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -38,13 +38,13 @@
3939 protected $revAction = false;
4040
4141 /**
 42+ * Sets the revision action.
4243 *
43 - *
4444 * @since 0.1
4545 *
46 - * @param EPRevisionAction $revAction
 46+ * @param EPRevisionAction|false $revAction
4747 */
48 - protected function setRevisionAction( EPRevisionAction $revAction ) {
 48+ protected function setRevisionAction( $revAction ) {
4949 $this->revAction = $revAction;
5050 }
5151
@@ -95,24 +95,13 @@
9696 *
9797 * @since 0.1
9898 *
99 - * @param EPRevision $revision
 99+ * @param EPRevisionedObject $object
100100 *
101101 * @return boolean Success indicator
102102 */
103 - protected function storeRevision( EPRevision $revision ) {
104 - if ( $this->storeRevisions ) {
105 - if ( $this->revAction !== false ) {
106 - $revision->setFields( array(
107 - 'minor_edit' => $this->revAction->isMinor(),
108 - 'deleted' => $this->revAction->isDelete(),
109 - 'time' => $this->revAction->getTime(),
110 - 'comment' => $this->revAction->getComment(),
111 - 'user_id' => $this->revAction->getUser()->getId(),
112 - 'user_text' => $this->revAction->getUser()->getName(),
113 - ) );
114 - }
115 -
116 - return $revision->save();
 103+ protected function storeRevision( EPRevisionedObject $object ) {
 104+ if ( $this->storeRevisions && $this->revAction !== false ) {
 105+ return EPRevision::newFromObject( $object, $this->revAction )->save();
117106 }
118107
119108 return true;
@@ -142,21 +131,6 @@
143132 }
144133
145134 /**
146 - * Returns the current revision of the object, ie what is in the database.
147 - *
148 - * @since 0.1
149 - *
150 - * @return EPRevisionedObject
151 - */
152 - protected function getCurrentRevision() {
153 - static::setReadDb( DB_MASTER );
154 - $revison = static::selectRow( null, array( 'id' => $this->getId() ) );
155 - static::setReadDb( DB_SLAVE );
156 -
157 - return EPRevision::newFromObject( $revison );
158 - }
159 -
160 - /**
161135 * Return if any fields got changed.
162136 *
163137 * @since 0.1
@@ -183,13 +157,17 @@
184158 * @see EPDBObject::saveExisting()
185159 */
186160 protected function saveExisting() {
 161+ if ( !$this->inSummaryMode ) {
 162+ static::setReadDb( DB_MASTER );
 163+ $currentObject = static::selectRow( null, array( 'id' => $this->getId() ) );
 164+ static::setReadDb( DB_SLAVE );
 165+ }
 166+
187167 $success = parent::saveExisting();
188168
189169 if ( $success && !$this->inSummaryMode ) {
190 - $revision = $this->getCurrentRevision();
191 -
192 - if ( $this->fieldsChanged( $revision->getObject(), true ) ) {
193 - $this->storeRevision( $revision );
 170+ if ( $this->fieldsChanged( $currentObject, true ) ) {
 171+ $this->storeRevision( $currentObject );
194172 $this->log( 'update' );
195173 }
196174 }
@@ -205,7 +183,7 @@
206184 $result = parent::insert();
207185
208186 if ( $result ) {
209 - $this->storeRevision( EPRevision::newFromObject( $this ) );
 187+ $this->storeRevision( $this );
210188 $this->log( 'add' );
211189 }
212190
@@ -246,8 +224,46 @@
247225 * @since 0.1
248226 */
249227 protected function onRemoved() {
250 - $this->storeRevision( EPRevision::newFromObject( $this ) );
 228+ $this->storeRevision( $this );
251229 $this->log( 'remove' );
252230 }
253231
 232+ public function getIdentifier() {
 233+ return null;
 234+ }
 235+
 236+ /**
 237+ * Save the object using the provided revision action info for logging and revision storage.
 238+ * PHP does not support method overloading, else this would be just "save" :/
 239+ *
 240+ * @since 0.1
 241+ *
 242+ * @param EPRevisionAction $revAction
 243+ *
 244+ * @return boolean Success indicator
 245+ */
 246+ public function revisionedSave( EPRevisionAction $revAction ) {
 247+ $this->setRevisionAction( $revAction );
 248+ $success = $this->save();
 249+ $this->setRevisionAction( false );
 250+ return $success;
 251+ }
 252+
 253+ /**
 254+ * Remove the object using the provided revision action info for logging and revision storage.
 255+ * PHP does not support method overloading, else this would be just "remove" :/
 256+ *
 257+ * @since 0.1
 258+ *
 259+ * @param EPRevisionAction $revAction
 260+ *
 261+ * @return boolean Success indicator
 262+ */
 263+ public function revisionedRemove( EPRevisionAction $revAction ) {
 264+ $this->setRevisionAction( $revAction );
 265+ $success = $this->remove();
 266+ $this->setRevisionAction( false );
 267+ return $success;
 268+ }
 269+
254270 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -43,6 +43,14 @@
4444 dirname( __FILE__ ) . '/sql/RenameAmbUserField.sql',
4545 true
4646 ) );
 47+
 48+ $updater->addExtensionUpdate( array(
 49+ 'addField',
 50+ 'ep_revisions',
 51+ 'rev_object_identifier',
 52+ dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql',
 53+ true
 54+ ) );
4755
4856 return true;
4957 }
@@ -242,7 +250,7 @@
243251 $type = $sktemplate->getRequest()->getText( 'action' );
244252 $isSpecial = $sktemplate->getTitle()->isSpecialPage();
245253
246 - if ( $type !== 'edit' || $exists ) {
 254+ if ( $exists ) {
247255 $links['views']['view'] = array(
248256 'class' => ( !$isSpecial && $type === '' ) ? 'selected' : false,
249257 'text' => wfMsg( 'ep-tab-view' ),
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -177,6 +177,7 @@
178178 CREATE TABLE IF NOT EXISTS /*_*/ep_revisions (
179179 rev_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
180180 rev_object_id INT unsigned NOT NULL,
 181+ rev_object_identifier VARCHAR(255) NULL,
181182 rev_type varbinary(32) NOT NULL,
182183 rev_comment TINYBLOB NOT NULL,
183184 rev_user_id INT unsigned NOT NULL default 0,
@@ -194,3 +195,4 @@
195196 CREATE INDEX /*i*/ep_revision_time ON /*_*/ep_revisions (rev_time);
196197 CREATE INDEX /*i*/ep_revision_minor_edit ON /*_*/ep_revisions (rev_minor_edit);
197198 CREATE INDEX /*i*/ep_revision_deleted ON /*_*/ep_revisions (rev_deleted);
 199+CREATE INDEX /*i*/ep_revision_object_identifier ON /*_*/ep_revisions (rev_object_identifier);
Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php
@@ -35,7 +35,9 @@
3636 $object = $c::get( $this->getTitle()->getText() );
3737
3838 if ( $object === false ) {
39 - // TODO
 39+ $this->getOutput()->addWikiMsg( 'ep-' . strtolower( $this->getName() ) . '-norevs' );
 40+
 41+
4042 }
4143 else {
4244 $this->displayRevisions( $object );
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -396,8 +396,13 @@
397397 foreach ( $unknownValues as $name => $value ) {
398398 $this->handleUnknownField( $item, $name, $value );
399399 }
 400+
 401+ $revAction = new EPRevisionAction();
 402+ $revAction->setUser( $this->getUser() );
 403+ $revAction->setComment( '' ); // TODO
 404+ $revAction->setMinor( false ); // TODO
400405
401 - $success = $item->save();
 406+ $success = $item->revisionedSave( $revAction );
402407
403408 if ( $success ) {
404409 return true;

Status & tagging log