X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/8989532d3de45b196373107c7a812a68ac0ff2d9..d75ce11339b35963b5f8c3d53190819c1c025716:/maintenance/getText.php diff --git a/maintenance/getText.php b/maintenance/getText.php new file mode 100644 index 00000000..6326267d --- /dev/null +++ b/maintenance/getText.php @@ -0,0 +1,58 @@ +mDescription = 'Outputs page text to stdout'; + $this->addOption( 'show-private', 'Show the text even if it\'s not available to the public' ); + $this->addArg( 'title', 'Page title' ); + } + + public function execute() { + $this->db = wfGetDB( DB_SLAVE ); + + $titleText = $this->getArg( 0 ); + $title = Title::newFromText( $titleText ); + if ( !$title ) { + $this->error( "$titleText is not a valid title.\n", true ); + } + + $rev = Revision::newFromTitle( $title ); + if ( !$rev ) { + $titleText = $title->getPrefixedText(); + $this->error( "Page $titleText does not exist.\n", true ); + } + $text = $rev->getText( $this->hasOption('show-private') ? Revision::RAW : Revision::FOR_PUBLIC ); + if ( $text === false ) { + $titleText = $title->getPrefixedText(); + $this->error( "Couldn't extract the text from $titleText.\n", true ); + } + $this->output( $text ); + } +} + +$maintClass = "GetTextMaint"; +require_once( DO_MAINTENANCE );