Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.16% covered (warning)
88.16%
67 / 76
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
OldChangesList
89.33% covered (warning)
89.33%
67 / 75
0.00% covered (danger)
0.00%
0 / 2
17.35
0.00% covered (danger)
0.00%
0 / 1
 recentChangesLine
95.45% covered (success)
95.45%
21 / 22
0.00% covered (danger)
0.00%
0 / 1
5
 formatChangeLine
86.79% covered (warning)
86.79%
46 / 53
0.00% covered (danger)
0.00%
0 / 1
12.33
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\RecentChanges;
8
9use MediaWiki\Html\Html;
10use MediaWiki\MainConfigNames;
11use MediaWiki\MediaWikiServices;
12use MediaWiki\Parser\Sanitizer;
13use MediaWiki\Revision\RevisionRecord;
14use MediaWiki\SpecialPage\SpecialPage;
15
16/**
17 * Generate a list of changes using the good old system (no javascript).
18 *
19 * @ingroup RecentChanges
20 */
21class OldChangesList extends ChangesList {
22
23    /**
24     * Format a line using the old system (aka without any javascript).
25     *
26     * @param RecentChange &$rc Passed by reference
27     * @param bool $watched (default false)
28     * @param int|null $linenumber (default null)
29     *
30     * @return string|bool
31     * @return-taint none
32     */
33    public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
34        $classes = $this->getHTMLClasses( $rc, $watched );
35        // use mw-line-even/mw-line-odd class only if linenumber is given (feature from T16468)
36        if ( $linenumber ) {
37            if ( $linenumber & 1 ) {
38                $classes[] = 'mw-line-odd';
39            } else {
40                $classes[] = 'mw-line-even';
41            }
42        }
43
44        $html = $this->formatChangeLine( $rc, $classes, $watched );
45
46        if ( $this->watchlist ) {
47            $classes[] = Sanitizer::escapeClass( 'watchlist-' .
48                $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
49        }
50
51        $attribs = $this->getDataAttributes( $rc );
52
53        if ( !$this->getHookRunner()->onOldChangesListRecentChangesLine(
54            $this, $html, $rc, $classes, $attribs )
55        ) {
56            return false;
57        }
58        $attribs = array_filter( $attribs,
59            Sanitizer::isReservedDataAttribute( ... ),
60            ARRAY_FILTER_USE_KEY
61        );
62
63        $dateheader = ''; // $html now contains only <li>...</li>, for hooks' convenience.
64        $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
65
66        $html = $this->getHighlightsContainerDiv() . $html;
67        $attribs['class'] = $classes;
68
69        return $dateheader . Html::rawElement( 'li', $attribs, $html ) . "\n";
70    }
71
72    /**
73     * @param RecentChange $rc
74     * @param string[] &$classes
75     * @param bool $watched
76     *
77     * @return string
78     */
79    private function formatChangeLine( RecentChange $rc, array &$classes, $watched ) {
80        $html = '';
81        $unpatrolled = $this->showAsUnpatrolled( $rc );
82
83        if ( $rc->mAttribs['rc_log_type'] ) {
84            $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
85            $this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'], false );
86            $flags = $this->recentChangesFlags( [ 'unpatrolled' => $unpatrolled,
87                'bot' => $rc->mAttribs['rc_bot'] ], '' );
88            if ( $flags !== '' ) {
89                $html .= ' ' . $flags;
90            }
91        // Log entries (old format) or log targets, and special pages
92        } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
93            [ $name, $htmlubpage ] = MediaWikiServices::getInstance()->getSpecialPageFactory()->
94                resolveAlias( $rc->mAttribs['rc_title'] );
95            if ( $name == 'Log' ) {
96                $this->insertLog( $html, $rc->getTitle(), $htmlubpage ?? '', false );
97            }
98        // Regular entries
99        } else {
100            $this->insertDiffHist( $html, $rc );
101            # M, N, b and ! (minor, new, bot and unpatrolled)
102            $html .= $this->recentChangesFlags(
103                [
104                    'newpage' => $rc->mAttribs['rc_source'] == RecentChange::SRC_NEW,
105                    'minor' => $rc->mAttribs['rc_minor'],
106                    'unpatrolled' => $unpatrolled,
107                    'bot' => $rc->mAttribs['rc_bot']
108                ],
109                ''
110            );
111            $html .= $this->getArticleLink( $rc, $unpatrolled, $watched );
112        }
113        # Edit/log timestamp
114        $this->insertTimestamp( $html, $rc );
115        # Bytes added or removed
116        if ( $this->getConfig()->get( MainConfigNames::RCShowChangedSize ) ) {
117            $cd = $this->formatCharacterDifference( $rc );
118            if ( $cd !== '' ) {
119                $html .= $cd . '  <span class="mw-changeslist-separator"></span> ';
120            }
121        }
122
123        if ( $rc->mAttribs['rc_source'] == RecentChange::SRC_LOG ) {
124            $html .= $this->insertLogEntry( $rc );
125        } elseif ( $this->isCategorizationWithoutRevision( $rc ) ) {
126            $html .= $this->insertComment( $rc );
127        } else {
128            # User tool links
129            $this->insertUserRelatedLinks( $html, $rc );
130            $html .= $this->insertComment( $rc );
131        }
132
133        # Tags
134        $this->insertTags( $html, $rc, $classes );
135        # Labels
136        $this->insertLabels( $html, $rc, $classes );
137        # Rollback
138        $this->insertRollback( $html, $rc );
139        # For subclasses
140        $this->insertExtra( $html, $rc, $classes );
141
142        # How many users watch this page
143        if ( $rc->numberofWatchingusers > 0 ) {
144            $html .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
145        }
146
147        $titleText = $rc->getTitle();
148        if ( !ChangesList::userCan( $rc, RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
149            $titleText = $this->msg( 'rev-deleted-event' )->escaped();
150        }
151
152        // @phan-suppress-next-line SecurityCheck-DoubleEscaped
153        $html = Html::rawElement( 'span', [
154            'class' => 'mw-changeslist-line-inner',
155            'data-target-page' => $titleText, // Used for reliable determination of the affiliated page
156        ], $html );
157        if ( is_callable( $this->changeLinePrefixer ) ) {
158            $prefix = ( $this->changeLinePrefixer )( $rc, $this, false );
159            $html = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix ) . $html;
160        }
161
162        return $html;
163    }
164}
165
166/** @deprecated class alias since 1.44 */
167class_alias( OldChangesList::class, 'OldChangesList' );