MediaWiki REL1_30
parse.php
Go to the documentation of this file.
1<?php
52require_once __DIR__ . '/Maintenance.php';
53
59class CLIParser extends Maintenance {
60 protected $parser;
61
62 public function __construct() {
63 parent::__construct();
64 $this->addDescription( 'Parse a given wikitext' );
65 $this->addOption(
66 'title',
67 'Title name for the given wikitext (Default: \'CLIParser\')',
68 false,
69 true
70 );
71 $this->addOption( 'tidy', 'Tidy the output' );
72 $this->addArg( 'file', 'File containing wikitext (Default: stdin)', false );
73 }
74
75 public function execute() {
76 $this->initParser();
77 print $this->render( $this->Wikitext() );
78 }
79
84 public function render( $wikitext ) {
85 return $this->parse( $wikitext )->getText();
86 }
87
92 protected function Wikitext() {
93 $php_stdin = 'php://stdin';
94 $input_file = $this->getArg( 0, $php_stdin );
95
96 if ( $input_file === $php_stdin && !$this->mQuiet ) {
97 $ctrl = wfIsWindows() ? 'CTRL+Z' : 'CTRL+D';
98 $this->error( basename( __FILE__ )
99 . ": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
100 }
101
102 return file_get_contents( $input_file );
103 }
104
105 protected function initParser() {
106 global $wgParserConf;
107 $parserClass = $wgParserConf['class'];
108 $this->parser = new $parserClass();
109 }
110
118 protected function getTitle() {
119 $title = $this->getOption( 'title' )
120 ? $this->getOption( 'title' )
121 : 'CLIParser';
122
123 return Title::newFromText( $title );
124 }
125
130 protected function parse( $wikitext ) {
132 if ( $this->getOption( 'tidy' ) ) {
133 $options->setTidy( true );
134 }
135 return $this->parser->parse(
136 $wikitext,
137 $this->getTitle(),
139 );
140 }
141}
142
143$maintClass = "CLIParser";
144require_once RUN_MAINTENANCE_IF_MAIN;
$wgParserConf
Parser configuration.
wfIsWindows()
Check if the operating system is Windows.
Maintenance script to parse some wikitext.
Definition parse.php:59
execute()
Do the actual work.
Definition parse.php:75
getTitle()
Title object to use for CLI parsing.
Definition parse.php:118
parse( $wikitext)
Definition parse.php:130
__construct()
Default constructor.
Definition parse.php:62
Wikitext()
Get wikitext from a the file passed as argument or STDIN.
Definition parse.php:92
initParser()
Definition parse.php:105
render( $wikitext)
Definition parse.php:84
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Set options of the Parser.
print
Definition cleanup.php:99
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition hooks.txt:1971
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
Definition parse.php:143