54 $this->infiles = explode(
';', $infile );
55 $this->reader =
new XMLReader();
56 $infile = array_shift( $this->infiles );
57 $this->reader->open( $infile,
null, LIBXML_PARSEHUGE );
70 public function prefetch( $page, $rev, $slot = SlotRecord::MAIN ) {
71 $page = intval( $page );
72 $rev = intval( $rev );
73 while ( $this->lastPage < $page && !$this->atEnd ) {
74 $this->
debug(
"BaseDump::prefetch at page $this->lastPage, looking for $page" );
77 if ( $this->lastPage > $page || $this->atEnd ) {
78 $this->
debug(
"BaseDump::prefetch already past page $page "
79 .
"looking for rev $rev [$this->lastPage, $this->lastRev]" );
83 while ( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) {
84 $this->
debug(
"BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, "
85 .
"looking for $page, $rev" );
88 if ( $this->lastRev == $rev && !$this->atEnd ) {
89 $this->
debug(
"BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
91 if ( $slot !== SlotRecord::MAIN ) {
92 $lastSlot = SlotRecord::MAIN;
93 while ( $lastSlot !== $slot ) {
94 if ( !$this->
skipTo(
'content',
'revision' ) ) {
97 if ( !$this->
skipTo(
'role',
'revision' ) ) {
106 $this->
debug(
"BaseDump::prefetch already past rev $rev on page $page "
107 .
"[$this->lastPage, $this->lastRev]" );
120 if ( $this->
skipTo(
'page',
'mediawiki' ) ) {
121 if ( $this->
skipTo(
'id' ) ) {
124 $this->atPageEnd =
false;
128 if ( count( $this->infiles ) ) {
129 $infile = array_shift( $this->infiles );
130 $this->reader->open( $infile,
null, LIBXML_PARSEHUGE );
131 $this->atEnd =
false;
137 if ( $this->
skipTo(
'revision' ) ) {
138 if ( $this->
skipTo(
'id' ) ) {
142 $this->atPageEnd =
true;
150 if ( !$this->
skipTo(
'text',
'revision' ) ) {
162 private function skipTo( $name, $parent =
'page' ) {
163 if ( $this->atEnd ) {
166 while ( $this->reader->read() ) {
167 if ( $this->reader->nodeType == XMLReader::ELEMENT
168 && $this->reader->name == $name
172 if ( $this->reader->nodeType == XMLReader::END_ELEMENT
173 && $this->reader->name == $parent
175 $this->
debug(
"BaseDump::skipTo found </$parent> searching for <$name>" );
181 return $this->
close();
192 if ( $this->atEnd ) {
195 if ( $this->reader->isEmptyElement ) {
199 while ( $this->reader->read() ) {
200 switch ( $this->reader->nodeType ) {
201 case XMLReader::TEXT:
203 case XMLReader::SIGNIFICANT_WHITESPACE:
204 $buffer .= $this->reader->value;
206 case XMLReader::END_ELEMENT:
211 return $this->
close();
218 $this->reader->close();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
nodeContents()
Shouldn't something like this be built-in to XMLReader? Fetches text contents of the current element,...
skipTo( $name, $parent='page')
prefetch( $page, $rev, $slot=SlotRecord::MAIN)
Attempts to fetch the text of a particular page revision from the dump stream.