MediaWiki REL1_31
WikiImporter Class Reference

XML file reader for the page data importer. More...

Collaboration diagram for WikiImporter:

Public Member Functions

 __construct (ImportSource $source, Config $config)
 Creates an ImportXMLReader drawing from the source provided.
 
 beforeImportPage ( $titleAndForeignTitle)
 Default per-page callback.
 
 debug ( $data)
 
 debugRevisionHandler (&$revision)
 Alternate per-revision callback, for debugging.
 
 disableStatisticsUpdate ()
 Statistics update can cause a lot of time.
 
 doImport ()
 Primary entry point.
 
 finishImportPage ( $title, $foreignTitle, $revCount, $sRevCount, $pageInfo)
 Mostly for hook use.
 
 getReader ()
 
 importLogItem ( $revision)
 Default per-revision callback, performs the import.
 
 importRevision ( $revision)
 Default per-revision callback, performs the import.
 
 importUpload ( $revision)
 Dummy for now...
 
 nodeAttribute ( $attr)
 Retrieves the contents of the named attribute of the current element.
 
 nodeContents ()
 Shouldn't something like this be built-in to XMLReader? Fetches text contents of the current element, assuming no sub-elements or such scary things.
 
 notice ( $msg)
 
 pageCallback ( $title)
 Notify the callback function when a new "<page>" is reached.
 
 setDebug ( $debug)
 Set debug mode...
 
 setImageBasePath ( $dir)
 
 setImportTitleFactory ( $factory)
 Sets the factory object to use to convert ForeignTitle objects into local Title objects.
 
 setImportUploads ( $import)
 
 setLogItemCallback ( $callback)
 Sets the action to perform as each log item reached.
 
 setNoticeCallback ( $callback)
 Set a callback that displays notice messages.
 
 setNoUpdates ( $noupdates)
 Set 'no updates' mode.
 
 setPageCallback ( $callback)
 Sets the action to perform as each new page in the stream is reached.
 
 setPageOffset ( $nthPage)
 Sets 'pageOffset' value.
 
 setPageOutCallback ( $callback)
 Sets the action to perform as each page in the stream is completed.
 
 setRevisionCallback ( $callback)
 Sets the action to perform as each page revision is reached.
 
 setSiteInfoCallback ( $callback)
 Sets the action to perform when site info is encountered.
 
 setTargetNamespace ( $namespace)
 Set a target namespace to override the defaults.
 
 setTargetRootPage ( $rootpage)
 Set a target root page under which all pages are imported.
 
 setUploadCallback ( $callback)
 Sets the action to perform as each file upload version is reached.
 
 setUsernamePrefix ( $usernamePrefix, $assignKnownUsers)
 
 throwXmlError ( $err)
 
 warn ( $data)
 

Private Member Functions

 dumpTemp ( $contents)
 
 handleContributor ()
 
 handleLogItem ()
 
 handlePage ()
 
 handleRevision (&$pageInfo)
 
 handleSiteInfo ()
 
 handleUpload (&$pageInfo)
 
 logItemCallback ( $revision)
 Notify the callback function of a new log item.
 
 pageOutCallback ( $title, $foreignTitle, $revCount, $sucCount, $pageInfo)
 Notify the callback function when a "</page>" is closed.
 
 processLogItem ( $logInfo)
 
 processRevision ( $pageInfo, $revisionInfo)
 
 processTitle ( $text, $ns=null)
 
 processUpload ( $pageInfo, $uploadInfo)
 
 revisionCallback ( $revision)
 Notify the callback function of a revision.
 
 siteInfoCallback ( $siteInfo)
 Notify the callback function of site info.
 

Private Attributes

Config $config
 
array $countableCache = []
 
bool $disableStatisticsUpdate = false
 
ExternalUserNames $externalUserNames
 
 $foreignNamespaces = null
 
