[dw-free] Add basic flagging to the translation system
[commit: http://hg.dwscoalition.org/dw-free/rev/84e8f72def77]
http://bugs.dwscoalition.org/show_bug.cgi?id=121
Add flagging for proofed and updated to the translation interface.
Patch by
pauamma.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=121
Add flagging for proofed and updated to the translation interface.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/update-db-general.pl
- htdocs/translate/edit.bml
- htdocs/translate/editpage.bml
- htdocs/translate/search.bml
- htdocs/translate/searchform.bml
-------------------------------------------------------------------------------- diff -r fd24f588f9b0 -r 84e8f72def77 bin/upgrading/update-db-general.pl --- a/bin/upgrading/update-db-general.pl Sat Mar 14 19:03:25 2009 +0000 +++ b/bin/upgrading/update-db-general.pl Sun Mar 15 05:05:18 2009 +0000 @@ -1285,6 +1285,10 @@ CREATE TABLE ml_items ( PRIMARY KEY (dmid, itid), itcode VARCHAR(80) NOT NULL, UNIQUE (dmid, itcode), + proofed TINYINT NOT NULL DEFAULT 0, -- boolean, really + INDEX (proofed), + updated TINYINT NOT NULL DEFAULT 0, -- boolean, really + INDEX (updated), notes MEDIUMTEXT ) TYPE=MYISAM EOC @@ -3967,6 +3971,18 @@ register_alter(sub { "ALTER TABLE poll2 MODIFY COLUMN whoview ENUM('all','trusted','ofentry','none') NOT NULL default 'all'" ); } + unless ( column_type( 'ml_items', 'proofed' ) ) { + do_alter( 'ml_items', + "ALTER TABLE ml_items ADD COLUMN proofed TINYINT NOT NULL DEFAULT 0 AFTER itcode" ); + do_alter( 'ml_items', + "ALTER TABLE ml_items ADD INDEX (proofed)" ); + do_alter( 'ml_items', + "ALTER TABLE ml_items ADD COLUMN updated TINYINT NOT NULL DEFAULT 0 AFTER proofed" ); + do_alter( 'ml_items', + "ALTER TABLE ml_items ADD INDEX (updated)" ); + } + + }); diff -r fd24f588f9b0 -r 84e8f72def77 htdocs/translate/edit.bml --- a/htdocs/translate/edit.bml Sat Mar 14 19:03:25 2009 +0000 +++ b/htdocs/translate/edit.bml Sun Mar 15 05:05:18 2009 +0000 @@ -4,7 +4,7 @@ </head> <frameset cols="200,*"> - <frameset rows="200,*"> + <frameset rows="230,*"> <frame name="search" src="searchform.bml?lang=<?_code return $FORM{'lang'}; _code?>"> <frame name="res" src="search.bml?lang=<?_code return $FORM{'lang'}; _code?>&stale=1%2B&search=sev"> </frameset> diff -r fd24f588f9b0 -r 84e8f72def77 htdocs/translate/editpage.bml --- a/htdocs/translate/editpage.bml Sat Mar 14 19:03:25 2009 +0000 +++ b/htdocs/translate/editpage.bml Sun Mar 15 05:05:18 2009 +0000 @@ -30,8 +30,11 @@ my $can_delete = LJ::check_priv($remote, "translate", "[itemdelete]"); my $can_rename = LJ::check_priv($remote, "translate", "[itemrename]"); + # Extra checkboxes for default language and root language (DW: en_DW and en) + my $extra_checkboxes = $l->{'lncode'} eq $LJ::DEFAULT_LANG || !defined $lp; + my $mode = { - '' => 'view', + '' => 'view', 'save' => 'save', }->{$FORM{'mode'}}; return "bogus mode" unless $mode; @@ -41,7 +44,7 @@ if ($mode eq "view") { my @load; - foreach (split /,/, $FORM{'items'}) + foreach (split /,/, $FORM{'items'}) { next unless /^(\d+):(\d+)$/; last if @load >= $MAX_EDIT; @@ -49,7 +52,7 @@ } return "Nothing to show." unless @load; - + $ret .= "<form method='post' action='editpage.bml'>"; $ret .= LJ::html_hidden('lang', $lang, 'mode', 'save'); @@ -57,12 +60,12 @@ # load item info my %ml_items; my $itwhere = join(" OR ", map { "(dmid=$_->{'dmid'} AND itid=$_->{'itid'})" } @load); - $sth = $dbr->prepare("SELECT dmid, itid, itcode, notes FROM ml_items WHERE $itwhere"); + $sth = $dbr->prepare("SELECT dmid, itid, itcode, proofed, updated, notes FROM ml_items WHERE $itwhere"); $sth->execute; - while (my ($dmid, $itid, $itcode, $notes) = $sth->fetchrow_array) { - $ml_items{"$dmid-$itid"} = { 'itcode' => $itcode, 'notes' => $notes }; + while (my ($dmid, $itid, $itcode, $proofed, $updated, $notes) = $sth->fetchrow_array) { + $ml_items{"$dmid-$itid"} = { 'itcode' => $itcode, 'proofed' => $proofed, 'updated' => $updated, 'notes' => $notes }; } - + # getting latest mappings for this lang and parent my %ml_text; my %ml_latest; @@ -77,10 +80,10 @@ # load text $sth = $dbr->prepare("SELECT dmid, txtid, lnid, itid, text FROM ml_text ". - "WHERE " . join(" OR ", - map { "(dmid=$_->[0] AND txtid=$_->[1])" } + "WHERE " . join(" OR ", + map { "(dmid=$_->[0] AND txtid=$_->[1])" } map { [ split(/-/, $_) ] } keys %ml_text)); - $sth->execute; + $sth->execute; while ($_ = $sth->fetchrow_hashref) { $ml_text{"$_->{'dmid'}-$_->{'txtid'}"} = $_; } @@ -91,7 +94,7 @@ # show all editing items my $ict = 0; - foreach my $i (@load) + foreach my $i (@load) { my ($dmid, $itid) = ($i->{'dmid'}, $i->{'itid'}); my $ituq = "$dmid-$itid"; @@ -110,7 +113,7 @@ "oldtxtid_$ict", $lat->{'txtid'}, "oldptxtid_$ict", $plat ? $plat->{'txtid'} : 0, ); - + # top bar $ret .= "<table bgcolor='#c0c0c0' width='100%'><tr><td><b>Code:</b> "; if ($dmid != 1) { @@ -154,7 +157,7 @@ # if wrong language, why populate it with stuff they'll just have to delete? $curtext = ""; } - + $ret .= "<dt><b>$l->{'lnname'}</b>:</b></dt><dd>"; my $disabled = "disabled='disabled'"; if ($lat->{'staleness'} >= 3) { @@ -166,7 +169,10 @@ "sev_$ict", "2", ); } else { - $ret .= "<input name='ed_$ict' type='checkbox' value='1' id='ed_$ict' onClick='a=document.getElementById(\"newtext_$ict\"); a.disabled=!this.checked; if (this.checked) a.focus();' /><label for='ed_$ict'>Edit Text</label>"; + my $js = "a=document.getElementById(\"newtext_$ict\"); a.disabled=!this.checked; if (this.checked) a.focus();"; + $js .= "a=document.getElementById(\"pr_$ict\"); a.disabled=!this.checked; a=document.getElementById(\"up_$ict\"); a.disabled=!this.checked;" + if $extra_checkboxes; + $ret .= "<input name='ed_$ict' type='checkbox' value='1' id='ed_$ict' onClick='$js' /><label for='ed_$ict'>Edit Text</label>"; if ($l->{'children'} && @{$l->{'children'}}) { $ret .= " Severity: "; $ret .= LJ::html_select({ 'name' => "sev_$ict", "selected" => 1 }, @@ -174,8 +180,23 @@ 1 => "Minor (notify translators)", 2 => "Major (require translation updates)"); } + $ret .= "<br />" unless $extra_checkboxes; + } + + if ( $extra_checkboxes ) { + $ret .= " "; + $ret .= LJ::html_check( { type => 'checkbox', label => 'Proofed', + selected => $it->{proofed}, value => 1, + name => "pr_$ict", id => "pr_$ict", + disabled => $disabled eq '' ? 0 : 1 } ); + $ret .= " "; + $ret .= LJ::html_check( { type => 'checkbox', label => 'Updated', + selected => $it->{updated}, value => 1, + name => "up_$ict", id => "up_$ict", + disabled => $disabled eq '' ? 0 : 1 } ); $ret .= "<br />"; } + if ($use_textarea) { $ret .= "<textarea name='newtext_$ict' id='newtext_$ict' $disabled wrap='soft' rows='10' cols='60'>$curtext</textarea>"; } else { @@ -193,7 +214,7 @@ $ret .= "No items to show. (since been deleted, perhaps?)"; } $ret .= "</form>"; - + return $ret; } @@ -213,21 +234,22 @@ push @errors, "Nothing saved."; $num = 0; } - + my $saved = 0; # do any saves? for (my $i=1; $i<=$num; $i++) { next unless $FORM{"ed_$i"}; - my ($dom, $itid, $oldtxtid, $oldptxtid, $sev) = - map { int($FORM{"${_}_$i"}+0) } qw(dom itid oldtxtid oldptxtid sev); + my ($dom, $itid, $oldtxtid, $oldptxtid, $sev, $proofed, $updated) = + map { int($FORM{"${_}_$i"}+0) } + qw(dom itid oldtxtid oldptxtid sev pr up); my $itcode = $dbr->selectrow_array("SELECT itcode FROM ml_items WHERE dmid=$dom AND itid=$itid"); unless (defined $itcode) { push @errors, "Bogus dmid/itid: $dom/$itid"; next; } - + $dbh ||= LJ::get_db_writer(); my $lat = $dbh->selectrow_hashref("SELECT * FROM ml_latest WHERE lnid=$l->{'lnid'} AND dmid=$dom AND itid=$itid"); unless ($lat) { @@ -264,7 +286,7 @@ } next; } - + # did anything even change, though? my $oldtext = $dbr->selectrow_array("SELECT text FROM ml_text WHERE dmid=$dom AND txtid=$lat->{'txtid'}"); if ($oldtext eq $text && $lat->{'staleness'} == 2) { @@ -274,9 +296,9 @@ # keep old txtid if text didn't change. my $opts = {}; - if ($oldtext eq $text) { - $opts->{'txtid'} = $lat->{'txtid'}; - $text = undef; + if ($oldtext eq $text) { + $opts->{'txtid'} = $lat->{'txtid'}; + $text = undef; $sev = 0; } @@ -292,12 +314,28 @@ $opts->{'userid'} = $remote->{'userid'}; my ($res, $msg) = LJ::Lang::web_set_text($dom, $l->{'lncode'}, $itcode, $text, $opts); - unless ($res) { - push @errors, $msg; - } else { + if ($res) { push @info, "OK: $itcode"; $saved = 1; + + if ( $extra_checkboxes ) { + # Not gonna bother to refactor to LJ::Lang as the whole + # translation system will get thrown away and redone later. + # FIXME: make sure my words don't come back to haunt me. + $dbh->do( "UPDATE ml_items SET proofed = ?, updated = ? " . + "WHERE dmid = ? AND itid = ?", undef, $proofed ? 1 : 0, + $updated ? 1 : 0, $dom, $itid ); + + if ( $dbh->err ) { + push @errors, $dbh->errstr; + } else { + push @info, "OK: $itcode (flags)"; + } + } + } else { + push @errors, $msg; } + push @info, LJ::run_hook('trans_editpage_bml_postsave', $opts) if LJ::are_hooks('trans_editpage_bml_postsave'); } diff -r fd24f588f9b0 -r 84e8f72def77 htdocs/translate/search.bml --- a/htdocs/translate/search.bml Sat Mar 14 19:03:25 2009 +0000 +++ b/htdocs/translate/search.bml Sun Mar 15 05:05:18 2009 +0000 @@ -6,10 +6,10 @@ my $dbr = LJ::get_db_reader(); my $sth; - + my $sql; - if ($FORM{'search'} eq 'sev') + if ($FORM{'search'} eq 'sev') { my $what = ">= 1"; if ($FORM{'stale'} =~ /^(\d+)(\+?)$/) { @@ -17,8 +17,8 @@ } $sql = "SELECT i.dmid, i.itid, i.itcode FROM ml_items i, ml_latest l WHERE l.lnid=$l->{'lnid'} AND l.staleness $what AND l.dmid=i.dmid AND l.itid=i.itid ORDER BY i.dmid, i.itcode"; } - - if ($FORM{'search'} eq 'txt') + + if ($FORM{'search'} eq 'txt') { my $remote = LJ::get_remote(); return "This search type is restricted to $l->{'lnname'} translators." unless @@ -32,7 +32,7 @@ if ($FORM{'searchwhat'} eq "code") { $sql = qq{ SELECT i.dmid, i.itid, i.itcode FROM ml_items i, ml_latest l - WHERE l.lnid=$l->{'lnid'} AND l.dmid=i.dmid AND i.itid=l.itid + WHERE l.lnid=$l->{'lnid'} AND l.dmid=i.dmid AND i.itid=l.itid $dmidwhere AND LOCATE($qtext, i.itcode) }; } else { @@ -40,11 +40,23 @@ if ($FORM{'searchwhat'} eq "parent") { $lnid = $l->{'parentlnid'}; } $sql = qq{ SELECT i.dmid, i.itid, i.itcode FROM ml_items i, ml_latest l, ml_text t - WHERE l.lnid=$lnid AND l.dmid=i.dmid AND i.itid=l.itid + WHERE l.lnid=$lnid AND l.dmid=i.dmid AND i.itid=l.itid $dmidwhere AND t.dmid=l.dmid AND t.txtid=l.txtid AND LOCATE($qtext, t.text) ORDER BY i.itcode }; - } + } + } + + if ($FORM{'search'} eq 'flg') { + return "This type of search isn't available for this language." + unless $l->{'lncode'} eq $LJ::DEFAULT_LANG || !$l->{'parentlnid'}; + + my $whereflags = join ' AND ', + map { $FORM{"searchflag$_"} eq 'yes' ? "$_ = 1" : "$_ = 0" } + grep { $FORM{"searchflag$_"} ne 'whatev' } qw(proofed updated); + $whereflags = "AND $whereflags" + if $whereflags ne ''; + $sql = "SELECT i.dmid, i.itid, i.itcode FROM ml_items i, ml_latest l WHERE l.lnid=$l->{'lnid'} AND l.dmid=i.dmid AND l.itid=i.itid $whereflags ORDER BY i.dmid, i.itcode"; } return "Bogus or unimplemented query type." unless $sql; @@ -68,10 +80,10 @@ $addlink->() if @page >= 10; } $addlink->(); - + if ($page == 0) { $ret .= "<i>(No matches)</i>"; } - + return $ret; - + } _code?> diff -r fd24f588f9b0 -r 84e8f72def77 htdocs/translate/searchform.bml --- a/htdocs/translate/searchform.bml Sat Mar 14 19:03:25 2009 +0000 +++ b/htdocs/translate/searchform.bml Sun Mar 15 05:05:18 2009 +0000 @@ -3,6 +3,7 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body marginwidth='0' marginheight='0'> + <form target='res' action='search.bml' method='get'> <input type='hidden' name='lang' value='<?_code $FORM{'lang'} _code?>'> <input type='hidden' name='search' value='sev'> @@ -33,7 +34,7 @@ _code?> <input type='hidden' name='lang' value='<?_code $FORM{'lang'} _code?>'> <input type='hidden' name='search' value='txt'> -<p>Search +<p>Search <?_code my $ret; my $l = LJ::Lang::get_lang($FORM{'lang'}); @@ -46,16 +47,34 @@ _code?> $ret .= "<br />Area: "; $ret .= LJ::html_select({ 'name' => 'searchdomain' }, 0, "(all)", - map { $_->{'dmid'}, $_->{'uniq'} } + map { $_->{'dmid'}, $_->{'uniq'} } sort { $a->{'dmid'} <=> $b->{'dmid'} } LJ::Lang::get_domains()); return $ret; _code?> <br />Text: <input name='searchtext' size='15'><input type='submit' value='Search'> </p> - - </form> +<?_code + my $l = LJ::Lang::get_lang($FORM{'lang'}); + return '' unless $l->{'lncode'} eq $LJ::DEFAULT_LANG || !$l->{'parentlnid'}; + + my $ret = <<HTML; +<form target='res' action='search.bml' method='get'> +<input type='hidden' name='lang' value='$l->{lncode}'> +<input type='hidden' name='search' value='flg'> +<p><table><tr><td>Prf:</td> +<td><input type='radio' name='searchflagproofed' value='whatev'>Both</td> +<td><input type='radio' name='searchflagproofed' value='yes'>Yes</td> +<td><input type='radio' name='searchflagproofed' value='no'>No</td></tr> +<tr><td>Upd:</td> +<td><input type='radio' name='searchflagupdated' value='whatev'>Both</td> +<td><input type='radio' name='searchflagupdated' value='yes'>Yes</td> +<td><input type='radio' name='searchflagupdated' value='no'>No</td></tr></table> +<input type='submit' value='Search'></p></form> +HTML + return $ret; +_code?> </body> </html> --------------------------------------------------------------------------------