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(): string {
25 return 'translation';
26 }
27
29 public function execute( $par ) {
30 $request = $this->getRequest();
31 $output = $this->getOutput();
32 $this->setHeaders();
33 $this->checkPermissions();
34 $this->outputHeader();
35
36 $output->addModules( 'ext.translate.special.pagepreparation' );
37 $output->addModuleStyles( [
38 'ext.translate.specialpages.styles',
39 'codex-styles'
40 ] );
41
42 $output->addHTML(
43 $this->getHtml( $request->getText( 'page', $par ?? '' ) )
44 );
45 $output->addHTML(
46 Html::errorBox(
47 $this->msg( 'tux-nojs' )->escaped(),
48 '',
49 'tux-nojs'
50 )
51 );
52 }
53
54 public function getHtml( string $inputValue ): string {
55 $diff = new DifferenceEngine( $this->getContext() );
56 $diffHeader = $diff->addHeader( ' ', $this->msg( 'pp-diff-old-header' )->escaped(),
57 $this->msg( 'pp-diff-new-header' )->escaped() );
58
59 $data = [
60 'pagenamePlaceholder' => $this->msg( 'pp-pagename-placeholder' )->text(),
61 'prepareButtonLabel' => $this->msg( 'pp-prepare-button-label' )->text(),
62 'saveButtonLabel' => $this->msg( 'pp-save-button-label' )->text(),
63 'cancelButtonLabel' => $this->msg( 'pp-cancel-button-label' )->text(),
64 'summaryValue' => $this->msg( 'pp-save-summary' )->inContentLanguage()->text(),
65 'inputValue' => $inputValue,
66 'diffHeaderHtml' => $diffHeader
67 ];
68
69 return $this->templateParser->processTemplate( 'PrepareTranslatablePageTemplate', $data );
70 }
71}