MediaWiki REL1_28
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->addArg( 'file', 'File containing wikitext (Default: stdin)', false );
72 }
73
74 public function execute() {
75 $this->initParser();
76 print $this->render( $this->Wikitext() );
77 }
78
83 public function render( $wikitext ) {
84 return $this->parse( $wikitext )->getText();
85 }
86
91 protected function Wikitext() {
92 $php_stdin = 'php://stdin';
93 $input_file = $this->getArg( 0, $php_stdin );
94
95 if ( $input_file === $php_stdin && !$this->mQuiet ) {
96 $ctrl = wfIsWindows() ? 'CTRL+Z' : 'CTRL+D';
97 $this->error( basename( __FILE__ )
98 . ": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
99 }
100
101 return file_get_contents( $input_file );
102 }
103
104 protected function initParser() {
106 $parserClass = $wgParserConf['class'];
107 $this->parser = new $parserClass();
108 }
109
117 protected function getTitle() {
118 $title = $this->getOption( 'title' )
119 ? $this->getOption( 'title' )
120 : 'CLIParser';
121
122 return Title::newFromText( $title );
123 }
124
129 protected function parse( $wikitext ) {
130 return $this->parser->parse(
131 $wikitext,
132 $this->getTitle(),
133 new ParserOptions()
134 );
135 }
136}
137
138$maintClass = "CLIParser";
139require_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:74
getTitle()
Title object to use for CLI parsing.
Definition parse.php:117
parse( $wikitext)
Definition parse.php:129
__construct()
Default constructor.
Definition parse.php:62
Wikitext()
Get wikitext from a the file passed as argument or STDIN.
Definition parse.php:91
initParser()
Definition parse.php:104
render( $wikitext)
Definition parse.php:83
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.
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
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
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:138