Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
66 / 72
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
OldChangesList
91.67% covered (success)
91.67%
66 / 72
0.00% covered (danger)
0.00%
0 / 2
16.15
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
90.00% covered (success)
90.00%
45 / 50
0.00% covered (danger)
0.00%
0 / 1
11.12
1<?php
2/**
3 * Generate a list of changes using the good old system (no javascript).
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23use MediaWiki\Html\Html;
24use MediaWiki\MainConfigNames;
25use MediaWiki\MediaWikiServices;
26use MediaWiki\Parser\Sanitizer;
27use MediaWiki\SpecialPage\SpecialPage;
28
29class OldChangesList extends ChangesList {
30
31    /**
32     * Format a line using the old system (aka without any javascript).
33     *
34     * @param RecentChange &$rc Passed by reference
35     * @param bool $watched (default false)
36     * @param int|null $linenumber (default null)
37     *
38     * @return string|bool
39     * @return-taint none
40     */
41    public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) {
42        $classes = $this->getHTMLClasses( $rc, $watched );
43        // use mw-line-even/mw-line-odd class only if linenumber is given (feature from T16468)
44        if ( $linenumber ) {
45            if ( $linenumber & 1 ) {
46                $classes[] = 'mw-line-odd';
47            } else {
48                $classes[] = 'mw-line-even';
49            }
50        }
51
52        $html = $this->formatChangeLine( $rc, $classes, $watched );
53
54        if ( $this->watchlist ) {
55            $classes[] = Sanitizer::escapeClass( 'watchlist-' .
56                $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] );
57        }
58
59        $attribs = $this->getDataAttributes( $rc );
60
61        if ( !$this->getHookRunner()->onOldChangesListRecentChangesLine(
62            $this, $html, $rc, $classes, $attribs )
63        ) {
64            return false;
65        }
66        $attribs = array_filter( $attribs,
67            [ Sanitizer::class, 'isReservedDataAttribute' ],
68            ARRAY_FILTER_USE_KEY
69        );
70
71        $dateheader = ''; // $html now contains only <li>...</li>, for hooks' convenience.
72        $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
73
74        $html = $this->getHighlightsContainerDiv() . $html;
75        $attribs['class'] = $classes;
76
77        return $dateheader . Html::rawElement( 'li', $attribs, $html ) . "\n";
78    }
79
80    /**
81     * @param RecentChange $rc
82     * @param string[] &$classes
83     * @param bool $watched
84     *
85     * @return string
86     */
87    private function formatChangeLine( RecentChange $rc, array &$classes, $watched ) {
88        $html = '';
89        $unpatrolled = $this->showAsUnpatrolled( $rc );
90
91        if ( $rc->mAttribs['rc_log_type'] ) {
92            $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] );
93            $this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'], false );
94            $flags = $this->recentChangesFlags( [ 'unpatrolled' => $unpatrolled,
95                'bot' => $rc->mAttribs['rc_bot'] ], '' );
96            if ( $flags !== '' ) {
97                $html .= ' ' . $flags;
98            }
99        // Log entries (old format) or log targets, and special pages
100        } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
101            [ $name, $htmlubpage ] = MediaWikiServices::getInstance()->getSpecialPageFactory()->
102                resolveAlias( $rc->mAttribs['rc_title'] );
103            if ( $name == 'Log' ) {
104                $this->insertLog( $html, $rc->getTitle(), $htmlubpage, false );
105            }
106        // Regular entries
107        } else {
108            $this->insertDiffHist( $html, $rc );
109            # M, N, b and ! (minor, new, bot and unpatrolled)
110            $html .= $this->recentChangesFlags(
111                [
112                    'newpage' => $rc->mAttribs['rc_type'] == RC_NEW,
113                    'minor' => $rc->mAttribs['rc_minor'],
114                    'unpatrolled' => $unpatrolled,
115                    'bot' => $rc->mAttribs['rc_bot']
116                ],
117                ''
118            );
119            $html .= $this->getArticleLink( $rc, $unpatrolled, $watched );
120        }
121        # Edit/log timestamp
122        $this->insertTimestamp( $html, $rc );
123        # Bytes added or removed
124        if ( $this->getConfig()->get( MainConfigNames::RCShowChangedSize ) ) {
125            $cd = $this->formatCharacterDifference( $rc );
126            if ( $cd !== '' ) {
127                $html .= $cd . '  <span class="mw-changeslist-separator"></span> ';
128            }
129        }
130
131        if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
132            $html .= $this->insertLogEntry( $rc );
133        } elseif ( $this->isCategorizationWithoutRevision( $rc ) ) {
134            $html .= $this->insertComment( $rc );
135        } else {
136            # User tool links
137            $this->insertUserRelatedLinks( $html, $rc );
138            # LTR/RTL direction mark
139            $html .= $this->getLanguage()->getDirMark();
140            $html .= $this->insertComment( $rc );
141        }
142
143        # Tags
144        $this->insertTags( $html, $rc, $classes );
145        # Rollback
146        $this->insertRollback( $html, $rc );
147        # For subclasses
148        $this->insertExtra( $html, $rc, $classes );
149
150        # How many users watch this page
151        if ( $rc->numberofWatchingusers > 0 ) {
152            $html .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers );
153        }
154
155        $html = Html::rawElement( 'span', [
156            'class' => 'mw-changeslist-line-inner',
157            'data-target-page' => $rc->getTitle(), // Used for reliable determination of the affiliated page
158        ], $html );
159        if ( is_callable( $this->changeLinePrefixer ) ) {
160            $prefix = call_user_func( $this->changeLinePrefixer, $rc, $this, false );
161            $html = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix ) . $html;
162        }
163
164        return $html;
165    }
166}