MediaWiki  master
LogFormatterTestCase.php
Go to the documentation of this file.
1 <?php
3 
8 
9  public function doTestLogFormatter( $row, $extra ) {
11  $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
12 
13  $formatter = LogFormatter::newFromRow( $row );
14 
15  $this->assertEquals(
16  $extra['text'],
17  self::removeSomeHtml( $formatter->getActionText() ),
18  'Action text is equal to expected text'
19  );
20 
21  $this->assertSame( // ensure types and array key order
22  $extra['api'],
23  self::removeApiMetaData( $formatter->formatParametersForApi() ),
24  'Api log params is equal to expected array'
25  );
26 
27  if ( isset( $extra['preload'] ) ) {
28  $this->assertArrayEquals(
29  $this->getLinkTargetsAsStrings( $extra['preload'] ),
31  $formatter->getPreloadTitles()
32  )
33  );
34  }
35  }
36 
37  private function getLinkTargetsAsStrings( array $linkTargets ) {
38  return array_map( function ( LinkTarget $t ) {
39  return $t->getInterwiki() . ':' . $t->getNamespace() . ':'
40  . $t->getDBkey() . '#' . $t->getFragment();
41  }, $linkTargets );
42  }
43 
44  protected function isLegacy( $extra ) {
45  return isset( $extra['legacy'] ) && $extra['legacy'];
46  }
47 
48  protected function expandDatabaseRow( $data, $legacy ) {
49  return [
50  // no log_id because no insert in database
51  'log_type' => $data['type'],
52  'log_action' => $data['action'],
53  'log_timestamp' => $data['timestamp'] ?? wfTimestampNow(),
54  'log_user' => $data['user'] ?? 0,
55  'log_user_text' => $data['user_text'] ?? 'User',
56  'log_actor' => $data['actor'] ?? 0,
57  'log_namespace' => $data['namespace'] ?? NS_MAIN,
58  'log_title' => $data['title'] ?? 'Main_Page',
59  'log_page' => $data['page'] ?? 0,
60  'log_comment_text' => $data['comment'] ?? '',
61  'log_comment_data' => null,
62  'log_params' => $legacy
63  ? LogPage::makeParamBlob( $data['params'] )
64  : LogEntryBase::makeParamBlob( $data['params'] ),
65  'log_deleted' => $data['deleted'] ?? 0,
66  ];
67  }
68 
69  private static function removeSomeHtml( $html ) {
70  $html = str_replace( '&quot;', '"', $html );
71  $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
72  return trim( strip_tags( $html ) );
73  }
74 
75  private static function removeApiMetaData( $val ) {
76  if ( is_array( $val ) ) {
77  unset( $val['_element'] );
78  unset( $val['_type'] );
79  foreach ( $val as $key => $value ) {
80  $val[$key] = self::removeApiMetaData( $value );
81  }
82  }
83  return $val;
84  }
85 }
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:1982
const NS_MAIN
Definition: Defines.php:60
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
$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:780
doTestLogFormatter( $row, $extra)
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
getInterwiki()
The interwiki component of this LinkTarget.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition: LogPage.php:417
expandDatabaseRow( $data, $legacy)
static makeParamBlob( $params)
Create a blob from a parameter array.