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