2009-11-22 11:30:13 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-07-17 05:40:40 +00:00
|
|
|
* Outputs page text to stdout.
|
|
|
|
|
* Useful for command-line editing automation.
|
2009-11-22 11:30:13 +00:00
|
|
|
* Example: php getText.php "page title" | sed -e '...' | php edit.php "page title"
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-07-17 05:40:40 +00:00
|
|
|
* @file
|
2009-11-22 11:30:13 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2009-11-22 11:30:13 +00:00
|
|
|
|
2012-07-17 05:40:40 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that outputs page text to stdout.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-11-22 11:30:13 +00:00
|
|
|
class GetTextMaint extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Outputs page text to stdout' );
|
2010-01-17 16:00:36 +00:00
|
|
|
$this->addOption( 'show-private', 'Show the text even if it\'s not available to the public' );
|
2009-11-22 11:30:13 +00:00
|
|
|
$this->addArg( 'title', 'Page title' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$titleText = $this->getArg( 0 );
|
|
|
|
|
$title = Title::newFromText( $titleText );
|
|
|
|
|
if ( !$title ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "$titleText is not a valid title.\n" );
|
2009-11-22 11:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rev = Revision::newFromTitle( $title );
|
|
|
|
|
if ( !$rev ) {
|
2010-01-17 16:00:36 +00:00
|
|
|
$titleText = $title->getPrefixedText();
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Page $titleText does not exist.\n" );
|
2009-11-22 11:30:13 +00:00
|
|
|
}
|
2014-04-23 08:53:03 +00:00
|
|
|
$content = $rev->getContent( $this->hasOption( 'show-private' )
|
|
|
|
|
? Revision::RAW
|
|
|
|
|
: Revision::FOR_PUBLIC );
|
|
|
|
|
|
2012-09-14 11:13:29 +00:00
|
|
|
if ( $content === false ) {
|
2010-01-17 16:00:36 +00:00
|
|
|
$titleText = $title->getPrefixedText();
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Couldn't extract the text from $titleText.\n" );
|
2010-01-17 16:00:36 +00:00
|
|
|
}
|
2012-09-14 11:13:29 +00:00
|
|
|
$this->output( $content->serialize() );
|
2009-11-22 11:30:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$maintClass = "GetTextMaint";
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|