Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
FlaggedRevsStableLogFormatter
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 4
306
0.00% covered (danger)
0.00%
0 / 1
 getMessageKey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMessageParameters
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
 getActionLinks
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 stabilitySettings
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
156
1<?php
2
3use MediaWiki\MediaWikiServices;
4use MediaWiki\Message\Message;
5use MediaWiki\Title\Title;
6
7class FlaggedRevsStableLogFormatter extends LogFormatter {
8
9    /**
10     * @inheritDoc
11     */
12    protected function getMessageKey(): string {
13        return 'logentry-stable-' . $this->entry->getSubtype();
14    }
15
16    /**
17     * @inheritDoc
18     */
19    protected function getMessageParameters(): array {
20        $params = parent::getMessageParameters();
21        $action = $this->entry->getSubtype();
22        if ( $action !== 'move_stable' ) {
23            # Add setting change description as a param
24            $settings = $this->entry->getParameters();
25            $settings = $this->entry->isLegacy() ? FlaggedRevsLog::expandParams( $settings ) : $settings;
26            $params[3] = self::stabilitySettings( $settings, false );
27        } else {
28            $oldName = $this->makePageLink( Title::newFromText( $params[3] ), [ 'redirect' => 'no' ] );
29            $params[3] = Message::rawParam( $oldName );
30        }
31        return $params;
32    }
33
34    /**
35     * @inheritDoc
36     */
37    public function getActionLinks(): string {
38        # Add history link showing edits right before the config change
39        $hist = $this->getLinkRenderer()->makeLink(
40            $this->entry->getTarget(),
41            $this->msg( 'hist' )->text(),
42            [],
43            [ 'action' => 'history', 'offset' => $this->entry->getTimestamp() ]
44        );
45        return $this->msg( 'parentheses' )->rawParams( $hist )->escaped();
46    }
47
48    /**
49     * Make a list of stability settings for display
50     * Also used for null edit summary
51     *
52     * @param array $pars assoc array
53     * @param bool $forContent
54     */
55    public static function stabilitySettings( array $pars, bool $forContent ): string {
56        global $wgLang;
57        $set = [];
58        $settings = '';
59        $langObj = $forContent ? MediaWikiServices::getInstance()->getContentLanguage() : $wgLang;
60        // Protection-based or deferral-based configs (precedence never changed)...
61        if ( !isset( $pars['precedence'] ) ) {
62            if ( isset( $pars['autoreview'] ) && strlen( $pars['autoreview'] ) ) {
63                $set[] = wfMessage( 'stable-log-restriction', $pars['autoreview'] )->inLanguage(
64                    $langObj )->escaped();
65            }
66        // General case...
67        } else {
68            // Default version shown on page view
69            if ( isset( $pars['override'] ) ) {
70                // Give grep a chance to find the usages:
71                // stabilization-def-short-0, stabilization-def-short-1
72                $set[] = wfMessage( 'stabilization-def-short' )->inLanguage( $langObj )->escaped() .
73                    wfMessage( 'colon-separator' )->inLanguage( $langObj )->escaped() .
74                    wfMessage( 'stabilization-def-short-' . $pars['override'] )
75                        ->inLanguage( $langObj )->escaped();
76            }
77            // Autoreview restriction
78            if ( isset( $pars['autoreview'] ) && strlen( $pars['autoreview'] ) ) {
79                $set[] = 'autoreview=' . $pars['autoreview'];
80            }
81        }
82        if ( $set ) {
83            $settings = '[' . $langObj->commaList( $set ) . ']';
84        }
85        # Expiry is a MW timestamp or 'infinity'
86        if ( isset( $pars['expiry'] ) && $pars['expiry'] != 'infinity' ) {
87            $expiry_description = wfMessage( 'stabilize-expiring',
88                $langObj->timeanddate( $pars['expiry'], false, false ),
89                $langObj->date( $pars['expiry'], false, false ),
90                $langObj->time( $pars['expiry'], false, false )
91            )->inLanguage( $langObj )->escaped();
92            if ( $settings != '' ) {
93                $settings .= ' ';
94            }
95            $settings .= wfMessage( 'parentheses' )->rawParams( $expiry_description )
96                ->inLanguage( $langObj )->escaped();
97        }
98        return $settings;
99    }
100}