Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.04% |
65 / 73 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OldChangesList | |
90.28% |
65 / 72 |
|
0.00% |
0 / 2 |
16.24 | |
0.00% |
0 / 1 |
| recentChangesLine | |
95.45% |
21 / 22 |
|
0.00% |
0 / 1 |
5 | |||
| formatChangeLine | |
88.00% |
44 / 50 |
|
0.00% |
0 / 1 |
11.21 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\RecentChanges; |
| 8 | |
| 9 | use MediaWiki\Html\Html; |
| 10 | use MediaWiki\MainConfigNames; |
| 11 | use MediaWiki\MediaWikiServices; |
| 12 | use MediaWiki\Parser\Sanitizer; |
| 13 | use MediaWiki\SpecialPage\SpecialPage; |
| 14 | |
| 15 | /** |
| 16 | * Generate a list of changes using the good old system (no javascript). |
| 17 | * |
| 18 | * @ingroup RecentChanges |
| 19 | */ |
| 20 | class OldChangesList extends ChangesList { |
| 21 | |
| 22 | /** |
| 23 | * Format a line using the old system (aka without any javascript). |
| 24 | * |
| 25 | * @param RecentChange &$rc Passed by reference |
| 26 | * @param bool $watched (default false) |
| 27 | * @param int|null $linenumber (default null) |
| 28 | * |
| 29 | * @return string|bool |
| 30 | * @return-taint none |
| 31 | */ |
| 32 | public function recentChangesLine( &$rc, $watched = false, $linenumber = null ) { |
| 33 | $classes = $this->getHTMLClasses( $rc, $watched ); |
| 34 | // use mw-line-even/mw-line-odd class only if linenumber is given (feature from T16468) |
| 35 | if ( $linenumber ) { |
| 36 | if ( $linenumber & 1 ) { |
| 37 | $classes[] = 'mw-line-odd'; |
| 38 | } else { |
| 39 | $classes[] = 'mw-line-even'; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | $html = $this->formatChangeLine( $rc, $classes, $watched ); |
| 44 | |
| 45 | if ( $this->watchlist ) { |
| 46 | $classes[] = Sanitizer::escapeClass( 'watchlist-' . |
| 47 | $rc->mAttribs['rc_namespace'] . '-' . $rc->mAttribs['rc_title'] ); |
| 48 | } |
| 49 | |
| 50 | $attribs = $this->getDataAttributes( $rc ); |
| 51 | |
| 52 | if ( !$this->getHookRunner()->onOldChangesListRecentChangesLine( |
| 53 | $this, $html, $rc, $classes, $attribs ) |
| 54 | ) { |
| 55 | return false; |
| 56 | } |
| 57 | $attribs = array_filter( $attribs, |
| 58 | Sanitizer::isReservedDataAttribute( ... ), |
| 59 | ARRAY_FILTER_USE_KEY |
| 60 | ); |
| 61 | |
| 62 | $dateheader = ''; // $html now contains only <li>...</li>, for hooks' convenience. |
| 63 | $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] ); |
| 64 | |
| 65 | $html = $this->getHighlightsContainerDiv() . $html; |
| 66 | $attribs['class'] = $classes; |
| 67 | |
| 68 | return $dateheader . Html::rawElement( 'li', $attribs, $html ) . "\n"; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @param RecentChange $rc |
| 73 | * @param string[] &$classes |
| 74 | * @param bool $watched |
| 75 | * |
| 76 | * @return string |
| 77 | */ |
| 78 | private function formatChangeLine( RecentChange $rc, array &$classes, $watched ) { |
| 79 | $html = ''; |
| 80 | $unpatrolled = $this->showAsUnpatrolled( $rc ); |
| 81 | |
| 82 | if ( $rc->mAttribs['rc_log_type'] ) { |
| 83 | $logtitle = SpecialPage::getTitleFor( 'Log', $rc->mAttribs['rc_log_type'] ); |
| 84 | $this->insertLog( $html, $logtitle, $rc->mAttribs['rc_log_type'], false ); |
| 85 | $flags = $this->recentChangesFlags( [ 'unpatrolled' => $unpatrolled, |
| 86 | 'bot' => $rc->mAttribs['rc_bot'] ], '' ); |
| 87 | if ( $flags !== '' ) { |
| 88 | $html .= ' ' . $flags; |
| 89 | } |
| 90 | // Log entries (old format) or log targets, and special pages |
| 91 | } elseif ( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) { |
| 92 | [ $name, $htmlubpage ] = MediaWikiServices::getInstance()->getSpecialPageFactory()-> |
| 93 | resolveAlias( $rc->mAttribs['rc_title'] ); |
| 94 | if ( $name == 'Log' ) { |
| 95 | $this->insertLog( $html, $rc->getTitle(), $htmlubpage ?? '', false ); |
| 96 | } |
| 97 | // Regular entries |
| 98 | } else { |
| 99 | $this->insertDiffHist( $html, $rc ); |
| 100 | # M, N, b and ! (minor, new, bot and unpatrolled) |
| 101 | $html .= $this->recentChangesFlags( |
| 102 | [ |
| 103 | 'newpage' => $rc->mAttribs['rc_source'] == RecentChange::SRC_NEW, |
| 104 | 'minor' => $rc->mAttribs['rc_minor'], |
| 105 | 'unpatrolled' => $unpatrolled, |
| 106 | 'bot' => $rc->mAttribs['rc_bot'] |
| 107 | ], |
| 108 | '' |
| 109 | ); |
| 110 | $html .= $this->getArticleLink( $rc, $unpatrolled, $watched ); |
| 111 | } |
| 112 | # Edit/log timestamp |
| 113 | $this->insertTimestamp( $html, $rc ); |
| 114 | # Bytes added or removed |
| 115 | if ( $this->getConfig()->get( MainConfigNames::RCShowChangedSize ) ) { |
| 116 | $cd = $this->formatCharacterDifference( $rc ); |
| 117 | if ( $cd !== '' ) { |
| 118 | $html .= $cd . ' <span class="mw-changeslist-separator"></span> '; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if ( $rc->mAttribs['rc_source'] == RecentChange::SRC_LOG ) { |
| 123 | $html .= $this->insertLogEntry( $rc ); |
| 124 | } elseif ( $this->isCategorizationWithoutRevision( $rc ) ) { |
| 125 | $html .= $this->insertComment( $rc ); |
| 126 | } else { |
| 127 | # User tool links |
| 128 | $this->insertUserRelatedLinks( $html, $rc ); |
| 129 | $html .= $this->insertComment( $rc ); |
| 130 | } |
| 131 | |
| 132 | # Tags |
| 133 | $this->insertTags( $html, $rc, $classes ); |
| 134 | # Labels |
| 135 | $this->insertLabels( $html, $rc, $classes ); |
| 136 | # Rollback |
| 137 | $this->insertRollback( $html, $rc ); |
| 138 | # For subclasses |
| 139 | $this->insertExtra( $html, $rc, $classes ); |
| 140 | |
| 141 | # How many users watch this page |
| 142 | if ( $rc->numberofWatchingusers > 0 ) { |
| 143 | $html .= ' ' . $this->numberofWatchingusers( $rc->numberofWatchingusers ); |
| 144 | } |
| 145 | |
| 146 | $html = Html::rawElement( 'span', [ |
| 147 | 'class' => 'mw-changeslist-line-inner', |
| 148 | 'data-target-page' => $rc->getTitle(), // Used for reliable determination of the affiliated page |
| 149 | ], $html ); |
| 150 | if ( is_callable( $this->changeLinePrefixer ) ) { |
| 151 | $prefix = ( $this->changeLinePrefixer )( $rc, $this, false ); |
| 152 | $html = Html::rawElement( 'span', [ 'class' => 'mw-changeslist-line-prefix' ], $prefix ) . $html; |
| 153 | } |
| 154 | |
| 155 | return $html; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** @deprecated class alias since 1.44 */ |
| 160 | class_alias( OldChangesList::class, 'OldChangesList' ); |