MediaWiki  REL1_19
getText.php
Go to the documentation of this file.
00001 <?php
00024 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
00025 
00026 class GetTextMaint extends Maintenance {
00027         public function __construct() {
00028                 parent::__construct();
00029                 $this->mDescription = 'Outputs page text to stdout';
00030                 $this->addOption( 'show-private', 'Show the text even if it\'s not available to the public' );
00031                 $this->addArg( 'title', 'Page title' );
00032         }
00033 
00034         public function execute() {
00035                 $this->db = wfGetDB( DB_SLAVE );
00036 
00037                 $titleText = $this->getArg( 0 );
00038                 $title = Title::newFromText( $titleText );
00039                 if ( !$title ) {
00040                         $this->error( "$titleText is not a valid title.\n", true );
00041                 }
00042 
00043                 $rev = Revision::newFromTitle( $title );
00044                 if ( !$rev ) {
00045                         $titleText = $title->getPrefixedText();
00046                         $this->error( "Page $titleText does not exist.\n", true );
00047                 }
00048                 $text = $rev->getText( $this->hasOption( 'show-private' ) ? Revision::RAW : Revision::FOR_PUBLIC );
00049                 if ( $text === false ) {
00050                         $titleText = $title->getPrefixedText();
00051                         $this->error( "Couldn't extract the text from $titleText.\n", true );
00052                 }
00053                 $this->output( $text );
00054         }
00055 }
00056 
00057 $maintClass = "GetTextMaint";
00058 require_once( RUN_MAINTENANCE_IF_MAIN );