X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flogging%2FLogEventsList.php;h=03d527667e7c319f8bd043b45a09930a0aa047f0;hb=64308ea1074fc26f19f0ec696b7e496bfe19bf53;hp=4de1a9748c55c4a891e5f5deb0040597498e7b7b;hpb=2425cbf5f8e3f40846e2f3b5f1ba8c8a64ff1dee;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/logging/LogEventsList.php b/includes/logging/LogEventsList.php index 4de1a9748c..2b1b81f5b5 100644 --- a/includes/logging/LogEventsList.php +++ b/includes/logging/LogEventsList.php @@ -42,7 +42,7 @@ class LogEventsList extends ContextSource { * * @param $context IContextSource Context to use; formerly it was Skin object. * @param $unused void Unused; used to be an OutputPage object. - * @param $flags int flags; can be a combinaison of self::NO_ACTION_LINK, + * @param int $flags flags; can be a combinaison of self::NO_ACTION_LINK, * self::NO_EXTRA_USER_LINKS or self::USE_REVDEL_CHECKBOXES. */ public function __construct( $context, $unused = null, $flags = 0 ) { @@ -63,6 +63,7 @@ class LogEventsList extends ContextSource { * @return Title object */ public function getDisplayTitle() { + wfDeprecated( __METHOD__, '1.20' ); return $this->getTitle(); } @@ -74,9 +75,9 @@ class LogEventsList extends ContextSource { public function showHeader( $type ) { wfDeprecated( __METHOD__, '1.19' ); // If only one log type is used, then show a special message... - $headerType = (count($type) == 1) ? $type[0] : ''; + $headerType = count( $type ) == 1 ? $type[0] : ''; $out = $this->getOutput(); - if( LogPage::isLogType( $headerType ) ) { + if ( LogPage::isLogType( $headerType ) ) { $page = new LogPage( $headerType ); $out->setPageTitle( $page->getName()->text() ); $out->addHTML( $page->getDescription()->parseAsBlock() ); @@ -88,7 +89,7 @@ class LogEventsList extends ContextSource { /** * Show options for the log list * - * @param $types string or Array + * @param string $types or Array * @param $user String * @param $page String * @param $pattern String @@ -97,14 +98,14 @@ class LogEventsList extends ContextSource { * @param $filter: array * @param $tagFilter: array? */ - public function showOptions( $types=array(), $user='', $page='', $pattern='', $year='', - $month = '', $filter = null, $tagFilter='' ) { + public function showOptions( $types = array(), $user = '', $page = '', $pattern = '', $year = '', + $month = '', $filter = null, $tagFilter = '' ) { global $wgScript, $wgMiserMode; $title = SpecialPage::getTitleFor( 'Log' ); // For B/C, we take strings, but make sure they are converted... - $types = ($types === '') ? array() : (array)$types; + $types = ( $types === '' ) ? array() : (array)$types; $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); @@ -117,7 +118,7 @@ class LogEventsList extends ContextSource { $html .= $this->getExtraInputs( $types ) . "\n"; // Title pattern, if allowed - if (!$wgMiserMode) { + if ( !$wgMiserMode ) { $html .= $this->getTitlePattern( $pattern ) . "\n"; } @@ -125,12 +126,12 @@ class LogEventsList extends ContextSource { $html .= Xml::tags( 'p', null, Xml::dateMenu( $year, $month ) ); // Tag filter - if ($tagSelector) { + if ( $tagSelector ) { $html .= Xml::tags( 'p', null, implode( ' ', $tagSelector ) ); } // Filter links - if ($filter) { + if ( $filter ) { $html .= Xml::tags( 'p', null, $this->getFilterLinks( $filter ) ); } @@ -156,13 +157,13 @@ class LogEventsList extends ContextSource { // Option value -> message mapping $links = array(); $hiddens = ''; // keep track for "go" button - foreach( $filter as $type => $val ) { + foreach ( $filter as $type => $val ) { // Should the below assignment be outside the foreach? // Then it would have to be copied. Not certain what is more expensive. $query = $this->getDefaultQuery(); $queryKey = "hide_{$type}_log"; - $hideVal = 1 - intval($val); + $hideVal = 1 - intval( $val ); $query[$queryKey] = $hideVal; $link = Linker::linkKnown( @@ -172,11 +173,13 @@ class LogEventsList extends ContextSource { $query ); + // Message: log-show-hide-patrol $links[$type] = $this->msg( "log-show-hide-{$type}" )->rawParams( $link )->escaped(); $hiddens .= Html::hidden( "hide_{$type}_log", $val ) . "\n"; } + // Build links - return ''.$this->getLanguage()->pipeList( $links ) . '' . $hiddens; + return '' . $this->getLanguage()->pipeList( $links ) . '' . $hiddens; } private function getDefaultQuery() { @@ -190,6 +193,7 @@ class LogEventsList extends ContextSource { unset( $this->mDefaultQuery['month'] ); unset( $this->mDefaultQuery['year'] ); } + return $this->mDefaultQuery; } @@ -198,9 +202,10 @@ class LogEventsList extends ContextSource { * @return String: Formatted HTML */ private function getTypeMenu( $queryTypes ) { - $queryType = count($queryTypes) == 1 ? $queryTypes[0] : ''; + $queryType = count( $queryTypes ) == 1 ? $queryTypes[0] : ''; $selector = $this->getTypeSelector(); $selector->setDefault( $queryType ); + return $selector->getHtml(); } @@ -212,7 +217,7 @@ class LogEventsList extends ContextSource { public function getTypeSelector() { $typesByName = array(); // Temporary array // First pass to load the log names - foreach( LogPage::validTypes() as $type ) { + foreach ( LogPage::validTypes() as $type ) { $page = new LogPage( $type ); $restriction = $page->getRestriction(); if ( $this->getUser()->isAllowed( $restriction ) ) { @@ -221,7 +226,7 @@ class LogEventsList extends ContextSource { } // Second pass to sort by name - asort($typesByName); + asort( $typesByName ); // Always put "All public logs" on top $public = $typesByName['']; @@ -229,7 +234,7 @@ class LogEventsList extends ContextSource { $typesByName = array( '' => $public ) + $typesByName; $select = new XmlSelect( 'type' ); - foreach( $typesByName as $type => $name ) { + foreach ( $typesByName as $type => $name ) { $select->addOption( $name, $type ); } @@ -241,9 +246,15 @@ class LogEventsList extends ContextSource { * @return String: Formatted HTML */ private function getUserInput( $user ) { - return '' . - Xml::inputLabel( $this->msg( 'specialloguserlabel' )->text(), 'user', 'mw-log-user', 15, $user ) . - ''; + $label = Xml::inputLabel( + $this->msg( 'specialloguserlabel' )->text(), + 'user', + 'mw-log-user', + 15, + $user + ); + + return '' . $label . ''; } /** @@ -251,9 +262,15 @@ class LogEventsList extends ContextSource { * @return String: Formatted HTML */ private function getTitleInput( $title ) { - return '' . - Xml::inputLabel( $this->msg( 'speciallogtitlelabel' )->text(), 'page', 'mw-log-page', 20, $title ) . - ''; + $label = Xml::inputLabel( + $this->msg( 'speciallogtitlelabel' )->text(), + 'page', + 'mw-log-page', + 20, + $title + ); + + return '' . $label . ''; } /** @@ -273,13 +290,14 @@ class LogEventsList extends ContextSource { private function getExtraInputs( $types ) { $offender = $this->getRequest()->getVal( 'offender' ); $user = User::newFromName( $offender, false ); - if( !$user || ($user->getId() == 0 && !IP::isIPAddress($offender) ) ) { + if ( !$user || ( $user->getId() == 0 && !IP::isIPAddress( $offender ) ) ) { $offender = ''; // Blank field if invalid } - if( count($types) == 1 && $types[0] == 'suppress' ) { + if ( count( $types ) == 1 && $types[0] == 'suppress' ) { return Xml::inputLabel( $this->msg( 'revdelete-offender' )->text(), 'offender', 'mw-log-offender', 20, $offender ); } + return ''; } @@ -307,7 +325,6 @@ class LogEventsList extends ContextSource { $formatter->setContext( $this->getContext() ); $formatter->setShowUserToolLinks( !( $this->flags & self::NO_EXTRA_USER_LINKS ) ); - $title = $entry->getTarget(); $time = htmlspecialchars( $this->getLanguage()->userTimeAndDate( $entry->getTimestamp(), $this->getUser() ) ); @@ -343,36 +360,51 @@ class LogEventsList extends ContextSource { * @return string */ private function getShowHideLinks( $row ) { - if( ( $this->flags == self::NO_ACTION_LINK ) // we don't want to see the links - || $row->log_type == 'suppress' ) { // no one can hide items from the suppress log + // We don't want to see the links and + // no one can hide items from the suppress log. + if ( ( $this->flags == self::NO_ACTION_LINK ) + || $row->log_type == 'suppress' + ) { return ''; } $del = ''; $user = $this->getUser(); // Don't show useless checkbox to people who cannot hide log entries - if( $user->isAllowed( 'deletedhistory' ) ) { - if( $row->log_deleted || $user->isAllowed( 'deletelogentry' ) ) { - $canHide = $user->isAllowed( 'deletelogentry' ); - if ( $this->flags & self::USE_REVDEL_CHECKBOXES ) { // Show checkboxes instead of links. - if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) { // If event was hidden from sysops + if ( $user->isAllowed( 'deletedhistory' ) ) { + $canHide = $user->isAllowed( 'deletelogentry' ); + if ( $row->log_deleted || $canHide ) { + // Show checkboxes instead of links. + if ( $canHide && $this->flags & self::USE_REVDEL_CHECKBOXES ) { + // If event was hidden from sysops + if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) { $del = Xml::check( 'deleterevisions', false, array( 'disabled' => 'disabled' ) ); } else { - $del = Xml::check( 'showhiderevisions', false, array( 'name' => 'ids[' . $row->log_id . ']' ) ); + $del = Xml::check( + 'showhiderevisions', + false, + array( 'name' => 'ids[' . $row->log_id . ']' ) + ); } } else { - if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) { // If event was hidden from sysops + // If event was hidden from sysops + if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) { $del = Linker::revDeleteLinkDisabled( $canHide ); } else { $query = array( 'target' => SpecialPage::getTitleFor( 'Log', $row->log_type )->getPrefixedDBkey(), - 'type' => 'logging', - 'ids' => $row->log_id, + 'type' => 'logging', + 'ids' => $row->log_id, + ); + $del = Linker::revDeleteLink( + $query, + self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), + $canHide ); - $del = Linker::revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), $canHide ); } } } } + return $del; } @@ -383,17 +415,18 @@ class LogEventsList extends ContextSource { * @param $right string * @return Boolean */ - public static function typeAction( $row, $type, $action, $right='' ) { - $match = is_array($type) ? + public static function typeAction( $row, $type, $action, $right = '' ) { + $match = is_array( $type ) ? in_array( $row->log_type, $type ) : $row->log_type == $type; - if( $match ) { + if ( $match ) { $match = is_array( $action ) ? in_array( $row->log_action, $action ) : $row->log_action == $action; - if( $match && $right ) { + if ( $match && $right ) { global $wgUser; $match = $wgUser->isAllowed( $right ); } } + return $match; } @@ -420,7 +453,7 @@ class LogEventsList extends ContextSource { * @return Boolean */ public static function userCanBitfield( $bitfield, $field, User $user = null ) { - if( $bitfield & $field ) { + if ( $bitfield & $field ) { if ( $bitfield & LogPage::DELETED_RESTRICTED ) { $permission = 'suppressrevision'; } else { @@ -431,10 +464,11 @@ class LogEventsList extends ContextSource { global $wgUser; $user = $wgUser; } + return $user->isAllowed( $permission ); - } else { - return true; } + + return true; } /** @@ -450,10 +484,10 @@ class LogEventsList extends ContextSource { * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey) * * @param $out OutputPage|String-by-reference - * @param $types String|Array Log types to show - * @param $page String|Title The page title to show log entries for - * @param $user String The user who made the log entries - * @param $param array Associative Array with the following additional options: + * @param string|array $types Log types to show + * @param string|Title $page The page title to show log entries for + * @param string $user The user who made the log entries + * @param array $param Associative Array with the following additional options: * - lim Integer Limit of items to show, default is 50 * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'") * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty @@ -465,18 +499,20 @@ class LogEventsList extends ContextSource { * set to '' to unset offset * - wrap String Wrap the message in html (usually something like "
$1
"). * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS) + * - useRequestParams boolean Set true to use Pager-related parameters in the WebRequest * @return Integer Number of total log items (not limited by $lim) */ public static function showLogExtract( - &$out, $types=array(), $page='', $user='', $param = array() + &$out, $types = array(), $page = '', $user = '', $param = array() ) { $defaultParameters = array( 'lim' => 25, 'conds' => array(), 'showIfEmpty' => true, - 'msgKey' => array(''), + 'msgKey' => array( '' ), 'wrap' => "$1", - 'flags' => 0 + 'flags' => 0, + 'useRequestParams' => false, ); # The + operator appends elements of remaining keys from the right # handed array to the left handed, whereas duplicated keys are NOT overwritten. @@ -488,6 +524,7 @@ class LogEventsList extends ContextSource { $msgKey = $param['msgKey']; $wrap = $param['wrap']; $flags = $param['flags']; + $useRequestParams = $param['useRequestParams']; if ( !is_array( $msgKey ) ) { $msgKey = array( $msgKey ); } @@ -501,13 +538,22 @@ class LogEventsList extends ContextSource { # Insert list of top 50 (or top $lim) items $loglist = new LogEventsList( $context, null, $flags ); $pager = new LogPager( $loglist, $types, $user, $page, '', $conds ); + if ( !$useRequestParams ) { + # Reset vars that may have been taken from the request + $pager->mLimit = 50; + $pager->mDefaultLimit = 50; + $pager->mOffset = ""; + $pager->mIsBackwards = false; + } if ( isset( $param['offset'] ) ) { # Tell pager to ignore WebRequest offset $pager->setOffset( $param['offset'] ); } - if( $lim > 0 ) $pager->mLimit = $lim; + if ( $lim > 0 ) { + $pager->mLimit = $lim; + } $logBody = $pager->getBody(); $s = ''; - if( $logBody ) { + if ( $logBody ) { if ( $msgKey[0] ) { $s = '
'; @@ -520,28 +566,29 @@ class LogEventsList extends ContextSource { } } $s .= $loglist->beginLogEventsList() . - $logBody . - $loglist->endLogEventsList(); - } else { - if ( $showIfEmpty ) { - $s = Html::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ), - $context->msg( 'logempty' )->parse() ); - } + $logBody . + $loglist->endLogEventsList(); + } elseif ( $showIfEmpty ) { + $s = Html::rawElement( 'div', array( 'class' => 'mw-warning-logempty' ), + $context->msg( 'logempty' )->parse() ); } - if( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link + if ( $pager->getNumRows() > $pager->mLimit ) { # Show "Full log" link $urlParam = array(); if ( $page instanceof Title ) { $urlParam['page'] = $page->getPrefixedDBkey(); } elseif ( $page != '' ) { $urlParam['page'] = $page; } - if ( $user != '') + if ( $user != '' ) { $urlParam['user'] = $user; - if ( !is_array( $types ) ) # Make it an array, if it isn't + } + if ( !is_array( $types ) ) { # Make it an array, if it isn't $types = array( $types ); + } # If there is exactly one log type, we can link to Special:Log?type=foo - if ( count( $types ) == 1 ) + if ( count( $types ) == 1 ) { $urlParam['type'] = $types[0]; + } $s .= Linker::link( SpecialPage::getTitleFor( 'Log' ), $context->msg( 'log-fulllog' )->escaped(), @@ -560,7 +607,7 @@ class LogEventsList extends ContextSource { /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */ if ( wfRunHooks( 'LogEventsListShowLogExtract', array( &$s, $types, $page, $user, $param ) ) ) { // $out can be either an OutputPage object or a String-by-reference - if ( $out instanceof OutputPage ){ + if ( $out instanceof OutputPage ) { $out->addHTML( $s ); } else { $out = $s; @@ -575,24 +622,32 @@ class LogEventsList extends ContextSource { * * @param $db DatabaseBase * @param $audience string, public/user + * @param $user User object to check, or null to use $wgUser * @return Mixed: string or false */ - public static function getExcludeClause( $db, $audience = 'public' ) { - global $wgLogRestrictions, $wgUser; + public static function getExcludeClause( $db, $audience = 'public', User $user = null ) { + global $wgLogRestrictions; + + if ( $audience != 'public' && $user === null ) { + global $wgUser; + $user = $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( $audience == 'public' || !$wgUser->isAllowed($right) ) { - $safeType = $db->strencode( $logType ); - $hiddenLogs[] = $safeType; + foreach ( $wgLogRestrictions as $logType => $right ) { + if ( $audience == 'public' || !$user->isAllowed( $right ) ) { + $hiddenLogs[] = $logType; } } - if( count($hiddenLogs) == 1 ) { + if ( count( $hiddenLogs ) == 1 ) { return 'log_type != ' . $db->addQuotes( $hiddenLogs[0] ); - } elseif( $hiddenLogs ) { - return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')'; + } elseif ( $hiddenLogs ) { + return 'log_type NOT IN (' . $db->makeList( $hiddenLogs ) . ')'; } + return false; } - } +}