MediaWiki  1.28.1
backupPrefetch.inc
Go to the documentation of this file.
1 <?php
42 class BaseDump {
43  protected $reader = null;
44  protected $atEnd = false;
45  protected $atPageEnd = false;
46  protected $lastPage = 0;
47  protected $lastRev = 0;
48  protected $infiles = null;
49 
50  public function __construct( $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  } else {
57  $this->reader->open( $infile );
58  }
59  }
60 
70  function prefetch( $page, $rev ) {
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" );
75  $this->nextPage();
76  }
77  if ( $this->lastPage > $page || $this->atEnd ) {
78  $this->debug( "BaseDump::prefetch already past page $page "
79  . "looking for rev $rev [$this->lastPage, $this->lastRev]" );
80 
81  return null;
82  }
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" );
86  $this->nextRev();
87  }
88  if ( $this->lastRev == $rev && !$this->atEnd ) {
89  $this->debug( "BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
90 
91  return $this->nextText();
92  } else {
93  $this->debug( "BaseDump::prefetch already past rev $rev on page $page "
94  . "[$this->lastPage, $this->lastRev]" );
95 
96  return null;
97  }
98  }
99 
100  function debug( $str ) {
101  wfDebug( $str . "\n" );
102  // global $dumper;
103  // $dumper->progress( $str );
104  }
105 
109  function nextPage() {
110  if ( $this->skipTo( 'page', 'mediawiki' ) ) {
111  if ( $this->skipTo( 'id' ) ) {
112  $this->lastPage = intval( $this->nodeContents() );
113  $this->lastRev = 0;
114  $this->atPageEnd = false;
115  }
116  } else {
117  $this->close();
118  if ( count( $this->infiles ) ) {
119  $infile = array_shift( $this->infiles );
120  $this->reader->open( $infile );
121  $this->atEnd = false;
122  }
123  }
124  }
125 
129  function nextRev() {
130  if ( $this->skipTo( 'revision' ) ) {
131  if ( $this->skipTo( 'id' ) ) {
132  $this->lastRev = intval( $this->nodeContents() );
133  }
134  } else {
135  $this->atPageEnd = true;
136  }
137  }
138 
143  function nextText() {
144  $this->skipTo( 'text' );
145 
146  return strval( $this->nodeContents() );
147  }
148 
155  function skipTo( $name, $parent = 'page' ) {
156  if ( $this->atEnd ) {
157  return false;
158  }
159  while ( $this->reader->read() ) {
160  if ( $this->reader->nodeType == XMLReader::ELEMENT
161  && $this->reader->name == $name
162  ) {
163  return true;
164  }
165  if ( $this->reader->nodeType == XMLReader::END_ELEMENT
166  && $this->reader->name == $parent
167  ) {
168  $this->debug( "BaseDump::skipTo found </$parent> searching for <$name>" );
169 
170  return false;
171  }
172  }
173 
174  return $this->close();
175  }
176 
185  function nodeContents() {
186  if ( $this->atEnd ) {
187  return null;
188  }
189  if ( $this->reader->isEmptyElement ) {
190  return "";
191  }
192  $buffer = "";
193  while ( $this->reader->read() ) {
194  switch ( $this->reader->nodeType ) {
195  case XMLReader::TEXT:
196  // case XMLReader::WHITESPACE:
197  case XMLReader::SIGNIFICANT_WHITESPACE:
198  $buffer .= $this->reader->value;
199  break;
200  case XMLReader::END_ELEMENT:
201  return $buffer;
202  }
203  }
204 
205  return $this->close();
206  }
207 
212  function close() {
213  $this->reader->close();
214  $this->atEnd = true;
215 
216  return null;
217  }
218 }
skipTo($name, $parent= 'page')
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
prefetch($page, $rev)
Attempts to fetch the text of a particular page revision from the dump stream.
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
$buffer
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:1721
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
__construct($infile)
nodeContents()
Shouldn't something like this be built-in to XMLReader? Fetches text contents of the current element...
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300