Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -121,6 +121,7 @@ |
122 | 122 | $wgAutoloadClasses['EPRevisions'] = dirname( __FILE__ ) . '/includes/EPRevisions.php'; |
123 | 123 | $wgAutoloadClasses['EPArticles'] = dirname( __FILE__ ) . '/includes/EPArticles.php'; |
124 | 124 | $wgAutoloadClasses['EPStudentActivityPager'] = dirname( __FILE__ ) . '/includes/EPStudentActivityPager.php'; |
| 125 | +$wgAutoloadClasses['EPRevisionDiff'] = dirname( __FILE__ ) . '/includes/EPRevisionDiff.php'; |
125 | 126 | |
126 | 127 | $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php'; |
127 | 128 | $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php'; |
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php |
— | — | @@ -64,8 +64,21 @@ |
65 | 65 | $success = $this->doUndo( $object, $revision ); |
66 | 66 | } |
67 | 67 | else { |
68 | | - $this->displayForm( $object, $revision ); |
69 | | - $success = null; |
| 68 | + $diff = $object->getUndoDiff( $revision ); |
| 69 | + |
| 70 | + if ( $diff->isValid() ) { |
| 71 | + if ( $diff->hasChanges() ) { |
| 72 | + $diff->setContext( $this->getContext() ); |
| 73 | + $diff->display(); |
| 74 | + |
| 75 | + $this->displayForm( $object, $revision ); |
| 76 | + } |
| 77 | + else { |
| 78 | + // TODO |
| 79 | + } |
| 80 | + |
| 81 | + $success = null; |
| 82 | + } |
70 | 83 | } |
71 | 84 | } |
72 | 85 | } |
Index: trunk/extensions/EducationProgram/includes/EPRevisionDiff.php |
— | — | @@ -17,40 +17,49 @@ |
18 | 18 | |
19 | 19 | protected $changedFields = array(); |
20 | 20 | |
21 | | - public static function newFromUndoRevision( IContextSource $context, EPRevision $revison, array $fields = null ) { |
| 21 | + protected $isValid = true; |
| 22 | + |
| 23 | + public static function newFromUndoRevision( EPRevisionedObject $currentObject, EPRevision $revison, array $fields = null ) { |
22 | 24 | $changedFields = array(); |
23 | 25 | |
24 | | - $oldObject = $revison->getPreviousRevision()->getObject(); |
| 26 | + $targetObject = $revison->getPreviousRevision()->getObject(); |
25 | 27 | |
26 | | - if ( $oldObject !== false ) { |
27 | | - $newObject = $revison->getObject(); |
| 28 | + if ( $targetObject !== false ) { |
| 29 | + $sourceObject = $revison->getObject(); |
28 | 30 | |
29 | | - $fields = is_null( $fields ) ? $newObject->getFieldNames() : $fields; |
| 31 | + $fields = is_null( $fields ) ? $sourceObject->getFieldNames() : $fields; |
30 | 32 | |
31 | 33 | foreach ( $fields as $fieldName ) { |
32 | | - if ( $this->getField( $fieldName ) === $newObject->getField( $fieldName ) ) { |
33 | | - $changedFields[$fieldName] = array( ); |
34 | | - $this->restoreField( $fieldName, $oldObject->getField( $fieldName ) ); |
| 34 | + if ( $currentObject->getField( $fieldName ) === $sourceObject->getField( $fieldName ) |
| 35 | + && $sourceObject->getField( $fieldName ) !== $targetObject->getField( $fieldName ) ) { |
| 36 | + |
| 37 | + $changedFields[$fieldName] = array( |
| 38 | + $sourceObject->getField( $fieldName ), |
| 39 | + $targetObject->getField( $fieldName ) |
| 40 | + ); |
35 | 41 | } |
36 | 42 | } |
37 | 43 | } |
38 | 44 | |
39 | | - return new self( $context, $changedFields ); |
| 45 | + $diff = new self( $changedFields ); |
| 46 | + |
| 47 | + $diff->setIsValid( $targetObject !== false ); |
| 48 | + |
| 49 | + return $diff; |
40 | 50 | } |
41 | 51 | |
42 | | - public function __construct( IContextSource $context, array $changedFields ) { |
43 | | - $this->setContext( $context ); |
| 52 | + public function __construct( array $changedFields ) { |
44 | 53 | $this->changedFields = $changedFields; |
45 | 54 | } |
46 | 55 | |
47 | 56 | public function display() { |
48 | 57 | $out = $this->getOutput(); |
49 | 58 | |
50 | | - $out->addHTML( '<table><tr>' ); |
| 59 | + $out->addHTML( '<table class="wikitable sortable"><tr>' ); |
51 | 60 | |
52 | 61 | $out->addElement( 'th', array(), '' ); |
53 | | - $out->addElement( 'th', array(), $this->msg()->plain( 'ep-diff-old' ) ); |
54 | | - $out->addElement( 'th', array(), $this->msg()->plain( 'ep-diff-new' ) ); |
| 62 | + $out->addElement( 'th', array(), $this->msg( 'ep-diff-old' )->plain() ); |
| 63 | + $out->addElement( 'th', array(), $this->msg( 'ep-diff-new' )->plain() ); |
55 | 64 | |
56 | 65 | $out->addHTML( '</tr>' ); |
57 | 66 | |
— | — | @@ -59,13 +68,34 @@ |
60 | 69 | |
61 | 70 | $out->addHtml( '<tr>' ); |
62 | 71 | |
63 | | - $out->addElement( '<th>', array(), $field ); |
64 | | - $out->addElement( '<td>', array(), $old ); |
65 | | - $out->addElement( '<td>', array(), $new ); |
| 72 | + $out->addElement( 'th', array(), $field ); |
| 73 | + $out->addElement( 'td', array(), $old ); |
| 74 | + $out->addElement( 'td', array(), $new ); |
66 | 75 | |
67 | 76 | $out->addHtml( '</tr>' ); |
68 | 77 | } |
| 78 | + |
| 79 | + $out->addHTML( '</table>' ); |
69 | 80 | } |
70 | 81 | |
| 82 | + /** |
| 83 | + * @return array |
| 84 | + */ |
| 85 | + public function getChangedFields() { |
| 86 | + return $this->changedFields; |
| 87 | + } |
71 | 88 | |
| 89 | + public function isValid() { |
| 90 | + return $this->isValid; |
| 91 | + } |
| 92 | + |
| 93 | + public function setIsValid( $isValid ) { |
| 94 | + $this->isValid = $isValid; |
| 95 | + } |
| 96 | + |
| 97 | + public function hasChanges() { |
| 98 | + return !empty( $this->changedFields ); |
| 99 | + } |
| 100 | + |
| 101 | + |
72 | 102 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -376,26 +376,17 @@ |
377 | 377 | * @return boolean Success indicator |
378 | 378 | */ |
379 | 379 | public function undoRevision( EPRevision $revison, array $fields = null ) { |
380 | | - $oldObject = $revison->getPreviousRevision()->getObject(); |
| 380 | + $diff = $this->getUndoDiff( $revison, $fields ); |
381 | 381 | |
382 | | - if ( $oldObject === false ) { |
383 | | - return false; |
| 382 | + foreach ( $diff->getChangedFields() as $fieldName => $values ) { |
| 383 | + $this->restoreField( $fieldName, $values[1] ); |
384 | 384 | } |
385 | 385 | |
386 | | - $newObject = $revison->getObject(); |
387 | | - |
388 | | - $fields = is_null( $fields ) ? $newObject->getFieldNames() : $fields; |
389 | | - |
390 | | - foreach ( $fields as $fieldName ) { |
391 | | - if ( $this->getField( $fieldName ) === $newObject->getField( $fieldName ) ) { |
392 | | - $this->restoreField( $fieldName, $oldObject->getField( $fieldName ) ); |
393 | | - } |
394 | | - } |
395 | | - |
396 | | - return true; |
| 386 | + return $diff->isValid(); |
397 | 387 | } |
398 | 388 | |
399 | 389 | /** |
| 390 | + * Get a diff for the changes that will happen when undoing the provided revision. |
400 | 391 | * |
401 | 392 | * @since 0.1 |
402 | 393 | * |
— | — | @@ -405,21 +396,7 @@ |
406 | 397 | * @return EPRevisionDiff |
407 | 398 | */ |
408 | 399 | public function getUndoDiff( EPRevision $revison, array $fields = null ) { |
409 | | - $oldObject = $revison->getPreviousRevision()->getObject(); |
410 | | - |
411 | | - if ( $oldObject === false ) { |
412 | | - return false; |
413 | | - } |
414 | | - |
415 | | - $newObject = $revison->getObject(); |
416 | | - |
417 | | - $fields = is_null( $fields ) ? $newObject->getFieldNames() : $fields; |
418 | | - |
419 | | - foreach ( $fields as $fieldName ) { |
420 | | - if ( $this->getField( $fieldName ) === $newObject->getField( $fieldName ) ) { |
421 | | - $this->restoreField( $fieldName, $oldObject->getField( $fieldName ) ); |
422 | | - } |
423 | | - } |
| 400 | + return EPRevisionDiff::newFromUndoRevision( $this, $revison, $fields ); |
424 | 401 | } |
425 | 402 | |
426 | 403 | /** |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -794,6 +794,10 @@ |
795 | 795 | 'duration-weeks' => '$1 {{PLURAL:$1|week|weeks}}', |
796 | 796 | 'duration-years' => '$1 {{PLURAL:$1|year|years}}', |
797 | 797 | 'duration-centuries' => '$1 {{PLURAL:$1|century|centuries}}', |
| 798 | + |
| 799 | + // Diffs |
| 800 | + 'ep-diff-old' => 'Old value', |
| 801 | + 'ep-diff-new' => 'New value', |
798 | 802 | ); |
799 | 803 | |
800 | 804 | /** Message documentation (Message documentation) |