59require_once __DIR__ .
'/Maintenance.php';
72 parent::__construct();
73 $this->addDescription(
'Parse a given wikitext' );
76 'Title name for the given wikitext (Default: \'CLIParser\')',
80 $this->addArg(
'file',
'File containing wikitext (Default: stdin)',
false );
81 $this->addOption(
'parsoid',
'Whether to use Parsoid',
false,
false,
'p' );
93 public function render( $wikitext ) {
94 $options = ParserOptions::newFromAnon();
95 $options->setOption(
'enableLimitReport',
false );
96 $po = $this->parser->parse(
102 $pipeline = $this->getServiceContainer()->getDefaultOutputPipeline();
103 return $pipeline->run( $po, $options, [
'wrapperDivClass' =>
'' ] )->getContentHolderText();
111 $php_stdin =
'php://stdin';
112 $input_file = $this->getArg( 0, $php_stdin );
114 if ( $input_file === $php_stdin && !$this->mQuiet ) {
116 $this->error( basename( __FILE__ )
117 .
": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
120 return file_get_contents( $input_file );
124 $services = $this->getServiceContainer();
125 if ( $this->hasOption(
'parsoid' ) ) {
126 $this->parser = $services->getParsoidParserFactory()->create();
128 $this->parser = $services->getParserFactory()->create();
140 $title = $this->getOption(
'title' ) ?:
'CLIParser';
142 return Title::newFromText( $title );
148require_once RUN_MAINTENANCE_IF_MAIN;
wfIsWindows()
Check if the operating system is Windows.
Maintenance script to parse some wikitext.
getTitle()
Title object to use for CLI parsing.
Wikitext()
Get wikitext from a the file passed as argument or STDIN.
Parser ParsoidParser $parser