MediaWiki REL1_37
HistoryBlobStub.php
Go to the documentation of this file.
1<?php
24
35 protected static $blobCache = [];
36
38 protected $mOldId;
39
41 protected $mHash;
42
44 protected $mRef;
45
50 public function __construct( $hash = '', $oldid = 0 ) {
51 $this->mHash = $hash;
52 }
53
59 public function setLocation( $id ) {
60 $this->mOldId = $id;
61 }
62
67 public function getLocation() {
68 return $this->mOldId;
69 }
70
75 public function setReferrer( $id ) {
76 $this->mRef = $id;
77 }
78
83 public function getReferrer() {
84 return $this->mRef;
85 }
86
90 public function getText() {
91 if ( isset( self::$blobCache[$this->mOldId] ) ) {
92 $obj = self::$blobCache[$this->mOldId];
93 } else {
95 $row = $dbr->selectRow(
96 'text',
97 [ 'old_flags', 'old_text' ],
98 [ 'old_id' => $this->mOldId ],
99 __METHOD__
100 );
101
102 if ( !$row ) {
103 return false;
104 }
105
106 $flags = explode( ',', $row->old_flags );
107 if ( in_array( 'external', $flags ) ) {
108 $url = $row->old_text;
109 $parts = explode( '://', $url, 2 );
110 if ( !isset( $parts[1] ) || $parts[1] == '' ) {
111 return false;
112 }
113 $row->old_text = MediaWikiServices::getInstance()
114 ->getExternalStoreAccess()
115 ->fetchFromURL( $url );
116 }
117
118 if ( !in_array( 'object', $flags ) ) {
119 return false;
120 }
121
122 if ( in_array( 'gzip', $flags ) ) {
123 // This shouldn't happen, but a bug in the compress script
124 // may at times gzip-compress a HistoryBlob object row.
125 $obj = unserialize( gzinflate( $row->old_text ) );
126 } else {
127 $obj = unserialize( $row->old_text );
128 }
129
130 if ( !is_object( $obj ) ) {
131 // Correct for old double-serialization bug.
132 $obj = unserialize( $obj );
133 }
134
135 // Save this item for reference; if pulling many
136 // items in a row we'll likely use it again.
137 $obj->uncompress();
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*/
unserialize( $serialized)
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
const DB_REPLICA
Definition defines.php:25