From c5685a7947b4196b23cb52de09613c7655b7afc5 Mon Sep 17 00:00:00 2001 From: "justdave%syndicomm.com" Date: Wed, 15 Jan 2003 06:48:17 +0000 Subject: [PATCH] Bug 184309: Adds an optional disabled state to quips, which allows quips to be moderated if the admin so chooses. Patch by Tobias Burnus r=joel, a=justdave git-svn-id: svn://10.0.0.236/trunk@136358 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/bugzilla/buglist.cgi | 2 +- mozilla/webtools/bugzilla/checksetup.pl | 4 + mozilla/webtools/bugzilla/defparams.pl | 9 +- mozilla/webtools/bugzilla/quips.cgi | 44 ++++++++- .../template/en/default/list/quips.html.tmpl | 91 ++++++++++++++----- 5 files changed, 115 insertions(+), 35 deletions(-) diff --git a/mozilla/webtools/bugzilla/buglist.cgi b/mozilla/webtools/bugzilla/buglist.cgi index 10e659a1f27..3c693fa69da 100755 --- a/mozilla/webtools/bugzilla/buglist.cgi +++ b/mozilla/webtools/bugzilla/buglist.cgi @@ -191,7 +191,7 @@ sub GetQuip { my $quip; - SendSQL("SELECT quip FROM quips ORDER BY RAND() LIMIT 1"); + SendSQL("SELECT quip FROM quips WHERE approved = 1 ORDER BY RAND() LIMIT 1"); if (MoreSQLData()) { ($quip) = FetchSQLData(); diff --git a/mozilla/webtools/bugzilla/checksetup.pl b/mozilla/webtools/bugzilla/checksetup.pl index e4d610b53fd..59ebb195567 100755 --- a/mozilla/webtools/bugzilla/checksetup.pl +++ b/mozilla/webtools/bugzilla/checksetup.pl @@ -3844,6 +3844,10 @@ if ($sth->rows == 0) { } } +# 2003-01-11, burnus@net-b.de, bug 184309 +# Support for quips approval +AddField('quips', 'approved', 'tinyint(1) NOT NULL DEFAULT 1'); + # 2002-11-XX Bug 180870 - remove manual shadowdb replication code if (TableExists('shadowlog')) { print "Removing shadowlog table\n"; diff --git a/mozilla/webtools/bugzilla/defparams.pl b/mozilla/webtools/bugzilla/defparams.pl index 0d6c2a3c7c7..922a9dfe2eb 100644 --- a/mozilla/webtools/bugzilla/defparams.pl +++ b/mozilla/webtools/bugzilla/defparams.pl @@ -226,11 +226,12 @@ sub check_netmask { name => 'enablequips', desc => 'Controls the appearance of quips at the top of buglists.', + 'the list.
  • approved - quips can be entered, but need ' . + 'be approved before shown
  • frozen - Bugzilla will display ' . + 'a quip but not permit new additions.
  • off - Bugzilla ' . + 'will not display quips.
  • ', type => 's', - choices => ['on','frozen','off'], + choices => ['on', 'approved', 'frozen', 'off'], default => 'on', checker => \&check_multi }, diff --git a/mozilla/webtools/bugzilla/quips.cgi b/mozilla/webtools/bugzilla/quips.cgi index d152234ac0b..51e9fc789e9 100755 --- a/mozilla/webtools/bugzilla/quips.cgi +++ b/mozilla/webtools/bugzilla/quips.cgi @@ -21,6 +21,7 @@ # Contributor(s): Owen Taylor # Gervase Markham # David Fallon +# Tobias Burnus use strict; @@ -46,18 +47,20 @@ my $action = $::FORM{'action'} || ""; if ($action eq "show") { # Read in the entire quip list - SendSQL("SELECT quipid,userid,quip FROM quips"); + SendSQL("SELECT quipid, userid, quip, approved FROM quips"); my $quips; my @quipids; while (MoreSQLData()) { - my ($quipid, $userid, $quip) = FetchSQLData(); - $quips->{$quipid} = {'userid' => $userid, 'quip' => $quip}; + my ($quipid, $userid, $quip, $approved) = FetchSQLData(); + $quips->{$quipid} = {'userid' => $userid, 'quip' => $quip, + 'approved' => $approved}; push(@quipids, $quipid); } my $users; foreach my $quipid (@quipids) { + my $userid = $quips->{$quipid}{'userid'}; if (not defined $users->{$userid}) { SendSQL("SELECT login_name FROM profiles WHERE userid = $userid"); $users->{$userid} = FetchSQLData(); @@ -70,18 +73,49 @@ if ($action eq "show") { } if ($action eq "add") { - (Param('enablequips') eq "on") || ThrowUserError("no_new_quips"); + (Param('enablequips') eq "on" or Param('enablequips') eq "approved") + || ThrowUserError("no_new_quips"); # Add the quip + my $approved = (Param('enablequips') eq "on") ? '1' : '0'; + $approved = 1 if(UserInGroup('admin')); my $comment = $::FORM{"quip"}; $comment || ThrowUserError("need_quip"); $comment !~ m/{'added_quip'} = $comment; } +if ($action eq 'approve') { + # Read in the entire quip list + SendSQL("SELECT quipid, approved FROM quips"); + + my %quips; + while (MoreSQLData()) { + my ($quipid, $approved) = FetchSQLData(); + $quips{$quipid} = $approved; + } + + my @approved; + my @unapproved; + foreach my $quipid (keys %quips) { + my $form = ($::FORM{'quipid_'.$quipid}) ? 1 : 0; + if($quips{$quipid} ne $form) { + if($form) { push(@approved, $quipid); } + else { push(@unapproved, $quipid); } + } + } + SendSQL("UPDATE quips SET approved = 1 WHERE quipid IN (" . + join(",", @approved) . ")") if($#approved > -1); + SendSQL("UPDATE quips SET approved = 0 WHERE quipid IN (" . + join(",", @unapproved) . ")") if($#unapproved > -1); + $vars->{ 'approved' } = \@approved; + $vars->{ 'unapproved' } = \@unapproved; +} + if ($action eq "delete") { if (!UserInGroup('admin')) { ThrowUserError("quips_edit_denied"); diff --git a/mozilla/webtools/bugzilla/template/en/default/list/quips.html.tmpl b/mozilla/webtools/bugzilla/template/en/default/list/quips.html.tmpl index c178c5838d9..4a6ef1ad50f 100644 --- a/mozilla/webtools/bugzilla/template/en/default/list/quips.html.tmpl +++ b/mozilla/webtools/bugzilla/template/en/default/list/quips.html.tmpl @@ -35,6 +35,9 @@

    Your quip '[% added_quip FILTER html %]' has been added. + [% IF Param("enablequips") == "approved" AND !UserInGroup('admin') %] + It will be used as soon as it gets approved. + [% END %]

    [% END %] @@ -47,10 +50,17 @@

    [% END %] +[% IF approved or unapproved %] +

    [% approved.size %] quips approved and [% unapproved.size %] quips unapproved

    +[% END %] +

    Bugzilla will pick a random quip for the headline on each bug list, and you can extend the quip list. Type in something clever or funny or boring (but not obscene or offensive, please) and bonk on the button. + [% IF Param("enablequips") == "approved" AND !UserInGroup('admin') %] + Note that your quip has to be approved before it is used. + [% END %]

    @@ -67,35 +77,66 @@ Existing quips:
      - [% FOREACH quip = quips %] -
    • [% quip FILTER html %]
    • + [% FOREACH quipid = quipids %] + [% NEXT IF NOT quips.$quipid.approved %] +
    • [% quips.$quipid.quip FILTER html %]
    • [% END %]
    [% ELSE %]

    Edit existing quips:

    - - - - - - - [% FOREACH quipid = quipids %] - - - - - - [% END %] - -
    QuipAuthorAction
    [% quips.$quipid.quip FILTER html %] - [% userid = quips.$quipid.userid %] - [% users.$userid FILTER html %] - [% "Unknown" IF NOT users.$userid %] - - - Delete - -
    +

    + Note: Only approved quips will be shown. + If enablequips is set to on, entered quips are automatically + approved. +

    + + + + + + + + + + [% FOREACH quipid = quipids %] + + + + + + + [% END %] + +
    QuipAuthorActionApproved
    [% quips.$quipid.quip FILTER html %] + [% userid = quips.$quipid.userid %] + [% users.$userid FILTER html %] + [% "Unknown" IF NOT users.$userid %] + + + Delete + + + +
    + + + +

    [% END %] [% ELSE %]