MediaWiki 1.40.4
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 {
101 $row = $dbr->selectRow(
102 'text',
103 [ 'old_flags', 'old_text' ],
104 [ 'old_id' => $this->mOldId ],
105 __METHOD__
106 );
107
108 if ( !$row ) {
109 return false;
110 }
111
112 $flags = explode( ',', $row->old_flags );
113 if ( in_array( 'external', $flags ) ) {
114 $url = $row->old_text;
115 $parts = explode( '://', $url, 2 );
116 if ( !isset( $parts[1] ) || $parts[1] == '' ) {
117 return false;
118 }
119 $row->old_text = MediaWikiServices::getInstance()
120 ->getExternalStoreAccess()
121 ->fetchFromURL( $url );
122 }
123
124 if ( !in_array( 'object', $flags ) ) {
125 return false;
126 }
127
128 if ( in_array( 'gzip', $flags ) ) {
129 // This shouldn't happen, but a bug in the compress script
130 // may at times gzip-compress a HistoryBlob object row.
131 $obj = HistoryBlobUtils::unserialize( gzinflate( $row->old_text ), true );
132 } else {
133 $obj = HistoryBlobUtils::unserialize( $row->old_text, true );
134 }
135
136 // Save this item for reference; if pulling many
137 // items in a row we'll likely use it again.
138 self::$blobCache = [ $this->mOldId => $obj ];
139 }
140
141 return $obj->getItem( $this->mHash );
142 }
143
149 public function getHash() {
150 return $this->mHash;
151 }
152}
153
154// Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
155// class name coerced to lowercase. We can improve efficiency by adding
156// autoload entries for the lowercase variants of these classes (T166759).
157// The code below is never executed, but it is picked up by the AutoloadGenerator
158// parser, which scans for class_alias() calls.
159/*
160class_alias( HistoryBlobStub::class, 'historyblobstub' );
161*/
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.
Service locator for MediaWiki core services.
const DB_REPLICA
Definition defines.php:26