ImportTitleFactory $importTitleFactory
 
 $mDebug
 
 $mImageBasePath
 
 $mImportUploads
 
 $mLogItemCallback
 
 $mNoticeCallback
 
 $mNoUpdates = false
 
 $mPageCallback
 
 $mPageOutCallback
 
 $mRevisionCallback
 
 $mSiteInfoCallback
 
 $mUploadCallback
 
 $pageOffset = 0
 
 $reader = null
 

Detailed Description

XML file reader for the page data importer.

implements Special:Import

Definition at line 33 of file WikiImporter.php.

Constructor & Destructor Documentation

◆ __construct()

WikiImporter::__construct ( ImportSource $source,
Config $config )

Creates an ImportXMLReader drawing from the source provided.

Parameters
ImportSource$source
Config$config
Exceptions
Exception

Definition at line 59 of file WikiImporter.php.

References $config, $source, UploadSourceAdapter\registerSource(), setLogItemCallback(), setPageCallback(), setPageOutCallback(), setRevisionCallback(), and setUploadCallback().

Member Function Documentation

◆ beforeImportPage()

WikiImporter::beforeImportPage ( $titleAndForeignTitle)

Default per-page callback.

Sets up some things related to site statistics

Parameters
array$titleAndForeignTitleTwo-element array, with Title object at index 0 and ForeignTitle object at index 1
Returns
bool

Definition at line 342 of file WikiImporter.php.

◆ debug()

WikiImporter::debug ( $data)

◆ debugRevisionHandler()

WikiImporter::debugRevisionHandler ( & $revision)

Alternate per-revision callback, for debugging.

Parameters
WikiRevision&$revision

Definition at line 442 of file WikiImporter.php.

References debug().

◆ disableStatisticsUpdate()

WikiImporter::disableStatisticsUpdate ( )

Statistics update can cause a lot of time.

Since
1.29

Definition at line 332 of file WikiImporter.php.

References disableStatisticsUpdate().

Referenced by disableStatisticsUpdate(), and finishImportPage().

◆ doImport()

WikiImporter::doImport ( )

Primary entry point.

Exceptions
Exception
MWException
Returns
bool

Definition at line 567 of file WikiImporter.php.

References $type, debug(), handleLogItem(), handlePage(), handleSiteInfo(), and warn().

◆ dumpTemp()

WikiImporter::dumpTemp ( $contents)
private
Parameters
string$contents
Returns
string

Definition at line 1005 of file WikiImporter.php.

References wfTempDir().

Referenced by handleUpload().

◆ finishImportPage()

WikiImporter::finishImportPage ( $title,
$foreignTitle,
$revCount,
$sRevCount,
$pageInfo )

Mostly for hook use.

Parameters
Title$title
ForeignTitle$foreignTitle
int$revCount
int$sRevCount
array$pageInfo
Returns
bool

Definition at line 405 of file WikiImporter.php.

References $args, disableStatisticsUpdate(), SiteStatsUpdate\factory(), and wfDebug().

◆ getReader()

WikiImporter::getReader ( )
Returns
null|XMLReader

Definition at line 102 of file WikiImporter.php.

References $reader.

◆ handleContributor()

WikiImporter::handleContributor ( )
private
Returns
array

Definition at line 1055 of file WikiImporter.php.

References nodeContents().

Referenced by handleLogItem(), handleRevision(), and handleUpload().

◆ handleLogItem()

WikiImporter::handleLogItem ( )
private

Definition at line 667 of file WikiImporter.php.

References debug(), handleContributor(), nodeContents(), processLogItem(), and warn().

Referenced by doImport().

◆ handlePage()

WikiImporter::handlePage ( )
private

◆ handleRevision()

WikiImporter::handleRevision ( & $pageInfo)
private
Parameters
array$pageInfo

Definition at line 828 of file WikiImporter.php.

References debug(), handleContributor(), nodeContents(), processRevision(), and warn().

Referenced by handlePage().

◆ handleSiteInfo()

WikiImporter::handleSiteInfo ( )
private

Definition at line 640 of file WikiImporter.php.

References $foreignNamespaces, debug(), nodeAttribute(), nodeContents(), and siteInfoCallback().

Referenced by doImport().

◆ handleUpload()

