r59331 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59330‎ | r59331 | r59332 >
Date:11:30, 22 November 2009
Author:maxsem
Status:resolved (Comments)
Tags:
Comment:
Small script to output page text to stdout
Modified paths:
  • /trunk/phase3/maintenance/getText.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/getText.php
@@ -0,0 +1,53 @@
 2+<?php
 3+/**
 4+ * Outputs page text to stdout, useful for command-line editing automation.
 5+ * Example: php getText.php "page title" | sed -e '...' | php edit.php "page title"
 6+ *
 7+ * This program is free software; you can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version.
 11+ *
 12+ * This program is distributed in the hope that it will be useful,
 13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15+ * GNU General Public License for more details.
 16+ *
 17+ * You should have received a copy of the GNU General Public License along
 18+ * with this program; if not, write to the Free Software Foundation, Inc.,
 19+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 20+ * http://www.gnu.org/copyleft/gpl.html
 21+ *
 22+ * @ingroup Maintenance
 23+ */
 24+
 25+require_once( dirname(__FILE__) . '/Maintenance.php' );
 26+
 27+class GetTextMaint extends Maintenance {
 28+ public function __construct() {
 29+ parent::__construct();
 30+ $this->mDescription = 'Outputs page text to stdout';
 31+ $this->addArg( 'title', 'Page title' );
 32+ }
 33+
 34+ public function execute() {
 35+ $this->db = wfGetDB( DB_MASTER );
 36+
 37+ $titleText = $this->getArg( 0 );
 38+ $title = Title::newFromText( $titleText );
 39+ if ( !$title ) {
 40+ $this->error( "$titleText is not a valid title\n", true );
 41+ }
 42+
 43+ $rev = Revision::newFromTitle( $title );
 44+ if ( !$rev ) {
 45+ $titleText = $title->getText();
 46+ $this->error( "Page $titleText does not exist\n", true );
 47+ }
 48+
 49+ $this->output( $rev->getText() );
 50+ }
 51+}
 52+
 53+$maintClass = "GetTextMaint";
 54+require_once( DO_MAINTENANCE );
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/getText.php
___________________________________________________________________
Name: svn:eol-style
155 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r61170Follow up r59331....platonides16:00, 17 January 2010

Comments

#Comment by Tim Starling (talk | contribs)   02:48, 12 January 2010

$rev->getText() may return false, this should be reported as an error.

#Comment by Platonides (talk | contribs)   16:06, 17 January 2010

Fixed in r61170

Status & tagging log