Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
MigrationEditPage | |
0.00% |
0 / 39 |
|
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 / 31 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ParserMigration; |
4 | |
5 | use Article; |
6 | use Content; |
7 | use MediaWiki\Context\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->getContext()->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 | $context = $this->getContext(); |
48 | $user = $context->getUser(); |
49 | $out = $context->getOutput(); |
50 | $parserOptions = $this->getPreviewParserOptions(); |
51 | $contentTransformer = MediaWikiServices::getInstance()->getService( 'ContentTransformer' ); |
52 | $pstContent = $contentTransformer->preSaveTransform( $content, $this->getTitle(), $user, $parserOptions ); |
53 | $mechanism = new Mechanism(); |
54 | $outputs = $mechanism->parse( |
55 | $pstContent, |
56 | $this->getTitle(), |
57 | $parserOptions, |
58 | $user, |
59 | [ 0, 1 ] |
60 | ); |
61 | |
62 | $skinOptions = $out->getSkin()->getOptions(); |
63 | $poOptions = [ |
64 | 'injectTOC' => $skinOptions['toc'], |
65 | 'enableSectionEditLinks' => false, |
66 | ]; |
67 | |
68 | $previewHTML = "<table class=\"mw-parsermigration-sxs\"><tbody><tr>\n" . |
69 | "<th>" . $context->msg( 'parsermigration-current' )->parse() . "</th>\n" . |
70 | "<th>" . $context->msg( 'parsermigration-new' )->parse() . "</th>\n" . |
71 | "</tr><tr>\n" . |
72 | "<td class=\"mw-parsermigration-left\">\n\n" . |
73 | $outputs[0]->getText( $poOptions ) . |
74 | "\n\n</td><td class=\"mw-parsermigration-right\">\n\n" . |
75 | $outputs[1]->getText( $poOptions ) . |
76 | "\n\n</td></tr></tbody></table>\n"; |
77 | |
78 | return [ |
79 | 'parserOutput' => $outputs[1], |
80 | 'html' => $previewHTML ]; |
81 | } |
82 | } |