r66268 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66267‎ | r66268 | r66269 >
Date:13:37, 12 May 2010
Author:werdna
Status:ok
Tags:
Comment:
Function accessibility changes, documentation, revert function rename for r66267
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/ImportXMLReader.php (modified) (history)
  • /trunk/phase3/includes/api/ApiImport.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialImport.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiImport.php
@@ -74,7 +74,7 @@
7575 $this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) );
7676 }
7777
78 - $importer = new ImportXMLReader( $source );
 78+ $importer = new WikiImporter( $source );
7979 if ( isset( $params['namespace'] ) ) {
8080 $importer->setTargetNamespace( $params['namespace'] );
8181 }
Index: trunk/phase3/includes/AutoLoader.php
@@ -605,7 +605,7 @@
606606 'WantedPagesPage' => 'includes/specials/SpecialWantedpages.php',
607607 'WantedTemplatesPage' => 'includes/specials/SpecialWantedtemplates.php',
608608 'WhatLinksHerePage' => 'includes/specials/SpecialWhatlinkshere.php',
609 - 'ImportXMLReader' => 'includes/ImportXMLReader.php',
 609+ 'WikiImporter' => 'includes/ImportXMLReader.php',
610610 'WikiRevision' => 'includes/Import.php',
611611 'WithoutInterwikiPage' => 'includes/specials/SpecialWithoutinterwiki.php',
612612
Index: trunk/phase3/includes/ImportXMLReader.php
@@ -3,12 +3,15 @@
44 * implements Special:Import
55 * @ingroup SpecialPage
66 */
7 -class ImportXMLReader {
 7+class WikiImporter {
88 private $reader = null;
99 private $mLogItemCallback, $mUploadCallback, $mRevisionCallback, $mPageCallback;
1010 private $mSiteInfoCallback, $mTargetNamespace, $mPageOutCallback;
1111 private $mDebug;
1212
 13+ /**
 14+ * Creates an ImportXMLReader drawing from the source provided
 15+ */
1316 function __construct( $source ) {
1417 $this->reader = new XMLReader();
1518
@@ -22,22 +25,22 @@
2326 $this->setLogItemCallback( array( $this, 'importLogItem' ) );
2427 }
2528
26 - function throwXmlError( $err ) {
 29+ private function throwXmlError( $err ) {
2730 $this->debug( "FAILURE: $err" );
2831 wfDebug( "WikiImporter XML error: $err\n" );
2932 }
3033
31 - function debug( $data ) {
 34+ private function debug( $data ) {
3235 if( $this->mDebug ) {
3336 wfDebug( "IMPORT: $data\n" );
3437 }
3538 }
3639
37 - function warn( $data ) {
 40+ private function warn( $data ) {
3841 wfDebug( "IMPORT: $data\n" );
3942 }
4043
41 - function notice( $data ) {
 44+ private function notice( $data ) {
4245 global $wgCommandLineMode;
4346 if( $wgCommandLineMode ) {
4447 print "$data\n";
@@ -59,7 +62,7 @@
6063 * @param $callback callback
6164 * @return callback
6265 */
63 - function setPageCallback( $callback ) {
 66+ public function setPageCallback( $callback ) {
6467 $previous = $this->mPageCallback;
6568 $this->mPageCallback = $callback;
6669 return $previous;
@@ -74,7 +77,7 @@
7578 * @param $callback callback
7679 * @return callback
7780 */
78 - function setPageOutCallback( $callback ) {
 81+ public function setPageOutCallback( $callback ) {
7982 $previous = $this->mPageOutCallback;
8083 $this->mPageOutCallback = $callback;
8184 return $previous;
@@ -85,7 +88,7 @@
8689 * @param $callback callback
8790 * @return callback
8891 */
89 - function setRevisionCallback( $callback ) {
 92+ public function setRevisionCallback( $callback ) {
9093 $previous = $this->mRevisionCallback;
9194 $this->mRevisionCallback = $callback;
9295 return $previous;
@@ -96,7 +99,7 @@
97100 * @param $callback callback
98101 * @return callback
99102 */
100 - function setUploadCallback( $callback ) {
 103+ public function setUploadCallback( $callback ) {
101104 $previous = $this->mUploadCallback;
102105 $this->mUploadCallback = $callback;
103106 return $previous;
@@ -107,7 +110,7 @@
108111 * @param $callback callback
109112 * @return callback
110113 */
111 - function setLogItemCallback( $callback ) {
 114+ public function setLogItemCallback( $callback ) {
112115 $previous = $this->mLogItemCallback;
113116 $this->mLogItemCallback = $callback;
114117 return $previous;
@@ -118,7 +121,7 @@
119122 * @param $callback callback
120123 * @return callback
121124 */
122 - function setSiteInfoCallback( $callback ) {
 125+ public function setSiteInfoCallback( $callback ) {
123126 $previous = $this->mSiteInfoCallback;
124127 $this->mSiteInfoCallback = $callback;
125128 return $previous;
@@ -127,7 +130,7 @@
128131 /**
129132 * Set a target namespace to override the defaults
130133 */
131 - function setTargetNamespace( $namespace ) {
 134+ public function setTargetNamespace( $namespace ) {
132135 if( is_null( $namespace ) ) {
133136 // Don't override namespaces
134137 $this->mTargetNamespace = null;
@@ -142,9 +145,8 @@
143146 /**
144147 * Default per-revision callback, performs the import.
145148 * @param $revision WikiRevision
146 - * @private
147149 */
148 - function importRevision( $revision ) {
 150+ public function importRevision( $revision ) {
149151 $dbw = wfGetDB( DB_MASTER );
150152 return $dbw->deadlockLoop( array( $revision, 'importOldRevision' ) );
151153 }
@@ -152,9 +154,8 @@
153155 /**
154156 * Default per-revision callback, performs the import.
155157 * @param $rev WikiRevision
156 - * @private
157158 */
158 - function importLogItem( $rev ) {
 159+ public function importLogItem( $rev ) {
159160 $dbw = wfGetDB( DB_MASTER );
160161 return $dbw->deadlockLoop( array( $rev, 'importLogItem' ) );
161162 }
@@ -162,7 +163,7 @@
163164 /**
164165 * Dummy for now...
165166 */
166 - function importUpload( $revision ) {
 167+ public function importUpload( $revision ) {
167168 //$dbw = wfGetDB( DB_MASTER );
168169 //return $dbw->deadlockLoop( array( $revision, 'importUpload' ) );
169170 return false;
@@ -171,9 +172,8 @@
172173 /**
173174 * Alternate per-revision callback, for debugging.
174175 * @param $revision WikiRevision
175 - * @private
176176 */
177 - function debugRevisionHandler( &$revision ) {
 177+ public function debugRevisionHandler( &$revision ) {
178178 $this->debug( "Got revision:" );
179179 if( is_object( $revision->title ) ) {
180180 $this->debug( "-- Title: " . $revision->title->getPrefixedText() );
@@ -189,7 +189,6 @@
190190 /**
191191 * Notify the callback function when a new <page> is reached.
192192 * @param $title Title
193 - * @private
194193 */
195194 function pageCallback( $title ) {
196195 if( is_callable( $this->mPageCallback ) ) {
@@ -203,16 +202,19 @@
204203 * @param $origTitle Title
205204 * @param $revisionCount int
206205 * @param $successCount Int: number of revisions for which callback returned true
207 - * @private
208206 */
209 - function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) {
 207+ private function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) {
210208 if( is_callable( $this->mPageOutCallback ) ) {
211209 call_user_func_array( $this->mPageOutCallback,
212210 array( $title, $origTitle, $revisionCount, $successCount ) );
213211 }
214212 }
215213
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 ) {
217219 if ( is_callable( $this->mRevisionCallback ) ) {
218220 return call_user_func_array( $this->mRevisionCallback,
219221 array( $revision, $this ) );
@@ -221,7 +223,11 @@
222224 }
223225 }
224226
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 ) {
226232 if ( is_callable( $this->mLogItemCallback ) ) {
227233 return call_user_func_array( $this->mLogItemCallback,
228234 array( $revision, $this ) );
@@ -237,7 +243,7 @@
238244 * @return string
239245 * @access private
240246 */
241 - function nodeContents() {
 247+ private function nodeContents() {
242248 if( $this->reader->isEmptyElement ) {
243249 return "";
244250 }
@@ -257,7 +263,8 @@
258264
259265 # --------------
260266
261 - function dumpElement() {
 267+ /** Left in for debugging */
 268+ private function dumpElement() {
262269 static $lookup = null;
263270 if (!$lookup) {
264271 $xmlReaderConstants = array(
@@ -294,7 +301,10 @@
295302 )."\n\n" );
296303 }
297304
298 - function doImport() {
 305+ /**
 306+ * Primary entry point
 307+ */
 308+ public function doImport() {
299309 $this->reader->read();
300310
301311 if ( $this->reader->name != 'mediawiki' ) {
@@ -339,7 +349,7 @@
340350 return true;
341351 }
342352
343 - function handleSiteInfo() {
 353+ private function handleSiteInfo() {
344354 // Site info is useful, but not actually used for dump imports.
345355 // Includes a quick short-circuit to save performance.
346356 if ( ! $this->mSiteInfoCallback ) {
@@ -349,7 +359,7 @@
350360 throw new MWException( "SiteInfo tag is not yet handled, do not set mSiteInfoCallback" );
351361 }
352362
353 - function handleLogItem() {
 363+ private function handleLogItem() {
354364 $this->debug( "Enter log item handler." );
355365 $logInfo = array();
356366
@@ -380,7 +390,7 @@
381391 $this->processLogItem( $logInfo );
382392 }
383393
384 - function processLogItem( $logInfo ) {
 394+ private function processLogItem( $logInfo ) {
385395 $revision = new WikiRevision;
386396
387397 $revision->setID( $logInfo['id'] );
@@ -404,7 +414,7 @@
405415 return $this->logItemCallback( $revision );
406416 }
407417
408 - function handlePage() {
 418+ private function handlePage() {
409419 // Handle page data.
410420 $this->debug( "Enter page handler." );
411421 $pageInfo = array( 'revisionCount' => 0, 'successfulRevisionCount' => 0 );
@@ -457,7 +467,7 @@
458468 $pageInfo['successfulRevisionCount'] );
459469 }
460470
461 - function handleRevision( &$pageInfo ) {
 471+ private function handleRevision( &$pageInfo ) {
462472 $this->debug( "Enter revision handler" );
463473 $revisionInfo = array();
464474
@@ -492,7 +502,7 @@
493503 }
494504 }
495505
496 - function processRevision( $pageInfo, $revisionInfo ) {
 506+ private function processRevision( $pageInfo, $revisionInfo ) {
497507 $revision = new WikiRevision;
498508
499509 $revision->setID( $revisionInfo['id'] );
@@ -517,7 +527,7 @@
518528 return $this->revisionCallback( $revision );
519529 }
520530
521 - function handleUpload( &$pageInfo ) {
 531+ private function handleUpload( &$pageInfo ) {
522532 $this->debug( "Enter upload handler" );
523533 $uploadInfo = array();
524534
@@ -550,7 +560,7 @@
551561 return $this->processUpload( $pageInfo, $uploadInfo );
552562 }
553563
554 - function processUpload( $pageInfo, $uploadInfo ) {
 564+ private function processUpload( $pageInfo, $uploadInfo ) {
555565 $revision = new WikiRevision;
556566
557567 $revision->setTitle( $pageInfo['_title'] );
@@ -572,7 +582,7 @@
573583 return $this->uploadCallback( $revision );
574584 }
575585
576 - function handleContributor() {
 586+ private function handleContributor() {
577587 $fields = array( 'id', 'ip', 'username' );
578588 $info = array();
579589
@@ -592,7 +602,7 @@
593603 return $info;
594604 }
595605
596 - function processTitle( $text ) {
 606+ private function processTitle( $text ) {
597607 $workTitle = $text;
598608 $origTitle = Title::newFromText( $workTitle );
599609 $title = null;
@@ -616,6 +626,7 @@
617627 }
618628 }
619629
 630+/** This is a horrible hack used to keep source compatibility */
620631 class UploadSourceAdapter {
621632 static $sourceRegistrations = array();
622633
Index: trunk/phase3/includes/specials/SpecialImport.php
@@ -107,7 +107,7 @@
108108 } else {
109109 $wgOut->addWikiMsg( "importstart" );
110110
111 - $importer = new ImportXMLReader( $source );
 111+ $importer = new WikiImporter( $source );
112112 if( !is_null( $this->namespace ) ) {
113113 $importer->setTargetNamespace( $this->namespace );
114114 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r66269Missing commits from r66268, revert class rename in r66267werdna13:38, 12 May 2010
r81238Cleanup for r66268, r66267: merge WikiImporter back into Import.php, where it...tstarling07:07, 31 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66267Rewrite of XML Dump Processing:...werdna13:28, 12 May 2010

Status & tagging log