MediaWiki  1.30.2
backupPrefetch.inc
Go to the documentation of this file.
1 <?php
42 class BaseDump {
44  protected $reader = null;
45  protected $atEnd = false;
46  protected $atPageEnd = false;
47  protected $lastPage = 0;
48  protected $lastRev = 0;
49  protected $infiles = null;
50 
51  public function __construct( $infile ) {
52  $this->infiles = explode( ';', $infile );
53  $this->reader = new XMLReader();
54  $infile = array_shift( $this->infiles );
55  if ( defined( 'LIBXML_PARSEHUGE' ) ) {
56  $this->reader->open( $infile, null, LIBXML_PARSEHUGE );
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 "
80  . "looking for rev $rev [$this->lastPage, $this->lastRev]" );
81 
82  return null;
83  }
84  while ( $this->lastRev < $rev && !$this->atEnd && !$this->atPageEnd ) {
85  $this->debug( "BaseDump::prefetch at page $this->lastPage, rev $this->lastRev, "
86  . "looking for $page, $rev" );
87  $this->nextRev();
88  }
89  if ( $this->lastRev == $rev && !$this->atEnd ) {
90  $this->debug( "BaseDump::prefetch hit on $page, $rev [$this->lastPage, $this->lastRev]" );
91 
92  return $this->nextText();
93  } else {
94  $this->debug( "BaseDump::prefetch already past rev $rev on page $page "
95  . "[$this->lastPage, $this->lastRev]" );
96 
97  return null;
98  }
99  }
100 
101  function debug( $str ) {
102  wfDebug( $str . "\n" );
103  // global $dumper;
104  // $dumper->progress( $str );
105  }
106 
110  function nextPage() {
111  if ( $this->skipTo( 'page', 'mediawiki' ) ) {
112  if ( $this->skipTo( 'id' ) ) {
113  $this->lastPage = intval( $this->nodeContents() );
114  $this->lastRev = 0;
115  $this->atPageEnd = false;
116  }
117  } else {
118  $this->close();
119  if ( count( $this->infiles ) ) {
120  $infile = array_shift( $this->infiles );
121  $this->reader->open( $infile );
122  $this->atEnd = false;
123  }
124  }
125  }
126 
130  function nextRev() {
131  if ( $this->skipTo( 'revision' ) ) {
132  if ( $this->skipTo( 'id' ) ) {
133  $this->lastRev = intval( $this->nodeContents() );
134  }
135  } else {
136  $this->atPageEnd = true;
137  }
138  }
139 
144  function nextText() {
145  $this->skipTo( 'text' );
146 
147  return strval( $this->nodeContents() );
148  }
149 
156  function skipTo( $name, $parent = 'page' ) {
157  if ( $this->atEnd ) {
158  return false;
159  }
160  while ( $this->reader->read() ) {
161  if ( $this->reader->nodeType == XMLReader::ELEMENT
162  && $this->reader->name == $name
163  ) {
164  return true;
165  }
166  if ( $this->reader->nodeType == XMLReader::END_ELEMENT
167  && $this->reader->name == $parent
168  ) {
169  $this->debug( "BaseDump::skipTo found </$parent> searching for <$name>" );
170 
171  return false;
172  }
173  }
174 
175  return $this->close();
176  }
177 
186  function nodeContents() {
187  if ( $this->atEnd ) {
188  return null;
189  }
190  if ( $this->reader->isEmptyElement ) {
191  return "";
192  }
193  $buffer = "";
194  while ( $this->reader->read() ) {
195  switch ( $this->reader->nodeType ) {
196  case XMLReader::TEXT:
197  // case XMLReader::WHITESPACE:
198  case XMLReader::SIGNIFICANT_WHITESPACE:
199  $buffer .= $this->reader->value;
200  break;
201  case XMLReader::END_ELEMENT:
202  return $buffer;
203  }
204  }
205 
206  return $this->close();
207  }
208 
213  function close() {
214  $this->reader->close();
215  $this->atEnd = true;
216 
217  return null;
218  }
219 }
BaseDump
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
Definition: backupPrefetch.inc:42
BaseDump\nodeContents
nodeContents()
Shouldn't something like this be built-in to XMLReader? Fetches text contents of the current element,...
Definition: backupPrefetch.inc:186
BaseDump\skipTo
skipTo( $name, $parent='page')
Definition: backupPrefetch.inc:156
captcha-old.count
count
Definition: captcha-old.py:249
BaseDump\$reader
XMLReader $reader
Definition: backupPrefetch.inc:44
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
BaseDump\prefetch
prefetch( $page, $rev)
Attempts to fetch the text of a particular page revision from the dump stream.
Definition: backupPrefetch.inc:71
php
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
BaseDump\__construct
__construct( $infile)
Definition: backupPrefetch.inc:51
BaseDump\nextRev
nextRev()
Definition: backupPrefetch.inc:130
BaseDump\$atEnd
$atEnd
Definition: backupPrefetch.inc:45
BaseDump\$infiles
$infiles
Definition: backupPrefetch.inc:49
BaseDump\$lastPage
$lastPage
Definition: backupPrefetch.inc:47
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:1047
BaseDump\$atPageEnd
$atPageEnd
Definition: backupPrefetch.inc:46
BaseDump\$lastRev
$lastRev
Definition: backupPrefetch.inc:48
BaseDump\close
close()
Definition: backupPrefetch.inc:213
BaseDump\debug
debug( $str)
Definition: backupPrefetch.inc:101
$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:1750
BaseDump\nextPage
nextPage()
Definition: backupPrefetch.inc:110
$buffer
$buffer
Definition: mwdoc-filter.php:49
BaseDump\nextText
nextText()
Definition: backupPrefetch.inc:144