From e899407d4868e626e359aae36feb961bc398ff97 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 26 Nov 2008 02:10:56 +0000 Subject: [PATCH] Refactor Special:Import to extend SpecialPage instead of wfSpecialImport() stuff. --- includes/AutoLoader.php | 1 + includes/SpecialPage.php | 2 +- includes/specials/SpecialImport.php | 225 ++++++++++++++++------------ 3 files changed, 128 insertions(+), 100 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index b531599c24..d34c0049d6 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -478,6 +478,7 @@ $wgAutoloadLocalClasses = array( 'ShortPagesPage' => 'includes/specials/SpecialShortpages.php', 'SpecialAllpages' => 'includes/specials/SpecialAllpages.php', 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php', + 'SpecialImport' => 'includes/specials/SpecialImport.php', 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php', 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php', 'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 731d2ef3d1..b282ebb315 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -146,7 +146,7 @@ class SpecialPage 'Log' => array( 'SpecialPage', 'Log' ), 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ), 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ), - 'Import' => array( 'SpecialPage', 'Import', 'import' ), + 'Import' => 'SpecialImport', 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ), 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ), 'Userrights' => 'UserrightsPage', diff --git a/includes/specials/SpecialImport.php b/includes/specials/SpecialImport.php index a87918eae1..b811d2943d 100644 --- a/includes/specials/SpecialImport.php +++ b/includes/specials/SpecialImport.php @@ -23,26 +23,50 @@ * @ingroup SpecialPage */ -/** - * Constructor - */ -function wfSpecialImport( $page = '' ) { - global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources; - global $wgImportTargetNamespace; - - $interwiki = false; - $namespace = $wgImportTargetNamespace; - $frompage = ''; - $history = true; - - if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; +class SpecialImport extends SpecialPage { + + private $interwiki = false; + private $namespace; + private $frompage = ''; + private $history = true; + + /** + * Constructor + */ + public function __construct() { + parent::__construct( 'Import', 'import' ); + global $wgImportTargetNamespace; + $this->namespace = $wgImportTargetNamespace; } - - if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') { + + /** + * Execute + */ + function execute( $par ) { + global $wgRequest; + + $this->setHeaders(); + $this->outputHeader(); + + if ( wfReadOnly() ) { + global $wgOut; + $wgOut->readOnlyPage(); + return; + } + + if ( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit' ) { + $this->doImport(); + } + $this->showForm(); + } + + /** + * Do the actual import + */ + private function doImport() { + global $wgOut, $wgRequest, $wgUser, $wgImportSources; $isUpload = false; - $namespace = $wgRequest->getIntOrNull( 'namespace' ); + $this->namespace = $wgRequest->getIntOrNull( 'namespace' ); $sourceName = $wgRequest->getVal( "source" ); if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) { @@ -55,16 +79,16 @@ function wfSpecialImport( $page = '' ) { return $wgOut->permissionRequired( 'importupload' ); } } elseif ( $sourceName == "interwiki" ) { - $interwiki = $wgRequest->getVal( 'interwiki' ); - if ( !in_array( $interwiki, $wgImportSources ) ) { + $this->interwiki = $wgRequest->getVal( 'interwiki' ); + if ( !in_array( $this->interwiki, $wgImportSources ) ) { $source = new WikiErrorMsg( "import-invalid-interwiki" ); } else { - $history = $wgRequest->getCheck( 'interwikiHistory' ); - $frompage = $wgRequest->getText( "frompage" ); + $this->history = $wgRequest->getCheck( 'interwikiHistory' ); + $this->frompage = $wgRequest->getText( "frompage" ); $source = ImportStreamSource::newFromInterwiki( - $interwiki, - $frompage, - $history ); + $this->interwiki, + $this->frompage, + $this->history ); } } else { $source = new WikiErrorMsg( "importunknownsource" ); @@ -76,10 +100,10 @@ function wfSpecialImport( $page = '' ) { $wgOut->addWikiMsg( "importstart" ); $importer = new WikiImporter( $source ); - if( !is_null( $namespace ) ) { - $importer->setTargetNamespace( $namespace ); + if( !is_null( $this->namespace ) ) { + $importer->setTargetNamespace( $this->namespace ); } - $reporter = new ImportReporter( $importer, $isUpload, $interwiki ); + $reporter = new ImportReporter( $importer, $isUpload, $this->interwiki ); $reporter->open(); $result = $importer->doImport(); @@ -99,79 +123,82 @@ function wfSpecialImport( $page = '' ) { } } - $action = $wgTitle->getLocalUrl( 'action=submit' ); - - if( $wgUser->isAllowed( 'importupload' ) ) { - $wgOut->addWikiMsg( "importtext" ); - $wgOut->addHTML( - Xml::openElement( 'fieldset' ). - Xml::element( 'legend', null, wfMsg( 'import-upload' ) ) . - Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) . - Xml::hidden( 'action', 'submit' ) . - Xml::hidden( 'source', 'upload' ) . - Xml::input( 'xmlimport', 50, '', array( 'type' => 'file' ) ) . ' ' . - Xml::hidden( 'editToken', $wgUser->editToken() ) . - Xml::submitButton( wfMsg( 'uploadbtn' ) ) . - Xml::closeElement( 'form' ) . - Xml::closeElement( 'fieldset' ) - ); - } else { - if( empty( $wgImportSources ) ) { - $wgOut->addWikiMsg( 'importnosources' ); - } - } + private function showForm() { + global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources; + $action = $wgTitle->getLocalUrl( 'action=submit' ); - if( !empty( $wgImportSources ) ) { - $wgOut->addHTML( - Xml::openElement( 'fieldset' ) . - Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) . - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) . - wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) . - Xml::hidden( 'action', 'submit' ) . - Xml::hidden( 'source', 'interwiki' ) . - Xml::hidden( 'editToken', $wgUser->editToken() ) . - Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) . - " - " . - Xml::openElement( 'select', array( 'name' => 'interwiki' ) ) - ); - foreach( $wgImportSources as $prefix ) { - $selected = ( $interwiki === $prefix ) ? ' selected="selected"' : ''; - $wgOut->addHTML( Xml::option( $prefix, $prefix, $selected ) ); + if( $wgUser->isAllowed( 'importupload' ) ) { + $wgOut->addWikiMsg( "importtext" ); + $wgOut->addHTML( + Xml::openElement( 'fieldset' ). + Xml::element( 'legend', null, wfMsg( 'import-upload' ) ) . + Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) . + Xml::hidden( 'action', 'submit' ) . + Xml::hidden( 'source', 'upload' ) . + Xml::input( 'xmlimport', 50, '', array( 'type' => 'file' ) ) . ' ' . + Xml::hidden( 'editToken', $wgUser->editToken() ) . + Xml::submitButton( wfMsg( 'uploadbtn' ) ) . + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) + ); + } else { + if( empty( $wgImportSources ) ) { + $wgOut->addWikiMsg( 'importnosources' ); + } + } + + if( !empty( $wgImportSources ) ) { + $wgOut->addHTML( + Xml::openElement( 'fieldset' ) . + Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) . + Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) . + wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) . + Xml::hidden( 'action', 'submit' ) . + Xml::hidden( 'source', 'interwiki' ) . + Xml::hidden( 'editToken', $wgUser->editToken() ) . + Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) . + " + " . + Xml::openElement( 'select', array( 'name' => 'interwiki' ) ) + ); + foreach( $wgImportSources as $prefix ) { + $selected = ( $this->interwiki === $prefix ) ? ' selected="selected"' : ''; + $wgOut->addHTML( Xml::option( $prefix, $prefix, $selected ) ); + } + $wgOut->addHTML( + Xml::closeElement( 'select' ) . + " + " . + Xml::input( 'frompage', 50, $this->frompage ) . + " + + + + + " . + Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $this->history ) . + " + + + + + " . + Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) . + Xml::namespaceSelector( $this->namespace, '' ) . + " + + + + + " . + Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) . + " + " . + Xml::closeElement( 'table' ). + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) + ); } - $wgOut->addHTML( - Xml::closeElement( 'select' ) . - " - " . - Xml::input( 'frompage', 50, $frompage ) . - " - - - - - " . - Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $history ) . - " - - - - - " . - Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) . - Xml::namespaceSelector( $namespace, '' ) . - " - - - - - " . - Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) . - " - " . - Xml::closeElement( 'table' ). - Xml::closeElement( 'form' ) . - Xml::closeElement( 'fieldset' ) - ); } } -- 2.20.1