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 = wfGetDB( DB_REPLICA );
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  return $obj->getItem( $this->mHash );
141  }
142 
148  public function getHash() {
149  return $this->mHash;
150  }
151 }
152 
153 // Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
154 // class name coerced to lowercase. We can improve efficiency by adding
155 // autoload entries for the lowercase variants of these classes (T166759).
156 // The code below is never executed, but it is picked up by the AutoloadGenerator
157 // parser, which scans for class_alias() calls.
158 /*
159 class_alias( HistoryBlobStub::class, 'historyblobstub' );
160 */
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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.
static unserialize(string $str, bool $allowDouble=false)
Unserialize a HistoryBlob.
Service locator for MediaWiki core services.
const DB_REPLICA
Definition: defines.php:26