51 $this->infiles = explode(
';', $infile );
52 $this->reader =
new XMLReader();
53 $infile = array_shift( $this->infiles );
54 if ( !$this->reader->open( $infile,
null, LIBXML_PARSEHUGE ) ) {
55 $this->
debug( __METHOD__ .
' was unable to open xml' );
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 or failed to open/read input file, "
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' ) ||
95 !$this->skipTo(
'role',
'revision' )
99 $lastSlot = $this->nodeContents();
103 return $this->nextText();
105 $this->
debug(
"BaseDump::prefetch already past rev $rev on page $page "
106 .
"[$this->lastPage, $this->lastRev]" );
121 private function nextPage() {
122 if ( $this->skipTo(
'page',
'mediawiki' ) ) {
123 if ( $this->skipTo(
'id' ) ) {
124 $this->lastPage = intval( $this->nodeContents() );
126 $this->atPageEnd =
false;
130 if ( count( $this->infiles ) ) {
131 $infile = array_shift( $this->infiles );
132 if ( !$this->reader->open( $infile,
null, LIBXML_PARSEHUGE ) ) {
133 $this->
debug( __METHOD__ .
' was unable to open xml' );
136 $this->atEnd =
false;
142 private function nextRev() {
143 if ( $this->skipTo(
'revision' ) ) {
144 if ( $this->skipTo(
'id' ) ) {
145 $this->lastRev = intval( $this->nodeContents() );
148 $this->atPageEnd =
true;
155 private function nextText() {
156 if ( !$this->skipTo(
'text',
'revision' ) ) {
160 return strval( $this->nodeContents() );
168 private function skipTo( $name, $parent =
'page' ) {
169 if ( $this->atEnd ) {
172 while ( $this->reader->read() ) {
173 if ( $this->reader->nodeType == XMLReader::ELEMENT
174 && $this->reader->name == $name
178 if ( $this->reader->nodeType == XMLReader::END_ELEMENT
179 && $this->reader->name == $parent
181 $this->
debug(
"BaseDump::skipTo found </$parent> searching for <$name>" );
187 return $this->
close();
197 private function nodeContents() {
198 if ( $this->atEnd ) {
201 if ( $this->reader->isEmptyElement ) {
205 while ( $this->reader->read() ) {
206 switch ( $this->reader->nodeType ) {
207 case XMLReader::TEXT:
209 case XMLReader::SIGNIFICANT_WHITESPACE:
210 $buffer .= $this->reader->value;
212 case XMLReader::END_ELEMENT:
217 return $this->
close();
224 $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.