X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fchangetags%2FChangeTags.php;h=12f738fedbba177e3be48be9cc5a03ed1a0cac54;hb=8b2139e1a773ab4be16a58c8cf2edb1c86b4b798;hp=95f48161d9950eca01d1d010575c173f68e4381a;hpb=d2344425f90dd2dc62cd7dc7704c149f4e0946c8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 95f48161d9..5aac495641 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -153,8 +153,10 @@ class ChangeTags { * * @since 1.25 */ - public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null, - &$rev_id = null, &$log_id = null, $params = null ) { + public static function updateTags( + $tagsToAdd, $tagsToRemove, + &$rc_id = null, &$rev_id = null, &$log_id = null, $params = null + ) { $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags... $tagsToRemove = array_filter( (array)$tagsToRemove ); @@ -169,18 +171,28 @@ class ChangeTags { // Might as well look for rcids and so on. if ( !$rc_id ) { // Info might be out of date, somewhat fractionally, on slave. + // LogEntry/LogPage and WikiPage match rev/log/rc timestamps, + // so use that relation to avoid full table scans. if ( $log_id ) { $rc_id = $dbw->selectField( - 'recentchanges', + array( 'logging', 'recentchanges' ), 'rc_id', - array( 'rc_logid' => $log_id ), + array( + 'log_id' => $log_id, + 'rc_timestamp = log_timestamp', + 'rc_logid = log_id' + ), __METHOD__ ); } elseif ( $rev_id ) { $rc_id = $dbw->selectField( - 'recentchanges', + array( 'revision', 'recentchanges' ), 'rc_id', - array( 'rc_this_oldid' => $rev_id ), + array( + 'rev_id' => $rev_id, + 'rc_timestamp = rev_timestamp', + 'rc_this_oldid = rev_id' + ), __METHOD__ ); } @@ -346,8 +358,12 @@ class ChangeTags { public static function canAddTagsAccompanyingChange( array $tags, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'applychangetags' ) ) { - return Status::newFatal( 'tags-apply-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'applychangetags' ) ) { + return Status::newFatal( 'tags-apply-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-apply-blocked' ); + } } // to be applied, a tag has to be explicitly defined @@ -413,8 +429,12 @@ class ChangeTags { public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'changetags' ) ) { - return Status::newFatal( 'tags-update-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'changetags' ) ) { + return Status::newFatal( 'tags-update-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-update-blocked' ); + } } if ( $tagsToAdd ) { @@ -611,17 +631,16 @@ class ChangeTags { * Build a text box to select a change tag * * @param string $selected Tag to select by default - * @param bool $fullForm - * - if false, then it returns an array of (label, form). - * - if true, it returns an entire form around the selector. - * @param Title $title Title object to send the form to. - * Used when, and only when $fullForm is true. + * @param bool $fullForm Affects return value, see below + * @param Title $title Title object to send the form to. Used only if $fullForm is true. + * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field + * You need to call OutputPage::enableOOUI() yourself. * @return string|array - * - if $fullForm is false: Array with - * - if $fullForm is true: String, html fragment + * - if $fullForm is false: an array of (label, selector). + * - if $fullForm is true: HTML of entire form built around the selector. */ public static function buildTagFilterSelector( $selected = '', - $fullForm = false, Title $title = null + $fullForm = false, Title $title = null, $ooui = false ) { global $wgUseTagFilter; @@ -634,14 +653,24 @@ class ChangeTags { 'label', array( 'for' => 'tagfilter' ), wfMessage( 'tag-filter' )->parse() - ), - Xml::input( + ) + ); + + if ( $ooui ) { + $data[] = new OOUI\TextInputWidget( array( + 'id' => 'tagfilter', + 'name' => 'tagfilter', + 'value' => $selected, + 'classes' => 'mw-tagfilter-input', + ) ); + } else { + $data[] = Xml::input( 'tagfilter', 20, $selected, array( 'class' => 'mw-tagfilter-input mw-ui-input mw-ui-input-inline', 'id' => 'tagfilter' ) - ) - ); + ); + } if ( !$fullForm ) { return $data; @@ -745,8 +774,12 @@ class ChangeTags { * @since 1.25 */ public static function canActivateTag( $tag, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } // defined tags cannot be activated (a defined tag is either extension- @@ -809,8 +842,12 @@ class ChangeTags { * @since 1.25 */ public static function canDeactivateTag( $tag, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } // only explicitly-defined tags can be deactivated @@ -864,8 +901,12 @@ class ChangeTags { * @since 1.25 */ public static function canCreateTag( $tag, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } // no empty tags @@ -993,8 +1034,12 @@ class ChangeTags { public static function canDeleteTag( $tag, User $user = null ) { $tagUsage = self::tagUsageStatistics(); - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self::listDefinedTags() ) ) { @@ -1069,15 +1114,20 @@ class ChangeTags { public static function listExtensionActivatedTags() { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'active-tags' ), - function() { + 300, + function ( $oldValue, &$ttl, array &$setOpts ) { + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + // Ask extensions which tags they consider active $extensionActive = array(); Hooks::run( 'ChangeTagsListActive', array( &$extensionActive ) ); return $extensionActive; }, - 300, - array( wfMemcKey( 'active-tags' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'active-tags' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); } @@ -1109,16 +1159,21 @@ class ChangeTags { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'valid-tags-db' ), - function() use ( $fname ) { + 300, + function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { $dbr = wfGetDB( DB_SLAVE ); - $tags = $dbr->selectFieldValues( - 'valid_tag', 'vt_tag', array(), $fname ); + + $setOpts += Database::getCacheSetOptions( $dbr ); + + $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', array(), $fname ); return array_filter( array_unique( $tags ) ); }, - 300, - array( wfMemcKey( 'valid-tags-db' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'valid-tags-db' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); } @@ -1134,14 +1189,19 @@ class ChangeTags { public static function listExtensionDefinedTags() { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'valid-tags-hook' ), - function() { + 300, + function ( $oldValue, &$ttl, array &$setOpts ) { + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + $tags = array(); Hooks::run( 'ListDefinedTags', array( &$tags ) ); return array_filter( array_unique( $tags ) ); }, - 300, - array( wfMemcKey( 'valid-tags-hook' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'valid-tags-hook' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); } @@ -1181,20 +1241,15 @@ class ChangeTags { * @return array Array of string => int */ public static function tagUsageStatistics() { - static $cachedStats = null; - - // Process cache to avoid I/O and repeated regens during holdoff - if ( $cachedStats !== null ) { - return $cachedStats; - } - $fname = __METHOD__; - $cachedStats = ObjectCache::getMainWANInstance()->getWithSetCallback( + return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'change-tag-statistics' ), - function() use ( $fname ) { - $out = array(); - + 300, + function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { $dbr = wfGetDB( DB_SLAVE, 'vslow' ); + + $setOpts += Database::getCacheSetOptions( $dbr ); + $res = $dbr->select( 'change_tag', array( 'ct_tag', 'hitcount' => 'count(*)' ), @@ -1203,18 +1258,19 @@ class ChangeTags { array( 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ) ); + $out = array(); foreach ( $res as $row ) { $out[$row->ct_tag] = $row->hitcount; } return $out; }, - 300, - array( wfMemcKey( 'change-tag-statistics' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'change-tag-statistics' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); - - return $cachedStats; } /**