62 $this->infiles = explode(
';', $infile );
63 $this->reader =
new XMLReader();
64 $infile = array_shift( $this->infiles );
65 if ( !$this->reader->open( $infile,
null, LIBXML_PARSEHUGE ) ) {
66 $this->
debug( __METHOD__ .
' was unable to open xml' );
81 public function prefetch( $page, $rev, $slot = SlotRecord::MAIN ) {
82 $page = intval( $page );
83 $rev = intval( $rev );
84 while ( $this->lastPage < $page && !$this->atEnd ) {
85 $this->
debug(
"BaseDump::prefetch at page $this->lastPage, looking for $page" );
88 if ( $this->lastPage > $page || $this->atEnd ) {
89 $this->
debug(
"BaseDump::prefetch already past page $page or failed to open/read input file, "
90 .
"looking for rev $rev [$this->lastPage, $this->lastRev]" );
94 while ( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) {
95 $this->
debug(
"BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, "
96 .
"looking for $page, $rev" );
99 if ( $this->lastRev == $rev && !$this->atEnd ) {
100 $this->
debug(
"BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
102 if ( $slot !== SlotRecord::MAIN ) {
103 $lastSlot = SlotRecord::MAIN;
104 while ( $lastSlot !== $slot ) {
105 if ( !$this->skipTo(
'content',
'revision' ) ||
106 !$this->skipTo(
'role',
'revision' )
110 $lastSlot = $this->nodeContents();
114 return $this->nextText();
116 $this->
debug(
"BaseDump::prefetch already past rev $rev on page $page "
117 .
"[$this->lastPage, $this->lastRev]" );
132 private function nextPage() {
133 if ( $this->skipTo(
'page',
'mediawiki' ) ) {
134 if ( $this->skipTo(
'id' ) ) {
135 $this->lastPage = intval( $this->nodeContents() );
137 $this->atPageEnd =
false;
141 if ( count( $this->infiles ) ) {
142 $infile = array_shift( $this->infiles );
143 if ( !$this->reader->open( $infile,
null, LIBXML_PARSEHUGE ) ) {
144 $this->
debug( __METHOD__ .
' was unable to open xml' );
147 $this->atEnd =
false;
153 private function nextRev() {
154 if ( $this->skipTo(
'revision' ) ) {
155 if ( $this->skipTo(
'id' ) ) {
156 $this->lastRev = intval( $this->nodeContents() );
159 $this->atPageEnd =
true;
166 private function nextText() {
167 if ( !$this->skipTo(
'text',
'revision' ) ) {
171 return strval( $this->nodeContents() );
179 private function skipTo( $name, $parent =
'page' ) {
180 if ( $this->atEnd ) {
183 while ( $this->reader->read() ) {
184 if ( $this->reader->nodeType == XMLReader::ELEMENT
185 && $this->reader->name == $name
189 if ( $this->reader->nodeType == XMLReader::END_ELEMENT
190 && $this->reader->name == $parent
192 $this->
debug(
"BaseDump::skipTo found </$parent> searching for <$name>" );
198 return $this->
close();
208 private function nodeContents() {
209 if ( $this->atEnd ) {
212 if ( $this->reader->isEmptyElement ) {
216 while ( $this->reader->read() ) {
217 switch ( $this->reader->nodeType ) {
218 case XMLReader::TEXT:
220 case XMLReader::SIGNIFICANT_WHITESPACE:
221 $buffer .= $this->reader->value;
223 case XMLReader::END_ELEMENT:
228 return $this->
close();
235 $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.