X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fchanges%2FEnhancedChangesList.php;h=1c4954575963bb8c8cbdea67e3fcfaf90851e044;hb=de8f8c8248341c007ab6a9365a3c40614bcf04dc;hp=f10307db79ef30f9a17f98c3e428e99e67ea87fc;hpb=304a56f7d81a114677f78463ffc32e5c3662e4b8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index f10307db79..1c49545759 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -161,35 +161,44 @@ class EnhancedChangesList extends ChangesList { protected function recentChangesBlockGroup( $block ) { # Add the namespace and title of the block as part of the class - $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' ); + $tableClasses = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' ); if ( $block[0]->mAttribs['rc_log_type'] ) { # Log entry - $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-' + $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-log-' . $block[0]->mAttribs['rc_log_type'] ); } else { - $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns' + $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-ns' . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] ); } - $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched - ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched'; - $r = Html::openElement( 'table', array( 'class' => $classes ) ) . - Html::openElement( 'tr' ); + if ( $block[0]->watched + && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched + ) { + $tableClasses[] = 'mw-changeslist-line-watched'; + } else { + $tableClasses[] = 'mw-changeslist-line-not-watched'; + } # Collate list of users $userlinks = array(); # Other properties - $unpatrolled = false; - $isnew = false; - $allBots = true; - $allMinors = true; $curId = 0; # Some catalyst variables... $namehidden = true; $allLogs = true; $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' ); + $collectedRcFlags = array( + // All are by bots? + 'bot' => true, + // Includes a new page? + 'newpage' => false, + // All are minor edits? + 'minor' => true, + // Contains an unpatrolled edit? + 'unpatrolled' => false, + ); foreach ( $block as $rcObj ) { if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) { - $isnew = true; + $collectedRcFlags['newpage'] = true; } // If all log actions to this page were hidden, then don't // give the name of the affected page for this block! @@ -201,7 +210,7 @@ class EnhancedChangesList extends ChangesList { $userlinks[$u] = 0; } if ( $rcObj->unpatrolled ) { - $unpatrolled = true; + $collectedRcFlags['unpatrolled'] = true; } if ( $rcObj->mAttribs['rc_type'] != RC_LOG ) { $allLogs = false; @@ -213,10 +222,10 @@ class EnhancedChangesList extends ChangesList { } if ( !$rcObj->mAttribs['rc_bot'] ) { - $allBots = false; + $collectedRcFlags['bot'] = false; } if ( !$rcObj->mAttribs['rc_minor'] ) { - $allMinors = false; + $collectedRcFlags['minor'] = false; } $userlinks[$u]++; @@ -237,63 +246,44 @@ class EnhancedChangesList extends ChangesList { array_push( $users, $text ); } - $users = ' ' - . $this->msg( 'brackets' )->rawParams( - implode( $this->message['semicolon-separator'], $users ) - )->escaped() . ''; - - $tl = ''; - $r .= "$tl"; - - # Main line - $r .= '' . $this->recentChangesFlags( array( - 'newpage' => $isnew, # show, when one have this flag - 'minor' => $allMinors, # show only, when all have this flag - 'unpatrolled' => $unpatrolled, # show, when one have this flag - 'bot' => $allBots, # show only, when all have this flag - ) ); - - # Timestamp - $r .= ' ' . $block[0]->timestamp . ' '; - # Article link + $articleLink = ''; + $revDeletedMsg = false; if ( $namehidden ) { - $r .= ' ' . - $this->msg( 'rev-deleted-event' )->escaped() . ''; + $revDeletedMsg = $this->msg( 'rev-deleted-event' )->escaped(); } elseif ( $allLogs ) { - $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); + $articleLink = $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); } else { - $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched ); + $articleLink = $this->getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched ); } - $r .= $this->getLanguage()->getDirMark(); - $queryParams['curid'] = $curId; # Sub-entries - $lines = ''; + $lines = array(); foreach ( $block as $i => $rcObj ) { $line = $this->getLineData( $block, $rcObj, $queryParams ); - $lines .= $line; if ( !$line ) { // completely ignore this RC entry if we don't want to render it unset( $block[$i] ); } + $lines[] = $line; } // Further down are some assumptions that $block is a 0-indexed array // with (count-1) as last key. Let's make sure it is. $block = array_values( $block ); - if ( empty( $block ) ) { + + if ( empty( $block ) || !$lines ) { // if we can't show anything, don't display this block altogether return ''; } - $r .= $this->getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ); - - $r .= ' . . '; + $logText = $this->getLogText( $block, $queryParams, $allLogs, + $collectedRcFlags['newpage'], $namehidden + ); # Character difference (does not apply if only log items) + $charDifference = false; if ( $RCShowChangedSize && !$allLogs ) { $last = 0; $first = count( $block ) - 1; @@ -305,37 +295,42 @@ class EnhancedChangesList extends ChangesList { $first--; } # Get net change - $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] ); - - if ( $chardiff == '' ) { - $r .= ' '; - } else { - $r .= ' ' . $chardiff . ' . . '; - } - } - - $r .= $users; - $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers ); - $r .= ''; - - if ( !$lines ) { - // if there are no lines to be rendered (all aborted by hook), don't render the block - return ''; - } - - $r .= $lines; - $r .= "\n"; + $charDifference = $this->formatCharacterDifference( $block[$first], $block[$last] ); + } + + $numberofWatchingusers = $this->numberofWatchingusers( $block[0]->numberofWatchingusers ); + $usersList = $this->msg( 'brackets' )->rawParams( + implode( $this->message['semicolon-separator'], $users ) + )->escaped(); + + $templateParams = array( + 'articleLink' => $articleLink, + 'charDifference' => $charDifference, + 'collectedRcFlags' => $this->recentChangesFlags( $collectedRcFlags ), + 'languageDirMark' => $this->getLanguage()->getDirMark(), + 'lines' => $lines, + 'logText' => $logText, + 'numberofWatchingusers' => $numberofWatchingusers, + 'rev-deleted-event' => $revDeletedMsg, + 'tableClasses' => $tableClasses, + 'timestamp' => $block[0]->timestamp, + 'users' => $usersList, + ); $this->rcCacheIndex++; - return $r; + $templateParser = new TemplateParser(); + return $templateParser->processTemplate( + 'EnhancedChangesListGroup', + $templateParams + ); } /** * @param RCCacheEntry[] $block * @param RCCacheEntry $rcObj * @param array $queryParams - * @return string + * @return array * @throws Exception * @throws FatalError * @throws MWException @@ -347,9 +342,13 @@ class EnhancedChangesList extends ChangesList { $classes = array(); $type = $rcObj->mAttribs['rc_type']; $data = array(); + $lineParams = array(); - $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched - ? ' class="mw-enhanced-watched"' : ''; + if ( $rcObj->watched + && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched + ) { + $lineParams['classes'] = array( 'mw-enhanced-watched' ); + } $separator = ' . . '; $data['recentChangesFlags'] = array( @@ -406,6 +405,8 @@ class EnhancedChangesList extends ChangesList { if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) { $data['logEntry'] = $this->insertLogEntry( $rcObj ); + } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) { + $data['comment'] = $this->insertComment( $rcObj ); } else { # User links $data['userLink'] = $rcObj->userlink; @@ -424,27 +425,23 @@ class EnhancedChangesList extends ChangesList { array( $this, &$data, $block, $rcObj ) ); if ( !$success ) { // skip entry if hook aborted it - return ''; + return array(); } - $line = ''; if ( isset( $data['recentChangesFlags'] ) ) { - $line .= $this->recentChangesFlags( $data['recentChangesFlags'] ); + $lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] ); unset( $data['recentChangesFlags'] ); } - $line .= ' '; if ( isset( $data['timestampLink'] ) ) { - $line .= '' . $data['timestampLink'] . ''; + $lineParams['timestampLink'] = $data['timestampLink']; unset( $data['timestampLink'] ); } // everything else: makes it easier for extensions to add or remove data - $line .= implode( '', $data ); - - $line .= "\n"; + $lineParams['data'] = array_values( $data ); - return $line; + return $lineParams; } /** @@ -498,7 +495,7 @@ class EnhancedChangesList extends ChangesList { /** @var $block0 RecentChange */ $block0 = $block[0]; $last = $block[count( $block ) - 1]; - if ( !$allLogs ) { + if ( !$allLogs && $rcObj->mAttribs['rc_type'] != RC_CATEGORIZE ) { if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { $links['total-changes'] = $nchanges[$n]; } elseif ( $isnew ) { @@ -530,7 +527,7 @@ class EnhancedChangesList extends ChangesList { } # History - if ( $allLogs ) { + if ( $allLogs || $rcObj->mAttribs['rc_type'] == RC_CATEGORIZE ) { // don't show history link for logs } elseif ( $namehidden || !$block0->getTitle()->exists() ) { $links['history'] = $this->message['enhancedrc-history']; @@ -606,15 +603,9 @@ class EnhancedChangesList extends ChangesList { } # Diff and hist links - if ( $type != RC_LOG ) { + if ( $type != RC_LOG && $type != RC_CATEGORIZE ) { $query['action'] = 'history'; - $data['historyLink'] = ' ' . $this->msg( 'parentheses' ) - ->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown( - $rcObj->getTitle(), - $this->message['hist'], - array(), - $query - ) )->escaped(); + $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query ); } $data['separatorAfterLinks'] = ' . . '; @@ -629,10 +620,15 @@ class EnhancedChangesList extends ChangesList { if ( $type == RC_LOG ) { $data['logEntry'] = $this->insertLogEntry( $rcObj ); + } elseif ( $this->isCategorizationWithoutRevision( $rcObj ) ) { + $data['comment'] = $this->insertComment( $rcObj ); } else { $data['userLink'] = $rcObj->userlink; $data['userTalkLink'] = $rcObj->usertalklink; $data['comment'] = $this->insertComment( $rcObj ); + if ( $type == RC_CATEGORIZE ) { + $data['historyLink'] = $this->getDiffHistLinks( $rcObj, $query ); + } $data['rollback'] = $this->getRollback( $rcObj ); } @@ -673,6 +669,33 @@ class EnhancedChangesList extends ChangesList { return $line; } + /** + * Returns value to be used in 'historyLink' element of $data param in + * EnhancedChangesListModifyBlockLineData hook. + * + * @since 1.27 + * + * @param RCCacheEntry $rc + * @param array $query array of key/value pairs to append as a query string + * @return string HTML + */ + public function getDiffHistLinks( RCCacheEntry $rc, array $query ) { + $pageTitle = $rc->getTitle(); + if ( $rc->getAttribute( 'rc_type' ) == RC_CATEGORIZE ) { + // For categorizations we must swap the category title with the page title! + $pageTitle = Title::newFromID( $rc->getAttribute( 'rc_cur_id' ) ); + } + + $retVal = ' ' . $this->msg( 'parentheses' ) + ->rawParams( $rc->difflink . $this->message['pipe-separator'] . Linker::linkKnown( + $pageTitle, + $this->message['hist'], + array(), + $query + ) )->escaped(); + return $retVal; + } + /** * If enhanced RC is in use, this function takes the previously cached * RC lines, arranges them, and outputs the HTML