From: Brion Vibber Date: Wed, 19 Oct 2005 00:05:22 +0000 (+0000) Subject: Test case files and fixes for text-prefetch two-and-a-half-pass dump. X-Git-Tag: 1.6.0~1397 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=189d24ef2d8f835af4d263673eda396783fdfffd;p=lhc%2Fweb%2Fwiklou.git Test case files and fixes for text-prefetch two-and-a-half-pass dump. Will want to test a little more before making another dump. :P --- diff --git a/maintenance/backupPrefetch.inc b/maintenance/backupPrefetch.inc index 759220da04..f40bc89350 100644 --- a/maintenance/backupPrefetch.inc +++ b/maintenance/backupPrefetch.inc @@ -18,6 +18,7 @@ class BaseDump { var $reader = null; var $atEnd = false; + var $atPageEnd = false; var $lastPage = 0; var $lastRev = 0; @@ -36,27 +37,31 @@ class BaseDump { * @return string or null */ function prefetch( $page, $rev ) { + $page = intval( $page ); + $rev = intval( $rev ); while( $this->lastPage < $page && !$this->atEnd ) { + $this->debug( "BaseDump::prefetch at page $this->lastPage, looking for $page" ); $this->nextPage(); } if( $this->lastPage > $page || $this->atEnd ) { - $this->debug( "BaseDump::prefetch already past page $page looking for rev $rev\n" ); + $this->debug( "BaseDump::prefetch already past page $page looking for rev $rev [$this->lastPage, $this->lastRev]" ); return null; } - while( $this->lastRev < $rev && !$this->atEnd ) { + while( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) { + $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, looking for $page, $rev" ); $this->nextRev(); } - if( $this->lastRev == $rev ) { - $this->debug( "BaseDump::prefetch hit on $page, $rev\n" ); + if( $this->lastRev == $rev && !$this->atEnd ) { + $this->debug( "BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" ); return $this->nextText(); } else { - $this->debug( "BaseDump::prefetch already past rev $rev on page $page\n" ); + $this->debug( "BaseDump::prefetch already past rev $rev on page $page [$this->lastPage, $this->lastRev]" ); return null; } } function debug( $str ) { - wfDebug( $str ); + wfDebug( $str . "\n" ); //global $dumper; //$dumper->progress( $str ); } @@ -65,19 +70,28 @@ class BaseDump { * @access private */ function nextPage() { - $this->skipTo( 'page' ); - $this->skipTo( 'id' ); - $this->lastPage = intval( $this->nodeContents() ); - $this->lastRev = 0; + if( $this->skipTo( 'page', 'mediawiki' ) ) { + if( $this->skipTo( 'id' ) ) { + $this->lastPage = intval( $this->nodeContents() ); + $this->lastRev = 0; + $this->atPageEnd = false; + } + } else { + $this->atEnd = true; + } } /** * @access private */ function nextRev() { - $this->skipTo( 'revision' ); - $this->skipTo( 'id' ); - $this->lastRev = intval( $this->nodeContents() ); + if( $this->skipTo( 'revision' ) ) { + if( $this->skipTo( 'id' ) ) { + $this->lastRev = intval( $this->nodeContents() ); + } + } else { + $this->atPageEnd = true; + } } /** @@ -91,7 +105,7 @@ class BaseDump { /** * @access private */ - function skipTo( $name ) { + function skipTo( $name, $parent='page' ) { if( $this->atEnd ) { return false; } @@ -100,6 +114,11 @@ class BaseDump { $this->reader->name == $name ) { return true; } + if( $this->reader->nodeType == XMLREADER_END_ELEMENT && + $this->reader->name == $parent ) { + $this->debug( "BaseDump::skipTo found searching for <$name>" ); + return false; + } } return $this->close(); } @@ -113,7 +132,7 @@ class BaseDump { */ function nodeContents() { if( $this->atEnd ) { - return false; + return null; } if( $this->reader->isEmptyElement ) { return ""; @@ -139,7 +158,7 @@ class BaseDump { function close() { $this->reader->close(); $this->atEnd = true; - return false; + return null; } } diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index ae55ec8f88..235196b43e 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -159,9 +159,11 @@ class TextPassDumper extends BackupDumper { if( $name == 'revision' ) { $this->egress->writeRevision( null, $this->buffer ); $this->buffer = ""; + $this->thisRev = ""; } elseif( $name == 'page' ) { $this->egress->writeClosePage( $this->buffer ); $this->buffer = ""; + $this->thisPage = ""; } elseif( $name == 'mediawiki' ) { $this->egress->writeCloseStream( $this->buffer ); $this->buffer = ""; @@ -172,9 +174,9 @@ class TextPassDumper extends BackupDumper { $this->clearOpenElement( null ); if( $this->lastName == "id" ) { if( $this->state == "revision" ) { - $this->thisRev = intval( $data ); + $this->thisRev .= $data; } elseif( $this->state == "page" ) { - $this->thisPage = intval( $data ); + $this->thisPage .= $data; } } $this->buffer .= htmlspecialchars( $data ); diff --git a/tests/test-prefetch-current.xml b/tests/test-prefetch-current.xml new file mode 100644 index 0000000000..a4c8bda30b --- /dev/null +++ b/tests/test-prefetch-current.xml @@ -0,0 +1,75 @@ + + + DemoWiki + http://example.com/wiki/Main_Page + MediaWiki 1.5.0 + first-letter + + Media + Special + + Talk + User + User talk + DemoWiki + DemoWIki talk + Image + Image talk + MediaWiki + MediaWiki talk + Template + Template talk + Help + Help talk + Category + Category talk + + + + First page + 1 + + 1 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 1 + page 1, rev 1 + + + 2 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 2 + page 1, rev 2 + + + 4 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 4 + page 1, rev 4 + + + + Second page + 2 + + 3 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 2, rev 3 + page 2, rev 3 + + + + Third page + 3 + + 5 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 3, rev 5 + page 3, rev 5 + + + diff --git a/tests/test-prefetch-previous.xml b/tests/test-prefetch-previous.xml new file mode 100644 index 0000000000..95eb82dd4f --- /dev/null +++ b/tests/test-prefetch-previous.xml @@ -0,0 +1,57 @@ + + + DemoWiki + http://example.com/wiki/Main_Page + MediaWiki 1.5.0 + first-letter + + Media + Special + + Talk + User + User talk + DemoWiki + DemoWIki talk + Image + Image talk + MediaWiki + MediaWiki talk + Template + Template talk + Help + Help talk + Category + Category talk + + + + First page + 1 + + 1 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 1 + page 1, rev 1 + + + 2 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 2 + page 1, rev 2 + + + + Second page + 2 + + 3 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 2, rev 3 + page 2, rev 3 + + + diff --git a/tests/test-prefetch-stub.xml b/tests/test-prefetch-stub.xml new file mode 100644 index 0000000000..59d43d2f35 --- /dev/null +++ b/tests/test-prefetch-stub.xml @@ -0,0 +1,75 @@ + + + DemoWiki + http://example.com/wiki/Main_Page + MediaWiki 1.5.0 + first-letter + + Media + Special + + Talk + User + User talk + DemoWiki + DemoWIki talk + Image + Image talk + MediaWiki + MediaWiki talk + Template + Template talk + Help + Help talk + Category + Category talk + + + + First page + 1 + + 1 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 1 + + + + 2 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 2 + + + + 4 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 1, rev 4 + + + + + Second page + 2 + + 3 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 2, rev 3 + + + + + Third page + 3 + + 5 + 2001-01-15T12:00:00Z + 10.0.0.1 + page 3, rev 5 + + + +