4 * Maintenance script allows creating or editing pages using
5 * the contents of a text file
9 * @author Rob Church <robchur@gmail.com>
12 $options = array( 'help', 'nooverwrite', 'norc' );
13 $optionsWithArgs = array( 'title', 'user', 'comment' );
14 require_once( 'commandLine.inc' );
15 echo( "Import Text File\n\n" );
17 if( count( $args ) < 1 || isset( $options['help'] ) ) {
22 echo( "Using {$filename}..." );
23 if( is_file( $filename ) ) {
25 $title = isset( $options['title'] ) ? $options['title'] : titleFromFilename( $filename );
26 $title = Title::newFromUrl( $title );
28 if( is_object( $title ) ) {
30 echo( "\nUsing title '" . $title->getPrefixedText() . "'..." );
31 if( !$title->exists() || !isset( $options['nooverwrite'] ) ) {
33 $text = file_get_contents( $filename );
34 $user = isset( $options['user'] ) ? $options['user'] : 'Maintenance script';
35 $user = User::newFromName( $user );
37 if( is_object( $user ) ) {
39 echo( "\nUsing username '" . $user->getName() . "'..." );
41 $comment = isset( $options['comment'] ) ? $options['comment'] : 'Importing text file';
42 $flags = 0 | ( isset( $options['norc'] ) ? EDIT_SUPPRESS_RC : 0 );
44 echo( "\nPerforming edit..." );
45 $article = new Article( $title );
46 $article->doEdit( $text, $comment, $flags );
50 echo( "invalid username.\n" );
54 echo( "page exists.\n" );
58 echo( "invalid title.\n" );
62 echo( "does not exist.\n" );
67 function titleFromFilename( $filename ) {
68 $parts = explode( '/', $filename );
69 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
75 USAGE: php importTextFile.php <options> <filename>
77 <filename> : Path to the file containing page content to import
82 Title for the new page; default is to use the filename as a base
84 User to be associated with the edit
88 Don't overwrite existing content
90 Don't update recent changes