]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/edit.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / maintenance / edit.php
1 <?php
2
3 $optionsWithArgs = array( 'u', 's' );
4
5 require_once( 'commandLine.inc' );
6
7 if ( count( $args ) == 0 || isset( $options['help'] ) ) {
8         print <<<EOT
9 Edit an article from the command line
10
11 Usage: php edit.php [options...] <title>
12
13 Options:
14   -u <user>         Username
15   -s <summary>      Edit summary
16   -m                Minor edit
17   -b                Bot (hidden) edit
18   -a                Enable autosummary
19   --no-rc           Do not show the change in recent changes
20
21 If the specified user does not exist, it will be created. 
22 The text for the edit will be read from stdin.
23
24 EOT;
25         exit( 1 );
26 }
27
28 $userName = isset( $options['u'] ) ? $options['u'] : 'Maintenance script';
29 $summary = isset( $options['s'] ) ? $options['s'] : '';
30 $minor = isset( $options['m'] );
31 $bot = isset( $options['b'] );
32 $autoSummary = isset( $options['a'] );
33 $noRC = isset( $options['no-rc'] );
34
35 $wgUser = User::newFromName( $userName );
36 if ( !$wgUser ) {
37         print "Invalid username\n";
38         exit( 1 );
39 }
40 if ( $wgUser->isAnon() ) {
41         $wgUser->addToDatabase();
42 }
43
44 $wgTitle = Title::newFromText( $args[0] );
45 if ( !$wgTitle ) {
46         print "Invalid title\n";
47         exit( 1 );
48 }
49
50 $wgArticle = new Article( $wgTitle );
51
52 # Read the text
53 $text = file_get_contents( 'php://stdin' );
54
55 # Do the edit
56 print "Saving... ";
57 $success = $wgArticle->doEdit( $text, $summary, 
58         ( $minor ? EDIT_MINOR : 0 ) |
59         ( $bot ? EDIT_FORCE_BOT : 0 ) | 
60         ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
61         ( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
62 if ( $success ) {
63         print "done\n";
64 } else {
65         print "failed\n";
66         exit( 1 );
67 }
68