public MediaWiki endUserGroupModification(final MediaWiki.UserGroupsToken userRightsToken, final Collection<String> add, final Collection<String> remove, final String reason) throws IOException, MediaWiki.MediaWikiException {
		final Map<String, String> getParams = paramValuesToMap("action", "userrights", "format", "xml");
		final Map<String, String> postParams = paramValuesToMap("user", userRightsToken.getUserName(), "token", userRightsToken.getTokenText(), "reason", reason);
		{
			final StringBuilder value = new StringBuilder();
			for (final String group : add) {
				if (value.length() > 0) {
					value.append('|');
				}
				value.append(group);
			}
			if (value.length() > 0) {
				postParams.put("add", value.toString());
			}
			value.setLength(0);
			for (final String group : remove) {
				if (value.length() > 0) {
					value.append('|');
				}
				value.append(group);
			}
			if (value.length() > 0) {
				postParams.put("remove", value.toString());
			}
		}

		final String url = createApiGetUrl(getParams);

		networkLock.lock();
		try {
			final InputStream in = post(url, postParams);
			final Document xml = parse(in);
			checkError(xml);

			final NodeList userrightsTags = xml.getElementsByTagName("userrights");

			if (userrightsTags.getLength() > 0)
				return this;
			else
				throw new MediaWiki.ResponseFormatException("expected <userrights> tag not present");
		} finally {
			networkLock.unlock();
		}
	}