MediaWiki  master
RevisionSlotsUpdate.php
Go to the documentation of this file.
1 <?php
23 namespace MediaWiki\Storage;
24 
25 use Content;
30 
37 
41  private $modifiedSlots = [];
42 
46  private $removedRoles = [];
47 
58  public static function newFromRevisionSlots(
59  RevisionSlots $newSlots,
60  RevisionSlots $parentSlots = null
61  ) {
62  $modified = $newSlots->getSlots();
63  $removed = [];
64 
65  if ( $parentSlots ) {
66  foreach ( $parentSlots->getSlots() as $role => $slot ) {
67  if ( !isset( $modified[$role] ) ) {
68  $removed[] = $role;
69  } elseif ( $slot->hasSameContent( $modified[$role] ) ) {
70  // Unset slots that had the same content in the parent revision from $modified.
71  unset( $modified[$role] );
72  }
73  }
74  }
75 
76  return new RevisionSlotsUpdate( $modified, $removed );
77  }
78 
92  public static function newFromContent( array $newContent, RevisionSlots $parentSlots = null ) {
93  $modified = [];
94 
95  foreach ( $newContent as $role => $content ) {
96  $slot = SlotRecord::newUnsaved( $role, $content );
97 
98  if ( $parentSlots
99  && $parentSlots->hasSlot( $role )
100  && $slot->hasSameContent( $parentSlots->getSlot( $role ) )
101  ) {
102  // Skip slots that had the same content in the parent revision from $modified.
103  continue;
104  }
105 
106  $modified[$role] = $slot;
107  }
108 
109  return new RevisionSlotsUpdate( $modified );
110  }
111 
116  public function __construct( array $modifiedSlots = [], array $removedRoles = [] ) {
117  foreach ( $modifiedSlots as $slot ) {
118  $this->modifySlot( $slot );
119  }
120 
121  foreach ( $removedRoles as $role ) {
122  $this->removeSlot( $role );
123  }
124  }
125 
137  public function getModifiedRoles() {
138  return array_keys( $this->modifiedSlots );
139  }
140 
147  public function getRemovedRoles() {
148  return array_keys( $this->removedRoles );
149  }
150 
156  public function getTouchedRoles() {
157  return array_merge( $this->getModifiedRoles(), $this->getRemovedRoles() );
158  }
159 
169  public function modifySlot( SlotRecord $slot ) {
170  $role = $slot->getRole();
171 
172  // XXX: We should perhaps require this to be an unsaved slot!
173  unset( $this->removedRoles[$role] );
174  $this->modifiedSlots[$role] = $slot;
175  }
176 
184  public function modifyContent( $role, Content $content ) {
185  $slot = SlotRecord::newUnsaved( $role, $content );
186  $this->modifySlot( $slot );
187  }
188 
197  public function removeSlot( $role ) {
198  unset( $this->modifiedSlots[$role] );
199  $this->removedRoles[$role] = true;
200  }
201 
217  public function getModifiedSlot( $role ) {
218  if ( isset( $this->modifiedSlots[$role] ) ) {
219  return $this->modifiedSlots[$role];
220  } else {
221  throw new RevisionAccessException( 'No such slot: ' . $role );
222  }
223  }
224 
234  public function isModifiedSlot( $role ) {
235  return isset( $this->modifiedSlots[$role] );
236  }
237 
247  public function isRemovedSlot( $role ) {
248  return isset( $this->removedRoles[$role] );
249  }
250 
261  public function hasSameUpdates( RevisionSlotsUpdate $other ) {
262  // NOTE: use != not !==, since the order of entries is not significant!
263 
264  if ( $this->getModifiedRoles() != $other->getModifiedRoles() ) {
265  return false;
266  }
267 
268  if ( $this->getRemovedRoles() != $other->getRemovedRoles() ) {
269  return false;
270  }
271 
272  foreach ( $this->getModifiedRoles() as $role ) {
273  $s = $this->getModifiedSlot( $role );
274  $t = $other->getModifiedSlot( $role );
275 
276  if ( !$s->hasSameContent( $t ) ) {
277  return false;
278  }
279  }
280 
281  return true;
282  }
283 
290  public function apply( MutableRevisionSlots $slots ) {
291  foreach ( $this->getModifiedRoles() as $role ) {
292  $slots->setSlot( $this->getModifiedSlot( $role ) );
293  }
294 
295  foreach ( $this->getRemovedRoles() as $role ) {
296  $slots->removeSlot( $role );
297  }
298  }
299 
300 }
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))
setSlot(SlotRecord $slot)
Sets the given slot.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
modifySlot(SlotRecord $slot)
Sets the given slot to be modified.
Value object representing a modification of revision slots.
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
isRemovedSlot( $role)
Returns whether the given role is to be removed from the page.
getTouchedRoles()
Returns a list of all slot roles that modified or removed.
static newFromContent(array $newContent, RevisionSlots $parentSlots=null)
Constructs a RevisionSlotsUpdate representing the update of $parentSlots when changing $newContent...
static newFromRevisionSlots(RevisionSlots $newSlots, RevisionSlots $parentSlots=null)
Constructs a RevisionSlotsUpdate representing the update that turned $parentSlots into $newSlots...
__construct(array $modifiedSlots=[], array $removedRoles=[])
hasSameUpdates(RevisionSlotsUpdate $other)
Returns true if $other represents the same update - that is, if all methods defined by RevisionSlotsU...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
SlotRecord [] $modifiedSlots
modified slots, using the slot role as the key.
isModifiedSlot( $role)
Returns whether getModifiedSlot() will return a SlotRecord for the given role.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
removeSlot( $role)
Remove the slot for the given role, discontinue the corresponding stream.
modifyContent( $role, Content $content)
Sets the content for the slot with the given role to be modified.
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
getRole()
Returns the role of the slot.
Definition: SlotRecord.php:489
getModifiedRoles()
Returns a list of modified slot roles, that is, roles modified by calling modifySlot(), and not later removed by calling removeSlot().
getModifiedSlot( $role)
Returns the SlotRecord associated with the given role, if the slot with that role was modified (and n...
Exception representing a failure to look up a revision.
apply(MutableRevisionSlots $slots)
Applies this update to the given MutableRevisionSlots, setting all modified slots, and removing all removed roles.
getSlots()
Returns an associative array that maps role names to SlotRecords.
static newUnsaved( $role, Content $content)
Constructs a new Slot from a Content object for a new revision.
Definition: SlotRecord.php:129
removeSlot( $role)
Remove the slot for the given role, discontinue the corresponding stream.
Mutable version of RevisionSlots, for constructing a new revision.
Value object representing the set of slots belonging to a revision.
getRemovedRoles()
Returns a list of removed slot roles, that is, roles removed by calling removeSlot(), and not later re-introduced by calling modifySlot().
$content
Definition: pageupdater.txt:72
bool [] $removedRoles
removed roles, stored in the keys of the array.