MediaWiki master
HistoryBlobStub.php
Go to the documentation of this file.
1<?php
9// NO_NAMESPACE Compatibility with serialized objects in permanent storage
10
12
29 protected static $blobCache = [];
30
32 protected $mOldId;
33
35 protected $mHash;
36
38 protected $mRef;
39
44 public function __construct( $hash = '', $oldid = 0 ) {
45 $this->mHash = $hash;
46 }
47
53 public function setLocation( $id ) {
54 $this->mOldId = $id;
55 }
56
61 public function getLocation() {
62 return $this->mOldId;
63 }
64
69 public function setReferrer( $id ) {
70 $this->mRef = $id;
71 }
72
77 public function getReferrer() {
78 return $this->mRef;
79 }
80
84 public function getText() {
85 if ( isset( self::$blobCache[$this->mOldId] ) ) {
86 $obj = self::$blobCache[$this->mOldId];
87 } else {
88 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
89 $row = $dbr->newSelectQueryBuilder()
90 ->select( [ 'old_flags', 'old_text' ] )
91 ->from( 'text' )
92 ->where( [ 'old_id' => $this->mOldId ] )
93 ->caller( __METHOD__ )->fetchRow();
94
95 if ( !$row ) {
96 return false;
97 }
98
99 $flags = explode( ',', $row->old_flags );
100 if ( in_array( 'external', $flags ) ) {
101 $url = $row->old_text;
102 $parts = explode( '://', $url, 2 );
103 if ( !isset( $parts[1] ) || $parts[1] == '' ) {
104 return false;
105 }
106 $row->old_text = MediaWikiServices::getInstance()
107 ->getExternalStoreAccess()
108 ->fetchFromURL( $url );
109 }
110
111 if ( !in_array( 'object', $flags ) ) {
112 return false;
113 }
114
115 if ( in_array( 'gzip', $flags ) ) {
116 // This shouldn't happen, but a bug in the compress script
117 // may at times gzip-compress a HistoryBlob object row.
118 $obj = HistoryBlobUtils::unserialize( gzinflate( $row->old_text ), true );
119 } else {
120 $obj = HistoryBlobUtils::unserialize( $row->old_text, true );
121 }
122
123 // Save this item for reference; if pulling many
124 // items in a row we'll likely use it again.
125 self::$blobCache = [ $this->mOldId => $obj ];
126 }
127
128 if ( method_exists( $obj, 'getItem' ) ) {
129 return $obj->getItem( $this->mHash );
130 }
131
132 return false;
133 }
134
140 public function getHash() {
141 return $this->mHash;
142 }
143}
144
145// Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
146// class name coerced to lowercase. We can improve efficiency by adding
147// autoload entries for the lowercase variants of these classes (T166759).
148// The code below is never executed, but it is picked up by the AutoloadGenerator
149// parser, which scans for class_alias() calls.
150/*
151class_alias( HistoryBlobStub::class, 'historyblobstub' );
152*/
Pointer object for an item within a CGZ blob stored in the text table.
setLocation( $id)
Sets the location (old_id) of the main object to which this object points.
getReferrer()
Gets the location of the referring object.
static array $blobCache
One-step cache variable to hold base blobs; operations that pull multiple revisions may often pull mu...
__construct( $hash='', $oldid=0)
getHash()
Get the content hash.
setReferrer( $id)
Sets the location (old_id) of the referring object.
getLocation()
Gets the location of the main object.
Service locator for MediaWiki core services.