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 MediaWiki\Content\Content; |
| 6 | use MediaWiki\Context\IContextSource; |
| 7 | use MediaWiki\EditPage\EditPage; |
| 8 | use MediaWiki\MediaWikiServices; |
| 9 | use MediaWiki\Page\Article; |
| 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 | /** @inheritDoc */ |
| 39 | protected function previewOnOpen() { |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @param Content $content |
| 45 | * @return array |
| 46 | */ |
| 47 | protected function doPreviewParse( Content $content ) { |
| 48 | $context = $this->getContext(); |
| 49 | $user = $context->getUser(); |
| 50 | $out = $context->getOutput(); |
| 51 | $parserOptions = $this->getPreviewParserOptions(); |
| 52 | $contentTransformer = MediaWikiServices::getInstance()->getService( 'ContentTransformer' ); |
| 53 | $pstContent = $contentTransformer->preSaveTransform( $content, $this->getTitle(), $user, $parserOptions ); |
| 54 | $mechanism = new Mechanism(); |
| 55 | $outputs = $mechanism->parse( |
| 56 | $pstContent, |
| 57 | $this->getTitle(), |
| 58 | $parserOptions, |
| 59 | $user, |
| 60 | [ 0, 1 ] |
| 61 | ); |
| 62 | |
| 63 | $skinOptions = $out->getSkin()->getOptions(); |
| 64 | $poOptions = [ |
| 65 | 'injectTOC' => $skinOptions['toc'], |
| 66 | 'enableSectionEditLinks' => false, |
| 67 | ]; |
| 68 | |
| 69 | $previewHTML = "<table class=\"mw-parsermigration-sxs\"><tbody><tr>\n" . |
| 70 | "<th>" . $context->msg( 'parsermigration-current' )->parse() . "</th>\n" . |
| 71 | "<th>" . $context->msg( 'parsermigration-new' )->parse() . "</th>\n" . |
| 72 | "</tr><tr>\n" . |
| 73 | "<td class=\"mw-parsermigration-left\">\n\n" . |
| 74 | $outputs[0]->runOutputPipeline( $parserOptions, $poOptions )->getContentHolderText() . |
| 75 | "\n\n</td><td class=\"mw-parsermigration-right\">\n\n" . |
| 76 | $outputs[1]->runOutputPipeline( $parserOptions, $poOptions )->getContentHolderText() . |
| 77 | "\n\n</td></tr></tbody></table>\n"; |
| 78 | |
| 79 | return [ |
| 80 | 'parserOutput' => $outputs[1], |
| 81 | 'html' => $previewHTML ]; |
| 82 | } |
| 83 | } |