https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112559
Revision: 112559
Author: jeroendedauw
Date: 2012-02-28 01:38:24 +0000 (Tue, 28 Feb 2012)
Log Message:
-----------
implemeted restore functionality, still needs much UI work though
Modified Paths:
--------------
trunk/extensions/EducationProgram/actions/EPRestoreAction.php
trunk/extensions/EducationProgram/actions/EPUndoAction.php
trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
Modified: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRestoreAction.php
2012-02-28 01:37:38 UTC (rev 112558)
+++ trunk/extensions/EducationProgram/actions/EPRestoreAction.php
2012-02-28 01:38:24 UTC (rev 112559)
@@ -55,13 +55,18 @@
$req = $this->getRequest();
if ( $req->wasPosted() &&
$this->getUser()->matchEditToken( $req->getText( 'restoreToken' ),
$this->getSalt() ) ) {
- $success = $this->doRestore( $object,
$req->getInt( 'revid' ) );
+ if ( $req->getCheck( 'revid' ) ) {
+ $success = $this->doRestore( $object,
$req->getInt( 'revid' ) );
+ }
+ else {
+ $success = false;
+ }
if ( $success ) {
$query = array( 'restored' => '1' ); //
TODO: handle
}
else {
- $query = array( 'delfailed' => '1' );
// TODO: handle
+ $query = array( 'restorefailed' => '1'
); // TODO: handle
}
$this->getOutput()->redirect(
$object->getTitle()->getLocalURL( $query ) );
@@ -85,15 +90,21 @@
* @return boolean Success indicator
*/
protected function doRestore( EPPageObject $object, $revId ) {
- $revAction = new EPRevisionAction();
+ $success = $object->restoreToRevisionId( $revId,
$object->getTable()->getRevertableFields() );
- $revAction->setUser( $this->getUser() );
- $revAction->setComment( $this->getRequest()->getText(
'summary', '' ) );
+ if ( $success ) {
+ $revAction = new EPRevisionAction();
- $success = $object->restoreToRevisionId( $revId );
+ $revAction->setUser( $this->getUser() );
+ $revAction->setComment( $this->getRequest()->getText(
'summary', '' ) );
+
+ $success = $object->revisionedSave( $revAction );
+
+ if ( $success ) {
+ // TODO: log
+ }
+ }
- // TODO: log
-
return $success;
}
@@ -115,7 +126,7 @@
'form',
array(
'method' => 'post',
- 'action' => $this->getTitle()->getLocalURL(
array( 'action' => 'restore' ) ),
+ 'action' => $this->getTitle()->getLocalURL(
array( 'action' => 'eprestore' ) ),
)
) );
@@ -151,6 +162,8 @@
),
wfMsg( $this->prefixMsg( 'cancel-button' ) )
);
+
+ $out->addHTML( Html::hidden( 'revid',
$this->getRequest()->getInt( 'revid' ) ) );
$out->addHTML( Html::hidden( 'restoreToken',
$this->getUser()->getEditToken( $this->getSalt() ) ) );
Modified: trunk/extensions/EducationProgram/actions/EPUndoAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndoAction.php 2012-02-28
01:37:38 UTC (rev 112558)
+++ trunk/extensions/EducationProgram/actions/EPUndoAction.php 2012-02-28
01:38:24 UTC (rev 112559)
@@ -110,7 +110,7 @@
'form',
array(
'method' => 'post',
- 'action' => $this->getTitle()->getLocalURL(
array( 'action' => 'undo' ) ),
+ 'action' => $this->getTitle()->getLocalURL(
array( 'action' => 'epundo' ) ),
)
) );
Modified: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-28 01:37:38 UTC (rev 112558)
+++ trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-28 01:38:24 UTC (rev 112559)
@@ -167,7 +167,7 @@
* @param EPRevisionedObject $originalObject
*/
protected function onUpdated( EPRevisionedObject $originalObject ) {
- $this->storeRevision( $originalObject );
+ $this->storeRevision( $this );
$this->log( 'update' );
}
@@ -193,7 +193,7 @@
* @since 0.1
*/
protected function onRemoved() {
- $this->storeRevision( $this );
+ //$this->storeRevision( $this );
$this->log( 'remove' );
parent::onRemoved();
}
@@ -292,18 +292,38 @@
}
- public function restoreToRevision( EPRevision $revison ) {
- // TODO
+ /**
+ * Restore the object to the provided revisions state.
+ *
+ * @since 0.1
+ *
+ * @param EPRevision $revison
+ * @param array|null $fields
+ *
+ * @return boolean Success indicator
+ */
+ public function restoreToRevision( EPRevision $revison, array $fields =
null ) {
+ $obejct = $revison->getObject();
+ $fields = is_null( $fields ) ? $obejct->getFieldNames() :
$fields;
+
+ foreach ( $fields as $fieldName ) {
+ $this->setField( $fieldName, $obejct->getField(
$fieldName ) );
+ }
+
+ return true;
}
/**
* Retore the object to a revision with the provided id.
*
+ * @since 0.1
+ *
* @param integer $revId
+ * @param array|null $fields
*
* @return boolean Success indicator
*/
- public function restoreToRevisionId( $revId ) {
+ public function restoreToRevisionId( $revId, array $fields = null ) {
$revision = $this->getRevisionById( $revId );
return $revision === false ? false : $this->restoreToRevision(
$revision );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs