MediaWiki  master
WikiImporter Class Reference

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

Collaboration diagram for WikiImporter:

Public Member Functions

 __construct (ImportSource $source, Config $config, HookContainer $hookContainer, Language $contentLanguage, NamespaceInfo $namespaceInfo, TitleFactory $titleFactory, WikiPageFactory $wikiPageFactory, UploadRevisionImporter $uploadRevisionImporter, PermissionManager $permissionManager, IContentHandlerFactory $contentHandlerFactory, SlotRoleRegistry $slotRoleRegistry)
 Creates an ImportXMLReader drawing from the source provided. More...
 
 beforeImportPage ( $titleAndForeignTitle)
 Default per-page callback. More...
 
 debug ( $data)
 
 disableStatisticsUpdate ()
 Statistics update can cause a lot of time. More...
 
 doImport ()
 Primary entry point. More...
 
 finishImportPage (PageIdentity $pageIdentity, $foreignTitle, $revCount, $sRevCount, $pageInfo)
 Mostly for hook use. More...
 
 getReader ()
 
 importLogItem ( $revision)
 Default per-revision callback, performs the import. More...
 
 importRevision ( $revision)
 Default per-revision callback, performs the import. More...
 
 importUpload ( $revision)
 Dummy for now... More...
 
 nodeAttribute ( $attr)
 Retrieves the contents of the named attribute of the current element. More...
 
 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. More...
 
 notice ( $msg,... $params)
 
 pageCallback ( $title)
 Notify the callback function when a new "<page>" is reached. More...
 
 setDebug ( $debug)
 Set debug mode... More...
 
 setImageBasePath ( $dir)
 
 setImportTitleFactory ( $factory)
 Sets the factory object to use to convert ForeignTitle objects into local Title objects. More...
 
 setImportUploads ( $import)
 
 setLogItemCallback ( $callback)
 Sets the action to perform as each log item reached. More...
 
 setNoticeCallback ( $callback)
 Set a callback that displays notice messages. More...
 
 setNoUpdates ( $noupdates)
 Set 'no updates' mode. More...
 
 setPageCallback ( $callback)
 Sets the action to perform as each new page in the stream is reached. More...
 
 setPageOffset ( $nthPage)
 Sets 'pageOffset' value. More...
 
 setPageOutCallback ( $callback)
 Sets the action to perform as each page in the stream is completed. More...
 
 setRevisionCallback ( $callback)
 Sets the action to perform as each page revision is reached. More...
 
 setSiteInfoCallback ( $callback)
 Sets the action to perform when site info is encountered. More...
 
 setTargetNamespace ( $namespace)
 Set a target namespace to override the defaults. More...
 
 setTargetRootPage ( $rootpage)
 Set a target root page under which all pages are imported. More...
 
 setUploadCallback ( $callback)
 Sets the action to perform as each file upload version is reached. More...
 
 setUsernamePrefix ( $usernamePrefix, $assignKnownUsers)
 
 throwXmlError ( $err)
 
 warn ( $data)
 

Private Member Functions

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

Private Attributes

Config $config
 
IContentHandlerFactory $contentHandlerFactory
 
Language $contentLanguage
 
array $countableCache = []
 
bool $disableStatisticsUpdate = false
 
ExternalUserNames $externalUserNames
 
array null $foreignNamespaces = null
 
HookRunner $hookRunner
 
ImportTitleFactory $importTitleFactory
 
bool null $mDebug
 
string null $mImageBasePath
 
bool null $mImportUploads
 
callable $mLogItemCallback
 
callable null $mNoticeCallback
 
bool $mNoUpdates = false
 
callable null $mPageCallback
 
callable null $mPageOutCallback
 
callable null $mRevisionCallback
 
callable null $mSiteInfoCallback
 
callable $mUploadCallback
 
NamespaceInfo $namespaceInfo
 
int $pageOffset = 0
 
PermissionManager $permissionManager
 
XMLReader $reader
 
SlotRoleRegistry $slotRoleRegistry
 
TitleFactory $titleFactory
 
UploadRevisionImporter $uploadRevisionImporter
 
WikiPageFactory $wikiPageFactory
 

Detailed Description

XML file reader for the page data importer.

implements Special:Import

Definition at line 46 of file WikiImporter.php.

Constructor & Destructor Documentation

◆ __construct()

WikiImporter::__construct ( ImportSource  $source,
Config  $config,
HookContainer  $hookContainer,
Language  $contentLanguage,
NamespaceInfo  $namespaceInfo,
TitleFactory  $titleFactory,
WikiPageFactory  $wikiPageFactory,
UploadRevisionImporter  $uploadRevisionImporter,
PermissionManager  $permissionManager,
IContentHandlerFactory  $contentHandlerFactory,
SlotRoleRegistry  $slotRoleRegistry 
)

Creates an ImportXMLReader drawing from the source provided.

Parameters
ImportSource$source
Config$config
HookContainer$hookContainer
Language$contentLanguage
NamespaceInfo$namespaceInfo
TitleFactory$titleFactory
WikiPageFactory$wikiPageFactory
UploadRevisionImporter$uploadRevisionImporter
PermissionManager$permissionManager
IContentHandlerFactory$contentHandlerFactory
SlotRoleRegistry$slotRoleRegistry
Exceptions
MWException

Definition at line 146 of file WikiImporter.php.

References $config, $contentHandlerFactory, $contentLanguage, $namespaceInfo, $permissionManager, $slotRoleRegistry, $source, $titleFactory, $uploadRevisionImporter, $wikiPageFactory, 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 484 of file WikiImporter.php.

References $title.

◆ debug()

WikiImporter::debug (   $data)

◆ disableStatisticsUpdate()

WikiImporter::disableStatisticsUpdate ( )

Statistics update can cause a lot of time.

Since
1.29

Definition at line 474 of file WikiImporter.php.

Referenced by finishImportPage().

◆ doImport()

WikiImporter::doImport ( )

Primary entry point.

Exceptions
Exception
MWException
Returns
bool

Definition at line 705 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 1201 of file WikiImporter.php.

References wfTempDir().

Referenced by handleUpload().

◆ finishImportPage()

WikiImporter::finishImportPage ( PageIdentity  $pageIdentity,
  $foreignTitle,
  $revCount,
  $sRevCount,
  $pageInfo 
)

Mostly for hook use.

Parameters
PageIdentity$pageIdentity
ForeignTitle$foreignTitle
int$revCount
int$sRevCount
array$pageInfo
Returns
bool

Definition at line 550 of file WikiImporter.php.

References $title, DeferredUpdates\addUpdate(), Title\castFromPageIdentity(), disableStatisticsUpdate(), SiteStatsUpdate\factory(), RequestContext\getMain(), and wfDebug().

◆ getContentHandler()

WikiImporter::getContentHandler (   $model)
private
Parameters
string$model
Returns
ContentHandler

Definition at line 1330 of file WikiImporter.php.

Referenced by makeContent().

◆ getDefaultContentModel()

WikiImporter::getDefaultContentModel (   $title,
  $role 
)
private
Parameters
Title$title
string$role
Returns
string

Definition at line 1340 of file WikiImporter.php.

References $title.

Referenced by makeContent().

◆ getReader()

WikiImporter::getReader ( )
Returns
null|XMLReader

Definition at line 213 of file WikiImporter.php.

References $reader.

◆ handleContent()

WikiImporter::handleContent ( )
private

Definition at line 1012 of file WikiImporter.php.

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

Referenced by handleRevision().

◆ handleContributor()

WikiImporter::handleContributor ( )
private
Returns
array

Definition at line 1254 of file WikiImporter.php.

References debug(), and nodeContents().

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

◆ handleLogItem()

WikiImporter::handleLogItem ( )
private

Definition at line 808 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 972 of file WikiImporter.php.

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

Referenced by handlePage().

◆ handleSiteInfo()

WikiImporter::handleSiteInfo ( )
private

Definition at line 781 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 1148 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 527 of file WikiImporter.php.

◆ importRevision()

WikiImporter::importRevision (   $revision)

Default per-revision callback, performs the import.

Parameters
WikiRevision$revision
Returns
bool

Definition at line 496 of file WikiImporter.php.

References notice().

◆ importUpload()

