27require_once __DIR__ .
'/includes/BackupDumper.php';
28require_once __DIR__ .
'/7zip.inc';
29require_once __DIR__ .
'/../includes/export/WikiExporter.php';
109 parent::__construct();
112This
script postprocesses XML dumps from dumpBackup.php to add
113page text which was stubbed out (
using --stub).
115XML input is accepted on stdin.
119 $this->stderr =
fopen(
"php://stderr",
"wt" );
121 $this->
addOption(
'stub',
'To load a compressed stub dump instead of stdin. ' .
122 'Specify as --stub=<type>:<file>.',
false,
true );
123 $this->
addOption(
'prefetch',
'Use a prior dump file as a text source, to savepressure on the ' .
124 'database. (Requires the XMLReader extension). Specify as --prefetch=<type>:<file>',
126 $this->
addOption(
'maxtime',
'Write out checkpoint file after this many minutes (writing' .
127 'out complete page, closing xml file properly, and opening new one' .
128 'with header). This option requires the checkpointfile option.',
false,
true );
129 $this->
addOption(
'checkpointfile',
'Use this string for checkpoint filenames,substituting ' .
130 'first pageid written for the first %s (required) and the last pageid written for the ' .
131 'second %s if it exists.',
false,
true,
false,
true );
132 $this->
addOption(
'quiet',
'Don\'t dump status reports to stderr.' );
133 $this->
addOption(
'full',
'Dump all revisions of every page' );
134 $this->
addOption(
'current',
'Base ETA on number of pages in database instead of all revisions' );
135 $this->
addOption(
'spawn',
'Spawn a subprocess for loading text records' );
136 $this->
addOption(
'buffersize',
'Buffer size in bytes to use for reading the stub. ' .
137 '(Default: 512KB, Minimum: 4KB)',
false,
true );
149 return MediaWikiServices::getInstance()->getBlobStore();
158 parent::processOptions();
160 if ( $this->
hasOption(
'buffersize' ) ) {
166 $this->prefetch =
new BaseDump( $url );
177 if ( $this->
hasOption(
'checkpointfile' ) ) {
178 $this->checkpointFiles = $this->
getOption(
'checkpointfile' );
182 $this->
history = WikiExporter::CURRENT;
186 $this->
history = WikiExporter::FULL;
211 if (
isset( $this->lb ) ) {
212 $this->lb->closeAll();
216 if ( $this->forcedDb !==
null ) {
217 $this->db = $this->forcedDb;
222 if (
isset( $this->db ) && $this->db->isOpen() ) {
223 throw new MWException(
'DB is set and has not been closed by the Load Balancer' );
233 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
234 $this->lb = $lbFactory->newMainLB();
235 }
catch ( Exception
$e ) {
237 .
" rotating DB failed to obtain new load balancer (" .
$e->getMessage() .
")" );
241 $this->db = $this->lb->getConnection(
DB_REPLICA,
'dump' );
242 }
catch ( Exception
$e ) {
244 .
" rotating DB failed to obtain new database (" .
$e->getMessage() .
")" );
249 parent::initProgress();
250 $this->timeOfCheckpoint = $this->startTime;
253 function dump( $history, $text = WikiExporter::TEXT ) {
256 if (
ini_get(
'display_errors' ) ) {
257 ini_set(
'display_errors',
'stderr' );
269 }
catch ( Exception
$e ) {
272 $this->
progress(
"Getting initial DB connection failed (" .
273 $e->getMessage() .
")" );
287 if ( $this->spawnProc ) {
295 $split = explode(
':',
$opt, 2 );
298 if ( count( $split ) === 2 ) {
301 $fileURIs = explode(
';', $param );
302 foreach ( $fileURIs as $URI ) {
308 $newURI =
"compress.zlib://$URI";
311 $newURI =
"compress.bzip2://$URI";
314 $newURI =
"mediawiki.compress.7z://$URI";
321 $val = implode(
';', $newFileURIs );
330 if ( !$this->prefetch ) {
331 parent::showReport();
336 if ( $this->reporting ) {
339 $deltaAll = $nowts - $this->startTime;
340 $deltaPart = $nowts - $this->lastTime;
341 $this->pageCountPart = $this->pageCount - $this->pageCountLast;
342 $this->revCountPart = $this->
revCount - $this->revCountLast;
346 $eta = $this->startTime + $deltaAll /
$portion;
348 if ( $this->fetchCount ) {
349 $fetchRate = 100.0 * $this->prefetchCount / $this->fetchCount;
353 $pageRate = $this->pageCount /
$deltaAll;
362 if ( $this->fetchCountLast ) {
363 $fetchRatePart = 100.0 * $this->prefetchCountLast / $this->fetchCountLast;
365 $fetchRatePart =
'-';
367 $pageRatePart = $this->pageCountPart /
$deltaPart;
368 $revRatePart = $this->revCountPart /
$deltaPart;
370 $fetchRatePart =
'-';
375 "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), "
376 .
"%d revs (%0.1f|%0.1f/sec all|curr), %0.1f%%|%0.1f%% "
377 .
"prefetched (all|curr), ETA %s [max %d]",
378 $now,
wfWikiID(), $this->ID, $this->pageCount, $pageRate,
379 $pageRatePart, $this->
revCount, $revRate, $revRatePart,
380 $fetchRate, $fetchRatePart, $etats, $this->maxCount
383 $this->revCountLast = $this->revCount;
384 $this->prefetchCountLast = $this->prefetchCount;
385 $this->fetchCountLast = $this->fetchCount;
390 $this->timeExceeded =
true;
394 if ( $this->maxTimeAllowed
395 && ( $this->lastTime - $this->timeOfCheckpoint > $this->maxTimeAllowed )
404 if ( ( $this->checkpointFiles && !$this->maxTimeAllowed )
405 || ( $this->maxTimeAllowed && !$this->checkpointFiles )
407 throw new MWException(
"Options checkpointfile and maxtime must be specified together.\n" );
409 foreach ( $this->checkpointFiles as $checkpointFile ) {
412 throw new MWException(
"Option checkpointfile must contain two '%s' "
413 .
"for substitution of first and last pageids, count is $count instead, "
414 .
"file is $checkpointFile.\n" );
418 if ( $this->checkpointFiles ) {
419 $filenameList = (
array)$this->egress->getFilenames();
420 if ( count( $filenameList ) != count( $this->checkpointFiles ) ) {
421 throw new MWException(
"One checkpointfile must be specified "
422 .
"for each output option, if maxtime is used.\n" );
434 $this->openElement =
false;
435 $this->atStart =
true;
437 $this->lastName =
"";
440 $this->thisRevModel =
null;
441 $this->thisRevFormat =
null;
448 [ $this,
'startElement' ],
449 [ $this,
'endElement' ]
460 wfDebug(
"TextDumpPass::readDump encountered XML parsing error\n" );
464 'XML import parse failure',
467 $byte . (
is_null( $chunk ) ?
null : (
'; "' .
substr( $chunk, $byte - $offset, 16 ) .
'"' ) ),
474 $offset +=
strlen( $chunk );
475 }
while ( $chunk !==
false && !
feof(
$input ) );
476 if ( $this->maxTimeAllowed ) {
477 $filenameList = (
array)$this->egress->getFilenames();
481 # we might have just written the header and footer and had no
482 # pages or revisions written... perhaps they were all deleted
483 # there's no pageID 0 so we use that. the caller is responsible
484 # for deciding what to do with a file containing only the
485 # siteinfo information and the mw tags.
486 if ( !$this->firstPageWritten ) {
487 $firstPageID =
str_pad( 0, 9,
"0", STR_PAD_LEFT );
488 $lastPageID =
str_pad( 0, 9,
"0", STR_PAD_LEFT );
490 $firstPageID =
str_pad( $this->firstPageWritten, 9,
"0", STR_PAD_LEFT );
491 $lastPageID =
str_pad( $this->lastPageWritten, 9,
"0", STR_PAD_LEFT );
494 $filenameCount = count( $filenameList );
496 $checkpointNameFilledIn =
sprintf( $this->checkpointFiles[$i], $firstPageID, $lastPageID );
500 $this->egress->closeAndRename( $newFilenames );
519 $handler = ContentHandler::getForModelID( $model );
520 $text =
$handler->exportTransform( $text, $format );
524 "Unable to apply export transformation for content model '$model': " .
552 function getText( $id, $model =
null, $format =
null ) {
555 $prefetchNotTried =
true;
560 static $consecutiveFailedTextRetrievals = 0;
568 $consecutiveFailedTextRetrievals = 0;
572 $row = $this->db->selectRow(
574 [
'rev_content_model',
'rev_content_format' ],
575 [
'rev_id' => $this->thisRev ],
580 $model = $row->rev_content_model;
581 $format = $row->rev_content_format;
585 if ( $model ===
null || $model ===
'' ) {
589 while ( $failures < $this->maxFailures ) {
599 if ( $text ===
false &&
isset( $this->prefetch ) && $prefetchNotTried ) {
600 $prefetchNotTried =
false;
601 $tryIsPrefetch =
true;
602 $text = $this->prefetch->prefetch( (
int)$this->thisPage, (
int)$this->thisRev );
604 if ( $text ===
null ) {
608 if (
is_string( $text ) && $model !==
false ) {
618 if ( $text ===
false ) {
620 $tryIsPrefetch =
false;
621 if ( $this->spawn ) {
627 if ( $text !==
false && $model !==
false ) {
636 if ( $text !==
false ) {
641 if ( $text ===
false ) {
642 throw new MWException(
"Generic error while obtaining text for id " . $id );
649 $revID =
intval( $this->thisRev );
650 if ( !
isset( $this->db ) ) {
655 $revLength =
strlen( $text );
657 $revLength = $this->db->selectField(
'revision',
'rev_len', [
'rev_id' => $revID ] );
660 if (
strlen( $text ) == $revLength ) {
661 if ( $tryIsPrefetch ) {
662 $this->prefetchCount++;
669 throw new MWException(
"Received text is unplausible for id " . $id );
670 }
catch ( Exception
$e ) {
671 $msg =
"getting/checking text " . $id .
" failed (" .
$e->getMessage() .
")";
672 if ( $failures + 1 < $this->maxFailures ) {
673 $msg .=
" (Will retry " . ( $this->maxFailures - $failures - 1 ) .
" more times)";
682 if ( !$tryIsPrefetch ) {
686 sleep( $this->failureTimeout );
689 if ( $this->spawn ) {
693 }
catch ( Exception
$e ) {
694 $this->
progress(
"Rebooting getText infrastructure failed (" .
$e->getMessage() .
")" .
695 " Trying to continue anyways" );
705 $consecutiveFailedTextRetrievals = $oldConsecutiveFailedTextRetrievals + 1;
706 if ( $consecutiveFailedTextRetrievals > $this->maxConsecutiveFailedTextRetrievals ) {
707 throw new MWException(
"Graceful storage failure" );
722 ? SqlBlobStore::makeAddressFromTextId( (
int)$id )
726 $text = $store->getBlob( $address );
729 $normalized = MediaWikiServices::getInstance()->getContentLanguage()
730 ->normalize( $stripped );
745 if ( !$this->spawnProc ) {
758 if (
file_exists(
"$IP/../multiversion/MWScript.php" ) ) {
763 "$IP/../multiversion/MWScript.php",
771 "$IP/maintenance/fetchText.php",
775 0 => [
"pipe",
"r" ],
776 1 => [
"pipe",
"w" ],
777 2 => [
"file",
"/dev/null",
"a" ] ];
780 $this->
progress(
"Spawning database subprocess: $cmd" );
781 $this->spawnProc =
proc_open( $cmd, $spec, $pipes );
782 if ( !$this->spawnProc ) {
783 $this->
progress(
"Subprocess spawn failed." );
797 if ( $this->spawnRead ) {
798 fclose( $this->spawnRead );
800 $this->spawnRead =
false;
801 if ( $this->spawnWrite ) {
802 fclose( $this->spawnWrite );
804 $this->spawnWrite =
false;
805 if ( $this->spawnErr ) {
806 fclose( $this->spawnErr );
808 $this->spawnErr =
false;
809 if ( $this->spawnProc ) {
810 pclose( $this->spawnProc );
812 $this->spawnProc =
false;
822 $address = SqlBlobStore::makeAddressFromTextId( (
int)$address );
825 $ok =
fwrite( $this->spawnWrite,
"$address\n" );
831 $ok =
fflush( $this->spawnWrite );
839 $newAddress =
fgets( $this->spawnRead );
840 if ( $newAddress ===
false ) {
843 $newAddress =
trim( $newAddress );
844 if (
strpos( $newAddress,
':' ) ===
false ) {
845 $newAddress = SqlBlobStore::makeAddressFromTextId(
intval( $newAddress ) );
848 if ( $newAddress !== $address ) {
852 $len =
fgets( $this->spawnRead );
854 if ( $len ===
false ) {
867 while ( $nbytes >
strlen( $text ) ) {
875 $gotbytes =
strlen( $text );
876 if ( $gotbytes != $nbytes ) {
877 $this->
progress(
"Expected $nbytes bytes from database subprocess, got $gotbytes " );
884 $normalized = MediaWikiServices::getInstance()->getContentLanguage()->
885 normalize( $stripped );
891 $this->checkpointJustWritten =
false;
894 $this->lastName =
$name;
896 if ( $name ==
'revision' ) {
897 $this->state =
$name;
898 $this->egress->writeOpenPage(
null, $this->buffer );
900 }
elseif ( $name ==
'page' ) {
901 $this->state =
$name;
902 if ( $this->atStart ) {
903 $this->egress->writeOpenStream( $this->buffer );
905 $this->atStart =
false;
911 $model =
trim( $this->thisRevModel );
912 $format =
trim( $this->thisRevFormat );
914 $model = $model ===
'' ?
null : $model;
915 $format = $format ===
'' ?
null : $format;
917 $text = $this->
getText( $id, $model, $format );
918 $this->openElement = [
$name, [
'xml:space' =>
'preserve' ] ];
919 if (
strlen( $text ) > 0 ) {
928 $this->checkpointJustWritten =
false;
930 if ( $this->openElement ) {
933 $this->buffer .=
"</$name>";
936 if ( $name ==
'revision' ) {
937 $this->egress->writeRevision(
null, $this->buffer );
940 $this->thisRevModel =
null;
941 $this->thisRevFormat =
null;
942 }
elseif ( $name ==
'page' ) {
943 if ( !$this->firstPageWritten ) {
944 $this->firstPageWritten =
trim( $this->thisPage );
946 $this->lastPageWritten =
trim( $this->thisPage );
947 if ( $this->timeExceeded ) {
948 $this->egress->writeClosePage( $this->buffer );
951 $this->egress->sink->write(
"\n" );
953 $this->buffer = $this->xmlwriterobj->closeStream();
954 $this->egress->writeCloseStream( $this->buffer );
957 $this->thisPage =
"";
960 $filenameList = (
array)$this->egress->getFilenames();
962 $firstPageID =
str_pad( $this->firstPageWritten, 9,
"0", STR_PAD_LEFT );
963 $lastPageID =
str_pad( $this->lastPageWritten, 9,
"0", STR_PAD_LEFT );
964 $filenamesCount = count( $filenameList );
966 $checkpointNameFilledIn =
sprintf( $this->checkpointFiles[$i], $firstPageID, $lastPageID );
970 $this->egress->closeRenameAndReopen( $newFilenames );
971 $this->buffer = $this->xmlwriterobj->openStream();
972 $this->timeExceeded =
false;
973 $this->timeOfCheckpoint = $this->lastTime;
974 $this->firstPageWritten =
false;
975 $this->checkpointJustWritten =
true;
977 $this->egress->writeClosePage( $this->buffer );
979 $this->thisPage =
"";
981 }
elseif ( $name ==
'mediawiki' ) {
982 $this->egress->writeCloseStream( $this->buffer );
989 if ( $this->lastName ==
"id" ) {
990 if ( $this->state ==
"revision" ) {
991 $this->thisRev .=
$data;
992 }
elseif ( $this->state ==
"page" ) {
993 $this->thisPage .=
$data;
995 }
elseif ( $this->lastName ==
"model" ) {
996 $this->thisRevModel .=
$data;
997 }
elseif ( $this->lastName ==
"format" ) {
998 $this->thisRevFormat .=
$data;
1003 if ( $this->checkpointJustWritten ) {
1004 if (
$data[0] ==
"\n" ) {
1007 $this->checkpointJustWritten =
false;
1013 if ( $this->openElement ) {
1014 $this->buffer .= Xml::element( $this->openElement[0], $this->openElement[1], $style );
1015 $this->openElement =
false;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Readahead helper for making large MediaWiki data dumps; reads in a previous XML dump to sequentially ...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
loadWithArgv( $argv)
Load params and arguments from a given array of command-line arguments.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
$maxConsecutiveFailedTextRetrievals
showReport()
Overridden to include prefetch ratio if enabled.
getTextDb( $id)
Loads the serialized content from storage.
endElement( $parser, $name)
clearOpenElement( $style)
getTextSpawned( $address)
getText( $id, $model=null, $format=null)
Tries to load revision text.
exportTransform( $text, $model, $format=null)
Applies applicable export transformations to $text.
startElement( $parser, $name, $attribs)
getTextSpawnedOnce( $address)
processOptions()
Processes arguments and sets $this->$sink accordingly.
characterData( $parser, $data)
initProgress( $history=WikiExporter::FULL)
Initialise starting time and maximum revision count.
execute()
Do the actual work.
dump( $history, $text=WikiExporter::TEXT)
bool XmlDumpWriter $xmlwriterobj
IMaintainableDatabase $db
bool resource $spawnWrite
rotateDb()
Drop the database connection $this->db and try to get a new one.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc next in line in page history
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
Allows to change the fields on the form that will be generated $name
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
script(document.cookie)%253c/script%253e</pre ></div > !! end !! test XSS is escaped(inline) !!input< source lang
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
const CONTENT_MODEL_WIKITEXT
Advanced database interface for IDatabase handles that include maintenance methods.
require_once RUN_MAINTENANCE_IF_MAIN
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(is_array($mode)) switch( $mode) $input