MediaWiki REL1_31
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() {
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::class;
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...
error( $err, $die=0)
Throw an error to the user.
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.
setTidy( $x)
Use tidy to cleanup output HTML?
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64
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:2001
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
Definition parse.php:143