26use InvalidArgumentException;
28use OutOfBoundsException;
29use Wikimedia\Assert\Assert;
81 $row = clone $slot->row;
84 foreach ( $overrides as $key =>
$value ) {
111 'slot_revision_id' =>
null,
130 Assert::parameterType(
'string', $role,
'$role' );
134 'slot_revision_id' =>
null,
135 'slot_origin' =>
null,
136 'content_size' =>
null,
137 'content_sha1' =>
null,
138 'slot_content_id' =>
null,
139 'content_address' =>
null,
140 'role_name' => $role,
170 Assert::parameterType(
'integer', $revisionId,
'$revisionId' );
172 Assert::parameterType(
'integer|null', $contentId,
'$contentId' );
173 Assert::parameterType(
'string', $contentAddress,
'$contentAddress' );
175 if ( $protoSlot->hasRevision() && $protoSlot->getRevision() !== $revisionId ) {
176 throw new LogicException(
177 "Mismatching revision ID $revisionId: "
178 .
"The slot already belongs to revision {$protoSlot->getRevision()}. "
179 .
"Use SlotRecord::newInherited() to re-use content between revisions."
183 if ( $protoSlot->hasAddress() && $protoSlot->getAddress() !== $contentAddress ) {
184 throw new LogicException(
185 "Mismatching blob address $contentAddress: "
186 .
"The slot already has content at {$protoSlot->getAddress()}."
190 if ( $protoSlot->hasContentId() && $protoSlot->getContentId() !== $contentId ) {
191 throw new LogicException(
192 "Mismatching content ID $contentId: "
193 .
"The slot already has content row {$protoSlot->getContentId()} associated."
197 if ( $protoSlot->isInherited() ) {
198 if ( !$protoSlot->hasAddress() ) {
199 throw new InvalidArgumentException(
200 "An inherited blob should have a content address!"
203 if ( !$protoSlot->hasField(
'slot_origin' ) ) {
204 throw new InvalidArgumentException(
205 "A saved inherited slot should have an origin set!"
208 $origin = $protoSlot->getOrigin();
210 $origin = $revisionId;
214 'slot_revision_id' => $revisionId,
215 'slot_content_id' => $contentId,
216 'slot_origin' => $origin,
217 'content_address' => $contentAddress,
237 Assert::parameterType(
'object',
$row,
'$row' );
238 Assert::parameterType(
'Content|callable',
$content,
'$content' );
241 property_exists(
$row,
'slot_revision_id' ),
242 '$row->slot_revision_id',
246 property_exists(
$row,
'slot_content_id' ),
247 '$row->slot_content_id',
251 property_exists(
$row,
'content_address' ),
252 '$row->content_address',
256 property_exists(
$row,
'model_name' ),
261 property_exists(
$row,
'slot_origin' ),
266 !property_exists(
$row,
'slot_inherited' ),
267 '$row->slot_inherited',
271 !property_exists(
$row,
'slot_revision' ),
272 '$row->slot_revision',
286 throw new LogicException( __CLASS__ .
' is not serializable.' );
305 if ( $this->content instanceof
Content ) {
309 $obj = call_user_func( $this->content, $this );
311 Assert::postcondition(
313 'Slot content callback should return a Content object'
316 $this->content = $obj;
332 if ( !isset( $this->row->$name ) ) {
334 if ( property_exists( $this->row, $name ) ) {
337 throw new OutOfBoundsException(
'No such field: ' . $name );
341 $value = $this->row->$name;
362 return strval( $this->
getField( $name ) );
375 return intval( $this->
getField( $name ) );
383 if ( isset( $this->row->$name ) ) {
385 if ( !is_string( $this->row->$name ) && is_callable( $this->row->$name ) ) {
390 return isset( $this->row->$name );
438 return $this->
hasField(
'content_address' );
449 return $this->
hasField(
'slot_origin' );
472 return $this->
hasField(
'slot_content_id' );
483 return $this->
hasField(
'slot_revision_id' );
529 $this->
setField(
'content_size', $size );
544 $format = $this->
hasField(
'format_name' )
548 $data = $this->
getContent()->serialize( $format );
550 $this->
setField(
'content_sha1', $sha1 );
568 $this->
setField(
'model_name', $model );
586 if ( $this->
hasField(
'format_name' ) ) {
598 $this->row->$name =
$value;
610 return \Wikimedia\base_convert( sha1(
$blob ), 16, 36, 31 );
633 if ( $other === $this ) {
643 && $this->getAddress() == $other->getAddress()
665class_alias( SlotRecord::class,
'MediaWiki\Storage\SlotRecord' );
Base interface for content objects.
getModel()
Returns the ID of the content model used by this Content object.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))