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' ) ) {
108 if ( !$this->skipTo(
'role',
'revision' ) ) {
111 $lastSlot = $this->nodeContents();
115 return $this->nextText();
117 $this->
debug(
"BaseDump::prefetch already past rev $rev on page $page "
118 .
"[$this->lastPage, $this->lastRev]" );
133 private function nextPage() {
134 if ( $this->skipTo(
'page',
'mediawiki' ) ) {
135 if ( $this->skipTo(
'id' ) ) {
136 $this->lastPage = intval( $this->nodeContents() );
138 $this->atPageEnd =
false;
142 if ( count( $this->infiles ) ) {
143 $infile = array_shift( $this->infiles );
144 if ( !$this->reader->open( $infile,
null, LIBXML_PARSEHUGE ) ) {
145 $this->
debug( __METHOD__ .
' was unable to open xml' );
148 $this->atEnd =
false;
154 private function nextRev() {
155 if ( $this->skipTo(
'revision' ) ) {
156 if ( $this->skipTo(
'id' ) ) {
157 $this->lastRev = intval( $this->nodeContents() );
160 $this->atPageEnd =
true;
167 private function nextText() {
168 if ( !$this->skipTo(
'text',
'revision' ) ) {
172 return strval( $this->nodeContents() );
180 private function skipTo( $name, $parent =
'page' ) {
181 if ( $this->atEnd ) {
184 while ( $this->reader->read() ) {
185 if ( $this->reader->nodeType == XMLReader::ELEMENT
186 && $this->reader->name == $name
190 if ( $this->reader->nodeType == XMLReader::END_ELEMENT
191 && $this->reader->name == $parent
193 $this->
debug(
"BaseDump::skipTo found </$parent> searching for <$name>" );
199 return $this->
close();
209 private function nodeContents() {
210 if ( $this->atEnd ) {
213 if ( $this->reader->isEmptyElement ) {
217 while ( $this->reader->read() ) {
218 switch ( $this->reader->nodeType ) {
219 case XMLReader::TEXT:
221 case XMLReader::SIGNIFICANT_WHITESPACE:
222 $buffer .= $this->reader->value;
224 case XMLReader::END_ELEMENT:
229 return $this->
close();
236 $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.