Remove un-needed comment transformation
[lhc/web/wiklou.git] / maintenance / importTextFile.php
1 <?php
2
3 /**
4 * Maintenance script allows creating or editing pages using
5 * the contents of a text file
6 *
7 * @addtogroup Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 $options = array( 'help', 'nooverwrite', 'norc' );
12 $optionsWithArgs = array( 'title', 'user', 'comment' );
13 require_once( 'commandLine.inc' );
14 echo( "Import Text File\n\n" );
15
16 if( count( $args ) < 1 || isset( $options['help'] ) ) {
17 showHelp();
18 } else {
19
20 $filename = $args[0];
21 echo( "Using {$filename}..." );
22 if( is_file( $filename ) ) {
23
24 $title = isset( $options['title'] ) ? $options['title'] : titleFromFilename( $filename );
25 $title = Title::newFromUrl( $title );
26 echo( "\nUsing title '" . $title->getPrefixedText() . "'..." );
27
28 if( is_object( $title ) ) {
29
30 if( !$title->exists() || !isset( $options['nooverwrite'] ) ) {
31
32 $text = file_get_contents( $filename );
33 $user = isset( $options['user'] ) ? $options['user'] : 'Maintenance script';
34 $user = User::newFromName( $user );
35 echo( "\nUsing username '" . $user->getName() . "'..." );
36
37 if( is_object( $user ) ) {
38
39 $wgUser =& $user;
40 $comment = isset( $options['comment'] ) ? $options['comment'] : 'Importing text file';
41 $flags = 0 | ( isset( $options['norc'] ) ? EDIT_SUPPRESS_RC : 0 );
42
43 echo( "\nPerforming edit..." );
44 $article = new Article( $title );
45 $article->doEdit( $text, $comment, $flags );
46 echo( "done.\n" );
47
48 } else {
49 echo( "invalid username.\n" );
50 }
51
52 } else {
53 echo( "page exists.\n" );
54 }
55
56 } else {
57 echo( "invalid title.\n" );
58 }
59
60 } else {
61 echo( "does not exist.\n" );
62 }
63
64 }
65
66 function titleFromFilename( $filename ) {
67 $parts = explode( '/', $filename );
68 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
69 return $parts[0];
70 }
71
72 function showHelp() {
73 echo( "Import the contents of a text file into a wiki page.\n" );
74 echo( "USAGE: php importTextFile.php <options> <filename>\n\n" );
75 echo( "<filename> : Path to the file containing page content to import\n\n" );
76 echo( "Options:\n\n" );
77 echo( "--title <title>\n\tTitle for the new page; default is to use the filename as a base\n" );
78 echo( "--user <user>\n\tUser to be associated with the edit\n" );
79 echo( "--comment <comment>\n\tEdit summary\n" );
80 echo( "--nooverwrite\n\tDon't overwrite existing content\n" );
81 echo( "--norc\n\tDon't update recent changes\n" );
82 echo( "--help\n\tShow this information\n" );
83 echo( "\n" );
84 }
85
86 ?>