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