Index: trunk/extensions/EducationProgram/includes/EPRevision.php |
— | — | @@ -46,6 +46,7 @@ |
47 | 47 | 'id' => 'id', |
48 | 48 | |
49 | 49 | 'object_id' => 'int', |
| 50 | + 'object_identifier' => 'str', |
50 | 51 | 'user_id' => 'int', |
51 | 52 | 'type' => 'str', |
52 | 53 | 'comment' => 'str', |
— | — | @@ -58,28 +59,34 @@ |
59 | 60 | } |
60 | 61 | |
61 | 62 | /** |
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. |
64 | 65 | * |
65 | 66 | * @since 0.1 |
66 | 67 | * |
67 | 68 | * @param EPDBObject $object |
68 | | - * @param boolean $deleted |
| 69 | + * @param EPRevisionAction $revAction |
69 | 70 | * |
70 | 71 | * @return EPRevision |
71 | 72 | */ |
72 | | - public static function newFromObject( EPDBObject $object, $deleted = false ) { |
| 73 | + public static function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) { |
73 | 74 | $fields = array( |
74 | 75 | '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(), |
77 | 78 | '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(), |
82 | 83 | 'data' => serialize( $object->toArray() ) |
83 | 84 | ); |
| 85 | + |
| 86 | + $identifier = $object->getIdentifier(); |
| 87 | + |
| 88 | + if ( !is_null( $identifier ) ) { |
| 89 | + $fields['object_identifier'] = $identifier; |
| 90 | + } |
84 | 91 | |
85 | 92 | return new static( $fields ); |
86 | 93 | } |
— | — | @@ -89,7 +96,7 @@ |
90 | 97 | * |
91 | 98 | * @since 0,1 |
92 | 99 | * |
93 | | - * @return EPDBObject |
| 100 | + * @return EPRevisionedObject |
94 | 101 | */ |
95 | 102 | public function getObject() { |
96 | 103 | $class = $this->getField( 'type' ); |
— | — | @@ -105,7 +112,7 @@ |
106 | 113 | * @param integer $revId |
107 | 114 | * @param integer|null $objectId |
108 | 115 | * |
109 | | - * @return EPDBObject|false |
| 116 | + * @return EPRevisionedObject|false |
110 | 117 | */ |
111 | 118 | public static function getObjectFromRevId( $revId, $objectId = null ) { |
112 | 119 | $conditions = array( |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -38,13 +38,13 @@ |
39 | 39 | protected $revAction = false; |
40 | 40 | |
41 | 41 | /** |
| 42 | + * Sets the revision action. |
42 | 43 | * |
43 | | - * |
44 | 44 | * @since 0.1 |
45 | 45 | * |
46 | | - * @param EPRevisionAction $revAction |
| 46 | + * @param EPRevisionAction|false $revAction |
47 | 47 | */ |
48 | | - protected function setRevisionAction( EPRevisionAction $revAction ) { |
| 48 | + protected function setRevisionAction( $revAction ) { |
49 | 49 | $this->revAction = $revAction; |
50 | 50 | } |
51 | 51 | |
— | — | @@ -95,24 +95,13 @@ |
96 | 96 | * |
97 | 97 | * @since 0.1 |
98 | 98 | * |
99 | | - * @param EPRevision $revision |
| 99 | + * @param EPRevisionedObject $object |
100 | 100 | * |
101 | 101 | * @return boolean Success indicator |
102 | 102 | */ |
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(); |
117 | 106 | } |
118 | 107 | |
119 | 108 | return true; |
— | — | @@ -142,21 +131,6 @@ |
143 | 132 | } |
144 | 133 | |
145 | 134 | /** |
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 | | - /** |
161 | 135 | * Return if any fields got changed. |
162 | 136 | * |
163 | 137 | * @since 0.1 |
— | — | @@ -183,13 +157,17 @@ |
184 | 158 | * @see EPDBObject::saveExisting() |
185 | 159 | */ |
186 | 160 | 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 | + |
187 | 167 | $success = parent::saveExisting(); |
188 | 168 | |
189 | 169 | 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 ); |
194 | 172 | $this->log( 'update' ); |
195 | 173 | } |
196 | 174 | } |
— | — | @@ -205,7 +183,7 @@ |
206 | 184 | $result = parent::insert(); |
207 | 185 | |
208 | 186 | if ( $result ) { |
209 | | - $this->storeRevision( EPRevision::newFromObject( $this ) ); |
| 187 | + $this->storeRevision( $this ); |
210 | 188 | $this->log( 'add' ); |
211 | 189 | } |
212 | 190 | |
— | — | @@ -246,8 +224,46 @@ |
247 | 225 | * @since 0.1 |
248 | 226 | */ |
249 | 227 | protected function onRemoved() { |
250 | | - $this->storeRevision( EPRevision::newFromObject( $this ) ); |
| 228 | + $this->storeRevision( $this ); |
251 | 229 | $this->log( 'remove' ); |
252 | 230 | } |
253 | 231 | |
| 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 | + |
254 | 270 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -43,6 +43,14 @@ |
44 | 44 | dirname( __FILE__ ) . '/sql/RenameAmbUserField.sql', |
45 | 45 | true |
46 | 46 | ) ); |
| 47 | + |
| 48 | + $updater->addExtensionUpdate( array( |
| 49 | + 'addField', |
| 50 | + 'ep_revisions', |
| 51 | + 'rev_object_identifier', |
| 52 | + dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql', |
| 53 | + true |
| 54 | + ) ); |
47 | 55 | |
48 | 56 | return true; |
49 | 57 | } |
— | — | @@ -242,7 +250,7 @@ |
243 | 251 | $type = $sktemplate->getRequest()->getText( 'action' ); |
244 | 252 | $isSpecial = $sktemplate->getTitle()->isSpecialPage(); |
245 | 253 | |
246 | | - if ( $type !== 'edit' || $exists ) { |
| 254 | + if ( $exists ) { |
247 | 255 | $links['views']['view'] = array( |
248 | 256 | 'class' => ( !$isSpecial && $type === '' ) ? 'selected' : false, |
249 | 257 | 'text' => wfMsg( 'ep-tab-view' ), |
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql |
— | — | @@ -177,6 +177,7 @@ |
178 | 178 | CREATE TABLE IF NOT EXISTS /*_*/ep_revisions ( |
179 | 179 | rev_id INT unsigned NOT NULL auto_increment PRIMARY KEY, |
180 | 180 | rev_object_id INT unsigned NOT NULL, |
| 181 | + rev_object_identifier VARCHAR(255) NULL, |
181 | 182 | rev_type varbinary(32) NOT NULL, |
182 | 183 | rev_comment TINYBLOB NOT NULL, |
183 | 184 | rev_user_id INT unsigned NOT NULL default 0, |
— | — | @@ -194,3 +195,4 @@ |
195 | 196 | CREATE INDEX /*i*/ep_revision_time ON /*_*/ep_revisions (rev_time); |
196 | 197 | CREATE INDEX /*i*/ep_revision_minor_edit ON /*_*/ep_revisions (rev_minor_edit); |
197 | 198 | 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 @@ |
36 | 36 | $object = $c::get( $this->getTitle()->getText() ); |
37 | 37 | |
38 | 38 | if ( $object === false ) { |
39 | | - // TODO |
| 39 | + $this->getOutput()->addWikiMsg( 'ep-' . strtolower( $this->getName() ) . '-norevs' ); |
| 40 | + |
| 41 | + |
40 | 42 | } |
41 | 43 | else { |
42 | 44 | $this->displayRevisions( $object ); |
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -396,8 +396,13 @@ |
397 | 397 | foreach ( $unknownValues as $name => $value ) { |
398 | 398 | $this->handleUnknownField( $item, $name, $value ); |
399 | 399 | } |
| 400 | + |
| 401 | + $revAction = new EPRevisionAction(); |
| 402 | + $revAction->setUser( $this->getUser() ); |
| 403 | + $revAction->setComment( '' ); // TODO |
| 404 | + $revAction->setMinor( false ); // TODO |
400 | 405 | |
401 | | - $success = $item->save(); |
| 406 | + $success = $item->revisionedSave( $revAction ); |
402 | 407 | |
403 | 408 | if ( $success ) { |
404 | 409 | return true; |