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