[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> edit.php (source)

   1  <?php
   2  /**
   3   * Make a page edit.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Maintenance
  22   */
  23  
  24  require_once  __DIR__ . '/Maintenance.php';
  25  
  26  /**
  27   * Maintenance script to make a page edit.
  28   *
  29   * @ingroup Maintenance
  30   */
  31  class EditCLI extends Maintenance {
  32  	public function __construct() {
  33          parent::__construct();
  34          $this->mDescription = "Edit an article from the command line, text is from stdin";
  35          $this->addOption( 'user', 'Username', false, true, 'u' );
  36          $this->addOption( 'summary', 'Edit summary', false, true, 's' );
  37          $this->addOption( 'minor', 'Minor edit', false, false, 'm' );
  38          $this->addOption( 'bot', 'Bot edit', false, false, 'b' );
  39          $this->addOption( 'autosummary', 'Enable autosummary', false, false, 'a' );
  40          $this->addOption( 'no-rc', 'Do not show the change in recent changes', false, false, 'r' );
  41          $this->addOption( 'nocreate', 'Don\'t create new pages', false, false );
  42          $this->addOption( 'createonly', 'Only create new pages', false, false );
  43          $this->addArg( 'title', 'Title of article to edit' );
  44      }
  45  
  46  	public function execute() {
  47          global $wgUser;
  48  
  49          $userName = $this->getOption( 'user', 'Maintenance script' );
  50          $summary = $this->getOption( 'summary', '' );
  51          $minor = $this->hasOption( 'minor' );
  52          $bot = $this->hasOption( 'bot' );
  53          $autoSummary = $this->hasOption( 'autosummary' );
  54          $noRC = $this->hasOption( 'no-rc' );
  55  
  56          $wgUser = User::newFromName( $userName );
  57          if ( !$wgUser ) {
  58              $this->error( "Invalid username", true );
  59          }
  60          if ( $wgUser->isAnon() ) {
  61              $wgUser->addToDatabase();
  62          }
  63  
  64          $title = Title::newFromText( $this->getArg() );
  65          if ( !$title ) {
  66              $this->error( "Invalid title", true );
  67          }
  68  
  69          if ( $this->hasOption( 'nocreate' ) && !$title->exists() ) {
  70              $this->error( "Page does not exist", true );
  71          } elseif ( $this->hasOption( 'createonly' ) && $title->exists() ) {
  72              $this->error( "Page already exists", true );
  73          }
  74  
  75          $page = WikiPage::factory( $title );
  76  
  77          # Read the text
  78          $text = $this->getStdin( Maintenance::STDIN_ALL );
  79          $content = ContentHandler::makeContent( $text, $title );
  80  
  81          # Do the edit
  82          $this->output( "Saving... " );
  83          $status = $page->doEditContent( $content, $summary,
  84              ( $minor ? EDIT_MINOR : 0 ) |
  85              ( $bot ? EDIT_FORCE_BOT : 0 ) |
  86              ( $autoSummary ? EDIT_AUTOSUMMARY : 0 ) |
  87              ( $noRC ? EDIT_SUPPRESS_RC : 0 ) );
  88          if ( $status->isOK() ) {
  89              $this->output( "done\n" );
  90              $exit = 0;
  91          } else {
  92              $this->output( "failed\n" );
  93              $exit = 1;
  94          }
  95          if ( !$status->isGood() ) {
  96              $this->output( $status->getWikiText() . "\n" );
  97          }
  98          exit( $exit );
  99      }
 100  }
 101  
 102  $maintClass = "EditCLI";
 103  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1