Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
PrepareTranslatablePageSpecialPage
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
2
 getHtml
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\PageTranslation;
5
6use DifferenceEngine;
7use MediaWiki\Html\Html;
8use MediaWiki\Html\TemplateParser;
9use MediaWiki\SpecialPage\SpecialPage;
10
11/**
12 * Contains code to prepare a page for translation
13 * @author Pratik Lahoti
14 * @license GPL-2.0-or-later
15 */
16class PrepareTranslatablePageSpecialPage extends SpecialPage {
17    private TemplateParser $templateParser;
18
19    public function __construct() {
20        parent::__construct( 'PagePreparation', 'pagetranslation' );
21        $this->templateParser = new TemplateParser( __DIR__ . '/templates' );
22    }
23
24    protected function getGroupName() {
25        return 'translation';
26    }
27
28    public function execute( $par ) {
29        $request = $this->getRequest();
30        $output = $this->getOutput();
31        $this->setHeaders();
32        $this->checkPermissions();
33        $this->outputHeader();
34
35        $output->addModules( 'ext.translate.special.pagepreparation' );
36        $output->addModuleStyles( [
37            'ext.translate.specialpages.styles',
38            'codex-styles'
39        ] );
40
41        $output->addHTML(
42            $this->getHtml( $request->getText( 'page', $par ?? '' ) )
43        );
44        $output->addHTML(
45            Html::errorBox(
46                $this->msg( 'tux-nojs' )->escaped(),
47                '',
48                'tux-nojs'
49            )
50        );
51    }
52
53    public function getHtml( string $inputValue ): string {
54        $diff = new DifferenceEngine( $this->getContext() );
55        $diffHeader = $diff->addHeader( ' ', $this->msg( 'pp-diff-old-header' )->escaped(),
56            $this->msg( 'pp-diff-new-header' )->escaped() );
57
58        $data = [
59            'pagenamePlaceholder' => $this->msg( 'pp-pagename-placeholder' )->text(),
60            'prepareButtonLabel' => $this->msg( 'pp-prepare-button-label' )->text(),
61            'saveButtonLabel' => $this->msg( 'pp-save-button-label' )->text(),
62            'cancelButtonLabel' => $this->msg( 'pp-cancel-button-label' )->text(),
63            'summaryValue' => $this->msg( 'pp-save-summary' )->inContentLanguage()->text(),
64            'inputValue' => $inputValue,
65            'diffHeaderHtml' => $diffHeader
66        ];
67
68        return $this->templateParser->processTemplate( 'PrepareTranslatablePageTemplate', $data );
69    }
70}