WikiImporter::importUpload (   $revision)

Dummy for now...

Parameters
WikiRevision$revision
Returns
bool

Definition at line 536 of file WikiImporter.php.

◆ logItemCallback()

WikiImporter::logItemCallback (   $revision)
private

Notify the callback function of a new log item.

Parameters
WikiRevision$revision
Returns
mixed|false

Definition at line 650 of file WikiImporter.php.

Referenced by processLogItem().

◆ makeContent()

WikiImporter::makeContent ( Title  $title,
  $revisionId,
  $contentInfo 
)
private
Parameters
Title$title
int$revisionId
array$contentInfo
Returns
Content
Exceptions
MWException

Definition at line 1051 of file WikiImporter.php.

References getContentHandler(), and getDefaultContentModel().

Referenced by processRevision(), and processUpload().

◆ 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 667 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: internal

Definition at line 678 of file WikiImporter.php.

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

◆ notice()

WikiImporter::notice (   $msg,
  $params 
)
Parameters
string$msg
mixed...$params

Definition at line 245 of file WikiImporter.php.

References wfDebug(), and wfMessage().

Referenced by importRevision(), and processTitle().

◆ pageCallback()

WikiImporter::pageCallback (   $title)

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

Parameters
array$title

Definition at line 608 of file WikiImporter.php.

References $title.

Referenced by handlePage().

◆ pageOutCallback()

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

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

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

Definition at line 622 of file WikiImporter.php.

Referenced by handlePage().

◆ processLogItem()

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

Definition at line 842 of file WikiImporter.php.

References logItemCallback(), and Title\newFromText().

Referenced by handleLogItem().

◆ processRevision()

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

Definition at line 1096 of file WikiImporter.php.

References $content, $title, makeContent(), revisionCallback(), and wfTimestampNow().

Referenced by handleRevision().

◆ processTitle()

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

Definition at line 1285 of file WikiImporter.php.

References $title, RequestContext\getMain(), and notice().

Referenced by handlePage().

◆ processUpload()

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

Definition at line 1212 of file WikiImporter.php.

References $content, $title, and makeContent().

Referenced by handleUpload().

◆ revisionCallback()

WikiImporter::revisionCallback (   $revision)
private

Notify the callback function of a revision.

Parameters
WikiRevision$revision
Returns
bool|mixed

Definition at line 634 of file WikiImporter.php.

Referenced by processRevision().

◆ setDebug()

WikiImporter::setDebug (   $debug)

Set debug mode...

Parameters
bool$debug

Definition at line 259 of file WikiImporter.php.

References $debug.

◆ setImageBasePath()

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

Definition at line 450 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 366 of file WikiImporter.php.

Referenced by setTargetNamespace(), and setTargetRootPage().

◆ setImportUploads()

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

Definition at line 457 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 344 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 287 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 267 of file WikiImporter.php.

◆ setPageCallback()

WikiImporter::setPageCallback (   $callback)

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

Parameters
callable | null$callback
Returns
callable|null

Definition at line 296 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 277 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 | null$callback
Returns
callable|null

Definition at line 311 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 | null$callback
Returns
callable|null

Definition at line 322 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 355 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 375 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 409 of file WikiImporter.php.

References $namespaceInfo, $title, Title\newFromText(), StatusValue\newGood(), 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 333 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 466 of file WikiImporter.php.

◆ siteInfoCallback()

WikiImporter::siteInfoCallback (   $siteInfo)
private

Notify the callback function of site info.

Parameters
array$siteInfo
Returns
mixed|false

Definition at line 593 of file WikiImporter.php.

Referenced by handleSiteInfo().

◆ throwXmlError()

WikiImporter::throwXmlError (   $err)
Parameters
string$err

Definition at line 220 of file WikiImporter.php.

References debug(), and wfDebug().

◆ warn()

WikiImporter::warn (   $data)
Parameters
string$data

Definition at line 237 of file WikiImporter.php.

References wfDebug().

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

Member Data Documentation

◆ $config

Config WikiImporter::$config
private

Definition at line 90 of file WikiImporter.php.

Referenced by __construct().

◆ $contentHandlerFactory

IContentHandlerFactory WikiImporter::$contentHandlerFactory
private

