Index: trunk/phase3/includes/api/ApiImport.php |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) ); |
76 | 76 | } |
77 | 77 | |
78 | | - $importer = new ImportXMLReader( $source ); |
| 78 | + $importer = new WikiImporter( $source ); |
79 | 79 | if ( isset( $params['namespace'] ) ) { |
80 | 80 | $importer->setTargetNamespace( $params['namespace'] ); |
81 | 81 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -605,7 +605,7 @@ |
606 | 606 | 'WantedPagesPage' => 'includes/specials/SpecialWantedpages.php', |
607 | 607 | 'WantedTemplatesPage' => 'includes/specials/SpecialWantedtemplates.php', |
608 | 608 | 'WhatLinksHerePage' => 'includes/specials/SpecialWhatlinkshere.php', |
609 | | - 'ImportXMLReader' => 'includes/ImportXMLReader.php', |
| 609 | + 'WikiImporter' => 'includes/ImportXMLReader.php', |
610 | 610 | 'WikiRevision' => 'includes/Import.php', |
611 | 611 | 'WithoutInterwikiPage' => 'includes/specials/SpecialWithoutinterwiki.php', |
612 | 612 | |
Index: trunk/phase3/includes/ImportXMLReader.php |
— | — | @@ -3,12 +3,15 @@ |
4 | 4 | * implements Special:Import |
5 | 5 | * @ingroup SpecialPage |
6 | 6 | */ |
7 | | -class ImportXMLReader { |
| 7 | +class WikiImporter { |
8 | 8 | private $reader = null; |
9 | 9 | private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback; |
10 | 10 | private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback; |
11 | 11 | private $mDebug; |
12 | 12 | |
| 13 | + /** |
| 14 | + * Creates an ImportXMLReader drawing from the source provided |
| 15 | + */ |
13 | 16 | function __construct( $source ) { |
14 | 17 | $this->reader = new XMLReader(); |
15 | 18 | |
— | — | @@ -22,22 +25,22 @@ |
23 | 26 | $this->setLogItemCallback( array( $this, 'importLogItem' ) ); |
24 | 27 | } |
25 | 28 | |
26 | | - function throwXmlError( $err ) { |
| 29 | + private function throwXmlError( $err ) { |
27 | 30 | $this->debug( "FAILURE: $err" ); |
28 | 31 | wfDebug( "WikiImporter XML error: $err\n" ); |
29 | 32 | } |
30 | 33 | |
31 | | - function debug( $data ) { |
| 34 | + private function debug( $data ) { |
32 | 35 | if( $this->mDebug ) { |
33 | 36 | wfDebug( "IMPORT: $data\n" ); |
34 | 37 | } |
35 | 38 | } |
36 | 39 | |
37 | | - function warn( $data ) { |
| 40 | + private function warn( $data ) { |
38 | 41 | wfDebug( "IMPORT: $data\n" ); |
39 | 42 | } |
40 | 43 | |
41 | | - function notice( $data ) { |
| 44 | + private function notice( $data ) { |
42 | 45 | global $wgCommandLineMode; |
43 | 46 | if( $wgCommandLineMode ) { |
44 | 47 | print "$data\n"; |
— | — | @@ -59,7 +62,7 @@ |
60 | 63 | * @param $callback callback |
61 | 64 | * @return callback |
62 | 65 | */ |
63 | | - function setPageCallback( $callback ) { |
| 66 | + public function setPageCallback( $callback ) { |
64 | 67 | $previous = $this->mPageCallback; |
65 | 68 | $this->mPageCallback = $callback; |
66 | 69 | return $previous; |
— | — | @@ -74,7 +77,7 @@ |
75 | 78 | * @param $callback callback |
76 | 79 | * @return callback |
77 | 80 | */ |
78 | | - function setPageOutCallback( $callback ) { |
| 81 | + public function setPageOutCallback( $callback ) { |
79 | 82 | $previous = $this->mPageOutCallback; |
80 | 83 | $this->mPageOutCallback = $callback; |
81 | 84 | return $previous; |
— | — | @@ -85,7 +88,7 @@ |
86 | 89 | * @param $callback callback |
87 | 90 | * @return callback |
88 | 91 | */ |
89 | | - function setRevisionCallback( $callback ) { |
| 92 | + public function setRevisionCallback( $callback ) { |
90 | 93 | $previous = $this->mRevisionCallback; |
91 | 94 | $this->mRevisionCallback = $callback; |
92 | 95 | return $previous; |
— | — | @@ -96,7 +99,7 @@ |
97 | 100 | * @param $callback callback |
98 | 101 | * @return callback |
99 | 102 | */ |
100 | | - function setUploadCallback( $callback ) { |
| 103 | + public function setUploadCallback( $callback ) { |
101 | 104 | $previous = $this->mUploadCallback; |
102 | 105 | $this->mUploadCallback = $callback; |
103 | 106 | return $previous; |
— | — | @@ -107,7 +110,7 @@ |
108 | 111 | * @param $callback callback |
109 | 112 | * @return callback |
110 | 113 | */ |
111 | | - function setLogItemCallback( $callback ) { |
| 114 | + public function setLogItemCallback( $callback ) { |
112 | 115 | $previous = $this->mLogItemCallback; |
113 | 116 | $this->mLogItemCallback = $callback; |
114 | 117 | return $previous; |
— | — | @@ -118,7 +121,7 @@ |
119 | 122 | * @param $callback callback |
120 | 123 | * @return callback |
121 | 124 | */ |
122 | | - function setSiteInfoCallback( $callback ) { |
| 125 | + public function setSiteInfoCallback( $callback ) { |
123 | 126 | $previous = $this->mSiteInfoCallback; |
124 | 127 | $this->mSiteInfoCallback = $callback; |
125 | 128 | return $previous; |
— | — | @@ -127,7 +130,7 @@ |
128 | 131 | /** |
129 | 132 | * Set a target namespace to override the defaults |
130 | 133 | */ |
131 | | - function setTargetNamespace( $namespace ) { |
| 134 | + public function setTargetNamespace( $namespace ) { |
132 | 135 | if( is_null( $namespace ) ) { |
133 | 136 | // Don't override namespaces |
134 | 137 | $this->mTargetNamespace = null; |
— | — | @@ -142,9 +145,8 @@ |
143 | 146 | /** |
144 | 147 | * Default per-revision callback, performs the import. |
145 | 148 | * @param $revision WikiRevision |
146 | | - * @private |
147 | 149 | */ |
148 | | - function importRevision( $revision ) { |
| 150 | + public function importRevision( $revision ) { |
149 | 151 | $dbw = wfGetDB( DB_MASTER ); |
150 | 152 | return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) ); |
151 | 153 | } |
— | — | @@ -152,9 +154,8 @@ |
153 | 155 | /** |
154 | 156 | * Default per-revision callback, performs the import. |
155 | 157 | * @param $rev WikiRevision |
156 | | - * @private |
157 | 158 | */ |
158 | | - function importLogItem( $rev ) { |
| 159 | + public function importLogItem( $rev ) { |
159 | 160 | $dbw = wfGetDB( DB_MASTER ); |
160 | 161 | return $dbw->deadlockLoop( array( $rev, 'importLogItem' ) ); |
161 | 162 | } |
— | — | @@ -162,7 +163,7 @@ |
163 | 164 | /** |
164 | 165 | * Dummy for now... |
165 | 166 | */ |
166 | | - function importUpload( $revision ) { |
| 167 | + public function importUpload( $revision ) { |
167 | 168 | //$dbw = wfGetDB( DB_MASTER ); |
168 | 169 | //return $dbw->deadlockLoop( array( $revision, 'importUpload' ) ); |
169 | 170 | return false; |
— | — | @@ -171,9 +172,8 @@ |
172 | 173 | /** |
173 | 174 | * Alternate per-revision callback, for debugging. |
174 | 175 | * @param $revision WikiRevision |
175 | | - * @private |
176 | 176 | */ |
177 | | - function debugRevisionHandler( &$revision ) { |
| 177 | + public function debugRevisionHandler( &$revision ) { |
178 | 178 | $this->debug( "Got revision:" ); |
179 | 179 | if( is_object( $revision->title ) ) { |
180 | 180 | $this->debug( "-- Title: " . $revision->title->getPrefixedText() ); |
— | — | @@ -189,7 +189,6 @@ |
190 | 190 | /** |
191 | 191 | * Notify the callback function when a new <page> is reached. |
192 | 192 | * @param $title Title |
193 | | - * @private |
194 | 193 | */ |
195 | 194 | function pageCallback( $title ) { |
196 | 195 | if( is_callable( $this->mPageCallback ) ) { |
— | — | @@ -203,16 +202,19 @@ |
204 | 203 | * @param $origTitle Title |
205 | 204 | * @param $revisionCount int |
206 | 205 | * @param $successCount Int: number of revisions for which callback returned true |
207 | | - * @private |
208 | 206 | */ |
209 | | - function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) { |
| 207 | + private function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) { |
210 | 208 | if( is_callable( $this->mPageOutCallback ) ) { |
211 | 209 | call_user_func_array( $this->mPageOutCallback, |
212 | 210 | array( $title, $origTitle, $revisionCount, $successCount ) ); |
213 | 211 | } |
214 | 212 | } |
215 | 213 | |
216 | | - function revisionCallback( $revision ) { |
| 214 | + /** |
| 215 | + * Notify the callback function of a revision |
| 216 | + * @param $revision A WikiRevision object |
| 217 | + */ |
| 218 | + private function revisionCallback( $revision ) { |
217 | 219 | if ( is_callable( $this->mRevisionCallback ) ) { |
218 | 220 | return call_user_func_array( $this->mRevisionCallback, |
219 | 221 | array( $revision, $this ) ); |
— | — | @@ -221,7 +223,11 @@ |
222 | 224 | } |
223 | 225 | } |
224 | 226 | |
225 | | - function logItemCallback( $revision ) { |
| 227 | + /** |
| 228 | + * Notify the callback function of a new log item |
| 229 | + * @param $revision A WikiRevision object |
| 230 | + */ |
| 231 | + private function logItemCallback( $revision ) { |
226 | 232 | if ( is_callable( $this->mLogItemCallback ) ) { |
227 | 233 | return call_user_func_array( $this->mLogItemCallback, |
228 | 234 | array( $revision, $this ) ); |
— | — | @@ -237,7 +243,7 @@ |
238 | 244 | * @return string |
239 | 245 | * @access private |
240 | 246 | */ |
241 | | - function nodeContents() { |
| 247 | + private function nodeContents() { |
242 | 248 | if( $this->reader->isEmptyElement ) { |
243 | 249 | return ""; |
244 | 250 | } |
— | — | @@ -257,7 +263,8 @@ |
258 | 264 | |
259 | 265 | # -------------- |
260 | 266 | |
261 | | - function dumpElement() { |
| 267 | + /** Left in for debugging */ |
| 268 | + private function dumpElement() { |
262 | 269 | static $lookup = null; |
263 | 270 | if (!$lookup) { |
264 | 271 | $xmlReaderConstants = array( |
— | — | @@ -294,7 +301,10 @@ |
295 | 302 | )."\n\n" ); |
296 | 303 | } |
297 | 304 | |
298 | | - function doImport() { |
| 305 | + /** |
| 306 | + * Primary entry point |
| 307 | + */ |
| 308 | + public function doImport() { |
299 | 309 | $this->reader->read(); |
300 | 310 | |
301 | 311 | if ( $this->reader->name != 'mediawiki' ) { |
— | — | @@ -339,7 +349,7 @@ |
340 | 350 | return true; |
341 | 351 | } |
342 | 352 | |
343 | | - function handleSiteInfo() { |
| 353 | + private function handleSiteInfo() { |
344 | 354 | // Site info is useful, but not actually used for dump imports. |
345 | 355 | // Includes a quick short-circuit to save performance. |
346 | 356 | if ( ! $this->mSiteInfoCallback ) { |
— | — | @@ -349,7 +359,7 @@ |
350 | 360 | throw new MWException( "SiteInfo tag is not yet handled, do not set mSiteInfoCallback" ); |
351 | 361 | } |
352 | 362 | |
353 | | - function handleLogItem() { |
| 363 | + private function handleLogItem() { |
354 | 364 | $this->debug( "Enter log item handler." ); |
355 | 365 | $logInfo = array(); |
356 | 366 | |
— | — | @@ -380,7 +390,7 @@ |
381 | 391 | $this->processLogItem( $logInfo ); |
382 | 392 | } |
383 | 393 | |
384 | | - function processLogItem( $logInfo ) { |
| 394 | + private function processLogItem( $logInfo ) { |
385 | 395 | $revision = new WikiRevision; |
386 | 396 | |
387 | 397 | $revision->setID( $logInfo['id'] ); |
— | — | @@ -404,7 +414,7 @@ |
405 | 415 | return $this->logItemCallback( $revision ); |
406 | 416 | } |
407 | 417 | |
408 | | - function handlePage() { |
| 418 | + private function handlePage() { |
409 | 419 | // Handle page data. |
410 | 420 | $this->debug( "Enter page handler." ); |
411 | 421 | $pageInfo = array( 'revisionCount' => 0, 'successfulRevisionCount' => 0 ); |
— | — | @@ -457,7 +467,7 @@ |
458 | 468 | $pageInfo['successfulRevisionCount'] ); |
459 | 469 | } |
460 | 470 | |
461 | | - function handleRevision( &$pageInfo ) { |
| 471 | + private function handleRevision( &$pageInfo ) { |
462 | 472 | $this->debug( "Enter revision handler" ); |
463 | 473 | $revisionInfo = array(); |
464 | 474 | |
— | — | @@ -492,7 +502,7 @@ |
493 | 503 | } |
494 | 504 | } |
495 | 505 | |
496 | | - function processRevision( $pageInfo, $revisionInfo ) { |
| 506 | + private function processRevision( $pageInfo, $revisionInfo ) { |
497 | 507 | $revision = new WikiRevision; |
498 | 508 | |
499 | 509 | $revision->setID( $revisionInfo['id'] ); |
— | — | @@ -517,7 +527,7 @@ |
518 | 528 | return $this->revisionCallback( $revision ); |
519 | 529 | } |
520 | 530 | |
521 | | - function handleUpload( &$pageInfo ) { |
| 531 | + private function handleUpload( &$pageInfo ) { |
522 | 532 | $this->debug( "Enter upload handler" ); |
523 | 533 | $uploadInfo = array(); |
524 | 534 | |
— | — | @@ -550,7 +560,7 @@ |
551 | 561 | return $this->processUpload( $pageInfo, $uploadInfo ); |
552 | 562 | } |
553 | 563 | |
554 | | - function processUpload( $pageInfo, $uploadInfo ) { |
| 564 | + private function processUpload( $pageInfo, $uploadInfo ) { |
555 | 565 | $revision = new WikiRevision; |
556 | 566 | |
557 | 567 | $revision->setTitle( $pageInfo['_title'] ); |
— | — | @@ -572,7 +582,7 @@ |
573 | 583 | return $this->uploadCallback( $revision ); |
574 | 584 | } |
575 | 585 | |
576 | | - function handleContributor() { |
| 586 | + private function handleContributor() { |
577 | 587 | $fields = array( 'id', 'ip', 'username' ); |
578 | 588 | $info = array(); |
579 | 589 | |
— | — | @@ -592,7 +602,7 @@ |
593 | 603 | return $info; |
594 | 604 | } |
595 | 605 | |
596 | | - function processTitle( $text ) { |
| 606 | + private function processTitle( $text ) { |
597 | 607 | $workTitle = $text; |
598 | 608 | $origTitle = Title::newFromText( $workTitle ); |
599 | 609 | $title = null; |
— | — | @@ -616,6 +626,7 @@ |
617 | 627 | } |
618 | 628 | } |
619 | 629 | |
| 630 | +/** This is a horrible hack used to keep source compatibility */ |
620 | 631 | class UploadSourceAdapter { |
621 | 632 | static $sourceRegistrations = array(); |
622 | 633 | |
Index: trunk/phase3/includes/specials/SpecialImport.php |
— | — | @@ -107,7 +107,7 @@ |
108 | 108 | } else { |
109 | 109 | $wgOut->addWikiMsg( "importstart" ); |
110 | 110 | |
111 | | - $importer = new ImportXMLReader( $source ); |
| 111 | + $importer = new WikiImporter( $source ); |
112 | 112 | if( !is_null( $this->namespace ) ) { |
113 | 113 | $importer->setTargetNamespace( $this->namespace ); |
114 | 114 | } |