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