https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112516
Revision: 112516
Author: jeroendedauw
Date: 2012-02-27 21:13:12 +0000 (Mon, 27 Feb 2012)
Log Message:
-----------
some work on revision restoring option
Modified Paths:
--------------
trunk/extensions/EducationProgram/actions/EPDeleteAction.php
trunk/extensions/EducationProgram/actions/EPEditAction.php
trunk/extensions/EducationProgram/actions/EPRestoreAction.php
trunk/extensions/EducationProgram/actions/EPUndoAction.php
trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
trunk/extensions/EducationProgram/resources/ep.formpage.js
trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
Modified: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPDeleteAction.php
2012-02-27 21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/actions/EPDeleteAction.php
2012-02-27 21:13:12 UTC (rev 112516)
@@ -143,7 +143,7 @@
array(
'id' => 'cancelDelete',
'class' => 'ep-delete-cancel ep-cancel',
- 'target-url' =>
$this->getTitle()->getLocalURL(),
+ 'data-target-url' =>
$this->getTitle()->getLocalURL(),
),
wfMsg( $this->prefixMsg( 'cancel-button' ) )
);
Modified: trunk/extensions/EducationProgram/actions/EPEditAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPEditAction.php 2012-02-27
21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/actions/EPEditAction.php 2012-02-27
21:13:12 UTC (rev 112516)
@@ -246,7 +246,7 @@
wfMsg( 'cancel' ),
'cancelEdit',
array(
- 'target-url' =>
$this->getReturnToTitle()->getFullURL(),
+ 'data-target-url' =>
$this->getReturnToTitle()->getFullURL(),
'class' => 'ep-cancel',
)
);
Modified: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRestoreAction.php
2012-02-27 21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/actions/EPRestoreAction.php
2012-02-27 21:13:12 UTC (rev 112516)
@@ -47,7 +47,7 @@
$req = $this->getRequest();
if ( $req->wasPosted() &&
$this->getUser()->matchEditToken( $req->getText( 'restoreToken' ),
$this->getSalt() ) ) {
- $success = $this->doRestore( $object );
+ $success = $this->doRestore( $object,
$req->getInt( 'revid' ) );
if ( $success ) {
$query = array( 'restored' => '1' ); //
TODO: handle
@@ -70,18 +70,23 @@
* Does the actual restore action.
*
* @since 0.1
+ *
+ * @param EPPageObject $object
+ * @param integer $revId
*
* @return boolean Success indicator
*/
- protected function doRestore( EPPageObject $object ) {
+ protected function doRestore( EPPageObject $object, $revId ) {
$revAction = new EPRevisionAction();
$revAction->setUser( $this->getUser() );
$revAction->setComment( $this->getRequest()->getText(
'summary', '' ) );
- // TODO
+ $success = $object->restoreToRevisionId( $revId );
- return false;
+ // TODO: log
+
+ return $success;
}
/**
@@ -134,7 +139,7 @@
array(
'id' => 'cancelRestore',
'class' => 'ep-restore-cancel ep-cancel',
- 'target-url' =>
$this->getTitle()->getLocalURL(),
+ 'data-target-url' =>
$this->getTitle()->getLocalURL(),
),
wfMsg( $this->prefixMsg( 'cancel-button' ) )
);
Modified: trunk/extensions/EducationProgram/actions/EPUndoAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndoAction.php 2012-02-27
21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/actions/EPUndoAction.php 2012-02-27
21:13:12 UTC (rev 112516)
@@ -134,7 +134,7 @@
array(
'id' => 'cancelRestore',
'class' => 'ep-undo-cancel ep-cancel',
- 'target-url' =>
$this->getTitle()->getLocalURL(),
+ 'data-target-url' =>
$this->getTitle()->getLocalURL(),
),
wfMsg( $this->prefixMsg( 'cancel-button' ) )
);
Modified: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-27 21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-27 21:13:12 UTC (rev 112516)
@@ -244,6 +244,46 @@
return null;
}
+ /**
+ * Get the revision with the provided id for this object.
+ * Returns false if there is no revision with this id for this object.
+ *
+ * @since 0.1
+ *
+ * @param integer $id
+ *
+ * @return EPRevision|false
+ */
+ public function getRevisionById( $id ) {
+ $objects = $this->getRevisions(
+ array( 'id' => $id ),
+ array( 'LIMIT' => 1 )
+ );
+
+ return count( $objects ) > 0 ? $objects[0] : false;
+ }
+
+ /**
+ * Returns the revisions of the object matching the provided conditions.
+ * If you set the type or object_id fields, other revisions might be
returned as well.
+ *
+ * @since 0.1
+ *
+ * @param array $conditions
+ * @param array $options
+ *
+ * @return array of EPRevision
+ */
+ public function getRevisions( array $conditions = array(), array
$options = array() ) {
+ return EPRevisions::singleton()->select( null, array_merge(
+ array(
+ 'type' => get_called_class(),
+ 'object_id' => $this->getId(),
+ ),
+ $conditions
+ ), $options );
+ }
+
public function undelete() {
}
@@ -252,4 +292,20 @@
}
+ public function restoreToRevision( EPRevision $revison ) {
+ // TODO
+ }
+
+ /**
+ * Retore the object to a revision with the provided id.
+ *
+ * @param integer $revId
+ *
+ * @return boolean Success indicator
+ */
+ public function restoreToRevisionId( $revId ) {
+ $revision = $this->getRevisionById( $revId );
+ return $revision === false ? false : $this->restoreToRevision(
$revision );
+ }
+
}
\ No newline at end of file
Modified: trunk/extensions/EducationProgram/resources/ep.formpage.js
===================================================================
--- trunk/extensions/EducationProgram/resources/ep.formpage.js 2012-02-27
21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/resources/ep.formpage.js 2012-02-27
21:13:12 UTC (rev 112516)
@@ -13,7 +13,7 @@
$( '#bodyContent' ).find( '[type="submit"]' ).button();
$( '.ep-cancel' ).button().click( function( event ) {
- window.location = $( this ).attr( 'target-url' );
+ window.location = $( this ).attr( 'data-target-url' );
event.preventDefault();
} );
Modified: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
2012-02-27 21:00:37 UTC (rev 112515)
+++ trunk/extensions/EducationProgram/specials/SpecialDisenroll.php
2012-02-27 21:13:12 UTC (rev 112516)
@@ -144,8 +144,8 @@
$out->addElement(
'button',
array(
- 'class' => 'ep-disenroll-cancel',
- 'target-url' =>
$course->getTitle()->getLocalURL(),
+ 'class' => 'ep-disenroll-cancel ep-cancel',
+ 'data-target-url' =>
$course->getTitle()->getLocalURL(),
),
wfMsg( 'ep-disenroll-cancel' )
);
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs