MediaWiki  1.23.15
backupPrefetch.inc
Go to the documentation of this file.
1 <?php
42 class BaseDump {
43  var $reader = null;
44  var $atEnd = false;
45  var $atPageEnd = false;
46  var $lastPage = 0;
47  var $lastRev = 0;
48  var $infiles = null;
49 
50  function BaseDump( $infile ) {
51  $this->infiles = explode( ';', $infile );
52  $this->reader = new XMLReader();
53  $infile = array_shift( $this->infiles );
54  if ( defined( 'LIBXML_PARSEHUGE' ) ) {
55  $this->reader->open( $infile, null, LIBXML_PARSEHUGE );
56  }
57  else {
58  $this->reader->open( $infile );
59  }
60  }
61 
71  function prefetch( $page, $rev ) {
72  $page = intval( $page );
73  $rev = intval( $rev );
74  while ( $this->lastPage < $page && !$this->atEnd ) {
75  $this->debug( "BaseDump::prefetch at page $this->lastPage, looking for $page" );
76  $this->nextPage();
77  }
78  if ( $this->lastPage > $page || $this->atEnd ) {
79  $this->debug( "BaseDump::prefetch already past page $page looking for rev $rev [$this->lastPage, $this->lastRev]" );
80  return null;
81  }
82  while ( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) {
83  $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, looking for $page, $rev" );
84  $this->nextRev();
85  }
86  if ( $this->lastRev == $rev && !$this->atEnd ) {
87  $this->debug( "BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
88  return $this->nextText();
89  } else {
90  $this->debug( "BaseDump::prefetch already past rev $rev on page $page [$this->lastPage, $this->lastRev]" );
91  return null;
92  }
93  }
94 
95  function debug( $str ) {
96  wfDebug( $str . "\n" );
97  // global $dumper;
98  // $dumper->progress( $str );
99  }
100 
104  function nextPage() {
105  if ( $this->skipTo( 'page', 'mediawiki' ) ) {
106  if ( $this->skipTo( 'id' ) ) {
107  $this->lastPage = intval( $this->nodeContents() );
108  $this->lastRev = 0;
109  $this->atPageEnd = false;
110  }
111  } else {
112  $this->close();
113  if ( count( $this->infiles ) ) {
114  $infile = array_shift( $this->infiles );
115  $this->reader->open( $infile );
116  $this->atEnd = false;
117  }
118  }
119  }
120 
124  function nextRev() {
125  if ( $this->skipTo( 'revision' ) ) {
126  if ( $this->skipTo( 'id' ) ) {
127  $this->lastRev = intval( $this->nodeContents() );
128  }
129  } else {
130  $this->atPageEnd = true;
131  }
132  }
133 
138  function nextText() {
139  $this->skipTo( 'text' );
140  return strval( $this->nodeContents() );
141  }
142 
149  function skipTo( $name, $parent = 'page' ) {
150  if ( $this->atEnd ) {
151  return false;
152  }
153  while ( $this->reader->read() ) {
154  if ( $this->reader->nodeType == XMLReader::ELEMENT &&
155  $this->reader->name == $name ) {
156  return true;
157  }
158  if ( $this->reader->nodeType == XMLReader::END_ELEMENT &&
159  $this->reader->name == $parent ) {
160  $this->debug( "BaseDump::skipTo found </$parent> searching for <$name>" );
161  return false;
162  }
163  }
164  return $this->close();
165  }
166 
175  function nodeContents() {
176  if ( $this->atEnd ) {
177  return null;
178  }
179  if ( $this->reader->isEmptyElement ) {
180  return "";
181  }
182  $buffer = "";
183  while ( $this->reader->read() ) {
184  switch ( $this->reader->nodeType ) {
185  case XMLReader::TEXT:
186 // case XMLReader::WHITESPACE:
187  case XMLReader::SIGNIFICANT_WHITESPACE:
188  $buffer .= $this->reader->value;
189  break;
190  case XMLReader::END_ELEMENT:
191  return $buffer;
192  }
193  }
194  return $this->close();
195  }
196 
201  function close() {
202  $this->reader->close();
203  $this->atEnd = true;
204  return null;
205  }
206 }
BaseDump
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
Definition: backupPrefetch.inc:42
BaseDump\BaseDump
BaseDump( $infile)
Definition: backupPrefetch.inc:50
BaseDump\nodeContents
nodeContents()
Shouldn't something like this be built-in to XMLReader? Fetches text contents of the current element,...
Definition: backupPrefetch.inc:175
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
BaseDump\skipTo
skipTo( $name, $parent='page')
Definition: backupPrefetch.inc:149
BaseDump\prefetch
prefetch( $page, $rev)
Attempts to fetch the text of a particular page revision from the dump stream.
Definition: backupPrefetch.inc:71
BaseDump\$reader
$reader
Definition: backupPrefetch.inc:43
BaseDump\nextRev
nextRev()
Definition: backupPrefetch.inc:124
BaseDump\$atEnd
$atEnd
Definition: backupPrefetch.inc:44
BaseDump\$infiles
$infiles
Definition: backupPrefetch.inc:48
BaseDump\$lastPage
$lastPage
Definition: backupPrefetch.inc:46
BaseDump\$atPageEnd
$atPageEnd
Definition: backupPrefetch.inc:45
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
BaseDump\$lastRev
$lastRev
Definition: backupPrefetch.inc:47
BaseDump\close
close()
Definition: backupPrefetch.inc:201
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1337
BaseDump\debug
debug( $str)
Definition: backupPrefetch.inc:95
BaseDump\nextPage
nextPage()
Definition: backupPrefetch.inc:104
BaseDump\nextText
nextText()
Definition: backupPrefetch.inc:138