MediaWiki master
HistoryBlobStub.php
Go to the documentation of this file.
1<?php
24
41 protected static $blobCache = [];
42
44 protected $mOldId;
45
47 protected $mHash;
48
50 protected $mRef;
51
56 public function __construct( $hash = '', $oldid = 0 ) {
57 $this->mHash = $hash;
58 }
59
65 public function setLocation( $id ) {
66 $this->mOldId = $id;
67 }
68
73 public function getLocation() {
74 return $this->mOldId;
75 }
76
81 public function setReferrer( $id ) {
82 $this->mRef = $id;
83 }
84
89 public function getReferrer() {
90 return $this->mRef;
91 }
92
96 public function getText() {
97 if ( isset( self::$blobCache[$this->mOldId] ) ) {
98 $obj = self::$blobCache[$this->mOldId];
99 } else {
100 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
101 $row = $dbr->newSelectQueryBuilder()
102 ->select( [ 'old_flags', 'old_text' ] )
103 ->from( 'text' )
104 ->where( [ 'old_id' => $this->mOldId ] )
105 ->caller( __METHOD__ )->fetchRow();
106
107 if ( !$row ) {
108 return false;
109 }
110
111 $flags = explode( ',', $row->old_flags );
112 if ( in_array( 'external', $flags ) ) {
113 $url = $row->old_text;
114 $parts = explode( '://', $url, 2 );
115 if ( !isset( $parts[1] ) || $parts[1] == '' ) {
116 return false;
117 }
118 $row->old_text = MediaWikiServices::getInstance()
119 ->getExternalStoreAccess()
120 ->fetchFromURL( $url );
121 }
122
123 if ( !in_array( 'object', $flags ) ) {
124 return false;
125 }
126
127 if ( in_array( 'gzip', $flags ) ) {
128 // This shouldn't happen, but a bug in the compress script
129 // may at times gzip-compress a HistoryBlob object row.
130 $obj = HistoryBlobUtils::unserialize( gzinflate( $row->old_text ), true );
131 } else {
132 $obj = HistoryBlobUtils::unserialize( $row->old_text, true );
133 }
134
135 // Save this item for reference; if pulling many
136 // items in a row we'll likely use it again.
137 self::$blobCache = [ $this->mOldId => $obj ];
138 }
139
140 if ( method_exists( $obj, 'getItem' ) ) {
141 return $obj->getItem( $this->mHash );
142 }
143
144 return false;
145 }
146
152 public function getHash() {
153 return $this->mHash;
154 }
155}
156
157// Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
158// class name coerced to lowercase. We can improve efficiency by adding
159// autoload entries for the lowercase variants of these classes (T166759).
160// The code below is never executed, but it is picked up by the AutoloadGenerator
161// parser, which scans for class_alias() calls.
162/*
163class_alias( HistoryBlobStub::class, 'historyblobstub' );
164*/
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.