Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
CRAP
89.47% covered (warning)
89.47%
34 / 38
EntitySchema\MediaWiki\Actions\UndoViewAction
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
7.06
89.47% covered (warning)
89.47%
34 / 38
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getName
n/a
0 / 0
1
n/a
0 / 0
 show
0.00% covered (danger)
0.00%
0 / 1
3.12
76.47% covered (warning)
76.47%
13 / 17
 showConfirmationForm
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
11 / 11
 displayUndoDiff
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
7 / 7
<?php
namespace EntitySchema\MediaWiki\Actions;
use IContextSource;
use Page;
use EntitySchema\MediaWiki\Content\EntitySchemaSlotDiffRenderer;
use EntitySchema\Presentation\ConfirmationFormRenderer;
use EntitySchema\Presentation\DiffRenderer;
/**
 * @license GPL-2.0-or-later
 */
class UndoViewAction extends AbstractUndoAction {
    private $slotDiffRenderer;
    public function __construct(
        Page $page,
        EntitySchemaSlotDiffRenderer $slotDiffRenderer,
        IContextSource $context = null
    ) {
        parent::__construct( $page, $context );
        $this->slotDiffRenderer = $slotDiffRenderer;
    }
    public function getName() {
        return 'edit';
    }
    public function show() {
        $this->getOutput()->enableOOUI();
        $this->getOutput()->setPageTitle(
            $this->msg(
                'entityschema-undo-heading',
                $this->getTitle()->getTitleValue()->getText()
            )
        );
        $req = $this->context->getRequest();
        $diffStatus = $this->getDiffFromRequest( $req );
        if ( !$diffStatus->isOK() ) {
            $this->showUndoErrorPage( $diffStatus );
            return;
        }
        $patchStatus = $this->tryPatching( $diffStatus->getValue() );
        if ( !$patchStatus->isOK() ) {
            $this->showUndoErrorPage( $patchStatus );
            return;
        }
        $this->displayUndoDiff( $diffStatus->getValue() );
        $this->showConfirmationForm( $req->getInt( 'undo' ) );
    }
    /**
     * Shows a form that can be used to confirm the requested undo/restore action.
     *
     * @param int $undidRevision
     */
    private function showConfirmationForm( $undidRevision = 0 ) {
        $req = $this->getRequest();
        $renderer = new ConfirmationFormRenderer( $this );
        $confFormHTML = $renderer->showUndoRestoreConfirmationForm(
            [
                'undo' => $req->getInt( 'undo' ),
                'undoafter' => $req->getInt( 'undoafter' ),
            ],
            'restore',
            $this->getTitle(),
            $this->getUser(),
            $undidRevision
        );
        $this->getOutput()->addHTML( $confFormHTML );
    }
    private function displayUndoDiff( $diff ) {
        $helper = new DiffRenderer( $this );
        $this->getOutput()->addHTML(
            $helper->renderSchemaDiffTable(
                $this->slotDiffRenderer->renderSchemaDiffRows( $diff ),
                $this->msg( 'entityschema-undo-old-revision' )
            )
        );
        $this->getOutput()->addModuleStyles( 'mediawiki.diff.styles' );
    }
}