MediaWiki REL1_32
LogFormatterTestCase.php
Go to the documentation of this file.
1<?php
2
7
8 public function doTestLogFormatter( $row, $extra ) {
9 RequestContext::resetMain();
10 $row = $this->expandDatabaseRow( $row, $this->isLegacy( $extra ) );
11
12 $formatter = LogFormatter::newFromRow( $row );
13
14 $this->assertEquals(
15 $extra['text'],
16 self::removeSomeHtml( $formatter->getActionText() ),
17 'Action text is equal to expected text'
18 );
19
20 $this->assertSame( // ensure types and array key order
21 $extra['api'],
22 self::removeApiMetaData( $formatter->formatParametersForApi() ),
23 'Api log params is equal to expected array'
24 );
25 }
26
27 protected function isLegacy( $extra ) {
28 return isset( $extra['legacy'] ) && $extra['legacy'];
29 }
30
31 protected function expandDatabaseRow( $data, $legacy ) {
32 return [
33 // no log_id because no insert in database
34 'log_type' => $data['type'],
35 'log_action' => $data['action'],
36 'log_timestamp' => $data['timestamp'] ?? wfTimestampNow(),
37 'log_user' => $data['user'] ?? 0,
38 'log_user_text' => $data['user_text'] ?? 'User',
39 'log_actor' => $data['actor'] ?? 0,
40 'log_namespace' => $data['namespace'] ?? NS_MAIN,
41 'log_title' => $data['title'] ?? 'Main_Page',
42 'log_page' => $data['page'] ?? 0,
43 'log_comment_text' => $data['comment'] ?? '',
44 'log_comment_data' => null,
45 'log_params' => $legacy
46 ? LogPage::makeParamBlob( $data['params'] )
47 : LogEntryBase::makeParamBlob( $data['params'] ),
48 'log_deleted' => $data['deleted'] ?? 0,
49 ];
50 }
51
52 private static function removeSomeHtml( $html ) {
53 $html = str_replace( '&quot;', '"', $html );
54 $html = preg_replace( '/\xE2\x80[\x8E\x8F]/', '', $html ); // Strip lrm/rlm
55 return trim( strip_tags( $html ) );
56 }
57
58 private static function removeApiMetaData( $val ) {
59 if ( is_array( $val ) ) {
60 unset( $val['_element'] );
61 unset( $val['_type'] );
62 foreach ( $val as $key => $value ) {
63 $val[$key] = self::removeApiMetaData( $value );
64 }
65 }
66 return $val;
67 }
68}
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogEntry.php:142
doTestLogFormatter( $row, $extra)
expandDatabaseRow( $data, $legacy)
static newFromRow( $row)
Handy shortcut for constructing a formatter directly from database row.
static makeParamBlob( $params)
Create a blob from a parameter array.
Definition LogPage.php:413
Base class that store and restore the Language objects.
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
const NS_MAIN
Definition Defines.php:64
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:2062
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:37