if ( !$tag ) {
continue;
}
- $description = self::tagDescription( $tag );
+ $description = self::tagDescription( $tag, $context );
if ( $description === false ) {
continue;
}
* we consider the tag hidden, and return false.
*
* @param string $tag Tag
+ * @param IContextSource $context
* @return string|bool Tag description or false if tag is to be hidden.
* @since 1.25 Returns false if tag is to be hidden.
*/
- public static function tagDescription( $tag ) {
- $msg = wfMessage( "tag-$tag" );
+ public static function tagDescription( $tag, IContextSource $context ) {
+ $msg = $context->msg( "tag-$tag" );
if ( !$msg->exists() ) {
// No such message, so return the HTML-escaped tag name.
return htmlspecialchars( $tag );
* @param int|null $rev_id The rev_id of the change to add the tags to
* @param int|null $log_id The log_id of the change to add the tags to
* @param string $params Params to put in the ct_params field of table 'change_tag'
+ * @param RecentChange|null $rc Recent change, in case the tagging accompanies the action
+ * (this should normally be the case)
*
* @throws MWException
* @return bool False if no changes are made, otherwise true
*/
public static function addTags( $tags, $rc_id = null, $rev_id = null,
- $log_id = null, $params = null
+ $log_id = null, $params = null, RecentChange $rc = null
) {
- $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params );
+ $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params, $rc );
return (bool)$result[0];
}
* Pass a variable whose value is null if the log_id is not relevant or unknown.
* @param string $params Params to put in the ct_params field of table
* 'change_tag' when adding tags
+ * @param RecentChange|null $rc Recent change being tagged, in case the tagging accompanies
+ * the action
+ * @param User|null $user Tagging user, in case the tagging is subsequent to the tagged action
*
* @throws MWException When $rc_id, $rev_id and $log_id are all null
* @return array Index 0 is an array of tags actually added, index 1 is an
*
* @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, RecentChange $rc = null,
+ User $user = null
) {
$tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags...
}
self::purgeTagUsageCache();
+
+ Hooks::run( 'ChangeTagsAfterUpdateTags', [ $tagsToAdd, $tagsToRemove, $prevTags,
+ $rc_id, $rev_id, $log_id, $params, $rc, $user ] );
+
return [ $tagsToAdd, $tagsToRemove, $prevTags ];
}
if ( !$user->isAllowed( 'applychangetags' ) ) {
return Status::newFatal( 'tags-apply-no-permission' );
} elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-apply-blocked' );
+ return Status::newFatal( 'tags-apply-blocked', $user->getName() );
}
}
if ( !$user->isAllowed( 'changetags' ) ) {
return Status::newFatal( 'tags-update-no-permission' );
} elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-update-blocked' );
+ return Status::newFatal( 'tags-update-blocked', $user->getName() );
}
}
// do it!
list( $tagsAdded, $tagsRemoved, $initialTags ) = self::updateTags( $tagsToAdd,
- $tagsToRemove, $rc_id, $rev_id, $log_id, $params );
+ $tagsToRemove, $rc_id, $rev_id, $log_id, $params, null, $user );
if ( !$tagsAdded && !$tagsRemoved ) {
// no-op, don't log it
return Status::newGood( (object)[
* Handles selecting tags, and filtering.
* Needs $tables to be set up properly, so we can figure out which join conditions to use.
*
- * @param string|array $tables Table names, see DatabaseBase::select
- * @param string|array $fields Fields used in query, see DatabaseBase::select
- * @param string|array $conds Conditions used in query, see DatabaseBase::select
- * @param array $join_conds Join conditions, see DatabaseBase::select
+ * @param string|array $tables Table names, see Database::select
+ * @param string|array $fields Fields used in query, see Database::select
+ * @param string|array $conds Conditions used in query, see Database::select
+ * @param array $join_conds Join conditions, see Database::select
* @param array $options Options, see Database::select
* @param bool|string $filter_tag Tag to select on
*
* Build a text box to select a change tag
*
* @param string $selected Tag to select by default
- * @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: an array of (label, selector).
- * - if $fullForm is true: HTML of entire form built around the selector.
+ * @param IContextSource|null $context
+ * @note Even though it takes null as a valid argument, an IContextSource is preferred
+ * in a new code, as the null value can change in the future
+ * @return array an array of (label, selector)
*/
- public static function buildTagFilterSelector( $selected = '',
- $fullForm = false, Title $title = null, $ooui = false
+ public static function buildTagFilterSelector(
+ $selected = '', $ooui = false, IContextSource $context = null
) {
- global $wgUseTagFilter;
+ if ( !$context ) {
+ $context = RequestContext::getMain();
+ }
- if ( !$wgUseTagFilter || !count( self::listDefinedTags() ) ) {
- return $fullForm ? '' : [];
+ $config = $context->getConfig();
+ if ( !$config->get( 'UseTagFilter' ) || !count( self::listDefinedTags() ) ) {
+ return [];
}
$data = [
Html::rawElement(
'label',
[ 'for' => 'tagfilter' ],
- wfMessage( 'tag-filter' )->parse()
+ $context->msg( 'tag-filter' )->parse()
)
];
);
}
- if ( !$fullForm ) {
- return $data;
- }
-
- $html = implode( ' ', $data );
- $html .= "\n" .
- Xml::element(
- 'input',
- [ 'type' => 'submit', 'value' => wfMessage( 'tag-filter-submit' )->text() ]
- );
- $html .= "\n" . Html::hidden( 'title', $title->getPrefixedText() );
- $html = Xml::tags(
- 'form',
- [ 'action' => $title->getLocalURL(), 'class' => 'mw-tagfilter-form', 'method' => 'get' ],
- $html
- );
-
- return $html;
+ return $data;
}
/**
if ( !$user->isAllowed( 'managechangetags' ) ) {
return Status::newFatal( 'tags-manage-no-permission' );
} elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-manage-blocked' );
+ return Status::newFatal( 'tags-manage-blocked', $user->getName() );
}
}
if ( !$user->isAllowed( 'managechangetags' ) ) {
return Status::newFatal( 'tags-manage-no-permission' );
} elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-manage-blocked' );
+ return Status::newFatal( 'tags-manage-blocked', $user->getName() );
}
}
if ( !$user->isAllowed( 'managechangetags' ) ) {
return Status::newFatal( 'tags-manage-no-permission' );
} elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-manage-blocked' );
+ return Status::newFatal( 'tags-manage-blocked', $user->getName() );
}
}
if ( !$user->isAllowed( 'deletechangetags' ) ) {
return Status::newFatal( 'tags-delete-no-permission' );
} elseif ( $user->isBlocked() ) {
- return Status::newFatal( 'tags-manage-blocked' );
+ return Status::newFatal( 'tags-manage-blocked', $user->getName() );
}
}