WikiImporter::handleUpload ( & $pageInfo)
private
Parameters
array$pageInfo
Returns
mixed

Definition at line 950 of file WikiImporter.php.

References $path, debug(), dumpTemp(), handleContributor(), nodeContents(), processUpload(), and warn().

Referenced by handlePage().

◆ importLogItem()

WikiImporter::importLogItem ( $revision)

Default per-revision callback, performs the import.

Parameters
WikiRevision$revision
Returns
bool

Definition at line 383 of file WikiImporter.php.

◆ importRevision()

WikiImporter::importRevision ( $revision)

Default per-revision callback, performs the import.

Parameters
WikiRevision$revision
Returns
bool

Definition at line 354 of file WikiImporter.php.

References notice().

◆ importUpload()

WikiImporter::importUpload ( $revision)

Dummy for now...

Parameters
WikiRevision$revision
Returns
bool

Definition at line 392 of file WikiImporter.php.

◆ logItemCallback()

WikiImporter::logItemCallback ( $revision)
private

Notify the callback function of a new log item.

Parameters
WikiRevision$revision
Returns
bool|mixed

Definition at line 514 of file WikiImporter.php.

Referenced by processLogItem().

◆ nodeAttribute()

WikiImporter::nodeAttribute ( $attr)

Retrieves the contents of the named attribute of the current element.

Parameters
string$attrThe name of the attribute
Returns
string The value of the attribute or an empty string if it is not set in the current element.

Definition at line 529 of file WikiImporter.php.

Referenced by handlePage(), and handleSiteInfo().

◆ nodeContents()

WikiImporter::nodeContents ( )

Shouldn't something like this be built-in to XMLReader? Fetches text contents of the current element, assuming no sub-elements or such scary things.

Returns
string
Access:\n private

Definition at line 540 of file WikiImporter.php.

References $buffer.

Referenced by handleContributor(), handleLogItem(), handlePage(), handleRevision(), handleSiteInfo(), and handleUpload().

◆ notice()

WikiImporter::notice ( $msg)

Definition at line 121 of file WikiImporter.php.

References $params, text, wfDebug(), and wfMessage().

Referenced by importRevision(), and processTitle().

◆ pageCallback()

WikiImporter::pageCallback ( $title)

Notify the callback function when a new "<page>" is reached.

Parameters
Title$title

Definition at line 473 of file WikiImporter.php.

Referenced by handlePage().

◆ pageOutCallback()

WikiImporter::pageOutCallback ( $title,
$foreignTitle,
$revCount,
$sucCount,
$pageInfo )
private

Notify the callback function when a "</page>" is closed.

Parameters
Title$title
ForeignTitle$foreignTitle
int$revCount
int$sucCountNumber of revisions for which callback returned true
array$pageInfoAssociative array of page information

Definition at line 487 of file WikiImporter.php.

References $args.

Referenced by handlePage().

◆ processLogItem()

WikiImporter::processLogItem ( $logInfo)
private
Parameters
array$logInfo
Returns
bool|mixed

Definition at line 703 of file WikiImporter.php.

References logItemCallback().

Referenced by handleLogItem().

◆ processRevision()

WikiImporter::processRevision ( $pageInfo,
$revisionInfo )
private
Parameters
array$pageInfo
array$revisionInfo
Exceptions
MWException
Returns
bool|mixed

Definition at line 870 of file WikiImporter.php.

References $handler, $wgMaxArticleSize, revisionCallback(), and wfTimestampNow().

Referenced by handleRevision().

◆ processTitle()

WikiImporter::processTitle ( $text,
$ns = null )
private
Parameters
string$text
string | null$ns
Returns
array|bool

Definition at line 1083 of file WikiImporter.php.

References $title, and notice().

Referenced by handlePage().

◆ processUpload()

WikiImporter::processUpload ( $pageInfo,
$uploadInfo )
private
Parameters
array$pageInfo
array$uploadInfo
Returns
mixed

Definition at line 1016 of file WikiImporter.php.

Referenced by handleUpload().

◆ revisionCallback()

WikiImporter::revisionCallback ( $revision)
private

