Remove unused parameter
[mediawiki.git] / maintenance / edit.php
blob6417804505bcd09716f1b2e1d74f72eb696fac8f
1 <?php
2 /**
3 * @file
4 * @ingroup Maintenance
5 */
7 $optionsWithArgs = array( 'u', 's' );
9 require_once( 'commandLine.inc' );
11 if ( count( $args ) == 0 || isset( $options['help'] ) ) {
12 print <<<EOT
13 Edit an article from the command line
15 Usage: php edit.php [options...] <title>
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
25 If the specified user does not exist, it will be created.
26 The text for the edit will be read from stdin.
28 EOT;
29 exit( 1 );
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'] );
39 $wgUser = User::newFromName( $userName );
40 if ( !$wgUser ) {
41 print "Invalid username\n";
42 exit( 1 );
44 if ( $wgUser->isAnon() ) {
45 $wgUser->addToDatabase();
48 $wgTitle = Title::newFromText( $args[0] );
49 if ( !$wgTitle ) {
50 print "Invalid title\n";
51 exit( 1 );
54 $wgArticle = new Article( $wgTitle );
56 # Read the text
57 $text = file_get_contents( 'php://stdin' );
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;
73 if ( !$status->isGood() ) {
74 print $status->getWikiText() . "\n";
76 exit( $exit );