3use Wikimedia\TestingAccessWrapper;
32 'action' =>
'stashedit',
34 'contentmodel' =>
'wikitext',
35 'contentformat' =>
'text/x-wiki',
38 if ( !array_key_exists(
'text',
$params ) &&
39 !array_key_exists(
'stashedtexthash',
$params )
44 if ( $val ===
null ) {
49 if ( isset(
$params[
'text'] ) ) {
50 $expectedText =
$params[
'text'];
51 } elseif ( isset(
$params[
'stashedtexthash'] ) ) {
54 if ( isset( $expectedText ) ) {
55 $expectedText = rtrim( str_replace(
"\r\n",
"\n", $expectedText ) );
56 $expectedHash = sha1( $expectedText );
62 $this->assertSame( $expectedResult,
$res[0][
'stashedit'][
'status'] );
63 $this->assertCount( $expectedResult ===
'stashed' ? 2 : 1,
$res[0][
'stashedit'] );
65 if ( $expectedResult ===
'stashed' ) {
66 $hash =
$res[0][
'stashedit'][
'texthash'];
68 $this->assertSame( $expectedText, $this->
getStashedText( $hash ) );
70 $this->assertSame( $expectedHash, $hash );
72 if ( isset(
$params[
'stashedtexthash'] ) ) {
73 $this->assertSame(
$params[
'stashedtexthash'], $expectedHash,
'Sanity' );
76 $this->assertSame( $origText, $this->
getStashedText( $expectedHash ) );
79 $this->assertArrayNotHasKey(
'warnings',
$res[0] );
91 $cache = ObjectCache::getLocalClusterInstance();
92 $key =
$cache->makeKey(
'stashedit',
'text', $hash );
93 return $cache->get( $key );
104 protected function getStashKey( $title = __CLASS__, $text =
'Content',
User $user =
null ) {
105 $titleObj = Title::newFromText(
$title );
110 $wrapper = TestingAccessWrapper::newFromClass( ApiStashEdit::class );
111 return $wrapper->getStashKey( $titleObj, $wrapper->getContentHash(
$content ),
$user );
127 [
'apierror-badformat-generic',
'application/json',
'wikitext' ] );
129 $this->
doStash( [
'contentformat' =>
'application/json' ] );
134 'apierror-missingparam-one-of',
135 Message::listParam( [
'<var>stashedtexthash</var>',
'<var>text</var>' ] ),
138 $this->
doStash( [
'text' =>
null ] );
144 $this->
doStash( [
'stashedtexthash' =>
$res[0][
'stashedit'][
'texthash'] ] );
149 $this->
doStash( [
'stashedtexthash' =>
'abc' ] );
154 $this->
doStash( [
'stashedtexthash' => str_repeat(
'0', 40 ) ] );
158 $res1 = $this->
doStash( [
'text' =>
"a\r\nb\rc\nd \t\n\r" ] );
159 $res2 = $this->
doStash( [
'text' =>
"a\nb\rc\nd" ] );
161 $this->assertSame( $res1[0][
'stashedit'][
'texthash'], $res2[0][
'stashedit'][
'texthash'] );
162 $this->assertSame(
"a\nb\rc\nd",
169 $name = ucfirst( __FUNCTION__ );
171 $this->
doStash( [
'title' =>
$name,
'baserevid' => pow( 2, 31 ) - 1 ] );
175 $name = ucfirst( __FUNCTION__ );
184 [
'page_latest' => 0 ],
185 [
'page_id' =>
$rev->getPage() ],
193 $name = ucfirst( __FUNCTION__ );
200 $name = ucfirst( __FUNCTION__ );
201 $oldRev = $this->
editPage(
$name,
"A\n\nB" )->value[
'revision'];
206 'baserevid' => $oldRev->getId(),
212 $name = ucfirst( __FUNCTION__ );
218 'baserevid' => $oldRev->getId(),
220 ],
null,
'editconflict' );
224 $name = ucfirst( __FUNCTION__ );
234 'baserevid' => $oldRev->getId(),
240 $name = ucfirst( __FUNCTION__ );
250 'baserevid' => $oldRev->getId(),
258 [
'stashedit' => [
'&can-bypass' =>
false,
'user' => [ 1, 60 ] ] ] );
260 $this->
doStash( [
'text' =>
'A' ] );
262 $this->
doStash( [
'text' =>
'B' ],
null,
'ratelimited' );
274 return ApiStashEdit::checkCache(
275 Title::newFromText( __CLASS__ ),
291 'Cache is user-specific'
295 $user->addGroup(
'bot' );
298 "We assume bots don't have cache entries"
302 $user->removeGroup(
'bot' );
303 $user->addGroup(
'sysop' );
312 $this->assertInstanceOf( stdClass::class, $this->docheckCache(
$user ) );
323 User $user, $text =
'Content', $howOld = ApiStashEdit::PRESUME_FRESH_TTL_SEC
331 $cache = ObjectCache::getLocalClusterInstance();
333 $editInfo =
$cache->get( $key );
334 $outputKey =
$cache->makeKey(
'stashed-edit-output', $editInfo->outputID );
335 $editInfo->output =
$cache->get( $outputKey );
336 $editInfo->output->setCacheTime(
wfTimestamp( TS_MW,
337 wfTimestamp( TS_UNIX, $editInfo->output->getCacheTime() ) - $howOld - 1 ) );
339 $cache->set( $key, $editInfo );
367 $this->
editPage( ucfirst( __FUNCTION__ ),
'' );
369 $user->clearInstanceCache();
371 "Cache should be invalidated when it's old and the user has an intervening edit" );
380 $this->
doStash( [
'text' => $text ] );
382 $cache = ObjectCache::getLocalClusterInstance();
385 $wrapper = TestingAccessWrapper::newFromObject(
$cache );
387 $this->assertEquals( $ttl, $wrapper->bag[$key][HashBagOStuff::KEY_EXP] - time(),
'', 1 );
392 '~~~' => [
'~~~', ApiStashEdit::MAX_SIGNATURE_TTL ],
393 '~~~~' => [
'~~~~', ApiStashEdit::MAX_SIGNATURE_TTL ],
394 '~~~~~' => [
'~~~~~', ApiStashEdit::MAX_SIGNATURE_TTL ],
400 'action' =>
'paraminfo',
401 'modules' =>
'stashedit',
404 $this->assertCount( 1,
$res[0][
'paraminfo'][
'modules'] );
405 $this->assertSame(
true,
$res[0][
'paraminfo'][
'modules'][0][
'internal'] );
411 $this->markTestSkipped();
414 $this->db->lock( $key, __METHOD__, 0 );
416 $this->
doStash( [],
null,
'busy' );
418 $this->db->unlock( $key, __METHOD__ );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
ApiStashEdit API medium Database.
testSignatureTtl( $text, $ttl)
signatureProvider
testMalformedStashedTextHash()
getStashKey( $title=__CLASS__, $text='Content', User $user=null)
Return a key that can be passed to the cache to obtain a PreparedEdit object.
testCheckCacheInterveningEdits()
testDeletedRevisionSection()
testMissingStashedTextHash()
doStash(array $params=[], User $user=null, $expectedResult='stashed')
Make a stashedit API call with suitable default parameters.
doStashOld(User $user, $text='Content', $howOld=ApiStashEdit::PRESUME_FRESH_TTL_SEC)
Stash an edit some time in the past, for testing expiry and freshness logic.
getStashedText( $hash)
Return the text stashed for $hash.
testMissingTextAndStashedTextHash()
doCheckCache(User $user, $text='Content')
Shortcut for calling ApiStashEdit::checkCache() without having to create Titles and Contents in every...
testCheckCacheOldNoEditsAnon()
testNonexistentBaseRevId()
testCheckCacheOldNoEdits()
testPageWithNoRevisions()
doApiRequestWithToken(array $params, array $session=null, User $user=null, $tokenType='auto')
Convenience function to access the token parameter of doApiRequest() more succinctly.
setExpectedApiException( $msg, $code=null, array $data=null, $httpCode=0)
Expect an ApiUsageException to be thrown with the given parameters, which are the same as ApiUsageExc...
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Content object for wiki text pages.
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
namespace and then decline to actually register it file or subcat img or subcat $title
Allows to change the fields on the form that will be generated $name
return true to allow those checks to and false if checking is done & $user
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
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
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))