r112988 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112987‎ | r112988 | r112989 >
Date:23:05, 4 March 2012
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parse.php
@@ -14,8 +14,8 @@
1515 *
1616 * Example2:
1717 * @code
18 - * $ echo "'''bold'''" > /tmp/foo
19 - * $ php parse.php --file /tmp/foo
 18+ * $ echo "'''bold'''" > /tmp/foo.txt
 19+ * $ php parse.php /tmp/foo.txt
2020 * <p><b>bold</b>
2121 * </p>$
2222 * @endcode
@@ -37,10 +37,10 @@
3838 protected $parser;
3939
4040 public function __construct() {
 41+ parent::__construct();
4142 $this->mDescription = "Parse a given wikitext";
4243 $this->addOption( 'title', 'Title name for the given wikitext (Default: \'CLIParser\')', false, true );
43 - $this->addOption( 'file', 'File containing wikitext (Default: stdin)', false, true );
44 - parent::__construct();
 44+ $this->addArg( 'file', 'File containing wikitext (Default: stdin)', false );
4545 }
4646
4747 public function execute() {
@@ -57,13 +57,19 @@
5858 }
5959
6060 /**
61 - * Get wikitext from --file or from STDIN
 61+ * Get wikitext from a the file passed as argument or STDIN
6262 * @return string Wikitext
6363 */
6464 protected function Wikitext() {
65 - return file_get_contents(
66 - $this->getOption( 'file', 'php://stdin' )
67 - );
 65+
 66+ $php_stdin = 'php://stdin';
 67+ $input_file = $this->getArg( 0, $php_stdin );
 68+
 69+ if( $input_file === $php_stdin ) {
 70+ fwrite( STDERR, basename(__FILE__) .": warning: reading wikitext from STDIN\n" );
 71+ }
 72+
 73+ return file_get_contents( $input_file );
6874 }
6975
7076 protected function initParser() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r113046Fix minor issue from r112988reedy16:38, 5 March 2012
r113157MFT r112563, r112566, r112838, r112872, r112873, r112988, r113001, r113024, r...reedy17:36, 6 March 2012

Comments

#Comment by Hashar (talk | contribs)   23:08, 4 March 2012

Would need a backport in REL1_19 , previous usage was not pleasant.

#Comment by MaxSem (talk | contribs)   10:19, 5 March 2012

Use $this->error() instead of manual fwrite()

#Comment by Hashar (talk | contribs)   16:42, 5 March 2012

Done by reedy in follow up r113046. Thanks!

Status & tagging log