X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FLogEventsList.php;h=ac6c9fc91d359499d4846934b0e09c36c3bf8693;hb=10500033b7264ac2ec2fdfacfbb72450888e8e81;hp=2e9fc2124c14f9500df1e5ccb4912cb28e089c7d;hpb=a45494196f14d61fce2e376e2614027dd4b15778;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index 2e9fc2124c..ac6c9fc91d 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -24,7 +24,7 @@ class LogEventsList { private $out; public $flags; - function __construct( $skin, $out, $flags = 0 ) { + public function __construct( $skin, $out, $flags = 0 ) { $this->skin = $skin; $this->out = $out; $this->flags = $flags; @@ -38,9 +38,11 @@ class LogEventsList { private function preCacheMessages() { // Precache various messages if( !isset( $this->message ) ) { - $messages = 'revertmerge protect_change unblocklink change-blocklink revertmove undeletelink revdel-restore rev-delundel hist'; - foreach( explode( ' ', $messages ) as $msg ) { - $this->message[$msg] = wfMsgExt( $msg, array( 'escape') ); + $messages = array( 'revertmerge', 'protect_change', 'unblocklink', 'change-blocklink', + 'revertmove', 'undeletelink', 'revdel-restore', 'rev-delundel', 'hist', 'diff', + 'pipe-separator' ); + foreach( $messages as $msg ) { + $this->message[$msg] = wfMsgExt( $msg, array( 'escapenoentities' ) ); } } } @@ -64,16 +66,19 @@ class LogEventsList { * @param $pattern String * @param $year Integer: year * @param $month Integer: month - * @param $filter Boolean + * @param $filter: array + * @param $tagFilter: array? */ public function showOptions( $type = '', $user = '', $page = '', $pattern = '', $year = '', - $month = '', $filter = null ) + $month = '', $filter = null, $tagFilter='' ) { global $wgScript, $wgMiserMode; $action = htmlspecialchars( $wgScript ); $title = SpecialPage::getTitleFor( 'Log' ); $special = htmlspecialchars( $title->getPrefixedDBkey() ); + $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); + $this->out->addHTML( "
" . Xml::element( 'legend', array(), wfMsg( 'log' ) ) . Xml::hidden( 'title', $special ) . "\n" . @@ -81,28 +86,31 @@ class LogEventsList { $this->getUserInput( $user ) . "\n" . $this->getTitleInput( $page ) . "\n" . ( !$wgMiserMode ? ($this->getTitlePattern( $pattern )."\n") : "" ) . - "

" . $this->getDateMenu( $year, $month ) . "\n" . - ( $filter ? "

".$this->getFilterLinks( $type, $filter )."\n" : "" ) . + "

" . Xml::dateMenu( $year, $month ) . "\n" . + ( $tagSelector ? Xml::tags( 'p', null, implode( ' ', $tagSelector ) ) :'' ). "\n" . + ( $filter ? "

".$this->getFilterLinks( $type, $filter )."\n" : "" ) . "\n" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "

\n" . "
" ); } private function getFilterLinks( $logType, $filter ) { - global $wgTitle; + global $wgTitle, $wgLang; // show/hide links $messages = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) ); // Option value -> message mapping $links = array(); + $hiddens = ''; // keep track for "go" button foreach( $filter as $type => $val ) { $hideVal = 1 - intval($val); $link = $this->skin->makeKnownLinkObj( $wgTitle, $messages[$hideVal], wfArrayToCGI( array( "hide_{$type}_log" => $hideVal ), $this->getDefaultQuery() ) ); $links[$type] = wfMsgHtml( "log-show-hide-{$type}", $link ); + $hiddens .= Xml::hidden( "hide_{$type}_log", $val ) . "\n"; } // Build links - return implode( ' | ', $links ); + return ''.$wgLang->pipeList( $links ) . '' . $hiddens; } private function getDefaultQuery() { @@ -162,7 +170,7 @@ class LogEventsList { * @return String: Formatted HTML */ private function getUserInput( $user ) { - return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'user', 15, $user ); + return Xml::inputLabel( wfMsg( 'specialloguserlabel' ), 'user', 'mw-log-user', 15, $user ); } /** @@ -170,38 +178,7 @@ class LogEventsList { * @return String: Formatted HTML */ private function getTitleInput( $title ) { - return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'page', 20, $title ); - } - - /** - * @param $year Integer - * @param $month Integer - * @return string Formatted HTML - */ - private function getDateMenu( $year, $month ) { - # Offset overrides year/month selection - if( $month && $month !== -1 ) { - $encMonth = intval( $month ); - } else { - $encMonth = ''; - } - if ( $year ) { - $encYear = intval( $year ); - } else if( $encMonth ) { - $thisMonth = intval( gmdate( 'n' ) ); - $thisYear = intval( gmdate( 'Y' ) ); - if( intval($encMonth) > $thisMonth ) { - $thisYear--; - } - $encYear = $thisYear; - } else { - $encYear = ''; - } - return Xml::label( wfMsg( 'year' ), 'year' ) . ' '. - Xml::input( 'year', 4, $encYear, array('id' => 'year', 'maxlength' => 4) ) . - ' '. - Xml::label( wfMsg( 'month' ), 'month' ) . ' '. - Xml::monthSelector( $encMonth, -1 ); + return Xml::inputLabel( wfMsg( 'speciallogtitlelabel' ), 'page', 'mw-log-page', 20, $title ); } /** @@ -229,6 +206,7 @@ class LogEventsList { global $wgLang, $wgUser, $wgContLang; $title = Title::makeTitle( $row->log_namespace, $row->log_title ); + $classes = array( "mw-logline-{$row->log_type}" ); $time = $wgLang->timeanddate( wfTimestamp(TS_MW, $row->log_timestamp), true ); // User links if( self::isDeleted($row,LogPage::DELETED_USER) ) { @@ -247,7 +225,7 @@ class LogEventsList { $paramArray = LogPage::extractParams( $row->log_params ); $revert = $del = ''; // Some user can hide log items and have review links - if( $wgUser->isAllowed( 'deleterevision' ) ) { + if( !($this->flags & self::NO_ACTION_LINK) && $wgUser->isAllowed( 'deleterevision' ) ) { $del = $this->getShowHideLinks( $row ) . ' '; } // Add review links and such... @@ -273,21 +251,29 @@ class LogEventsList { $this->skin->link( SpecialPage::getTitleFor( 'Ipblocklist' ), $this->message['unblocklink'], array(), - array( 'action' => 'unblock', 'ip' => urlencode( $row->log_title ) ), + array( 'action' => 'unblock', 'ip' => $row->log_title ), 'known' ) - . ' ' . wfMsg( 'pipe-separator' ) . ' ' . - $this->skin->link( SpecialPage::getTitleFor( 'Blockip', htmlspecialchars( $row->log_title ) ), + . $this->message['pipe-separator'] . + $this->skin->link( SpecialPage::getTitleFor( 'Blockip', $row->log_title ), $this->message['change-blocklink'], array(), array(), 'known' ) . ')'; // Show change protection link - } else if( self::typeAction($row,'protect',array('modify','protect','unprotect')) ) { - $revert .= ' (' . $this->skin->makeKnownLinkObj( $title, $this->message['hist'], - 'action=history&offset=' . urlencode($row->log_timestamp) ) . ')'; - if( $wgUser->isAllowed('protect') && $row->log_action != 'unprotect' ) { - $revert .= ' (' . $this->skin->makeKnownLinkObj( $title, $this->message['protect_change'], - 'action=unprotect' ) . ')'; + } else if( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) { + $revert .= ' (' . + $this->skin->link( $title, + $this->message['hist'], + array(), + array( 'action' => 'history', 'offset' => $row->log_timestamp ) ); + if( $wgUser->isAllowed( 'protect' ) ) { + $revert .= $this->message['pipe-separator'] . + $this->skin->link( $title, + $this->message['protect_change'], + array(), + array( 'action' => 'protect' ), + 'known' ); } + $revert .= ')'; // Show unmerge link } else if( self::typeAction($row,'merge','merge','mergehistory') ) { $merge = SpecialPage::getTitleFor( 'Mergehistory' ); @@ -296,31 +282,36 @@ class LogEventsList { 'mergepoint' => $paramArray[1] ) ) ) . ')'; // If an edit was hidden from a page give a review link to the history } else if( self::typeAction($row,array('delete','suppress'),'revision','deleterevision') ) { - if( count($paramArray) == 2 ) { + if( count($paramArray) >= 2 ) { $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); // Different revision types use different URL params... $key = $paramArray[0]; - // Link to each hidden object ID, $paramArray[1] is the url param + // $paramArray[1] is a CVS of the IDs $Ids = explode( ',', $paramArray[1] ); - $revParams = ''; - foreach( $Ids as $n => $id ) { - $revParams .= '&' . urlencode($key) . '[]=' . urlencode($id); + $query = urlencode($paramArray[1]); + $revert = array(); + // Diff link for single rev deletions + if( $key === 'oldid' && count($Ids) == 1 ) { + $token = urlencode( $wgUser->editToken( intval($Ids[0]) ) ); + $revert[] = $this->skin->makeKnownLinkObj( $title, $this->message['diff'], + 'diff='.intval($Ids[0])."&unhide=1&token=$token" ); } - $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'], - 'target=' . $title->getPrefixedUrl() . $revParams ) . ')'; + // View/modify link... + $revert[] = $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'], + 'target='.$title->getPrefixedUrl()."&$key=$query" ); + // Pipe links + $revert = '(' . implode(' | ',$revert) . ')'; } // Hidden log items, give review link } else if( self::typeAction($row,array('delete','suppress'),'event','deleterevision') ) { - if( count($paramArray) == 1 ) { + if( count($paramArray) >= 1 ) { $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); + // $paramArray[1] is a CVS of the IDs $Ids = explode( ',', $paramArray[0] ); + $query = urlencode($paramArray[0]); // Link to each hidden object ID, $paramArray[1] is the url param - $logParams = ''; - foreach( $Ids as $n => $id ) { - $logParams .= '&logid[]=' . intval($id); - } $revert = '(' . $this->skin->makeKnownLinkObj( $revdel, $this->message['revdel-restore'], - 'target=' . $title->getPrefixedUrl() . $logParams ) . ')'; + 'target='.$title->getPrefixedUrl()."&logid=$query" ) . ')'; } // Self-created users } else if( self::typeAction($row,'newusers','create2') ) { @@ -331,7 +322,8 @@ class LogEventsList { $revert = $this->skin->userToolLinks( 1, $title->getDBkey() ); } if( $time < '20080129000000' ) { - # Suppress $comment from old entries (before 2008-01-29), not needed and can contain incorrect links + # Suppress $comment from old entries (before 2008-01-29), + # not needed and can contain incorrect links $comment = ''; } // Do nothing. The implementation is handled by the hook modifiying the passed-by-ref parameters. @@ -343,10 +335,20 @@ class LogEventsList { if( self::isDeleted($row,LogPage::DELETED_ACTION) ) { $action = '' . wfMsgHtml('rev-deleted-event') . ''; } else { - $action = LogPage::actionText( $row->log_type, $row->log_action, $title, $this->skin, $paramArray, true ); + $action = LogPage::actionText( $row->log_type, $row->log_action, $title, + $this->skin, $paramArray, true ); + } + + // Any tags... + list($tagDisplay, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'logevent' ); + $classes = array_merge( $classes, $newClasses ); + + if( $revert != '' ) { + $revert = '' . $revert . ''; } - return "
  • $del$time $userLink $action $comment $revert
  • \n"; + return Xml::tags( 'li', array( "class" => implode( ' ', $classes ) ), + $del . $time . ' ' . $userLink . ' ' . $action . ' ' . $comment . ' ' . $revert . " $tagDisplay" ) . "\n"; } /** @@ -357,19 +359,19 @@ class LogEventsList { $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); // If event was hidden from sysops if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { - $del = $this->message['rev-delundel']; + $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), + '('.$this->message['rev-delundel'].')' ); } else if( $row->log_type == 'suppress' ) { - // No one should be hiding from the oversight log - $del = $this->message['rev-delundel']; + $del = ''; // No one should be hiding from the oversight log } else { $target = SpecialPage::getTitleFor( 'Log', $row->log_type ); - $del = $this->skin->makeKnownLinkObj( $revdel, $this->message['rev-delundel'], - 'target=' . $target->getPrefixedUrl() . '&logid='.$row->log_id ); - // Bolden oversighted content - if( self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) - $del = "$del"; + $page = Title::makeTitle( $row->log_namespace, $row->log_title ); + $query = array( 'target' => $target->getPrefixedDBkey(), + 'logid' => $row->log_id, 'page' => $page->getPrefixedDBkey() ); + $del = $this->skin->revDeleteLink( $query, + self::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ); } - return "($del)"; + return $del; } /** @@ -380,7 +382,8 @@ class LogEventsList { * @return bool */ public static function typeAction( $row, $type, $action, $right='' ) { - $match = is_array($type) ? in_array($row->log_type,$type) : $row->log_type == $type; + $match = is_array($type) ? + in_array($row->log_type,$type) : $row->log_type == $type; if( $match ) { $match = is_array($action) ? in_array($row->log_action,$action) : $row->log_action == $action; @@ -452,15 +455,16 @@ class LogEventsList { /** * SQL clause to skip forbidden log types for this user * @param $db Database + * @param $audience string, public/user * @return mixed (string or false) */ - public static function getExcludeClause( $db ) { + public static function getExcludeClause( $db, $audience = 'public' ) { global $wgLogRestrictions, $wgUser; // Reset the array, clears extra "where" clauses when $par is used $hiddenLogs = array(); // Don't show private logs to unprivileged users foreach( $wgLogRestrictions as $logType => $right ) { - if( !$wgUser->isAllowed($right) ) { + if( $audience == 'public' || !$wgUser->isAllowed($right) ) { $safeType = $db->strencode( $logType ); $hiddenLogs[] = $safeType; } @@ -492,23 +496,25 @@ class LogPager extends ReverseChronologicalPager { * @param $year Integer * @param $month Integer */ - function __construct( $list, $type = '', $user = '', $title = '', $pattern = '', - $conds = array(), $year = false, $month = false ) + public function __construct( $list, $type = '', $user = '', $title = '', $pattern = '', + $conds = array(), $year = false, $month = false, $tagFilter = '' ) { parent::__construct(); $this->mConds = $conds; $this->mLogEventsList = $list; - $this->limitType( $type ); + $this->limitType( $type ); // also excludes hidden types $this->limitUser( $user ); $this->limitTitle( $title, $pattern ); $this->getDateCond( $year, $month ); + $this->mTagFilter = $tagFilter; } public function getDefaultQuery() { $query = parent::getDefaultQuery(); $query['type'] = $this->type; + $query['user'] = $this->user; $query['month'] = $this->mMonth; $query['year'] = $this->mYear; return $query; @@ -535,24 +541,29 @@ class LogPager extends ReverseChronologicalPager { /** * Set the log reader to return only entries of the given type. * Type restrictions enforced here - * @param $type String: A log type ('upload', 'delete', etc) + * @param $types String or array: Log types ('upload', 'delete', etc) */ - private function limitType( $type ) { + private function limitType( $types ) { global $wgLogRestrictions, $wgUser; + // If $types is not an array, make it an array + $types = (array)$types; // Don't even show header for private logs; don't recognize it... - if( isset($wgLogRestrictions[$type]) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) { - $type = ''; + foreach ( $types as $type ) { + if( isset( $wgLogRestrictions[$type] ) && !$wgUser->isAllowed($wgLogRestrictions[$type]) ) { + $types = array_diff( $types, array( $type ) ); + } } - // Don't show private logs to unpriviledged users - $hideLogs = LogEventsList::getExcludeClause( $this->mDb ); + // Don't show private logs to unprivileged users. + // Also, only show them upon specific request to avoid suprises. + $audience = $types ? 'user' : 'public'; + $hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience ); if( $hideLogs !== false ) { $this->mConds[] = $hideLogs; } - if( !$type ) { - return false; + if( $types ) { + $this->type = $types; + $this->mConds['log_type'] = $types; } - $this->type = $type; - $this->mConds['log_type'] = $type; } /** @@ -574,7 +585,12 @@ class LogPager extends ReverseChronologicalPager { but for now it won't pass anywhere behind the optimizer */ $this->mConds[] = "NULL"; } else { + global $wgUser; $this->mConds['log_user'] = $userid; + // Paranoia: avoid brute force searches (bug 17342) + if( !$wgUser->isAllowed( 'suppressrevision' ) ) { + $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_USER . ' = 0'; + } $this->user = $usertitle->getText(); } } @@ -586,7 +602,7 @@ class LogPager extends ReverseChronologicalPager { * @param $pattern String */ private function limitTitle( $page, $pattern ) { - global $wgMiserMode; + global $wgMiserMode, $wgUser; $title = Title::newFromText( $page ); if( strlen($page) == 0 || !$title instanceof Title ) @@ -615,6 +631,10 @@ class LogPager extends ReverseChronologicalPager { $this->mConds['log_namespace'] = $ns; $this->mConds['log_title'] = $title->getDBkey(); } + // Paranoia: avoid brute force searches (bug 17342) + if( !$wgUser->isAllowed( 'suppressrevision' ) ) { + $this->mConds[] = 'log_deleted & ' . LogPage::DELETED_ACTION . ' = 0'; + } } public function getQueryInfo() { @@ -627,13 +647,19 @@ class LogPager extends ReverseChronologicalPager { } else { $index = array( 'USE INDEX' => array( 'logging' => 'times' ) ); } - return array( + $info = array( 'tables' => array( 'logging', 'user' ), 'fields' => array( 'log_type', 'log_action', 'log_user', 'log_namespace', 'log_title', 'log_params', 'log_comment', 'log_id', 'log_deleted', 'log_timestamp', 'user_name', 'user_editcount' ), 'conds' => $this->mConds, - 'options' => $index + 'options' => $index, + 'join_conds' => array( 'user' => array( 'INNER JOIN', 'user_id=log_user' ) ), ); + + ChangeTags::modifyDisplayQuery( $info['tables'], $info['fields'], $info['conds'], + $info['join_conds'], $info['options'], $this->mTagFilter ); + + return $info; } function getIndexField() { @@ -684,6 +710,10 @@ class LogPager extends ReverseChronologicalPager { public function getMonth() { return $this->mMonth; } + + public function getTagFilter() { + return $this->mTagFilter; + } } /** @@ -697,6 +727,7 @@ class LogReader { */ function __construct( $request ) { global $wgUser, $wgOut; + wfDeprecated(__METHOD__); # Get parameters $type = $request->getVal( 'type' ); $user = $request->getText( 'user' ); @@ -704,6 +735,7 @@ class LogReader { $pattern = $request->getBool( 'pattern' ); $year = $request->getIntOrNull( 'year' ); $month = $request->getIntOrNull( 'month' ); + $tagFilter = $request->getVal( 'tagfilter' ); # Don't let the user get stuck with a certain date $skip = $request->getText( 'offset' ) || $request->getText( 'dir' ) == 'prev'; if( $skip ) { @@ -712,7 +744,7 @@ class LogReader { } # Use new list class to output results $loglist = new LogEventsList( $wgUser->getSkin(), $wgOut, 0 ); - $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month ); + $this->pager = new LogPager( $loglist, $type, $user, $title, $pattern, $year, $month, $tagFilter ); } /** @@ -743,6 +775,7 @@ class LogViewer { */ function __construct( &$reader, $flags = 0 ) { global $wgUser; + wfDeprecated(__METHOD__); $this->reader =& $reader; $this->reader->pager->mLogEventsList->flags = $flags; # Aliases for shorter code...