Definition at line 126 of file WikiImporter.php.

Referenced by __construct().

◆ $contentLanguage

Language WikiImporter::$contentLanguage
private

Definition at line 108 of file WikiImporter.php.

Referenced by __construct().

◆ $countableCache

array WikiImporter::$countableCache = []
private

Definition at line 99 of file WikiImporter.php.

◆ $disableStatisticsUpdate

bool WikiImporter::$disableStatisticsUpdate = false
private

Definition at line 102 of file WikiImporter.php.

◆ $externalUserNames

ExternalUserNames WikiImporter::$externalUserNames
private

Definition at line 105 of file WikiImporter.php.

◆ $foreignNamespaces

array null WikiImporter::$foreignNamespaces = null
private

Definition at line 51 of file WikiImporter.php.

Referenced by handleSiteInfo().

◆ $hookRunner

HookRunner WikiImporter::$hookRunner
private

Definition at line 96 of file WikiImporter.php.

◆ $importTitleFactory

ImportTitleFactory WikiImporter::$importTitleFactory
private

Definition at line 93 of file WikiImporter.php.

◆ $mDebug

bool null WikiImporter::$mDebug
private

Definition at line 75 of file WikiImporter.php.

◆ $mImageBasePath

string null WikiImporter::$mImageBasePath
private

Definition at line 81 of file WikiImporter.php.

◆ $mImportUploads

bool null WikiImporter::$mImportUploads
private

Definition at line 78 of file WikiImporter.php.

◆ $mLogItemCallback

callable WikiImporter::$mLogItemCallback
private

Definition at line 54 of file WikiImporter.php.

Referenced by setLogItemCallback().

◆ $mNoticeCallback

callable null WikiImporter::$mNoticeCallback
private

Definition at line 72 of file WikiImporter.php.

◆ $mNoUpdates

bool WikiImporter::$mNoUpdates = false
private

Definition at line 84 of file WikiImporter.php.

◆ $mPageCallback

callable null WikiImporter::$mPageCallback
private

Definition at line 63 of file WikiImporter.php.

Referenced by setPageCallback().

◆ $mPageOutCallback

callable null WikiImporter::$mPageOutCallback
private

Definition at line 69 of file WikiImporter.php.

Referenced by setPageOutCallback().

◆ $mRevisionCallback

callable null WikiImporter::$mRevisionCallback
private

Definition at line 60 of file WikiImporter.php.

Referenced by setRevisionCallback().

◆ $mSiteInfoCallback

callable null WikiImporter::$mSiteInfoCallback
private

Definition at line 66 of file WikiImporter.php.

Referenced by setSiteInfoCallback().

◆ $mUploadCallback

callable WikiImporter::$mUploadCallback
private

Definition at line 57 of file WikiImporter.php.

Referenced by setUploadCallback().

◆ $namespaceInfo

NamespaceInfo WikiImporter::$namespaceInfo
private

Definition at line 111 of file WikiImporter.php.

Referenced by __construct(), and setTargetRootPage().

◆ $pageOffset

int WikiImporter::$pageOffset = 0
private

Definition at line 87 of file WikiImporter.php.

◆ $permissionManager

PermissionManager WikiImporter::$permissionManager
private

Definition at line 123 of file WikiImporter.php.

Referenced by __construct().

◆ $reader

XMLReader WikiImporter::$reader
private

Definition at line 48 of file WikiImporter.php.

Referenced by getReader().

◆ $slotRoleRegistry

SlotRoleRegistry WikiImporter::$slotRoleRegistry
private

Definition at line 129 of file WikiImporter.php.

Referenced by __construct().

◆ $titleFactory

TitleFactory WikiImporter::$titleFactory
private

Definition at line 114 of file WikiImporter.php.

Referenced by __construct().

◆ $uploadRevisionImporter

UploadRevisionImporter WikiImporter::$uploadRevisionImporter
private

Definition at line 120 of file WikiImporter.php.

Referenced by __construct().

◆ $wikiPageFactory

WikiPageFactory WikiImporter::$wikiPageFactory
private

Definition at line 117 of file WikiImporter.php.

Referenced by __construct().


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