wiki.techinc.nl/maintenance/view.php
Ammar Abdulhamid 6228801c68 Add check for page existence
Currently even if the page does not exist at all this script just says
"there's no content" which is partially true. If the page does exist but with
no content and/or blank the same answer is also given, which is OK in that case
but less so in the former case.

Also handle special pages instead of throwing exception.

Change-Id: Ia15b336d989d3605ead1891e3396380e8e6d4347
2020-03-09 10:50:00 +01:00

65 lines
1.9 KiB
PHP

<?php
/**
* Show page contents.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Maintenance
*/
use MediaWiki\Revision\RevisionRecord;
require_once __DIR__ . '/Maintenance.php';
/**
* Maintenance script to show page contents.
*
* @ingroup Maintenance
*/
class ViewCLI extends Maintenance {
public function __construct() {
parent::__construct();
$this->addDescription( 'Show article contents on the command line' );
$this->addArg( 'title', 'Title of article to view' );
}
public function execute() {
$title = Title::newFromText( $this->getArg( 0 ) );
if ( !$title ) {
$this->fatalError( "Invalid title" );
} elseif ( $title->isSpecialPage() ) {
$this->fatalError( "Special Pages not supported" );
} elseif ( !$title->exists() ) {
$this->fatalError( "Page does not exist" );
}
$page = WikiPage::factory( $title );
$content = $page->getContent( RevisionRecord::RAW );
if ( !$content ) {
$this->fatalError( "Page has no content" );
}
if ( !$content instanceof TextContent ) {
$this->fatalError( "Non-text content models not supported" );
}
$this->output( $content->getText() );
}
}
$maintClass = ViewCLI::class;
require_once RUN_MAINTENANCE_IF_MAIN;