X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Flogging%2FLogEventsList.php;h=03d527667e7c319f8bd043b45a09930a0aa047f0;hb=64308ea1074fc26f19f0ec696b7e496bfe19bf53;hp=6016641c4314288147f1223ae409f6a183610c5a;hpb=4c5214f27f722b9b3c54b68a7e9d72a60915e053;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/logging/LogEventsList.php b/includes/logging/LogEventsList.php index 6016641c43..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,27 +157,29 @@ 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( - $this->getDisplayTitle(), + $this->getTitle(), $messages[$hideVal], array(), $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 "