MediaWiki  master
HistoryBlobStub.php
Go to the documentation of this file.
1 <?php
33  protected static $blobCache = [];
34 
36  public $mOldId;
37 
39  public $mHash;
40 
42  public $mRef;
43 
48  function __construct( $hash = '', $oldid = 0 ) {
49  $this->mHash = $hash;
50  }
51 
57  function setLocation( $id ) {
58  $this->mOldId = $id;
59  }
60 
65  function setReferrer( $id ) {
66  $this->mRef = $id;
67  }
68 
73  function getReferrer() {
74  return $this->mRef;
75  }
76 
80  function getText() {
81  if ( isset( self::$blobCache[$this->mOldId] ) ) {
82  $obj = self::$blobCache[$this->mOldId];
83  } else {
84  $dbr = wfGetDB( DB_REPLICA );
85  $row = $dbr->selectRow(
86  'text',
87  [ 'old_flags', 'old_text' ],
88  [ 'old_id' => $this->mOldId ]
89  );
90 
91  if ( !$row ) {
92  return false;
93  }
94 
95  $flags = explode( ',', $row->old_flags );
96  if ( in_array( 'external', $flags ) ) {
97  $url = $row->old_text;
98  $parts = explode( '://', $url, 2 );
99  if ( !isset( $parts[1] ) || $parts[1] == '' ) {
100  return false;
101  }
102  $row->old_text = ExternalStore::fetchFromURL( $url );
103 
104  }
105 
106  if ( !in_array( 'object', $flags ) ) {
107  return false;
108  }
109 
110  if ( in_array( 'gzip', $flags ) ) {
111  // This shouldn't happen, but a bug in the compress script
112  // may at times gzip-compress a HistoryBlob object row.
113  $obj = unserialize( gzinflate( $row->old_text ) );
114  } else {
115  $obj = unserialize( $row->old_text );
116  }
117 
118  if ( !is_object( $obj ) ) {
119  // Correct for old double-serialization bug.
120  $obj = unserialize( $obj );
121  }
122 
123  // Save this item for reference; if pulling many
124  // items in a row we'll likely use it again.
125  $obj->uncompress();
126  self::$blobCache = [ $this->mOldId => $obj ];
127  }
128 
129  return $obj->getItem( $this->mHash );
130  }
131 
137  function getHash() {
138  return $this->mHash;
139  }
140 }
141 
142 // phpcs:ignore Generic.CodeAnalysis.UnconditionalIfStatement.Found
143 if ( false ) {
144  // Blobs generated by MediaWiki < 1.5 on PHP 4 were serialized with the
145  // class name coerced to lowercase. We can improve efficiency by adding
146  // autoload entries for the lowercase variants of these classes (T166759).
147  // The code below is never executed, but it is picked up by the AutoloadGenerator
148  // parser, which scans for class_alias() calls.
149  class_alias( HistoryBlobStub::class, 'historyblobstub' );
150 }
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.
unserialize( $serialized)
setReferrer( $id)
Sets the location (old_id) of the referring object.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
__construct( $hash='', $oldid=0)
getHash()
Get the content hash.
static array $blobCache
One-step cache variable to hold base blobs; operations that pull multiple revisions may often pull mu...
const DB_REPLICA
Definition: defines.php:25
getReferrer()
Gets the location of the referring object.
static fetchFromURL( $url, array $params=[])
Fetch data from given URL.