Debian Codegraph @

includes/recentchanges/OldChangesList.php

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