Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
PrepareTranslatablePageSpecialPage.php
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
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}