8use Wikimedia\Parsoid\Utils\ContentUtils;
47require_once __DIR__ .
'/Maintenance.php';
60 parent::__construct();
64 'Title name for the given wikitext (Default: \'CLIParser\')',
68 $this->
addArg(
'file',
'File containing wikitext (Default: stdin)',
false );
69 $this->
addOption(
'parsoid',
'Whether to use Parsoid',
false,
false,
'p' );
70 $this->
addOption(
'show-rich-attributes',
'Show rich attributes',
false );
82 public function render( $wikitext ) {
83 $options = ParserOptions::newFromAnon();
84 $options->setOption(
'enableLimitReport',
false );
85 $po = $this->parser->parse(
92 $po = $pipeline->run( $po, $options, [
'wrapperDivClass' =>
'' ] );
93 if ( $this->
getOption(
'show-rich-attributes' ) ) {
94 $df = $po->getContentHolder()->getAsDom();
95 $df ??= $po->getContentHolder()->createFragment();
96 return ContentUtils::dumpDOM( $df,
'', [
'quiet' =>
true ] );
98 return $po->getContentHolderText();
106 $php_stdin =
'php://stdin';
107 $input_file = $this->
getArg( 0, $php_stdin );
109 if ( $input_file === $php_stdin && !$this->mQuiet ) {
111 $this->
error( basename( __FILE__ )
112 .
": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
115 return file_get_contents( $input_file );
121 $this->parser = $services->getParsoidParserFactory()->create();
123 $this->parser = $services->getParserFactory()->create();
135 $title = $this->
getOption(
'title' ) ?:
'CLIParser';
137 return Title::newFromText( $title );
143require_once RUN_MAINTENANCE_IF_MAIN;
wfIsWindows()
Check if the operating system is Windows.
Maintenance script to parse some wikitext.
execute()
Do the actual work.
getTitle()
Title object to use for CLI parsing.
__construct()
Default constructor.
Wikitext()
Get wikitext from a the file passed as argument or STDIN.
Parser ParsoidParser $parser
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.