Fork me on GitHub
Subscribe 3

Ticket #222 (fixed enhancement)

Word required for censoring feature

  • Created: 2010-12-26 11:07:50
  • Reported by: adaur
  • Assigned to: Reines
  • Milestone: 1.4.4
  • Component: usability
  • Priority: low

Hi

When you want to censor a word, you have to enter a replacement word.

This should not be required, because it can be useful to replace a word by nothing; I deleted the replacement word in phpmyadmin and everything worked.

History

Reines 2010-12-28 23:25:05

  • Milestone set to 1.4.4.

Reines 2011-01-22 16:46:31

  • Owner set to Reines.

This should now allow an empty replacement to be entered.

adaur 2011-01-22 18:22:39

What about this?

//
// Replace censored words in $text
//
function censor_words($text)
{
    global $db, $lang_common;
    static $search_for, $replace_with;

    // If not already built in a previous call, build an array of censor words and their replacement text
    if (!isset($search_for))
    {
        $result = $db->query('SELECT search_for, replace_with FROM '.$db->prefix.'censoring') or error('Unable to fetch censor word list', __FILE__, __LINE__, $db->error());
        $num_words = $db->num_rows($result);

        $search_for = array();
        for ($i = 0; $i < $num_words; ++$i)
        {
            list($search_for[$i], $replace_with[$i]) = $db->fetch_row($result);
            $search_for[$i] = '/(?<=\W)('.str_replace('\*', '\w*?', preg_quote($search_for[$i], '/')).')(?=\W)/i';
        }
    }

    if (!empty($search_for))
        $text = substr(preg_replace($search_for, $replace_with, ' '.$text.' '), 1, -1);

    if (!empty($text))
        return $text;
    else
        message($lang_common['Bad request']);
}

Reines 2011-01-23 11:47:15

  • Status changed from open to fixed.

Giving a bad request error is far too generic - plus censoring is done during viewing of a post, not during creation of a post, so that would be giving the bad request error to people viewing the post, not the person trying to make it.

I don't really see an easy solution here - if an admin is to make a censor remove a word, there could well already be posts consisting of just that which would be turned to empty posts. We obviously don't want to delete them, but then blocking future such posts would be inconsistent.

I'm tempted to leave it how it is now - if an admin chooses to have a blank replacement then that's their decision.

Franz 2011-01-23 14:45:49

I saw that in your commit you suggested censoring first, and then check for empty posts. Did you at least do that part?

Reines 2011-01-23 14:50:13

No. We could do that, but then we should also probably be checking the minimum length, all caps, and so on against the censored copy too - which we don't do at the moment, even though the existing censor feature can easily make a post end up shorter than the minimum length for example.

We can do this if you think it is important, but I would argue it is a separate issue, considering the issue is already there for minimum length etc.

Franz 2011-01-23 15:05:41

I think it's an issue then. I suppose we could just move up the censoring itself, right?

Reines 2011-01-23 15:18:10

Possibly, though that then means it isn't possible to later un-censor a word, or go back to the original in any way.

Reines 2011-01-23 18:05:02

  • Status changed from fixed to open.

Reines 2011-01-26 11:22:52

  • Status changed from open to fixed.