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' )
58 $mock->expects( $this->
any() )
59 ->method(
'getDBkey' )
61 $mock->expects( $this->
any() )
62 ->method(
'getArticleID' )
64 $mock->expects( $this->
any() )
65 ->method(
'getContentModel' )
89 $this->
assertNull(
$rev->getContent(),
'no content object should be available' );
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();
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'
192 $expectedException->getMessage(),
193 $expectedException->getCode()
204 InvalidArgumentException::class
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;
287 'rev_page' => 77777777,
288 'rev_comment_text' =>
'',
289 'rev_comment_data' =>
null,
316 yield [
'123', 123 ];
331 yield [
'123', 123,
'GOaT' ];
332 yield [ 456, 456,
'GOaT' ];
341 $rev->setUserIdAndName( $inputId, $name );
348 yield [ [
'parent_id' =>
'123' ], 123 ];
349 yield [ [
'parent_id' => 456 ], 456 ];
362 yield
'Generic test' => [
363 'This is a goat of revision text.',
366 'old_text' =>
'This is a goat of revision text.',
369 yield
'garbage in, garbage out' => [
386 yield
'Generic gzip test' => [
387 'This is a small goat of revision text.',
389 'old_flags' =>
'gzip',
390 'old_text' =>
gzdeflate(
'This is a small goat of revision text.' ),
405 yield
'Generic gzip test' => [
406 'This is a small goat of revision text.',
408 'old_flags' =>
'gzip',
409 'old_text' =>
'DEAD BEEF',
439 ->disableOriginalConstructor()
451 ->disableOriginalConstructor()
453 $factory->expects( $this->
any() )
454 ->method(
'newBlobStore' )
455 ->willReturn( $blobStore );
456 $factory->expects( $this->
any() )
457 ->method(
'newSqlBlobStore' )
458 ->willReturn( $blobStore );
468 ->disableOriginalConstructor()
477 MediaWikiServices::getInstance()->getCommentStore(),
478 MediaWikiServices::getInstance()->getContentModelStore(),
479 MediaWikiServices::getInstance()->getSlotRoleStore(),
480 MediaWikiServices::getInstance()->getSlotRoleRegistry(),
482 MediaWikiServices::getInstance()->getActorMigration()
488 yield
'Utf8Native' => [
489 "Wiki est l'\xc3\xa9cole superieur !",
493 'old_flags' =>
'utf-8',
494 'old_text' =>
"Wiki est l'\xc3\xa9cole superieur !",
497 yield
'Utf8Legacy' => [
498 "Wiki est l'\xc3\xa9cole superieur !",
503 'old_text' =>
"Wiki est l'\xe9cole superieur !",
514 $blobStore->setLegacyEncoding( $encoding, Language::factory(
$lang ) );
526 yield
'Utf8NativeGzip' => [
527 "Wiki est l'\xc3\xa9cole superieur !",
531 'old_flags' =>
'gzip,utf-8',
532 'old_text' =>
gzdeflate(
"Wiki est l'\xc3\xa9cole superieur !" ),
535 yield
'Utf8LegacyGzip' => [
536 "Wiki est l'\xc3\xa9cole superieur !",
540 'old_flags' =>
'gzip',
541 'old_text' =>
gzdeflate(
"Wiki est l'\xe9cole superieur !" ),
554 $blobStore->setLegacyEncoding( $encoding, Language::factory(
$lang ) );
565 $row->old_text =
"Wiki est l'\xc3\xa9cole superieur !";
568 "Flags should contain 'utf-8'" );
570 "Flags should not contain 'gzip'" );
571 $this->
assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
572 $row->old_text,
"Direct check" );
573 $this->
assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
584 $blobStore->setCompressBlobs(
true );
588 $row->old_text =
"Wiki est l'\xc3\xa9cole superieur !";
591 "Flags should contain 'utf-8'" );
593 "Flags should contain 'gzip'" );
594 $this->
assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
595 gzinflate( $row->old_text ),
"Direct check" );
596 $this->
assertEquals(
"Wiki est l'\xc3\xa9cole superieur !",
609 'rev_id=page_latest',
610 'page_namespace' => $title->getNamespace(),
611 'page_title' => $title->getDBkey()
616 'rev_page' => $title->getArticleID(),
617 'rev_timestamp' =>
'20171017114835',
618 'rev_user_text' =>
'127.0.0.1',
620 'rev_minor_edit' =>
'0',
621 'rev_deleted' =>
'0',
623 'rev_parent_id' =>
'1',
624 'rev_sha1' =>
'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
625 'rev_comment_text' =>
'Goat Comment!',
626 'rev_comment_data' =>
null,
627 'rev_comment_cid' =>
null,
628 'rev_content_format' =>
'GOATFORMAT',
629 'rev_content_model' =>
'GOATMODEL',
632 $domain = MediaWikiServices::getInstance()->getDBLoadBalancer()->getLocalDomainID();
634 $db->expects( $this->
any() )
635 ->method(
'getDomainId' )
638 ->method(
'selectRow' )
641 'revision',
'page',
'user',
642 'temp_rev_comment' =>
'revision_comment_temp',
'comment_rev_comment' =>
'comment',
643 'temp_rev_user' =>
'revision_actor_temp',
'actor_rev_user' =>
'actor',
655 ->willReturn( $row );
659 $this->
assertEquals( $title->getArticleID(), $revision->getTitle()->getArticleID() );
660 $this->
assertEquals( $row->rev_id, $revision->getId() );
661 $this->
assertEquals( $row->rev_len, $revision->getSize() );
662 $this->
assertEquals( $row->rev_sha1, $revision->getSha1() );
663 $this->
assertEquals( $row->rev_parent_id, $revision->getParentId() );
664 $this->
assertEquals( $row->rev_timestamp, $revision->getTimestamp() );
665 $this->
assertEquals( $row->rev_comment_text, $revision->getComment() );
666 $this->
assertEquals( $row->rev_user_text, $revision->getUserText() );
670 yield
'(no legacy encoding), false in false out' => [
false,
false, [],
false ];
671 yield
'(no legacy encoding), empty in empty out' => [
false,
'', [],
'' ];
672 yield
'(no legacy encoding), empty in empty out' => [
false,
'A', [],
'A' ];
673 yield
'(no legacy encoding), string in with gzip flag returns string' => [
675 false,
"sttttr\002\022\000", [
'gzip' ],
'AAAABBAAA',
677 yield
'(no legacy encoding), string in with object flag returns false' => [
679 false,
"s:4:\"JOJO\";", [
'object' ],
false,
681 yield
'(no legacy encoding), serialized object in with object flag returns string' => [
688 yield
'(no legacy encoding), serialized object in with object & gzip flag returns string' => [
692 [
'object',
'gzip' ],
695 yield
'(ISO-8859-1 encoding), string in string out' => [
697 iconv(
'utf-8',
'ISO-8859-1',
"1®Àþ1" ),
701 yield
'(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
703 gzdeflate( iconv(
'utf-8',
'ISO-8859-1',
"4®Àþ4" ) ),
707 yield
'(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
713 yield
'(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
716 [
'gzip',
'object' ],
732 if ( $legacyEncoding ) {
733 $blobStore->setLegacyEncoding( $legacyEncoding, Language::factory(
'en' ) );
744 yield
'Just text' => [
745 (
object)[
'old_text' =>
'SomeText' ],
750 yield
'gzip text' => [
752 'old_text' =>
"sttttr\002\022\000",
753 'old_flags' =>
'gzip'
758 yield
'gzip text and different prefix' => [
760 'jojo_text' =>
"sttttr\002\022\000",
761 'jojo_flags' =>
'gzip'
781 yield
'Just some text' => [
'someNonUrlText' ];
782 yield
'No second URL part' => [
'someProtocol://' ];
797 'old_flags' =>
'external',
809 'ExternalStoreFactory',
816 'old_text' =>
'ForTesting://cluster1/12345',
817 'old_flags' =>
'external,gzip',
831 'ExternalStoreFactory',
836 ->disableOriginalConstructor()
846 'old_text' =>
'ForTesting://cluster1/12345',
847 'old_flags' =>
'external,gzip',
853 $cacheKey =
$cache->makeGlobalKey(
856 $lb->getLocalDomainID(),
884 ->disableOriginalConstructor()
887 $rec->method(
'getSize' )
903 $emptyHash = SlotRecord::base36Sha1(
'' );
904 $this->
assertSame( $emptyHash,
$rev->getSha1(),
'Sha1 of no slots is hash of empty string' );
906 $rec->setSha1(
'deadbeef' );
917 ->disableOriginalConstructor()
920 $rec->method(
'getSha1' )
936 $this->
assertNull(
$rev->getContent(),
'Content of no slots is null' );
939 $rec->setContent( SlotRecord::MAIN,
$content );
950 ->disableOriginalConstructor()
953 $rec->method(
'getContent' )
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Simple store for keeping values in an associative array for the current process.
Content for JavaScript pages.
Test cases in RevisionTest should not interact with the Database.
testConstructFromEmptyArray()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testSetUserIdAndName( $inputId, $expectedId, $name)
provideSetUserIdAndName Revision::setUserIdAndName
provideConstructFromArray()
testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData)
Revision::getRevisionText provideGetRevisionTextWithGzipAndLegacyEncoding.
testConstructFromArray( $rowArray)
provideConstructFromArray Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevision...
testGetParentId( $rowArray, $expected)
provideGetParentId Revision::getParentId()
testGetId( $rowArray, $expectedId)
provideGetId Revision::getId
testGetSize()
Revision::getSize.
testConstructFromRowWithBadPageId()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testSetId( $input, $expected)
provideSetId Revision::setId
testConstructFromRow(array $arrayData, callable $assertions)
provideConstructFromRow Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFr...
testGetRevisionWithZlibExtension( $expected, $rowData)
Revision::getRevisionText provideGetRevisionTextWithZlibExtension.
provideConstructFromRow()
provideGetRevisionTextWithLegacyEncoding()
testConstructFromArrayWithBadPageId()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testGetSize_failure()
Revision::getSize.
mockBlobStoreFactory( $blobStore)
provideSetUserIdAndName()
provideDecompressRevisionText()
provideConstructFromArrayThrowsExceptions()
testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException)
provideConstructFromArrayThrowsExceptions Revision::__construct \MediaWiki\Revision\RevisionStore::ne...
provideGetRevisionTextWithZlibExtension()
testGetRevisionText( $expected, $rowData, $prefix='old_', $wiki=false)
Revision::getRevisionText provideGetRevisionText.
testGetRevisionWithZlibExtension_badData( $expected, $rowData)
Revision::getRevisionText provideGetRevisionTextWithZlibExtension_badData.
testGetSha1()
Revision::getSha1.
testCompressRevisionTextUtf8()
Revision::compressRevisionText.
testGetSha1_failure()
Revision::getSha1.
testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal( $row, $prefix, $expected)
provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal Revision::getRevisionText
provideConstructFromArray_userSetAsExpected()
testGetContent()
Revision::getContent.
testConstructFromArray_userSetAsExpected(array $rowArray, $expectedUserId, $expectedUserName)
provideConstructFromArray_userSetAsExpected Revision::__construct \MediaWiki\Revision\RevisionStore::...
testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData)
Revision::getRevisionText provideGetRevisionTextWithLegacyEncoding.
provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal()
provideGetRevisionTextWithGzipAndLegacyEncoding()
testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected)
provideDecompressRevisionText Revision::decompressRevisionText
getMockTitle( $model=CONTENT_MODEL_WIKITEXT)
testGetContent_failure()
Revision::getContent.
testLoadFromTitle()
Revision::loadFromTitle.
testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts( $text)
provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts Revision::getRevisionText
testGetRevisionText_external_noOldId()
Revision::getRevisionText.
provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts()
provideGetRevisionTextWithZlibExtension_badData()
testCompressRevisionTextUtf8Gzip()
Revision::compressRevisionText.
testConstructFromNothing()
Revision::__construct \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray.
testGetRevisionText_external_oldId()
Revision::getRevisionText.
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
static decompressRevisionText( $text, $flags)
Re-converts revision text according to it's flags.
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
static loadFromTitle( $db, $title, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
Content object implementation for representing flat text.
Represents a page (or page fragment) title within MediaWiki.
Multi-datacenter aware caching interface.
Content object for wiki text pages.
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
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
processing should stop and the error should be shown to the user * false
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
const SCHEMA_COMPAT_WRITE_BOTH
const SCHEMA_COMPAT_READ_NEW
const CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_JAVASCRIPT
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))
if(is_array($mode)) switch( $mode) $input
if(!isset( $args[0])) $lang