Notify the callback function of a revision.

Parameters
WikiRevision$revision
Returns
bool|mixed

Definition at line 500 of file WikiImporter.php.

Referenced by processRevision().

◆ setDebug()

WikiImporter::setDebug ( $debug)

Set debug mode...

Parameters
bool$debug

Definition at line 138 of file WikiImporter.php.

References $debug.

◆ setImageBasePath()

WikiImporter::setImageBasePath ( $dir)
Parameters
string$dir

Definition at line 308 of file WikiImporter.php.

◆ setImportTitleFactory()

WikiImporter::setImportTitleFactory ( $factory)

Sets the factory object to use to convert ForeignTitle objects into local Title objects.

Parameters
ImportTitleFactory$factory

Definition at line 245 of file WikiImporter.php.

Referenced by setTargetNamespace(), and setTargetRootPage().

◆ setImportUploads()

WikiImporter::setImportUploads ( $import)
Parameters
bool$import

Definition at line 315 of file WikiImporter.php.

◆ setLogItemCallback()

WikiImporter::setLogItemCallback ( $callback)

Sets the action to perform as each log item reached.

Parameters
callable$callback
Returns
callable

Definition at line 223 of file WikiImporter.php.

References $mLogItemCallback.

Referenced by __construct().

◆ setNoticeCallback()

WikiImporter::setNoticeCallback ( $callback)

Set a callback that displays notice messages.

Parameters
callable$callback
Returns
callable

Definition at line 166 of file WikiImporter.php.

References wfSetVar().

◆ setNoUpdates()

WikiImporter::setNoUpdates ( $noupdates)

Set 'no updates' mode.

In this mode, the link tables will not be updated by the importer

Parameters
bool$noupdates

Definition at line 146 of file WikiImporter.php.

◆ setPageCallback()

WikiImporter::setPageCallback ( $callback)

Sets the action to perform as each new page in the stream is reached.

Parameters
callable$callback
Returns
callable

Definition at line 175 of file WikiImporter.php.

References $mPageCallback.

Referenced by __construct().

◆ setPageOffset()

WikiImporter::setPageOffset ( $nthPage)

Sets 'pageOffset' value.

So it will skip the first n-1 pages and start from the nth page. It's 1-based indexing.

Parameters
int$nthPage
Since
1.29

Definition at line 156 of file WikiImporter.php.

◆ setPageOutCallback()

WikiImporter::setPageOutCallback ( $callback)

Sets the action to perform as each page in the stream is completed.

