Файловый менеджер - Редактировать - /var/www/html/historyblob.zip
Ðазад
PK ! �#y��# �# DiffHistoryBlob.phpnu �Iw�� <?php /** * Efficient concatenated text storage. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ /** * Diff-based history compression * Requires xdiff and zlib * * WARNING: Objects of this class are serialized and permanently stored in the DB. * Do not change the name or visibility of any property! */ class DiffHistoryBlob implements HistoryBlob { /** @var string[] Uncompressed item cache */ public $mItems = []; /** @var int Total uncompressed size */ public $mSize = 0; /** * @var array|null Array of diffs. If a diff D from A to B is notated D = B - A, * and Z is an empty string: * * { item[map[i]] - item[map[i-1]] where i > 0 * diff[i] = { * { item[map[i]] - Z where i = 0 */ public $mDiffs; /** @var array The diff map, see above */ public $mDiffMap; /** @var string The key for getText() */ public $mDefaultKey; /** @var string|null Compressed storage */ public $mCompressed; /** @var bool True if the object is locked against further writes */ public $mFrozen = false; /** * @var int The maximum uncompressed size before the object becomes sad * Should be less than max_allowed_packet */ public $mMaxSize = 10_000_000; /** @var int The maximum number of text items before the object becomes sad */ public $mMaxCount = 100; /** Constants from xdiff.h */ private const XDL_BDOP_INS = 1; private const XDL_BDOP_CPY = 2; private const XDL_BDOP_INSB = 3; public function __construct() { if ( !function_exists( 'gzdeflate' ) ) { throw new RuntimeException( "Need zlib support to read or write DiffHistoryBlob\n" ); } } /** * @param string $text * @return string */ public function addItem( $text ) { if ( $this->mFrozen ) { throw new BadMethodCallException( __METHOD__ . ": Cannot add more items after sleep/wakeup" ); } $this->mItems[] = $text; $this->mSize += strlen( $text ); $this->mDiffs = null; // later return (string)( count( $this->mItems ) - 1 ); } /** * @param string $key * @return string */ public function getItem( $key ) { return $this->mItems[(int)$key]; } /** * @param string $text */ public function setText( $text ) { $this->mDefaultKey = $this->addItem( $text ); } /** * @return string */ public function getText() { return $this->getItem( $this->mDefaultKey ); } private function compress() { if ( !function_exists( 'xdiff_string_rabdiff' ) ) { throw new RuntimeException( "Need xdiff support to write DiffHistoryBlob\n" ); } if ( isset( $this->mDiffs ) ) { // Already compressed return; } if ( $this->mItems === [] ) { return; } // Create two diff sequences: one for main text and one for small text $sequences = [ 'small' => [ 'tail' => '', 'diffs' => [], 'map' => [], ], 'main' => [ 'tail' => '', 'diffs' => [], 'map' => [], ], ]; $smallFactor = 0.5; $mItemsCount = count( $this->mItems ); for ( $i = 0; $i < $mItemsCount; $i++ ) { $text = $this->mItems[$i]; if ( $i == 0 ) { $seqName = 'main'; } else { $mainTail = $sequences['main']['tail']; if ( strlen( $text ) < strlen( $mainTail ) * $smallFactor ) { $seqName = 'small'; } else { $seqName = 'main'; } } $tail = $sequences[$seqName]['tail']; $diff = $this->diff( $tail, $text ); $sequences[$seqName]['diffs'][] = $diff; $sequences[$seqName]['map'][] = $i; $sequences[$seqName]['tail'] = $text; } // Knit the sequences together $tail = ''; $this->mDiffs = []; $this->mDiffMap = []; foreach ( $sequences as $seq ) { if ( $seq['diffs'] === [] ) { continue; } if ( $tail === '' ) { $this->mDiffs[] = $seq['diffs'][0]; } else { $head = $this->patch( '', $seq['diffs'][0] ); $this->mDiffs[] = $this->diff( $tail, $head ); } $this->mDiffMap[] = $seq['map'][0]; $diffsCount = count( $seq['diffs'] ); for ( $i = 1; $i < $diffsCount; $i++ ) { $this->mDiffs[] = $seq['diffs'][$i]; $this->mDiffMap[] = $seq['map'][$i]; } $tail = $seq['tail']; } } /** * @param string $t1 * @param string $t2 * @return string */ private function diff( $t1, $t2 ) { return xdiff_string_rabdiff( $t1, $t2 ); } /** * @param string $base * @param string $diff * @return bool|string */ private function patch( $base, $diff ) { if ( function_exists( 'xdiff_string_bpatch' ) ) { return xdiff_string_bpatch( $base, $diff ); } # Pure PHP implementation $header = unpack( 'Vofp/Vcsize', substr( $diff, 0, 8 ) ); # Check the checksum $ofp = $this->xdiffAdler32( $base ); if ( $ofp !== substr( $diff, 0, 4 ) ) { wfDebug( __METHOD__ . ": incorrect base checksum" ); return false; } if ( $header['csize'] != strlen( $base ) ) { wfDebug( __METHOD__ . ": incorrect base length" ); return false; } $p = 8; $out = ''; while ( $p < strlen( $diff ) ) { $x = unpack( 'Cop', substr( $diff, $p, 1 ) ); $op = $x['op']; ++$p; switch ( $op ) { case self::XDL_BDOP_INS: $x = unpack( 'Csize', substr( $diff, $p, 1 ) ); $p++; $out .= substr( $diff, $p, $x['size'] ); $p += $x['size']; break; case self::XDL_BDOP_INSB: $x = unpack( 'Vcsize', substr( $diff, $p, 4 ) ); $p += 4; $out .= substr( $diff, $p, $x['csize'] ); $p += $x['csize']; break; case self::XDL_BDOP_CPY: $x = unpack( 'Voff/Vcsize', substr( $diff, $p, 8 ) ); $p += 8; $out .= substr( $base, $x['off'], $x['csize'] ); break; default: wfDebug( __METHOD__ . ": invalid op" ); return false; } } return $out; } /** * Compute a binary "Adler-32" checksum as defined by LibXDiff, i.e. with * the bytes backwards and initialised with 0 instead of 1. See T36428. * * @param string $s * @return string */ public function xdiffAdler32( $s ) { static $init = null; $init ??= str_repeat( "\xf0", 205 ) . "\xee" . str_repeat( "\xf0", 67 ) . "\x02"; // The real Adler-32 checksum of $init is zero, so it initialises the // state to zero, as it is at the start of LibXDiff's checksum // algorithm. Appending the subject string then simulates LibXDiff. return strrev( hash( 'adler32', $init . $s, true ) ); } private function uncompress() { if ( !$this->mDiffs ) { return; } $tail = ''; $mDiffsCount = count( $this->mDiffs ); for ( $diffKey = 0; $diffKey < $mDiffsCount; $diffKey++ ) { $textKey = $this->mDiffMap[$diffKey]; $text = $this->patch( $tail, $this->mDiffs[$diffKey] ); $this->mItems[$textKey] = $text; $tail = $text; } } /** * @return array */ public function __sleep() { $this->compress(); if ( $this->mItems === [] ) { $info = false; } else { // Take forward differences to improve the compression ratio for sequences $map = ''; $prev = 0; foreach ( $this->mDiffMap as $i ) { if ( $map !== '' ) { $map .= ','; } $map .= $i - $prev; $prev = $i; } $info = [ 'diffs' => $this->mDiffs, 'map' => $map ]; } if ( isset( $this->mDefaultKey ) ) { $info['default'] = $this->mDefaultKey; } $this->mCompressed = gzdeflate( serialize( $info ) ); return [ 'mCompressed' ]; } public function __wakeup() { // addItem() doesn't work if mItems is partially filled from mDiffs $this->mFrozen = true; $info = HistoryBlobUtils::unserializeArray( gzinflate( $this->mCompressed ) ); $this->mCompressed = null; if ( !$info ) { // Empty object return; } if ( isset( $info['default'] ) ) { $this->mDefaultKey = $info['default']; } $this->mDiffs = $info['diffs']; if ( isset( $info['base'] ) ) { // Old format $this->mDiffMap = range( 0, count( $this->mDiffs ) - 1 ); array_unshift( $this->mDiffs, pack( 'VVCV', 0, 0, self::XDL_BDOP_INSB, strlen( $info['base'] ) ) . $info['base'] ); } else { // New format $map = explode( ',', $info['map'] ); $cur = 0; $this->mDiffMap = []; foreach ( $map as $i ) { $cur += $i; $this->mDiffMap[] = $cur; } } $this->uncompress(); } /** * Helper function for compression jobs * Returns true until the object is "full" and ready to be committed * * @return bool */ public function isHappy() { return $this->mSize < $this->mMaxSize && count( $this->mItems ) < $this->mMaxCount; } } PK ! �Eѕ� � HistoryBlobCurStub.phpnu �Iw�� <?php /** * Efficient concatenated text storage. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ use MediaWiki\MediaWikiServices; /** * To speed up conversion from 1.4 to 1.5 schema, text rows can refer to the * leftover cur table as the backend. This avoids expensively copying hundreds * of megabytes of data during the conversion downtime. */ class HistoryBlobCurStub { /** @var int */ public $mCurId; /** * @param int $curid The cur_id pointed to */ public function __construct( $curid = 0 ) { $this->mCurId = $curid; } /** * Sets the location (cur_id) of the main object to which this object * points * * @param int $id */ public function setLocation( $id ) { $this->mCurId = $id; } /** * @return string|false */ public function getText() { $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); $row = $dbr->newSelectQueryBuilder() ->select( [ 'cur_text' ] ) ->from( 'cur' ) ->where( [ 'cur_id' => $this->mCurId ] ) ->caller( __METHOD__ )->fetchRow(); return $row ? $row->cur_text : false; } } // Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the // class name coerced to lowercase. We can improve efficiency by adding // autoload entries for the lowercase variants of these classes (T166759). // The code below is never executed, but it is picked up by the AutoloadGenerator // parser, which scans for class_alias() calls. /* class_alias( HistoryBlobCurStub::class, 'historyblobcurstub' ); */ PK ! ���,� � ConcatenatedGzipHistoryBlob.phpnu �Iw�� <?php /** * Efficient concatenated text storage. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ /** * Concatenated gzip (CGZ) storage * Improves compression ratio by concatenating like objects before gzipping * * WARNING: Objects of this class are serialized and permanently stored in the DB. * Do not change the name or visibility of any property! */ class ConcatenatedGzipHistoryBlob implements HistoryBlob { /** @var int */ public $mVersion = 0; /** @var bool */ public $mCompressed = false; /** @var string[]|string Array if uncompressed, string if compressed */ public $mItems = []; /** @var string */ public $mDefaultHash = ''; /** @var int */ public $mSize = 0; /** @var int */ public $mMaxSize = 10_000_000; /** @var int */ public $mMaxCount = 100; public function __construct() { if ( !function_exists( 'gzdeflate' ) ) { throw new RuntimeException( "Need zlib support to read or write this " . "kind of history object (ConcatenatedGzipHistoryBlob)\n" ); } } /** * @param string $text * @return string */ public function addItem( $text ) { $this->uncompress(); $hash = md5( $text ); if ( !isset( $this->mItems[$hash] ) ) { $this->mItems[$hash] = $text; $this->mSize += strlen( $text ); } return $hash; } /** * @param string $hash * @return string|false */ public function getItem( $hash ) { $this->uncompress(); if ( array_key_exists( $hash, $this->mItems ) ) { return $this->mItems[$hash]; } else { return false; } } /** * @param string $text * @return void */ public function setText( $text ) { $this->uncompress(); $this->mDefaultHash = $this->addItem( $text ); } /** * @return string|false */ public function getText() { $this->uncompress(); return $this->getItem( $this->mDefaultHash ); } /** * Remove an item * * @param string $hash */ public function removeItem( $hash ) { $this->mSize -= strlen( $this->mItems[$hash] ); unset( $this->mItems[$hash] ); } /** * Compress the bulk data in the object */ public function compress() { if ( !$this->mCompressed ) { $this->mItems = gzdeflate( serialize( $this->mItems ) ); $this->mCompressed = true; } } /** * Uncompress bulk data */ public function uncompress() { if ( $this->mCompressed ) { $this->mItems = HistoryBlobUtils::unserializeArray( gzinflate( $this->mItems ) ); $this->mCompressed = false; } } /** * @return array */ public function __sleep() { $this->compress(); return [ 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' ]; } public function __wakeup() { $this->uncompress(); } /** * Helper function for compression jobs * Returns true until the object is "full" and ready to be committed * * @return bool */ public function isHappy() { return $this->mSize < $this->mMaxSize && count( $this->mItems ) < $this->mMaxCount; } } // Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the // class name coerced to lowercase. We can improve efficiency by adding // autoload entries for the lowercase variants of these classes (T166759). // The code below is never executed, but it is picked up by the AutoloadGenerator // parser, which scans for class_alias() calls. /* class_alias( ConcatenatedGzipHistoryBlob::class, 'concatenatedgziphistoryblob' ); */ PK ! �ۮ1� � HistoryBlob.phpnu �Iw�� <?php /** * Efficient concatenated text storage. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ /** * Base class for general text storage via the "object" flag in old_flags, or * two-part external storage URLs. Used for represent efficient concatenated * storage, and migration-related pointer objects. */ interface HistoryBlob { /** * Adds an item of text, returns a stub object which points to the item. * You must call setLocation() on the stub object before storing it to the * database * * @param string $text * * @return string The key for getItem() */ public function addItem( $text ); /** * Get item by key, or false if the key is not present * * @param string $key * * @return string|bool */ public function getItem( $key ); /** * Set the "default text" * This concept is an odd property of the current DB schema, whereby each text item has a revision * associated with it. The default text is the text of the associated revision. There may, however, * be other revisions in the same object. * * Default text is not required for two-part external storage URLs. * * @param string $text */ public function setText( $text ); /** * Get default text. * * @return string|false */ public function getText(); } PK ! 'Nǜ� � HistoryBlobUtils.phpnu �Iw�� <?php use MediaWiki\Storage\BlobAccessException; class HistoryBlobUtils { /** * Get the classes which are allowed to be contained in a text or ES row * * @return string[] */ public static function getAllowedClasses() { return [ ConcatenatedGzipHistoryBlob::class, DiffHistoryBlob::class, HistoryBlobCurStub::class, HistoryBlobStub::class ]; } /** * Unserialize a HistoryBlob * * @param string $str * @param bool $allowDouble Allow double serialization * @return HistoryBlob|HistoryBlobStub|HistoryBlobCurStub|null */ public static function unserialize( string $str, bool $allowDouble = false ) { $obj = unserialize( $str, [ 'allowed_classes' => self::getAllowedClasses() ] ); if ( is_string( $obj ) && $allowDouble ) { // Correct for old double-serialization bug (needed by HistoryBlobStub only) $obj = unserialize( $obj, [ 'allowed_classes' => self::getAllowedClasses() ] ); } foreach ( self::getAllowedClasses() as $class ) { if ( $obj instanceof $class ) { return $obj; } } return null; } /** * Unserialize array data with no classes * * @param string $str * @return array */ public static function unserializeArray( string $str ): array { $array = unserialize( $str, [ 'allowed_classes' => false ] ); if ( !is_array( $array ) ) { throw new BlobAccessException( "Expected array in serialized string" ); } return $array; } } PK ! ��w w HistoryBlobStub.phpnu �Iw�� <?php /** * Efficient concatenated text storage. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @file */ use MediaWiki\MediaWikiServices; /** * Pointer object for an item within a CGZ blob stored in the text table. * * WARNING: Objects of this class are serialized and permanently stored in the DB. * Do not change the name or visibility of any property! * * Note: the property visibility was changed in 2020 from public to protected. * This may cause problems in future. */ class HistoryBlobStub { /** * @var array One-step cache variable to hold base blobs; operations that * pull multiple revisions may often pull multiple times from the same * blob. By keeping the last-used one open, we avoid redundant * unserialization and decompression overhead. */ protected static $blobCache = []; /** @var int */ protected $mOldId; /** @var string */ protected $mHash; /** @var string */ protected $mRef; /** * @param string $hash The content hash of the text * @param int $oldid The old_id for the CGZ object */ public function __construct( $hash = '', $oldid = 0 ) { $this->mHash = $hash; } /** * Sets the location (old_id) of the main object to which this object * points * @param int $id */ public function setLocation( $id ) { $this->mOldId = $id; } /** * Gets the location of the main object * @return int */ public function getLocation() { return $this->mOldId; } /** * Sets the location (old_id) of the referring object * @param string $id */ public function setReferrer( $id ) { $this->mRef = $id; } /** * Gets the location of the referring object * @return string */ public function getReferrer() { return $this->mRef; } /** * @return string|false */ public function getText() { if ( isset( self::$blobCache[$this->mOldId] ) ) { $obj = self::$blobCache[$this->mOldId]; } else { $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); $row = $dbr->newSelectQueryBuilder() ->select( [ 'old_flags', 'old_text' ] ) ->from( 'text' ) ->where( [ 'old_id' => $this->mOldId ] ) ->caller( __METHOD__ )->fetchRow(); if ( !$row ) { return false; } $flags = explode( ',', $row->old_flags ); if ( in_array( 'external', $flags ) ) { $url = $row->old_text; $parts = explode( '://', $url, 2 ); if ( !isset( $parts[1] ) || $parts[1] == '' ) { return false; } $row->old_text = MediaWikiServices::getInstance() ->getExternalStoreAccess() ->fetchFromURL( $url ); } if ( !in_array( 'object', $flags ) ) { return false; } if ( in_array( 'gzip', $flags ) ) { // This shouldn't happen, but a bug in the compress script // may at times gzip-compress a HistoryBlob object row. $obj = HistoryBlobUtils::unserialize( gzinflate( $row->old_text ), true ); } else { $obj = HistoryBlobUtils::unserialize( $row->old_text, true ); } // Save this item for reference; if pulling many // items in a row we'll likely use it again. self::$blobCache = [ $this->mOldId => $obj ]; } if ( method_exists( $obj, 'getItem' ) ) { return $obj->getItem( $this->mHash ); } return false; } /** * Get the content hash * * @return string */ public function getHash() { return $this->mHash; } } // Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the // class name coerced to lowercase. We can improve efficiency by adding // autoload entries for the lowercase variants of these classes (T166759). // The code below is never executed, but it is picked up by the AutoloadGenerator // parser, which scans for class_alias() calls. /* class_alias( HistoryBlobStub::class, 'historyblobstub' ); */ PK ! �#y��# �# DiffHistoryBlob.phpnu �Iw�� PK ! �Eѕ� � �# HistoryBlobCurStub.phpnu �Iw�� PK ! ���,� � �, ConcatenatedGzipHistoryBlob.phpnu �Iw�� PK ! �ۮ1� � = HistoryBlob.phpnu �Iw�� PK ! 'Nǜ� � )E HistoryBlobUtils.phpnu �Iw�� PK ! ��w w �J HistoryBlobStub.phpnu �Iw�� PK � �\
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка