5use InvalidArgumentException;
21 'slot_content_id' => 33,
22 'content_size' =>
'5',
23 'content_sha1' =>
'someHash',
24 'content_address' =>
'tt:456',
27 'slot_revision_id' =>
'2',
29 'role_name' =>
'myRole',
38 $this->assertTrue( $record->hasAddress() );
39 $this->assertTrue( $record->hasRevision() );
40 $this->assertTrue( $record->isInherited() );
41 $this->assertSame(
'A', $record->getContent()->getNativeData() );
42 $this->assertSame( 5, $record->getSize() );
43 $this->assertSame(
'someHash', $record->getSha1() );
45 $this->assertSame( 2, $record->getRevision() );
46 $this->assertSame( 1, $record->getOrigin() );
47 $this->assertSame(
'tt:456', $record->getAddress() );
48 $this->assertSame( 33, $record->getContentId() );
50 $this->assertSame(
'myRole', $record->getRole() );
55 'content_size' =>
null,
56 'content_sha1' =>
null,
57 'format_name' =>
function () {
60 'slot_revision_id' =>
'2',
64 $content =
function () {
70 $this->assertTrue( $record->hasAddress() );
71 $this->assertTrue( $record->hasRevision() );
72 $this->assertFalse( $record->isInherited() );
73 $this->assertSame(
'A', $record->getContent()->getNativeData() );
74 $this->assertSame( 1, $record->getSize() );
75 $this->assertNotNull( $record->getSha1() );
77 $this->assertSame( 2, $record->getRevision() );
78 $this->assertSame( 2, $record->getRevision() );
79 $this->assertSame(
'tt:456', $record->getAddress() );
80 $this->assertSame( 33, $record->getContentId() );
82 $this->assertSame(
'myRole', $record->getRole() );
86 $record = SlotRecord::newUnsaved(
'myRole',
new WikitextContent(
'A' ) );
88 $this->assertFalse( $record->hasAddress() );
89 $this->assertFalse( $record->hasRevision() );
90 $this->assertFalse( $record->isInherited() );
91 $this->assertSame(
'A', $record->getContent()->getNativeData() );
92 $this->assertSame( 1, $record->getSize() );
93 $this->assertNotNull( $record->getSha1() );
95 $this->assertSame(
'myRole', $record->getRole() );
99 yield
'both null' => [
null, null ];
103 yield
'null content' => [ (
object)[],
null ];
110 $this->setExpectedException( InvalidArgumentException::class );
115 $record = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
116 $this->setExpectedException( IncompleteRevisionException::class );
118 $record->getContentId();
122 $record = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
123 $this->setExpectedException( IncompleteRevisionException::class );
125 $record->getAddress();
129 $unsaved = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
130 yield
'unsaved' => [ $unsaved ];
133 $inherited = SlotRecord::newInherited( $parent );
134 yield
'inherited' => [ $inherited ];
141 $record = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
142 $this->setExpectedException( IncompleteRevisionException::class );
151 $record = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
152 $this->setExpectedException( IncompleteRevisionException::class );
158 yield [
'',
'phoiac9h4m842xq45sp7s6u21eteeq1' ];
159 yield [
'Lorem ipsum',
'hcr5u40uxr81d3nx89nvwzclfz6r9c5' ];
168 $this->assertSame( $hash, SlotRecord::base36Sha1( $text ) );
170 $record = SlotRecord::newUnsaved(
'main',
new WikitextContent( $text ) );
171 $this->assertSame( $hash, $record->getSha1() );
178 $this->setExpectedException( SuppressedDataException::class );
183 $row = $this->
makeRow( [
'slot_revision_id' => 7,
'slot_origin' => 7 ] );
187 $inherited = SlotRecord::newInherited( $parent );
189 $this->assertSame( $parent->getContentId(), $inherited->getContentId() );
190 $this->assertSame( $parent->getAddress(), $inherited->getAddress() );
191 $this->assertSame( $parent->getContent(), $inherited->getContent() );
192 $this->assertTrue( $inherited->isInherited() );
193 $this->assertFalse( $inherited->hasRevision() );
196 $this->assertFalse( $parent->isInherited() );
197 $this->assertSame( 7, $parent->getRevision() );
201 $saved = SlotRecord::newSaved(
203 $inherited->getContentId(),
204 $inherited->getAddress(),
207 $this->assertSame( $parent->getContentId(), $saved->getContentId() );
208 $this->assertSame( $parent->getAddress(), $saved->getAddress() );
209 $this->assertSame( $parent->getContent(), $saved->getContent() );
210 $this->assertTrue( $saved->isInherited() );
211 $this->assertTrue( $saved->hasRevision() );
212 $this->assertSame( 10, $saved->getRevision() );
215 $this->assertSame( 7, $parent->getRevision() );
216 $this->assertFalse( $inherited->hasRevision() );
221 $unsaved = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
225 $saved = SlotRecord::newSaved( 10, 20,
'theNewAddress', $unsaved );
226 $this->assertFalse( $saved->isInherited() );
227 $this->assertTrue( $saved->hasRevision() );
228 $this->assertTrue( $saved->hasAddress() );
229 $this->assertSame(
'theNewAddress', $saved->getAddress() );
230 $this->assertSame( 20, $saved->getContentId() );
231 $this->assertSame(
'A', $saved->getContent()->getNativeData() );
232 $this->assertSame( 10, $saved->getRevision() );
233 $this->assertSame( 10, $saved->getOrigin() );
236 $this->assertFalse( $unsaved->hasAddress() );
237 $this->assertFalse( $unsaved->hasRevision() );
243 'content_address' =>
'address:1',
245 'slot_revision_id' => 1,
249 yield
'mismatching address' => [ 1, 10,
'address:BAD', $freshSlot ];
250 yield
'mismatching revision' => [ 5, 10,
'address:1', $freshSlot ];
251 yield
'mismatching content ID' => [ 1, 17,
'address:1', $freshSlot ];
253 $inheritedRow = $this->
makeRow( [
254 'content_id' =>
null,
255 'content_address' =>
null,
257 'slot_revision_id' => 1,
261 yield
'inherited, but no address' => [ 1, 10,
'address:2', $inheritedSlot ];
273 $this->setExpectedException( LogicException::class );
274 SlotRecord::newSaved( $revisionId, $contentId, $contentAddress, $protoSlot );
278 $unsaved = SlotRecord::newUnsaved(
'main',
new WikitextContent(
'A' ) );
280 yield
'bad revision id' => [
'xyzzy', 5,
'address', $unsaved ];
281 yield
'bad content id' => [ 7,
'xyzzy',
'address', $unsaved ];
282 yield
'bad content address' => [ 7, 5, 77, $unsaved ];
294 $this->setExpectedException( InvalidArgumentException::class );
295 SlotRecord::newSaved( $revisionId, $contentId, $contentAddress, $protoSlot );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Content object for wiki text pages.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
const CONTENT_MODEL_WIKITEXT
const CONTENT_FORMAT_WIKITEXT
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
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
if(is_array($mode)) switch( $mode) $input