Callback accepts the page title (as a Title object), a second object with the original title form (in case it's been overridden into a local namespace), and a count of revisions.

Parameters
callable$callback
Returns
callable

Definition at line 190 of file WikiImporter.php.

References $mPageOutCallback.

Referenced by __construct().

◆ setRevisionCallback()

WikiImporter::setRevisionCallback ( $callback)

Sets the action to perform as each page revision is reached.

Parameters
callable$callback
Returns
callable

Definition at line 201 of file WikiImporter.php.

References $mRevisionCallback.

Referenced by __construct().

◆ setSiteInfoCallback()

WikiImporter::setSiteInfoCallback ( $callback)

Sets the action to perform when site info is encountered.

Parameters
callable$callback
Returns
callable

Definition at line 234 of file WikiImporter.php.

References $mSiteInfoCallback.

◆ setTargetNamespace()

WikiImporter::setTargetNamespace ( $namespace)

Set a target namespace to override the defaults.

Parameters
null | int$namespace
Returns
bool

Definition at line 254 of file WikiImporter.php.

References setImportTitleFactory().

Referenced by setTargetRootPage().

◆ setTargetRootPage()

WikiImporter::setTargetRootPage ( $rootpage)

Set a target root page under which all pages are imported.

Parameters
null | string$rootpage
Returns
Status

Definition at line 276 of file WikiImporter.php.

References $wgContLang, NS_MAIN, setImportTitleFactory(), setTargetNamespace(), and wfMessage().

◆ setUploadCallback()

WikiImporter::setUploadCallback ( $callback)

Sets the action to perform as each file upload version is reached.

Parameters
callable$callback
Returns
callable

Definition at line 212 of file WikiImporter.php.

References $mUploadCallback.

Referenced by __construct().

◆ setUsernamePrefix()

WikiImporter::setUsernamePrefix ( $usernamePrefix,
$assignKnownUsers )
Since
1.31
Parameters
string$usernamePrefixPrefix to apply to unknown (and possibly also known) usernames
bool$assignKnownUsersWhether to apply the prefix to usernames that exist locally

Definition at line 324 of file WikiImporter.php.

◆ siteInfoCallback()

WikiImporter::siteInfoCallback ( $siteInfo)
private

Notify the callback function of site info.

Parameters
array$siteInfo
Returns
bool|mixed

Definition at line 460 of file WikiImporter.php.

Referenced by handleSiteInfo().

◆ throwXmlError()

WikiImporter::throwXmlError ( $err)

Definition at line 106 of file WikiImporter.php.

References debug(), and wfDebug().

◆ warn()

WikiImporter::warn ( $data)

Definition at line 117 of file WikiImporter.php.

References wfDebug().

Referenced by doImport(), handleLogItem(), handlePage(), handleRevision(), and handleUpload().

Member Data Documentation

◆ $config

Config WikiImporter::$config
private

Definition at line 43 of file WikiImporter.php.

Referenced by __construct().

◆ $countableCache

array WikiImporter::$countableCache = []
private

Definition at line 47 of file WikiImporter.php.

◆ $disableStatisticsUpdate

bool WikiImporter::$disableStatisticsUpdate = false
private

Definition at line 49 of file WikiImporter.php.

◆ $externalUserNames

ExternalUserNames WikiImporter::$externalUserNames
private

Definition at line 51 of file WikiImporter.php.

◆ $foreignNamespaces

WikiImporter::$foreignNamespaces = null
private

Definition at line 35 of file WikiImporter.php.

Referenced by handleSiteInfo().

◆ $importTitleFactory

ImportTitleFactory WikiImporter::$importTitleFactory
private

Definition at line 45 of file WikiImporter.php.

◆ $mDebug

WikiImporter::$mDebug
private

Definition at line 38 of file WikiImporter.php.

◆ $mImageBasePath

WikiImporter::$mImageBasePath
private

Definition at line 39 of file WikiImporter.php.

◆ $mImportUploads

WikiImporter::$mImportUploads
private

Definition at line 39 of file WikiImporter.php.

◆ $mLogItemCallback

WikiImporter::$mLogItemCallback
private

Definition at line 36 of file WikiImporter.php.

Referenced by setLogItemCallback().

◆ $mNoticeCallback

WikiImporter::$mNoticeCallback
private

Definition at line 38 of file WikiImporter.php.

◆ $mNoUpdates

WikiImporter::$mNoUpdates = false
private

Definition at line 40 of file WikiImporter.php.

◆ $mPageCallback

WikiImporter::$mPageCallback
private

Definition at line 36 of file WikiImporter.php.

Referenced by setPageCallback().

◆ $mPageOutCallback

WikiImporter::$mPageOutCallback
private

Definition at line 37 of file WikiImporter.php.

Referenced by setPageOutCallback().

◆ $mRevisionCallback

WikiImporter::$mRevisionCallback
private

Definition at line 36 of file WikiImporter.php.

Referenced by setRevisionCallback().

◆ $mSiteInfoCallback

WikiImporter::$mSiteInfoCallback
private

Definition at line 37 of file WikiImporter.php.

Referenced by setSiteInfoCallback().

◆ $mUploadCallback

WikiImporter::$mUploadCallback
private

Definition at line 36 of file WikiImporter.php.

Referenced by setUploadCallback().

◆ $pageOffset

WikiImporter::$pageOffset = 0
private

Definition at line 41 of file WikiImporter.php.

◆ $reader

WikiImporter::$reader = null
private

Definition at line 34 of file WikiImporter.php.

Referenced by getReader().


The documentation for this class was generated from the following file: