MediaWiki  REL1_24
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         $content = $rev->getContent( $this->hasOption( 'show-private' )
00056             ? Revision::RAW
00057             : Revision::FOR_PUBLIC );
00058 
00059         if ( $content === false ) {
00060             $titleText = $title->getPrefixedText();
00061             $this->error( "Couldn't extract the text from $titleText.\n", true );
00062         }
00063         $this->output( $content->serialize() );
00064     }
00065 }
00066 
00067 $maintClass = "GetTextMaint";
00068 require_once RUN_MAINTENANCE_IF_MAIN;