<?php
+
+use MediaWiki\MediaWikiServices;
+
/**
* Parse some wikitext.
*
* @file
* @ingroup Maintenance
* @author Antoine Musso <hashar at free dot fr>
- * @license GNU General Public License 2.0 or later
+ * @license GPL-2.0-or-later
*/
require_once __DIR__ . '/Maintenance.php';
public function __construct() {
parent::__construct();
- $this->mDescription = "Parse a given wikitext";
+ $this->addDescription( 'Parse a given wikitext' );
$this->addOption(
'title',
'Title name for the given wikitext (Default: \'CLIParser\')',
false,
true
);
+ $this->addOption( 'no-tidy', 'Don\'t tidy the output (deprecated)' );
$this->addArg( 'file', 'File containing wikitext (Default: stdin)', false );
}
public function execute() {
$this->initParser();
- print $this->render( $this->WikiText() );
+ print $this->render( $this->Wikitext() );
}
/**
* @return string HTML Rendering
*/
public function render( $wikitext ) {
- return $this->parse( $wikitext )->getText();
+ return $this->parse( $wikitext )->getText( [ 'wrapperDivClass' => '' ] );
}
/**
* @return string Wikitext
*/
protected function Wikitext() {
-
$php_stdin = 'php://stdin';
$input_file = $this->getArg( 0, $php_stdin );
- if ( $input_file === $php_stdin ) {
+ if ( $input_file === $php_stdin && !$this->mQuiet ) {
$ctrl = wfIsWindows() ? 'CTRL+Z' : 'CTRL+D';
$this->error( basename( __FILE__ )
. ": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
}
protected function initParser() {
- global $wgParserConf;
- $parserClass = $wgParserConf['class'];
- $this->parser = new $parserClass();
+ $this->parser = MediaWikiServices::getInstance()->getParserFactory()->create();
}
/**
* @return ParserOutput
*/
protected function parse( $wikitext ) {
+ $options = ParserOptions::newCanonical();
+ $options->setOption( 'enableLimitReport', false );
+ if ( $this->getOption( 'no-tidy' ) ) {
+ $options->setTidy( false );
+ }
return $this->parser->parse(
$wikitext,
$this->getTitle(),
- new ParserOptions()
+ $options
);
}
}
-$maintClass = "CLIParser";
+$maintClass = CLIParser::class;
require_once RUN_MAINTENANCE_IF_MAIN;