Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.10% |
37 / 42 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
UndoViewAction | |
88.10% |
37 / 42 |
|
60.00% |
3 / 5 |
7.08 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
show | |
77.78% |
14 / 18 |
|
0.00% |
0 / 1 |
3.10 | |||
showConfirmationForm | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
displayUndoDiff | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace EntitySchema\MediaWiki\Actions; |
6 | |
7 | use Diff\DiffOp\Diff\Diff; |
8 | use EntitySchema\MediaWiki\Content\EntitySchemaSlotDiffRenderer; |
9 | use EntitySchema\Presentation\ConfirmationFormRenderer; |
10 | use EntitySchema\Presentation\DiffRenderer; |
11 | use MediaWiki\Context\IContextSource; |
12 | use MediaWiki\Page\Article; |
13 | use MediaWiki\Revision\RevisionStore; |
14 | |
15 | /** |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | class UndoViewAction extends AbstractUndoAction { |
19 | |
20 | private EntitySchemaSlotDiffRenderer $slotDiffRenderer; |
21 | |
22 | public function __construct( |
23 | Article $article, |
24 | IContextSource $context, |
25 | EntitySchemaSlotDiffRenderer $slotDiffRenderer, |
26 | RevisionStore $revisionStore |
27 | ) { |
28 | parent::__construct( $article, $context, $revisionStore ); |
29 | $this->slotDiffRenderer = $slotDiffRenderer; |
30 | } |
31 | |
32 | public function getName(): string { |
33 | return 'edit'; |
34 | } |
35 | |
36 | public function show(): void { |
37 | $this->getOutput()->enableOOUI(); |
38 | |
39 | $this->getOutput()->setPageTitleMsg( |
40 | $this->msg( |
41 | 'entityschema-undo-heading', |
42 | $this->getTitle()->getTitleValue()->getText() |
43 | ) |
44 | ); |
45 | |
46 | $req = $this->getContext()->getRequest(); |
47 | $diffStatus = $this->getDiffFromRequest( $req ); |
48 | if ( !$diffStatus->isOK() ) { |
49 | $this->showUndoErrorPage( $diffStatus ); |
50 | return; |
51 | } |
52 | |
53 | $patchStatus = $this->tryPatching( $diffStatus->getValue() ); |
54 | if ( !$patchStatus->isOK() ) { |
55 | $this->showUndoErrorPage( $patchStatus ); |
56 | return; |
57 | } |
58 | |
59 | $this->displayUndoDiff( $diffStatus->getValue() ); |
60 | $this->showConfirmationForm( $req->getInt( 'undo' ) ); |
61 | } |
62 | |
63 | /** |
64 | * Shows a form that can be used to confirm the requested undo/restore action. |
65 | */ |
66 | private function showConfirmationForm( int $undidRevision = 0 ): void { |
67 | $req = $this->getRequest(); |
68 | $renderer = new ConfirmationFormRenderer( $this ); |
69 | $confFormHTML = $renderer->showUndoRestoreConfirmationForm( |
70 | [ |
71 | 'undo' => $req->getInt( 'undo' ), |
72 | 'undoafter' => $req->getInt( 'undoafter' ), |
73 | ], |
74 | 'restore', |
75 | $this->getTitle(), |
76 | $this->getUser(), |
77 | $undidRevision |
78 | ); |
79 | |
80 | $this->getOutput()->addHTML( $confFormHTML ); |
81 | } |
82 | |
83 | private function displayUndoDiff( Diff $diff ): void { |
84 | |
85 | $helper = new DiffRenderer( $this, $this->slotDiffRenderer ); |
86 | $this->getOutput()->addHTML( |
87 | $helper->renderSchemaDiffTable( |
88 | $this->slotDiffRenderer->renderSchemaDiffRows( $diff ), |
89 | $this->msg( 'entityschema-undo-old-revision' ) |
90 | ) |
91 | ); |
92 | |
93 | $this->getOutput()->addModuleStyles( 'mediawiki.diff.styles' ); |
94 | } |
95 | |
96 | } |