Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -478,6 +478,7 @@ |
479 | 479 | 'ShortPagesPage' => 'includes/specials/SpecialShortpages.php', |
480 | 480 | 'SpecialAllpages' => 'includes/specials/SpecialAllpages.php', |
481 | 481 | 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php', |
| 482 | + 'SpecialImport' => 'includes/specials/SpecialImport.php', |
482 | 483 | 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php', |
483 | 484 | 'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php', |
484 | 485 | 'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php', |
Index: trunk/phase3/includes/specials/SpecialImport.php |
— | — | @@ -23,26 +23,50 @@ |
24 | 24 | * @ingroup SpecialPage |
25 | 25 | */ |
26 | 26 | |
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; |
42 | 41 | } |
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; |
45 | 69 | $isUpload = false; |
46 | | - $namespace = $wgRequest->getIntOrNull( 'namespace' ); |
| 70 | + $this->namespace = $wgRequest->getIntOrNull( 'namespace' ); |
47 | 71 | $sourceName = $wgRequest->getVal( "source" ); |
48 | 72 | |
49 | 73 | if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) { |
— | — | @@ -55,16 +79,16 @@ |
56 | 80 | return $wgOut->permissionRequired( 'importupload' ); |
57 | 81 | } |
58 | 82 | } 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 ) ) { |
61 | 85 | $source = new WikiErrorMsg( "import-invalid-interwiki" ); |
62 | 86 | } else { |
63 | | - $history = $wgRequest->getCheck( 'interwikiHistory' ); |
64 | | - $frompage = $wgRequest->getText( "frompage" ); |
| 87 | + $this->history = $wgRequest->getCheck( 'interwikiHistory' ); |
| 88 | + $this->frompage = $wgRequest->getText( "frompage" ); |
65 | 89 | $source = ImportStreamSource::newFromInterwiki( |
66 | | - $interwiki, |
67 | | - $frompage, |
68 | | - $history ); |
| 90 | + $this->interwiki, |
| 91 | + $this->frompage, |
| 92 | + $this->history ); |
69 | 93 | } |
70 | 94 | } else { |
71 | 95 | $source = new WikiErrorMsg( "importunknownsource" ); |
— | — | @@ -76,10 +100,10 @@ |
77 | 101 | $wgOut->addWikiMsg( "importstart" ); |
78 | 102 | |
79 | 103 | $importer = new WikiImporter( $source ); |
80 | | - if( !is_null( $namespace ) ) { |
81 | | - $importer->setTargetNamespace( $namespace ); |
| 104 | + if( !is_null( $this->namespace ) ) { |
| 105 | + $importer->setTargetNamespace( $this->namespace ); |
82 | 106 | } |
83 | | - $reporter = new ImportReporter( $importer, $isUpload, $interwiki ); |
| 107 | + $reporter = new ImportReporter( $importer, $isUpload, $this->interwiki ); |
84 | 108 | |
85 | 109 | $reporter->open(); |
86 | 110 | $result = $importer->doImport(); |
— | — | @@ -99,79 +123,82 @@ |
100 | 124 | } |
101 | 125 | } |
102 | 126 | |
103 | | - $action = $wgTitle->getLocalUrl( 'action=submit' ); |
| 127 | + private function showForm() { |
| 128 | + global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources; |
| 129 | + $action = $wgTitle->getLocalUrl( 'action=submit' ); |
104 | 130 | |
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 | + } |
122 | 149 | } |
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 | + ); |
142 | 202 | } |
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 | | - ); |
176 | 203 | } |
177 | 204 | } |
178 | 205 | |
Index: trunk/phase3/includes/SpecialPage.php |
— | — | @@ -146,7 +146,7 @@ |
147 | 147 | 'Log' => array( 'SpecialPage', 'Log' ), |
148 | 148 | 'Blockip' => array( 'SpecialPage', 'Blockip', 'block' ), |
149 | 149 | 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ), |
150 | | - 'Import' => array( 'SpecialPage', 'Import', 'import' ), |
| 150 | + 'Import' => 'SpecialImport', |
151 | 151 | 'Lockdb' => array( 'SpecialPage', 'Lockdb', 'siteadmin' ), |
152 | 152 | 'Unlockdb' => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ), |
153 | 153 | 'Userrights' => 'UserrightsPage', |