https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112988
Revision: 112988
Author: hashar
Date: 2012-03-04 23:05:44 +0000 (Sun, 04 Mar 2012)
Log Message:
-----------
make file an argument, --title is script specific
--file did not make that many sense, it is easier to just pass the filename
as an argument
Call to parent constructor was misplaced, that made the script specific
options pretends they were generic maintenance parameters.
Modified Paths:
--------------
trunk/phase3/maintenance/parse.php
Modified: trunk/phase3/maintenance/parse.php
===================================================================
--- trunk/phase3/maintenance/parse.php 2012-03-04 22:56:43 UTC (rev 112987)
+++ trunk/phase3/maintenance/parse.php 2012-03-04 23:05:44 UTC (rev 112988)
@@ -14,8 +14,8 @@
*
* Example2:
* @code
- * $ echo "'''bold'''" > /tmp/foo
- * $ php parse.php --file /tmp/foo
+ * $ echo "'''bold'''" > /tmp/foo.txt
+ * $ php parse.php /tmp/foo.txt
* <p><b>bold</b>
* </p>$
* @endcode
@@ -37,10 +37,10 @@
protected $parser;
public function __construct() {
+ parent::__construct();
$this->mDescription = "Parse a given wikitext";
$this->addOption( 'title', 'Title name for the given wikitext
(Default: \'CLIParser\')', false, true );
- $this->addOption( 'file', 'File containing wikitext (Default:
stdin)', false, true );
- parent::__construct();
+ $this->addArg( 'file', 'File containing wikitext (Default:
stdin)', false );
}
public function execute() {
@@ -57,13 +57,19 @@
}
/**
- * Get wikitext from --file or from STDIN
+ * Get wikitext from a the file passed as argument or STDIN
* @return string Wikitext
*/
protected function Wikitext() {
- return file_get_contents(
- $this->getOption( 'file', 'php://stdin' )
- );
+
+ $php_stdin = 'php://stdin';
+ $input_file = $this->getArg( 0, $php_stdin );
+
+ if( $input_file === $php_stdin ) {
+ fwrite( STDERR, basename(__FILE__) .": warning: reading
wikitext from STDIN\n" );
+ }
+
+ return file_get_contents( $input_file );
}
protected function initParser() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs