This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
/
EditEntityAction.php
88 lines (74 loc) · 1.89 KB
/
EditEntityAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace Wikibase;
use Content;
/**
* Handles the edit action for Wikibase entities.
*
* @since 0.1
*
* @file
* @ingroup Wikibase
* @ingroup Action
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
abstract class EditEntityAction extends ViewEntityAction {
/**
* @see Action::getName()
*
* @since 0.1
*
* @return string
*/
public function getName() {
return 'edit';
}
/**
* @see FormlessAction::show
*
* @since 0.1
*/
public function show() {
$req = $this->getRequest();
if ( $req->getCheck( 'undo' ) ) {
$latestRevId = $this->getTitle()->getLatestRevID();
if ( $latestRevId !== 0 ) {
$latestRevision = \Revision::newFromId( $latestRevId );
$olderRevision = \Revision::newFromId( $req->getInt( 'undo' ) );
$newerRevision = \Revision::newFromId( $req->getInt( 'undoafter' ) );
if ( !is_null( $latestRevision ) && !is_null( $olderRevision ) && !is_null( $newerRevision ) ) {
/**
* @var EntityContent $latestContent
* @var EntityContent $olderContent
* @var EntityContent $newerContent
*/
$olderContent = $olderRevision->getContent();
$newerContent = $newerRevision->getContent();
$latestContent = $latestRevision->getContent();
$diff = $olderContent->getEntity()->getDiff( $newerContent->getEntity() );
$diff = $diff->getApplicableDiff( $latestContent->getEntity()->toArray() );
// TODO: add relevant resources
// TODO: set title and stuffs
// TODO: add summary and submit things
$this->displayUndoDiff( $diff );
}
}
}
else {
parent::show();
}
}
/**
* Displays the undo diff.
*
* @since 0.1
*
* @param EntityDiff $diff
*/
protected function displayUndoDiff( EntityDiff $diff ) {
$diffView = $diff->getView();
$diffView->setContext( $this->getContext() );
$this->getOutput()->addHTML( $diffView->getHtml() );
}
}