Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
MigrationEditPage | |
0.00% |
0 / 38 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getActionURL | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setHeaders | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
previewOnOpen | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doPreviewParse | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ParserMigration; |
4 | |
5 | use Article; |
6 | use Content; |
7 | use IContextSource; |
8 | use MediaWiki\EditPage\EditPage; |
9 | use MediaWiki\MediaWikiServices; |
10 | use MediaWiki\Title\Title; |
11 | |
12 | class MigrationEditPage extends EditPage { |
13 | |
14 | /** |
15 | * @param IContextSource $context |
16 | * @param Title $title |
17 | */ |
18 | public function __construct( IContextSource $context, Title $title ) { |
19 | $article = Article::newFromTitle( $title, $context ); |
20 | parent::__construct( $article ); |
21 | $this->setContextTitle( $title ); |
22 | } |
23 | |
24 | /** |
25 | * @param Title $title |
26 | * @return string |
27 | */ |
28 | protected function getActionURL( Title $title ) { |
29 | return $title->getLocalURL( [ 'action' => 'parsermigration-edit' ] ); |
30 | } |
31 | |
32 | public function setHeaders() { |
33 | parent::setHeaders(); |
34 | $out = $this->context->getOutput(); |
35 | $out->addModuleStyles( 'ext.parsermigration.edit' ); |
36 | } |
37 | |
38 | protected function previewOnOpen() { |
39 | return true; |
40 | } |
41 | |
42 | /** |
43 | * @param Content $content |
44 | * @return array |
45 | */ |
46 | protected function doPreviewParse( Content $content ) { |
47 | $user = $this->context->getUser(); |
48 | $out = $this->context->getOutput(); |
49 | $parserOptions = $this->getPreviewParserOptions(); |
50 | $contentTransformer = MediaWikiServices::getInstance()->getService( 'ContentTransformer' ); |
51 | $pstContent = $contentTransformer->preSaveTransform( $content, $this->getTitle(), $user, $parserOptions ); |
52 | $mechanism = new Mechanism(); |
53 | $outputs = $mechanism->parse( |
54 | $pstContent, |
55 | $this->getTitle(), |
56 | $parserOptions, |
57 | $user, |
58 | [ 0, 1 ] |
59 | ); |
60 | |
61 | $skinOptions = $out->getSkin()->getOptions(); |
62 | $poOptions = [ |
63 | 'injectTOC' => $skinOptions['toc'], |
64 | 'enableSectionEditLinks' => false, |
65 | ]; |
66 | |
67 | $previewHTML = "<table class=\"mw-parsermigration-sxs\"><tbody><tr>\n" . |
68 | "<th>" . $this->context->msg( 'parsermigration-current' )->parse() . "</th>\n" . |
69 | "<th>" . $this->context->msg( 'parsermigration-new' )->parse() . "</th>\n" . |
70 | "</tr><tr>\n" . |
71 | "<td class=\"mw-parsermigration-left\">\n\n" . |
72 | $outputs[0]->getText( $poOptions ) . |
73 | "\n\n</td><td class=\"mw-parsermigration-right\">\n\n" . |
74 | $outputs[1]->getText( $poOptions ) . |
75 | "\n\n</td></tr></tbody></table>\n"; |
76 | |
77 | return [ |
78 | 'parserOutput' => $outputs[1], |
79 | 'html' => $previewHTML ]; |
80 | } |
81 | } |