When saving preferences, check hook and authentication plugin, and actually save...
[mediawiki.git] / maintenance / edit.php
blob75b6c3338e41cd1123970ee3ad502bbbd689a1bd
1 <?php
3 $optionsWithArgs = array( 'u', 's' );
5 require_once( 'commandLine.inc' );
7 if ( count( $args ) == 0 || isset( $options['help'] ) ) {
8 print <<<EOT
9 Edit an article from the command line
11 Usage: php edit.php [options...] <title>
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
21 If the specified user does not exist, it will be created.
22 The text for the edit will be read from stdin.
24 EOT;
25 exit( 1 );
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'] );
35 $wgUser = User::newFromName( $userName );
36 if ( !$wgUser ) {
37 print "Invalid username\n";
38 exit( 1 );
40 if ( $wgUser->isAnon() ) {
41 $wgUser->addToDatabase();
44 $wgTitle = Title::newFromText( $args[0] );
45 if ( !$wgTitle ) {
46 print "Invalid title\n";
47 exit( 1 );
50 $wgArticle = new Article( $wgTitle );
52 # Read the text
53 $text = file_get_contents( 'php://stdin' );
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 );