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