MediaWiki  master
LogFormatterTestCase.php
Go to the documentation of this file.
1 <?php
3 
8 
9  public function doTestLogFormatter( $row, $extra, $userGroups = [] ) {
11  $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
12 
13  $context = new RequestContext();
14  $context->setUser( $this->getTestUser( $userGroups )->getUser() );
15 
16  $formatter = LogFormatter::newFromRow( $row );
17  $formatter->setContext( $context );
18 
19  $this->assertEquals(
20  $extra['text'],
21  self::removeSomeHtml( $formatter->getActionText() ),
22  'Action text is equal to expected text'
23  );
24 
25  $this->assertSame( // ensure types and array key order
26  $extra['api'],
27  self::removeApiMetaData( $formatter->formatParametersForApi() ),
28  'Api log params is equal to expected array'
29  );
30 
31  if ( isset( $extra['preload'] ) ) {
32  $this->assertArrayEquals(
33  $this->getLinkTargetsAsStrings( $extra['preload'] ),
35  $formatter->getPreloadTitles()
36  )
37  );
38  }
39  }
40 
41  private function getLinkTargetsAsStrings( array $linkTargets ) {
42  return array_map( function ( LinkTarget $t ) {
43  return $t->getInterwiki() . ':' . $t->getNamespace() . ':'
44  . $t->getDBkey() . '#' . $t->getFragment();
45  }, $linkTargets );
46  }
47 
48  protected function isLegacy( $extra ) {
49  return isset( $extra['legacy'] ) && $extra['legacy'];
50  }
51 
52  protected function expandDatabaseRow( $data, $legacy ) {
53  return [
54  // no log_id because no insert in database
55  'log_type' => $data['type'],
56  'log_action' => $data['action'],
57  'log_timestamp' => $data['timestamp'] ?? wfTimestampNow(),
58  'log_user' => $data['user'] ?? 0,
59  'log_user_text' => $data['user_text'] ?? 'User',
60  'log_actor' => $data['actor'] ?? 0,
61  'log_namespace' => $data['namespace'] ?? NS_MAIN,
62  'log_title' => $data['title'] ?? 'Main_Page',
63  'log_page' => $data['page'] ?? 0,
64  'log_comment_text' => $data['comment'] ?? '',
65  'log_comment_data' => null,
66  'log_params' => $legacy
67  ? LogPage::makeParamBlob( $data['params'] )
68  : LogEntryBase::makeParamBlob( $data['params'] ),
69  'log_deleted' => $data['deleted'] ?? 0,
70  ];
71  }
72 
73  private static function removeSomeHtml( $html ) {
74  $html = str_replace( '&quot;', '"', $html );
75  $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
76  return trim( strip_tags( $html ) );
77  }
78 
79  private static function removeApiMetaData( $val ) {
80  if ( is_array( $val ) ) {
81  unset( $val['_element'] );
82  unset( $val['_type'] );
83  foreach ( $val as $key => $value ) {
84  $val[$key] = self::removeApiMetaData( $value );
85  }
86  }
87  return $val;
88  }
89 }
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1972
const NS_MAIN
Definition: Defines.php:60
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
doTestLogFormatter( $row, $extra, $userGroups=[])
$value
getNamespace()
Get the namespace index.
getFragment()
Get the link fragment (i.e.
getLinkTargetsAsStrings(array $linkTargets)
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getDBkey()
Get the main part with underscores.
static resetMain()
Resets singleton returned by getMain().
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
Definition: hooks.txt:767
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
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
Definition: distributors.txt:9
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
Definition: injection.txt:35
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2621
getInterwiki()
The interwiki component of this LinkTarget.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogPage.php:418
expandDatabaseRow( $data, $legacy)
static makeParamBlob( $params)
Create a blob from a parameter array.