Topic on Manual talk:ImportTextFiles.php

Usage examples don't match

10
Tcrimsonk (talkcontribs)

In Usage:

php importTextFiles.php [options...] <file> [<file>...]

the command includes <file> but the Example a few paragraphs down does not.

Meanwhile, the --help text when running the command says to use <files> (plural).

When I try to run with <file> or with <files> the script returns the error "The system cannot find the file specified" whether I use an absolute or relative path to the .txt file I want to import.

This, that and the other (talkcontribs)

I suspect the inconsistency comes from the fact that you can use it with multiple filenames, i.e. <file> [<file>...], or with a wildcard, i.e. <files>, just like any command-line tool that accepts multiple filenames.

Do you get errors if you pass the exact same file specifier to cat (Mac/Linux) or type (Windows)?

This, that and the other (talkcontribs)

Oh, and the example is passing <file>: it's the meteo-*.txt at the very end.

Tcrimsonk (talkcontribs)

I created a simple art1.txt which contains only This is some text for art1 and I've placed copies of it in the folder with php.exe, in the maintenance directory, in the main mediawiki install directory, and on the root of C:\.

When I run the following commands from the maintenance directory, I get the following results:

type art1.txt returns This is some text for art1

importTextFiles.php art1.txt returns Argument <files> required!(followed by the entire help message)

importTextFiles.php <file> art1.txt returns The system cannot find the file specified

importTextFiles.php <files> art1.txt returns The system cannot find the file specified

The second command above is why I think the Example on this manual page is incorrect, because the example lacks a <file> or <files> argument.

I've tried all of the above with art1.txt saved as ANSI and as UTF-8 in Notepad.

Tcrimsonk (talkcontribs)

I decided to try using edit.php to see if I got the same result. That script requires that the article already exist, so I created the page Art4 in my wiki and Art4.txt in the maintenance folder.

Sure enough: edit.php <title>Art4 Art4.txt returns The system cannot find the file specified.

So it must be something to do with my PHP installation (Running version 5.6.21) or maybe the way I have the path / .php extension association set up.

For what it's worth, I'm able to run other PHP maintenance scripts fine, as long as they don't require filename arguments.

This, that and the other (talkcontribs)

Does it work if you supply a full path as the filename argument, for example, php importTextFiles.php C:\Whatever\Folders\Blah\art1.txt ?

Tcrimsonk (talkcontribs)

I FINALLY got something to work: C:\>C:\Bitnami\mediawiki-1.26.3-0\php\php.exe C:\Bitnami\mediawiki-1.26.3-0\apps\mediawiki\htdocs\maintenance\importTextFiles.php c:\art1.txt

This command will import art1.txt However, when I use a wildcard to try and import art1, art2, and art3 as follows: C:\>C:\Bitnami\mediawiki-1.26.3-0\php\php.exe C:\Bitnami\mediawiki-1.26.3-0\apps\mediawiki\htdocs\maintenance\importTextFiles.php c:\art*.txt Then I get a differently-worded error: Fatal error: The file 'c:\art*.txt' does not exist!

This, that and the other (talkcontribs)

Does it still fail if you include the "php" command at the beginning of the command line, like:

C:\Bitnami\mediawiki-1.26.3-0\php\php.exe C:\Bitnami\mediawiki-1.26.3-0\apps\mediawiki\htdocs\maintenance\importTextFiles.php c:\art*.txt

If this fails, it is most likely because Windows' command line handling differs from Unix command line handling. This script was written with Unix command line handling in mind. Unix expands wildcards before passing the command line to the program, while Windows does not expand wildcards.

Try editing maintenance/importTextFiles.php. Replace line 66, which begins with $this->error, with the following lines of code:

				$found = false;
				foreach ( glob( $arg ) as $filename ) {
					$found = true;
					$files[$filename] = file_get_contents( $filename );
				}
				if ( !$found ) {
					$this->error( "Fatal error: The file '$arg' does not exist!", 1 );
				}

If that fixes your problem, I'll submit a patch to try to get this fix into MediaWiki 1.28.

Tcrimsonk (talkcontribs)

That fixed it! Thank you!

Nyetman (talkcontribs)

For me

  • using XAMPP on Windows 7 Professional,
  • with the change to importTextFiles.php suggested above
  • and assuming running from c:\xampp

these commands didn't work:

  • php\php htdocs\wiki\maintenance\importTextFiles.php tmp\pages\*.txt
  • php\php htdocs\wiki\maintenance\importTextFiles.php c:\xampp\tmp\pages\*.txt
  • php\php htdocs\wiki\maintenance\importTextFiles.php tmp/pages/*.txt

Only this command worked:

  • php\php htdocs\wiki\maintenance\importTextFiles.php c:/xampp/tmp/pages/*.txt

Something to keep in mind.

Reply to "Usage examples don't match"