MediaWiki master
OldChangesList.php
Go to the documentation of this file.
1<?php
8
15
22
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
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
167class_alias( OldChangesList::class, 'OldChangesList' );
const NS_SPECIAL
Definition Defines.php:40
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
A class containing constants representing the names of configuration variables.
const RCShowChangedSize
Name constant for the RCShowChangedSize setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:32
Base class for lists of recent changes shown on special pages.
numberofWatchingusers( $count)
Returns the string which indicates the number of watching users.
getHTMLClasses( $rc, $watched)
Get an array of default HTML class attributes for the change.
getHighlightsContainerDiv()
Get the container for highlights that are used in the new StructuredFilters system.
insertLogEntry( $rc)
Insert a formatted action.
getArticleLink(&$rc, $unpatrolled, $watched)
Get the HTML link to the changed page, possibly with a prefix from hook handlers, and a suffix for te...
insertLog(&$s, $title, $logtype, $useParentheses=true)
recentChangesFlags( $flags, $nothing="\u{00A0}")
Returns the appropriate flags for new page, minor change and patrolling.
static userCan( $rc, $field, ?Authority $performer=null)
Determine if the current user is allowed to view a particular field of this revision,...
insertComment( $rc)
Insert a formatted comment.
insertUserRelatedLinks(&$s, &$rc)
Insert links to user page, user talk page and eventually a blocking link.
insertDiffHist(&$s, &$rc, $unpatrolled=null)
insertRollback(&$s, &$rc)
Insert a rollback link.
isCategorizationWithoutRevision( $rcObj)
Determines whether a revision is linked to this change; this may not be the case when the categorizat...
insertTimestamp(&$s, $rc)
Insert time timestamp string from $rc into $s.
formatCharacterDifference(RecentChange $old, ?RecentChange $new=null)
Format the character difference of one or several changes.
getDataAttributes(RecentChange $rc)
Get recommended data attributes for a change line.
Generate a list of changes using the good old system (no javascript).
recentChangesLine(&$rc, $watched=false, $linenumber=null)
Format a line using the old system (aka without any javascript).
Utility class for creating and reading rows in the recentchanges table.
Page revision base class.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...