35 parent::setUpBeforeClass();
40 Language::getLocalisationCache()->recache(
'en' );
46 Language::getLocalisationCache()->recache(
'en' );
48 parent::tearDownAfterClass();
55 'wgLogTypes' => [
'phpunit' ],
56 'wgLogActionsHandlers' => [
'phpunit/test' => LogFormatter::class,
57 'phpunit/param' => LogFormatter::class ],
62 $this->title = Title::newFromText(
'SomeTitle' );
63 $this->target = Title::newFromText(
'TestTarget' );
66 $this->context->setUser( $this->user );
67 $this->context->setTitle( $this->title );
68 $this->context->setLanguage( RequestContext::getMain()->getLanguage() );
70 $this->user_comment =
'<User comment about action>';
75 $logEntry->setPerformer( $this->user );
76 $logEntry->setTarget( $this->title );
77 $logEntry->setComment(
'A very good reason' );
79 $logEntry->setParameters(
$params );
90 $formatter->setContext( $this->context );
92 $formatter->setShowUserToolLinks(
false );
93 $paramsWithoutTools = $formatter->getMessageParametersForTesting();
96 $formatter2->setContext( $this->context );
97 $formatter2->setShowUserToolLinks(
true );
98 $paramsWithTools = $formatter2->getMessageParametersForTesting();
101 $this->user->getId(),
102 $this->user->getName()
106 $this->user->getId(),
107 $this->user->getName(),
108 $this->user->getEditCount()
111 $titleLink =
Linker::link( $this->title,
null, [], [] );
115 $this->assertEquals( $paramsWithoutTools[1], $paramsWithTools[1] );
116 $this->assertEquals( $paramsWithoutTools[2], $paramsWithTools[2] );
118 $this->assertEquals( $userLink, $paramsWithoutTools[0][
'raw'] );
119 $this->assertEquals( $userLink . $userTools, $paramsWithTools[0][
'raw'] );
121 $this->assertEquals( $this->user->getName(), $paramsWithoutTools[1] );
123 $this->assertEquals( $titleLink, $paramsWithoutTools[2][
'raw'] );
136 $formatter->setContext( $this->context );
138 $logParam = $formatter->getActionText();
140 $this->assertEquals( $expected, $logParam );
148 $params = [
'4:msg:msg' =>
'log-description-phpunit' ];
149 $expected =
wfMessage(
'log-description-phpunit' )->text();
153 $formatter->setContext( $this->context );
155 $logParam = $formatter->getActionText();
157 $this->assertEquals( $expected, $logParam );
165 $params = [
'4:msg-content:msgContent' =>
'log-description-phpunit' ];
166 $expected =
wfMessage(
'log-description-phpunit' )->inContentLanguage()->text();
170 $formatter->setContext( $this->context );
172 $logParam = $formatter->getActionText();
174 $this->assertEquals( $expected, $logParam );
184 $params = [
'4:number:number' => 123456789 ];
185 $expected =
$wgLang->formatNum( 123456789 );
189 $formatter->setContext( $this->context );
191 $logParam = $formatter->getActionText();
193 $this->assertEquals( $expected, $logParam );
201 $params = [
'4:user-link:userLink' => $this->user->getName() ];
203 $this->user->getId(),
204 $this->user->getName()
209 $formatter->setContext( $this->context );
211 $logParam = $formatter->getActionText();
213 $this->assertEquals( $expected, $logParam );
221 $params = [
'4:title-link:titleLink' => $this->title->getText() ];
226 $formatter->setContext( $this->context );
228 $logParam = $formatter->getActionText();
230 $this->assertEquals( $expected, $logParam );
238 $params = [
'4:plain:plain' =>
'Some plain text' ];
239 $expected =
'Some plain text';
243 $formatter->setContext( $this->context );
245 $logParam = $formatter->getActionText();
247 $this->assertEquals( $expected, $logParam );
257 $formatter->setContext( $this->context );
261 $this->assertEquals( $comment, $formatter->getComment() );
272 $formatter->setContext( $this->context );
277 $this->assertEquals( $expected, $formatter->formatParametersForApi() );
282 [ 0,
'value', [
'value' ] ],
283 [
'named',
'value', [
'named' =>
'value' ] ],
284 [
'::key',
'value', [
'key' =>
'value' ] ],
285 [
'4::key',
'value', [
'key' =>
'value' ] ],
286 [
'4:raw:key',
'value', [
'key' =>
'value' ] ],
287 [
'4:plain:key',
'value', [
'key' =>
'value' ] ],
288 [
'4:bool:key',
'1', [
'key' =>
true ] ],
289 [
'4:bool:key',
'0', [
'key' =>
false ] ],
290 [
'4:number:key',
'123', [
'key' => 123 ] ],
291 [
'4:number:key',
'123.5', [
'key' => 123.5 ] ],
295 [
'4:timestamp:key',
'20150102030405', [
'key' =>
'2015-01-02T03:04:05Z' ] ],
296 [
'4:msg:key',
'parentheses', [
297 'key_key' =>
'parentheses',
298 'key_text' =>
wfMessage(
'parentheses' )->text(),
300 [
'4:msg-content:key',
'parentheses', [
301 'key_key' =>
'parentheses',
302 'key_text' =>
wfMessage(
'parentheses' )->inContentLanguage()->text(),
304 [
'4:title:key',
'project:foo', [
306 'key_title' => Title::newFromText(
'project:foo' )->getFullText(),
308 [
'4:title-link:key',
'project:foo', [
310 'key_title' => Title::newFromText(
'project:foo' )->getFullText(),
312 [
'4:title-link:key',
'<invalid>', [
314 'key_title' => SpecialPage::getTitleFor(
'Badtitle',
'<invalid>' )->getFullText(),
316 [
'4:user:key',
'foo', [
'key' =>
'Foo' ] ],
317 [
'4:user-link:key',
'foo', [
'key' =>
'Foo' ] ],
364 $sep = $this->context->msg(
'colon-separator' )->text();
368 $this->context->msg(
'blocklogentry',
'SomeTitle',
'duration',
'(flags)' )->plain()
369 . $sep . $this->user_comment,
372 '5::duration' =>
'duration',
373 '6::flags' =>
'flags',
377 # block/block - legacy
379 $this->context->msg(
'blocklogentry',
'SomeTitle',
'duration',
'(flags)' )->plain()
380 . $sep . $this->user_comment,
392 $this->context->msg(
'unblocklogentry',
'SomeTitle' )->plain() . $sep . $this->user_comment,
399 $this->context->msg(
'reblock-logentry',
'SomeTitle',
'duration',
'(flags)' )->plain()
400 . $sep . $this->user_comment,
403 '5::duration' =>
'duration',
404 '6::flags' =>
'flags',
415 $sep = $this->context->msg(
'colon-separator' )->text();
419 $this->context->msg(
'deletedarticle',
'SomeTitle' )->plain() . $sep . $this->user_comment,
427 $this->context->msg(
'undeletedarticle',
'SomeTitle' )->plain() . $sep . $this->user_comment,
441 'newusers',
'newusers',
446 'newusers',
'create',
450 'created new account SomeTitle',
451 'newusers',
'create2',
455 'Account created automatically',
456 'newusers',
'autocreate',
467 '4::target' => $this->target->getPrefixedText(),
470 $sep = $this->context->msg(
'colon-separator' )->text();
474 $this->context->msg(
'1movedto2',
'SomeTitle',
'TestTarget' )
475 ->plain() . $sep . $this->user_comment,
483 $this->context->msg(
'1movedto2_redir',
'SomeTitle',
'TestTarget' )
484 ->plain() . $sep . $this->user_comment,
485 'move',
'move_redir',
498 $this->context->msg(
'patrol-log-line',
'revision 777',
'[[SomeTitle]]',
'' )->plain(),
502 '5::previd' =>
'666',
514 '4::description' =>
'[edit=sysop] (indefinite) [move=sysop] (indefinite)'
516 $sep = $this->context->msg(
'colon-separator' )->text();
520 $this->context->msg(
'protectedarticle',
'SomeTitle ' . $protectParams[
'4::description'] )
521 ->plain() . $sep . $this->user_comment,
522 'protect',
'protect',
529 $this->context->msg(
'unprotectedarticle',
'SomeTitle' )->plain() . $sep . $this->user_comment,
530 'protect',
'unprotect',
538 'modifiedarticleprotection',
539 'SomeTitle ' . $protectParams[
'4::description']
540 )->plain() . $sep . $this->user_comment,
548 $this->context->msg(
'movedarticleprotection',
'SomeTitle',
'OldTitle' )
549 ->plain() . $sep . $this->user_comment,
550 'protect',
'move_prot',
552 '4::oldtitle' =>
'OldTitle'
563 $sep = $this->context->msg(
'colon-separator' )->text();
567 $this->context->msg(
'uploadedimage',
'SomeTitle' )->plain() . $sep . $this->user_comment,
575 $this->context->msg(
'overwroteimage',
'SomeTitle' )->plain() . $sep . $this->user_comment,
576 'upload',
'overwrite',
587 $sep = $this->context->msg(
'colon-separator' )->text();
591 $this->context->msg(
'pagemerge-logentry',
'SomeTitle',
'Dest',
'timestamp' )->plain()
592 . $sep . $this->user_comment,
596 '5::mergepoint' =>
'timestamp',
607 $sep = $this->context->msg(
'colon-separator' )->text();
610 $msg = $this->context->msg(
'import-logentry-upload',
'SomeTitle' )->plain() .
621 $msg = $this->context->msg(
'import-logentry-interwiki',
'SomeTitle' )->plain() .
626 'import',
'interwiki',
641 $comment =
null, $msg =
'', $legacy =
false
644 $logEntry->setPerformer( $this->user );
645 $logEntry->setTarget( $this->title );
646 if ( $comment !==
null ) {
647 $logEntry->setComment( $comment );
649 $logEntry->setParameters(
$params );
650 $logEntry->setLegacy( $legacy );
653 $formatter->setContext( $this->context );
const META_TYPE
Key for the 'type' metadata item.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
static userToolLinksRedContribs( $userId, $userText, $edits=null)
Alias for userToolLinks( $userId, $userText, true );.
static commentBlock( $comment, $title=null, $local=false, $wikiId=null)
Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty strin...
Class for creating new log entries and inserting them into the database.
Group all the pieces relevant to the context of a request into one instance.
Represents a title within MediaWiki.
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.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
processing should stop and the error should be shown to the user * false
$wgExtensionMessagesFiles['ExtensionNameMagic']