Go to the documentation of this file.
23 'wgMultiContentRevisionSchemaMigrationStage',
29 yield
'with text' => [
31 'text' =>
'hello world.',
35 yield
'with content' => [
50 ->disableOriginalConstructor()
52 $mock->expects( $this->
any() )
53 ->method(
'getNamespace' )
55 $mock->expects( $this->
any() )
56 ->method(
'getPrefixedText' )
57 ->will( $this->returnValue(
'RevisionTest' ) );
58 $mock->expects( $this->
any() )
59 ->method(
'getDBkey' )
60 ->will( $this->returnValue(
'RevisionTest' ) );
61 $mock->expects( $this->
any() )
62 ->method(
'getArticleID' )
63 ->will( $this->returnValue( 23 ) );
64 $mock->expects( $this->
any() )
65 ->method(
'getContentModel' )
66 ->will( $this->returnValue( $model ) );
78 $this->assertNotNull(
$rev->getContent(),
'no content object available' );
89 $this->assertNull(
$rev->getContent(),
'no content object should be available' );
97 Wikimedia\suppressWarnings();
99 $this->assertSame( 77777777,
$rev->getPage() );
100 Wikimedia\restoreWarnings();
104 yield
'no user defaults to wgUser' => [
111 yield
'user text and id' => [
114 'user_text' =>
'SomeTextUserName',
121 yield
'user text only' => [
124 'user_text' =>
'111.111.111.111',
147 if ( $expectedUserId ===
null ) {
148 $expectedUserId = $testUser->getId();
150 if ( $expectedUserName ===
null ) {
151 $expectedUserName = $testUser->getName();
155 $this->assertEquals( $expectedUserId,
$rev->getUser() );
156 $this->assertEquals( $expectedUserName,
$rev->getUserText() );
160 yield
'content and text_id both not empty' => [
163 'text_id' =>
'someid',
165 new MWException(
'The text_id field is only available in the pre-MCR schema' )
168 yield
'with bad content object (class)' => [
169 [
'content' =>
new stdClass() ],
170 new MWException(
'content field must contain a Content object' )
172 yield
'with bad content object (string)' => [
173 [
'content' =>
'ImAGoat' ],
174 new MWException(
'content field must contain a Content object' )
176 yield
'bad row format' => [
177 'imastring, not a row',
178 new InvalidArgumentException(
179 '$row must be a row object, an associative array, or a RevisionRecord'
190 $this->setExpectedException(
191 get_class( $expectedException ),
192 $expectedException->getMessage(),
193 $expectedException->getCode()
203 $this->setExpectedException(
210 yield
'Full construction' => [
214 'rev_timestamp' =>
'20171017114835',
215 'rev_user_text' =>
'127.0.0.1',
217 'rev_minor_edit' =>
'0',
218 'rev_deleted' =>
'0',
220 'rev_parent_id' =>
'1',
221 'rev_sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
222 'rev_comment_text' =>
'Goat Comment!',
223 'rev_comment_data' =>
null,
224 'rev_comment_cid' =>
null,
227 $testCase->assertSame( 42,
$rev->getId() );
228 $testCase->assertSame( 23,
$rev->getPage() );
229 $testCase->assertSame(
'20171017114835',
$rev->getTimestamp() );
230 $testCase->assertSame(
'127.0.0.1',
$rev->getUserText() );
231 $testCase->assertSame( 0,
$rev->getUser() );
232 $testCase->assertSame(
false,
$rev->isMinor() );
234 $testCase->assertSame( 46,
$rev->getSize() );
235 $testCase->assertSame( 1,
$rev->getParentId() );
236 $testCase->assertSame(
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
$rev->getSha1() );
237 $testCase->assertSame(
'Goat Comment!',
$rev->getComment() );
240 yield
'default field values' => [
244 'rev_timestamp' =>
'20171017114835',
245 'rev_user_text' =>
'127.0.0.1',
247 'rev_minor_edit' =>
'0',
248 'rev_deleted' =>
'0',
249 'rev_comment_text' =>
'Goat Comment!',
250 'rev_comment_data' =>
null,
251 'rev_comment_cid' =>
null,
255 $testCase->assertSame(
null,
$rev->getParentId(),
'revision id' );
258 $testCase->assertSame(
$rev->getTimestamp(),
'20171017114835',
'timestamp' );
259 $testCase->assertSame(
$rev->getUserText(),
'127.0.0.1',
'user name' );
260 $testCase->assertSame(
$rev->getUser(), 0,
'user id' );
261 $testCase->assertSame(
$rev->getComment(),
'Goat Comment!' );
262 $testCase->assertSame(
false,
$rev->isMinor(),
'minor edit' );
263 $testCase->assertSame( 0,
$rev->getVisibility(),
'visibility flags' );
274 $row = (
object)$arrayData;
276 $assertions( $this,
$rev );
286 Wikimedia\suppressWarnings();
287 $rev =
new Revision( (
object)[
'rev_page' => 77777777 ] );
288 $this->assertSame( 77777777,
$rev->getPage() );
289 Wikimedia\restoreWarnings();
293 yield
'Generic test' => [
294 'This is a goat of revision text.',
297 'old_text' =>
'This is a goat of revision text.',
319 $this->assertEquals( $expectedId,
$rev->getId() );
323 yield [
'123', 123 ];
334 $this->assertSame( $expected,
$rev->getId() );
338 yield [
'123', 123,
'GOaT' ];
339 yield [ 456, 456,
'GOaT' ];
348 $rev->setUserIdAndName( $inputId,
$name );
355 yield [ [
'parent_id' =>
'123' ], 123 ];
356 yield [ [
'parent_id' => 456 ], 456 ];
365 $this->assertSame( $expected,
$rev->getParentId() );
379 yield
'Generic gzip test' => [
380 'This is a small goat of revision text.',
382 'old_flags' =>
'gzip',
383 'old_text' => gzdeflate(
'This is a small goat of revision text.' ),
398 yield
'Generic gzip test' => [
399 'This is a small goat of revision text.',
401 'old_flags' =>
'gzip',
402 'old_text' =>
'DEAD BEEF',
413 Wikimedia\suppressWarnings();
419 Wikimedia\suppressWarnings(
true );
432 ->disableOriginalConstructor()
444 ->disableOriginalConstructor()
446 $factory->expects( $this->
any() )
447 ->method(
'newBlobStore' )
448 ->willReturn( $blobStore );
449 $factory->expects( $this->
any() )
450 ->method(
'newSqlBlobStore' )
451 ->willReturn( $blobStore );
461 ->disableOriginalConstructor()
470 MediaWikiServices::getInstance()->getCommentStore(),
471 MediaWikiServices::getInstance()->getContentModelStore(),
472 MediaWikiServices::getInstance()->getSlotRoleStore(),
474 MediaWikiServices::getInstance()->getActorMigration()
480 yield
'Utf8Native' => [
481 "Wiki est l'\xc3\xa9cole superieur !",
485 'old_flags' =>
'utf-8',
486 'old_text' =>
"Wiki est l'\xc3\xa9cole superieur !",
489 yield
'Utf8Legacy' => [
490 "Wiki est l'\xc3\xa9cole superieur !",
495 'old_text' =>
"Wiki est l'\xe9cole superieur !",
518 yield
'Utf8NativeGzip' => [
519 "Wiki est l'\xc3\xa9cole superieur !",
523 'old_flags' =>
'gzip,utf-8',
524 'old_text' => gzdeflate(
"Wiki est l'\xc3\xa9cole superieur !" ),
527 yield
'Utf8LegacyGzip' => [
528 "Wiki est l'\xc3\xa9cole superieur !",
532 'old_flags' =>
'gzip',
533 'old_text' => gzdeflate(
"Wiki est l'\xe9cole superieur !" ),
557 $row->old_text =
"Wiki est l'\xc3\xa9cole superieur !";
559 $this->assertTrue(
false !== strpos( $row->old_flags,
'utf-8' ),
560 "Flags should contain 'utf-8'" );
561 $this->assertFalse(
false !== strpos( $row->old_flags,
'gzip' ),
562 "Flags should not contain 'gzip'" );
563 $this->assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
564 $row->old_text,
"Direct check" );
565 $this->assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
576 $blobStore->setCompressBlobs(
true );
580 $row->old_text =
"Wiki est l'\xc3\xa9cole superieur !";
582 $this->assertTrue(
false !== strpos( $row->old_flags,
'utf-8' ),
583 "Flags should contain 'utf-8'" );
584 $this->assertTrue(
false !== strpos( $row->old_flags,
'gzip' ),
585 "Flags should contain 'gzip'" );
586 $this->assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
587 gzinflate( $row->old_text ),
"Direct check" );
588 $this->assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
602 'rev_id=page_latest',
603 'page_namespace' =>
$title->getNamespace(),
604 'page_title' =>
$title->getDBkey()
609 'rev_page' =>
$title->getArticleID(),
610 'rev_timestamp' =>
'20171017114835',
611 'rev_user_text' =>
'127.0.0.1',
613 'rev_minor_edit' =>
'0',
614 'rev_deleted' =>
'0',
616 'rev_parent_id' =>
'1',
617 'rev_sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
618 'rev_comment_text' =>
'Goat Comment!',
619 'rev_comment_data' =>
null,
620 'rev_comment_cid' =>
null,
621 'rev_content_format' =>
'GOATFORMAT',
622 'rev_content_model' =>
'GOATMODEL',
625 $domain = MediaWikiServices::getInstance()->getDBLoadBalancer()->getLocalDomainID();
627 $db->expects( $this->
any() )
628 ->method(
'getDomainId' )
629 ->will( $this->returnValue( $domain ) );
630 $db->expects( $this->once() )
631 ->method(
'selectRow' )
633 $this->equalTo( [
'revision',
'page',
'user' ] ),
635 $this->isType(
'array' ),
636 $this->equalTo( $conditions ),
638 $this->stringContains(
'fetchRevisionRowFromConds' ),
640 $this->isType(
'array' ),
642 $this->isType(
'array' )
644 ->willReturn( $row );
648 $this->assertEquals(
$title->getArticleID(), $revision->getTitle()->getArticleID() );
649 $this->assertEquals( $row->rev_id, $revision->getId() );
650 $this->assertEquals( $row->rev_len, $revision->getSize() );
651 $this->assertEquals( $row->rev_sha1, $revision->getSha1() );
652 $this->assertEquals( $row->rev_parent_id, $revision->getParentId() );
653 $this->assertEquals( $row->rev_timestamp, $revision->getTimestamp() );
654 $this->assertEquals( $row->rev_comment_text, $revision->getComment() );
655 $this->assertEquals( $row->rev_user_text, $revision->getUserText() );
659 yield
'(no legacy encoding), false in false out' => [
false,
false, [],
false ];
660 yield
'(no legacy encoding), empty in empty out' => [
false,
'', [],
'' ];
661 yield
'(no legacy encoding), empty in empty out' => [
false,
'A', [],
'A' ];
662 yield
'(no legacy encoding), string in with gzip flag returns string' => [
664 false,
"sttttr\002\022\000", [
'gzip' ],
'AAAABBAAA',
666 yield
'(no legacy encoding), string in with object flag returns false' => [
668 false,
"s:4:\"JOJO\";", [
'object' ],
false,
670 yield
'(no legacy encoding), serialized object in with object flag returns string' => [
677 yield
'(no legacy encoding), serialized object in with object & gzip flag returns string' => [
681 [
'object',
'gzip' ],
684 yield
'(ISO-8859-1 encoding), string in string out' => [
686 iconv(
'utf-8',
'ISO-8859-1',
"1®Àþ1" ),
690 yield
'(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
692 gzdeflate( iconv(
'utf-8',
'ISO-8859-1',
"4®Àþ4" ) ),
696 yield
'(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
702 yield
'(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
705 [
'gzip',
'object' ],
721 if ( $legacyEncoding ) {
740 yield
'Just text' => [
741 (
object)[
'old_text' =>
'SomeText' ],
746 yield
'gzip text' => [
748 'old_text' =>
"sttttr\002\022\000",
749 'old_flags' =>
'gzip'
754 yield
'gzip text and different prefix' => [
756 'jojo_text' =>
"sttttr\002\022\000",
757 'jojo_flags' =>
'gzip'
777 yield
'Just some text' => [
'someNonUrlText' ];
778 yield
'No second URL part' => [
'someProtocol://' ];
788 Wikimedia\suppressWarnings();
793 'old_flags' =>
'external',
797 Wikimedia\suppressWarnings(
true );
805 'ExternalStoreFactory',
812 'old_text' =>
'ForTesting://cluster1/12345',
813 'old_flags' =>
'external,gzip',
827 'ExternalStoreFactory',
832 ->disableOriginalConstructor()
842 'old_text' =>
'ForTesting://cluster1/12345',
843 'old_flags' =>
'external,gzip',
849 $cacheKey =
$cache->makeGlobalKey(
852 $lb->getLocalDomainID(),
855 $this->assertSame(
'AAAABBAAA',
$cache->get( $cacheKey ) );
867 $this->assertSame( 0,
$rev->getSize(),
'Size of no slots is 0' );
870 $this->assertSame( 13,
$rev->getSize() );
880 ->disableOriginalConstructor()
883 $rec->method(
'getSize' )
887 $this->assertNull(
$rev->getSize() );
899 $emptyHash = SlotRecord::base36Sha1(
'' );
900 $this->assertSame( $emptyHash,
$rev->getSha1(),
'Sha1 of no slots is hash of empty string' );
902 $rec->setSha1(
'deadbeef' );
903 $this->assertSame(
'deadbeef',
$rev->getSha1() );
913 ->disableOriginalConstructor()
916 $rec->method(
'getSha1' )
920 $this->assertNull(
$rev->getSha1() );
932 $this->assertNull(
$rev->getContent(),
'Content of no slots is null' );
935 $rec->setContent( SlotRecord::MAIN,
$content );
946 ->disableOriginalConstructor()
949 $rec->method(
'getContent' )
953 $this->assertNull(
$rev->getContent() );
testSetId( $input, $expected)
provideSetId Revision::setId
testGetSha1()
Revision::getSha1.
testConstructFromEmptyArray()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
const SCHEMA_COMPAT_READ_NEW
processing should stop and the error should be shown to the user * false
provideDecompressRevisionText()
testGetRevisionWithZlibExtension_badData( $expected, $rowData)
Revision::getRevisionText provideGetRevisionTextWithZlibExtension_badData.
Simple store for keeping values in an associative array for the current process.
if(!isset( $args[0])) $lang
testConstructFromArray_userSetAsExpected(array $rowArray, $expectedUserId, $expectedUserName)
provideConstructFromArray_userSetAsExpected Revision::__construct \MediaWiki\Revision\RevisionStore::...
testGetRevisionText_external_oldId()
Revision::getRevisionText.
testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException)
provideConstructFromArrayThrowsExceptions Revision::__construct \MediaWiki\Revision\RevisionStore::ne...
testGetRevisionText_returnsFalseWhenNoTextField()
Revision::getRevisionText.
provideGetRevisionTextWithZlibExtension()
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
testConstructFromRowWithBadPageId()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testConstructFromRow(array $arrayData, callable $assertions)
provideConstructFromRow Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFr...
testGetSize_failure()
Revision::getSize.
const CONTENT_MODEL_WIKITEXT
testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData)
Revision::getRevisionText provideGetRevisionTextWithGzipAndLegacyEncoding.
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
provideConstructFromArray()
provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts()
mockBlobStoreFactory( $blobStore)
testCompressRevisionTextUtf8Gzip()
Revision::compressRevisionText.
namespace and then decline to actually register it file or subcat img or subcat $title
testSetUserIdAndName( $inputId, $expectedId, $name)
provideSetUserIdAndName Revision::setUserIdAndName
testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData)
Revision::getRevisionText provideGetRevisionTextWithLegacyEncoding.
if(is_array( $mode)) switch( $mode) $input
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
provideGetRevisionTextWithGzipAndLegacyEncoding()
provideConstructFromArrayThrowsExceptions()
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
testGetContent()
Revision::getContent.
Content object for wiki text pages.
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))
Test cases in RevisionTest should not interact with the Database.
Content for JavaScript pages.
provideGetRevisionTextWithLegacyEncoding()
Allows to change the fields on the form that will be generated $name
testGetSize()
Revision::getSize.
provideGetRevisionTextWithZlibExtension_badData()
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
provideSetUserIdAndName()
provideConstructFromArray_userSetAsExpected()
Multi-datacenter aware caching interface.
testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected)
provideDecompressRevisionText Revision::decompressRevisionText
testConstructFromArray( $rowArray)
provideConstructFromArray Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevision...
testGetRevisionText_external_noOldId()
Revision::getRevisionText.
testGetContent_failure()
Revision::getContent.
testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal( $row, $prefix, $expected)
provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal Revision::getRevisionText
Content object implementation for representing flat text.
testGetRevisionText( $expected, $rowData, $prefix='old_', $wiki=false)
Revision::getRevisionText provideGetRevisionText.
provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal()
testConstructFromArrayWithBadPageId()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts( $text)
provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts Revision::getRevisionText
testConstructFromNothing()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testGetId( $rowArray, $expectedId)
provideGetId Revision::getId
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
testLoadFromTitle()
Revision::loadFromTitle.
const SCHEMA_COMPAT_WRITE_BOTH
testGetSha1_failure()
Revision::getSha1.
static factory( $code)
Get a cached or new language object for a given language code.
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
const CONTENT_MODEL_JAVASCRIPT
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 $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
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 MediaWikiServices
static decompressRevisionText( $text, $flags)
Re-converts revision text according to it's flags.
static loadFromTitle( $db, $title, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
provideConstructFromRow()
getMockTitle( $model=CONTENT_MODEL_WIKITEXT)
testCompressRevisionTextUtf8()
Revision::compressRevisionText.
testGetRevisionWithZlibExtension( $expected, $rowData)
Revision::getRevisionText provideGetRevisionTextWithZlibExtension.
testGetParentId( $rowArray, $expected)
provideGetParentId Revision::getParentId()
Represents a page (or page fragment) title within MediaWiki.