r43963 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43962‎ | r43963 | r43964 >
Date:02:10, 26 November 2008
Author:demon
Status:ok
Tags:
Comment:
Refactor Special:Import to extend SpecialPage instead of wfSpecialImport() stuff.
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialImport.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/AutoLoader.php
@@ -478,6 +478,7 @@
479479 'ShortPagesPage' => 'includes/specials/SpecialShortpages.php',
480480 'SpecialAllpages' => 'includes/specials/SpecialAllpages.php',
481481 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php',
 482+ 'SpecialImport' => 'includes/specials/SpecialImport.php',
482483 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
483484 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php',
484485 'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php',
Index: trunk/phase3/includes/specials/SpecialImport.php
@@ -23,26 +23,50 @@
2424 * @ingroup SpecialPage
2525 */
2626
27 -/**
28 - * Constructor
29 - */
30 -function wfSpecialImport( $page = '' ) {
31 - global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources;
32 - global $wgImportTargetNamespace;
33 -
34 - $interwiki = false;
35 - $namespace = $wgImportTargetNamespace;
36 - $frompage = '';
37 - $history = true;
38 -
39 - if ( wfReadOnly() ) {
40 - $wgOut->readOnlyPage();
41 - return;
 27+class SpecialImport extends SpecialPage {
 28+
 29+ private $interwiki = false;
 30+ private $namespace;
 31+ private $frompage = '';
 32+ private $history = true;
 33+
 34+ /**
 35+ * Constructor
 36+ */
 37+ public function __construct() {
 38+ parent::__construct( 'Import', 'import' );
 39+ global $wgImportTargetNamespace;
 40+ $this->namespace = $wgImportTargetNamespace;
4241 }
43 -
44 - if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') {
 42+
 43+ /**
 44+ * Execute
 45+ */
 46+ function execute( $par ) {
 47+ global $wgRequest;
 48+
 49+ $this->setHeaders();
 50+ $this->outputHeader();
 51+
 52+ if ( wfReadOnly() ) {
 53+ global $wgOut;
 54+ $wgOut->readOnlyPage();
 55+ return;
 56+ }
 57+
 58+ if ( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit' ) {
 59+ $this->doImport();
 60+ }
 61+ $this->showForm();
 62+ }
 63+
 64+ /**
 65+ * Do the actual import
 66+ */
 67+ private function doImport() {
 68+ global $wgOut, $wgRequest, $wgUser, $wgImportSources;
4569 $isUpload = false;
46 - $namespace = $wgRequest->getIntOrNull( 'namespace' );
 70+ $this->namespace = $wgRequest->getIntOrNull( 'namespace' );
4771 $sourceName = $wgRequest->getVal( "source" );
4872
4973 if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) {
@@ -55,16 +79,16 @@
5680 return $wgOut->permissionRequired( 'importupload' );
5781 }
5882 } elseif ( $sourceName == "interwiki" ) {
59 - $interwiki = $wgRequest->getVal( 'interwiki' );
60 - if ( !in_array( $interwiki, $wgImportSources ) ) {
 83+ $this->interwiki = $wgRequest->getVal( 'interwiki' );
 84+ if ( !in_array( $this->interwiki, $wgImportSources ) ) {
6185 $source = new WikiErrorMsg( "import-invalid-interwiki" );
6286 } else {
63 - $history = $wgRequest->getCheck( 'interwikiHistory' );
64 - $frompage = $wgRequest->getText( "frompage" );
 87+ $this->history = $wgRequest->getCheck( 'interwikiHistory' );
 88+ $this->frompage = $wgRequest->getText( "frompage" );
6589 $source = ImportStreamSource::newFromInterwiki(
66 - $interwiki,
67 - $frompage,
68 - $history );
 90+ $this->interwiki,
 91+ $this->frompage,
 92+ $this->history );
6993 }
7094 } else {
7195 $source = new WikiErrorMsg( "importunknownsource" );
@@ -76,10 +100,10 @@
77101 $wgOut->addWikiMsg( "importstart" );
78102
79103 $importer = new WikiImporter( $source );
80 - if( !is_null( $namespace ) ) {
81 - $importer->setTargetNamespace( $namespace );
 104+ if( !is_null( $this->namespace ) ) {
 105+ $importer->setTargetNamespace( $this->namespace );
82106 }
83 - $reporter = new ImportReporter( $importer, $isUpload, $interwiki );
 107+ $reporter = new ImportReporter( $importer, $isUpload, $this->interwiki );
84108
85109 $reporter->open();
86110 $result = $importer->doImport();
@@ -99,79 +123,82 @@
100124 }
101125 }
102126
103 - $action = $wgTitle->getLocalUrl( 'action=submit' );
 127+ private function showForm() {
 128+ global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources;
 129+ $action = $wgTitle->getLocalUrl( 'action=submit' );
104130
105 - if( $wgUser->isAllowed( 'importupload' ) ) {
106 - $wgOut->addWikiMsg( "importtext" );
107 - $wgOut->addHTML(
108 - Xml::openElement( 'fieldset' ).
109 - Xml::element( 'legend', null, wfMsg( 'import-upload' ) ) .
110 - Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
111 - Xml::hidden( 'action', 'submit' ) .
112 - Xml::hidden( 'source', 'upload' ) .
113 - Xml::input( 'xmlimport', 50, '', array( 'type' => 'file' ) ) . ' ' .
114 - Xml::hidden( 'editToken', $wgUser->editToken() ) .
115 - Xml::submitButton( wfMsg( 'uploadbtn' ) ) .
116 - Xml::closeElement( 'form' ) .
117 - Xml::closeElement( 'fieldset' )
118 - );
119 - } else {
120 - if( empty( $wgImportSources ) ) {
121 - $wgOut->addWikiMsg( 'importnosources' );
 131+ if( $wgUser->isAllowed( 'importupload' ) ) {
 132+ $wgOut->addWikiMsg( "importtext" );
 133+ $wgOut->addHTML(
 134+ Xml::openElement( 'fieldset' ).
 135+ Xml::element( 'legend', null, wfMsg( 'import-upload' ) ) .
 136+ Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
 137+ Xml::hidden( 'action', 'submit' ) .
 138+ Xml::hidden( 'source', 'upload' ) .
 139+ Xml::input( 'xmlimport', 50, '', array( 'type' => 'file' ) ) . ' ' .
 140+ Xml::hidden( 'editToken', $wgUser->editToken() ) .
 141+ Xml::submitButton( wfMsg( 'uploadbtn' ) ) .
 142+ Xml::closeElement( 'form' ) .
 143+ Xml::closeElement( 'fieldset' )
 144+ );
 145+ } else {
 146+ if( empty( $wgImportSources ) ) {
 147+ $wgOut->addWikiMsg( 'importnosources' );
 148+ }
122149 }
123 - }
124 -
125 - if( !empty( $wgImportSources ) ) {
126 - $wgOut->addHTML(
127 - Xml::openElement( 'fieldset' ) .
128 - Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
129 - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
130 - wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
131 - Xml::hidden( 'action', 'submit' ) .
132 - Xml::hidden( 'source', 'interwiki' ) .
133 - Xml::hidden( 'editToken', $wgUser->editToken() ) .
134 - Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) .
135 - "<tr>
136 - <td>" .
137 - Xml::openElement( 'select', array( 'name' => 'interwiki' ) )
138 - );
139 - foreach( $wgImportSources as $prefix ) {
140 - $selected = ( $interwiki === $prefix ) ? ' selected="selected"' : '';
141 - $wgOut->addHTML( Xml::option( $prefix, $prefix, $selected ) );
 150+
 151+ if( !empty( $wgImportSources ) ) {
 152+ $wgOut->addHTML(
 153+ Xml::openElement( 'fieldset' ) .
 154+ Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
 155+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
 156+ wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
 157+ Xml::hidden( 'action', 'submit' ) .
 158+ Xml::hidden( 'source', 'interwiki' ) .
 159+ Xml::hidden( 'editToken', $wgUser->editToken() ) .
 160+ Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) .
 161+ "<tr>
 162+ <td>" .
 163+ Xml::openElement( 'select', array( 'name' => 'interwiki' ) )
 164+ );
 165+ foreach( $wgImportSources as $prefix ) {
 166+ $selected = ( $this->interwiki === $prefix ) ? ' selected="selected"' : '';
 167+ $wgOut->addHTML( Xml::option( $prefix, $prefix, $selected ) );
 168+ }
 169+ $wgOut->addHTML(
 170+ Xml::closeElement( 'select' ) .
 171+ "</td>
 172+ <td>" .
 173+ Xml::input( 'frompage', 50, $this->frompage ) .
 174+ "</td>
 175+ </tr>
 176+ <tr>
 177+ <td>
 178+ </td>
 179+ <td>" .
 180+ Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $this->history ) .
 181+ "</td>
 182+ </tr>
 183+ <tr>
 184+ <td>
 185+ </td>
 186+ <td>" .
 187+ Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
 188+ Xml::namespaceSelector( $this->namespace, '' ) .
 189+ "</td>
 190+ </tr>
 191+ <tr>
 192+ <td>
 193+ </td>
 194+ <td>" .
 195+ Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) .
 196+ "</td>
 197+ </tr>" .
 198+ Xml::closeElement( 'table' ).
 199+ Xml::closeElement( 'form' ) .
 200+ Xml::closeElement( 'fieldset' )
 201+ );
142202 }
143 - $wgOut->addHTML(
144 - Xml::closeElement( 'select' ) .
145 - "</td>
146 - <td>" .
147 - Xml::input( 'frompage', 50, $frompage ) .
148 - "</td>
149 - </tr>
150 - <tr>
151 - <td>
152 - </td>
153 - <td>" .
154 - Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $history ) .
155 - "</td>
156 - </tr>
157 - <tr>
158 - <td>
159 - </td>
160 - <td>" .
161 - Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
162 - Xml::namespaceSelector( $namespace, '' ) .
163 - "</td>
164 - </tr>
165 - <tr>
166 - <td>
167 - </td>
168 - <td>" .
169 - Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) .
170 - "</td>
171 - </tr>" .
172 - Xml::closeElement( 'table' ).
173 - Xml::closeElement( 'form' ) .
174 - Xml::closeElement( 'fieldset' )
175 - );
176203 }
177204 }
178205
Index: trunk/phase3/includes/SpecialPage.php
@@ -146,7 +146,7 @@
147147 'Log' => array( 'SpecialPage', 'Log' ),
148148 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ),
149149 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
150 - 'Import' => array( 'SpecialPage', 'Import', 'import' ),
 150+ 'Import' => 'SpecialImport',
151151 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
152152 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
153153 'Userrights' => 'UserrightsPage',

Follow-up revisions

RevisionCommit summaryAuthorDate
r44501Quick hack to disable import for non privileged users. Prolly a regression fr...raymond14:06, 12 December 2008

Status & tagging log