Index: trunk/extensions/EducationProgram/actions/EPRestoreAction.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | $req = $this->getRequest(); |
49 | 49 | |
50 | 50 | if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), $this->getSalt() ) ) { |
51 | | - $success = $this->doRestore( $object ); |
| 51 | + $success = $this->doRestore( $object, $req->getInt( 'revid' ) ); |
52 | 52 | |
53 | 53 | if ( $success ) { |
54 | 54 | $query = array( 'restored' => '1' ); // TODO: handle |
— | — | @@ -70,18 +70,23 @@ |
71 | 71 | * Does the actual restore action. |
72 | 72 | * |
73 | 73 | * @since 0.1 |
| 74 | + * |
| 75 | + * @param EPPageObject $object |
| 76 | + * @param integer $revId |
74 | 77 | * |
75 | 78 | * @return boolean Success indicator |
76 | 79 | */ |
77 | | - protected function doRestore( EPPageObject $object ) { |
| 80 | + protected function doRestore( EPPageObject $object, $revId ) { |
78 | 81 | $revAction = new EPRevisionAction(); |
79 | 82 | |
80 | 83 | $revAction->setUser( $this->getUser() ); |
81 | 84 | $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) ); |
82 | 85 | |
83 | | - // TODO |
| 86 | + $success = $object->restoreToRevisionId( $revId ); |
84 | 87 | |
85 | | - return false; |
| 88 | + // TODO: log |
| 89 | + |
| 90 | + return $success; |
86 | 91 | } |
87 | 92 | |
88 | 93 | /** |
— | — | @@ -134,7 +139,7 @@ |
135 | 140 | array( |
136 | 141 | 'id' => 'cancelRestore', |
137 | 142 | 'class' => 'ep-restore-cancel ep-cancel', |
138 | | - 'target-url' => $this->getTitle()->getLocalURL(), |
| 143 | + 'data-target-url' => $this->getTitle()->getLocalURL(), |
139 | 144 | ), |
140 | 145 | wfMsg( $this->prefixMsg( 'cancel-button' ) ) |
141 | 146 | ); |
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -246,7 +246,7 @@ |
247 | 247 | wfMsg( 'cancel' ), |
248 | 248 | 'cancelEdit', |
249 | 249 | array( |
250 | | - 'target-url' => $this->getReturnToTitle()->getFullURL(), |
| 250 | + 'data-target-url' => $this->getReturnToTitle()->getFullURL(), |
251 | 251 | 'class' => 'ep-cancel', |
252 | 252 | ) |
253 | 253 | ); |
Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | array( |
145 | 145 | 'id' => 'cancelDelete', |
146 | 146 | 'class' => 'ep-delete-cancel ep-cancel', |
147 | | - 'target-url' => $this->getTitle()->getLocalURL(), |
| 147 | + 'data-target-url' => $this->getTitle()->getLocalURL(), |
148 | 148 | ), |
149 | 149 | wfMsg( $this->prefixMsg( 'cancel-button' ) ) |
150 | 150 | ); |
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | array( |
136 | 136 | 'id' => 'cancelRestore', |
137 | 137 | 'class' => 'ep-undo-cancel ep-cancel', |
138 | | - 'target-url' => $this->getTitle()->getLocalURL(), |
| 138 | + 'data-target-url' => $this->getTitle()->getLocalURL(), |
139 | 139 | ), |
140 | 140 | wfMsg( $this->prefixMsg( 'cancel-button' ) ) |
141 | 141 | ); |
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php |
— | — | @@ -144,8 +144,8 @@ |
145 | 145 | $out->addElement( |
146 | 146 | 'button', |
147 | 147 | array( |
148 | | - 'class' => 'ep-disenroll-cancel', |
149 | | - 'target-url' => $course->getTitle()->getLocalURL(), |
| 148 | + 'class' => 'ep-disenroll-cancel ep-cancel', |
| 149 | + 'data-target-url' => $course->getTitle()->getLocalURL(), |
150 | 150 | ), |
151 | 151 | wfMsg( 'ep-disenroll-cancel' ) |
152 | 152 | ); |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -244,6 +244,46 @@ |
245 | 245 | return null; |
246 | 246 | } |
247 | 247 | |
| 248 | + /** |
| 249 | + * Get the revision with the provided id for this object. |
| 250 | + * Returns false if there is no revision with this id for this object. |
| 251 | + * |
| 252 | + * @since 0.1 |
| 253 | + * |
| 254 | + * @param integer $id |
| 255 | + * |
| 256 | + * @return EPRevision|false |
| 257 | + */ |
| 258 | + public function getRevisionById( $id ) { |
| 259 | + $objects = $this->getRevisions( |
| 260 | + array( 'id' => $id ), |
| 261 | + array( 'LIMIT' => 1 ) |
| 262 | + ); |
| 263 | + |
| 264 | + return count( $objects ) > 0 ? $objects[0] : false; |
| 265 | + } |
| 266 | + |
| 267 | + /** |
| 268 | + * Returns the revisions of the object matching the provided conditions. |
| 269 | + * If you set the type or object_id fields, other revisions might be returned as well. |
| 270 | + * |
| 271 | + * @since 0.1 |
| 272 | + * |
| 273 | + * @param array $conditions |
| 274 | + * @param array $options |
| 275 | + * |
| 276 | + * @return array of EPRevision |
| 277 | + */ |
| 278 | + public function getRevisions( array $conditions = array(), array $options = array() ) { |
| 279 | + return EPRevisions::singleton()->select( null, array_merge( |
| 280 | + array( |
| 281 | + 'type' => get_called_class(), |
| 282 | + 'object_id' => $this->getId(), |
| 283 | + ), |
| 284 | + $conditions |
| 285 | + ), $options ); |
| 286 | + } |
| 287 | + |
248 | 288 | public function undelete() { |
249 | 289 | |
250 | 290 | } |
— | — | @@ -252,4 +292,20 @@ |
253 | 293 | |
254 | 294 | } |
255 | 295 | |
| 296 | + public function restoreToRevision( EPRevision $revison ) { |
| 297 | + // TODO |
| 298 | + } |
| 299 | + |
| 300 | + /** |
| 301 | + * Retore the object to a revision with the provided id. |
| 302 | + * |
| 303 | + * @param integer $revId |
| 304 | + * |
| 305 | + * @return boolean Success indicator |
| 306 | + */ |
| 307 | + public function restoreToRevisionId( $revId ) { |
| 308 | + $revision = $this->getRevisionById( $revId ); |
| 309 | + return $revision === false ? false : $this->restoreToRevision( $revision ); |
| 310 | + } |
| 311 | + |
256 | 312 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/resources/ep.formpage.js |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | $( '#bodyContent' ).find( '[type="submit"]' ).button(); |
15 | 15 | |
16 | 16 | $( '.ep-cancel' ).button().click( function( event ) { |
17 | | - window.location = $( this ).attr( 'target-url' ); |
| 17 | + window.location = $( this ).attr( 'data-target-url' ); |
18 | 18 | event.preventDefault(); |
19 | 19 | } ); |
20 | 20 | |