MediaWiki
REL1_19
|
00001 <?php 00034 require_once( dirname(__FILE__) . '/Maintenance.php' ); 00035 00036 class CLIParser extends Maintenance { 00037 protected $parser; 00038 00039 public function __construct() { 00040 parent::__construct(); 00041 $this->mDescription = "Parse a given wikitext"; 00042 $this->addOption( 'title', 'Title name for the given wikitext (Default: \'CLIParser\')', false, true ); 00043 $this->addArg( 'file', 'File containing wikitext (Default: stdin)', false ); 00044 } 00045 00046 public function execute() { 00047 $this->initParser(); 00048 print $this->render( $this->WikiText() ); 00049 } 00050 00055 public function render( $wikitext ) { 00056 return $this->parse( $wikitext )->getText(); 00057 } 00058 00063 protected function Wikitext() { 00064 00065 $php_stdin = 'php://stdin'; 00066 $input_file = $this->getArg( 0, $php_stdin ); 00067 00068 if( $input_file === $php_stdin ) { 00069 $this->error( basename(__FILE__) .": warning: reading wikitext from STDIN\n" ); 00070 } 00071 00072 return file_get_contents( $input_file ); 00073 } 00074 00075 protected function initParser() { 00076 global $wgParserConf; 00077 $parserClass = $wgParserConf['class']; 00078 $this->parser = new $parserClass(); 00079 } 00080 00088 protected function getTitle( ) { 00089 $title = 00090 $this->getOption( 'title' ) 00091 ? $this->getOption( 'title' ) 00092 : 'CLIParser' ; 00093 return Title::newFromText( $title ); 00094 } 00095 00100 protected function parse( $wikitext ) { 00101 return $this->parser->parse( 00102 $wikitext 00103 , $this->getTitle() 00104 , new ParserOptions() 00105 ); 00106 } 00107 } 00108 00109 $maintClass = "CLIParser"; 00110 require_once( RUN_MAINTENANCE_IF_MAIN );