r112516 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112515‎ | r112516 | r112517 >
Date:21:13, 27 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some work on revision restoring option
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EPDeleteAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPRestoreAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndoAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.formpage.js (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialDisenroll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
@@ -47,7 +47,7 @@
4848 $req = $this->getRequest();
4949
5050 if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'restoreToken' ), $this->getSalt() ) ) {
51 - $success = $this->doRestore( $object );
 51+ $success = $this->doRestore( $object, $req->getInt( 'revid' ) );
5252
5353 if ( $success ) {
5454 $query = array( 'restored' => '1' ); // TODO: handle
@@ -70,18 +70,23 @@
7171 * Does the actual restore action.
7272 *
7373 * @since 0.1
 74+ *
 75+ * @param EPPageObject $object
 76+ * @param integer $revId
7477 *
7578 * @return boolean Success indicator
7679 */
77 - protected function doRestore( EPPageObject $object ) {
 80+ protected function doRestore( EPPageObject $object, $revId ) {
7881 $revAction = new EPRevisionAction();
7982
8083 $revAction->setUser( $this->getUser() );
8184 $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) );
8285
83 - // TODO
 86+ $success = $object->restoreToRevisionId( $revId );
8487
85 - return false;
 88+ // TODO: log
 89+
 90+ return $success;
8691 }
8792
8893 /**
@@ -134,7 +139,7 @@
135140 array(
136141 'id' => 'cancelRestore',
137142 'class' => 'ep-restore-cancel ep-cancel',
138 - 'target-url' => $this->getTitle()->getLocalURL(),
 143+ 'data-target-url' => $this->getTitle()->getLocalURL(),
139144 ),
140145 wfMsg( $this->prefixMsg( 'cancel-button' ) )
141146 );
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -246,7 +246,7 @@
247247 wfMsg( 'cancel' ),
248248 'cancelEdit',
249249 array(
250 - 'target-url' => $this->getReturnToTitle()->getFullURL(),
 250+ 'data-target-url' => $this->getReturnToTitle()->getFullURL(),
251251 'class' => 'ep-cancel',
252252 )
253253 );
Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
@@ -143,7 +143,7 @@
144144 array(
145145 'id' => 'cancelDelete',
146146 'class' => 'ep-delete-cancel ep-cancel',
147 - 'target-url' => $this->getTitle()->getLocalURL(),
 147+ 'data-target-url' => $this->getTitle()->getLocalURL(),
148148 ),
149149 wfMsg( $this->prefixMsg( 'cancel-button' ) )
150150 );
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php
@@ -134,7 +134,7 @@
135135 array(
136136 'id' => 'cancelRestore',
137137 'class' => 'ep-undo-cancel ep-cancel',
138 - 'target-url' => $this->getTitle()->getLocalURL(),
 138+ 'data-target-url' => $this->getTitle()->getLocalURL(),
139139 ),
140140 wfMsg( $this->prefixMsg( 'cancel-button' ) )
141141 );
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
@@ -144,8 +144,8 @@
145145 $out->addElement(
146146 'button',
147147 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(),
150150 ),
151151 wfMsg( 'ep-disenroll-cancel' )
152152 );
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -244,6 +244,46 @@
245245 return null;
246246 }
247247
 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+
248288 public function undelete() {
249289
250290 }
@@ -252,4 +292,20 @@
253293
254294 }
255295
 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+
256312 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/resources/ep.formpage.js
@@ -13,7 +13,7 @@
1414 $( '#bodyContent' ).find( '[type="submit"]' ).button();
1515
1616 $( '.ep-cancel' ).button().click( function( event ) {
17 - window.location = $( this ).attr( 'target-url' );
 17+ window.location = $( this ).attr( 'data-target-url' );
1818 event.preventDefault();
1919 } );
2020

Status & tagging log