ssafronova (ssafronova) wrote in changelog,
ssafronova
ssafronova
changelog

[livejournal] r16133: LJSV-787: Entry tags are only shown when...

Committer: ssafronova
LJSV-787: Entry tags are only shown when editing entry
U   trunk/cgi-bin/ljprotocol.pl
U   trunk/cgi-bin/taglib.pl
U   trunk/htdocs/editjournal.bml
U   trunk/htdocs/edittags.bml
U   trunk/htdocs/edittags.bml.text
U   trunk/htdocs/update.bml
U   trunk/htdocs/update.bml.text
Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/cgi-bin/ljprotocol.pl	2010-01-25 11:14:09 UTC (rev 16133)
@@ -1585,6 +1585,7 @@
 
         my $logtag_opts = {
             remote => $u,
+            skipped_tags => [], # do all possible and report impossible
         };
 
         if (ref $taginput eq 'ARRAY') {
@@ -1595,6 +1596,9 @@
         }
 
         my $rv = LJ::Tags::update_logtags($uowner, $jitemid, $logtag_opts);
+        push @{$res->{warnings} ||= []}, LJ::Lang::ml('/update.bml.tags.skipped', { 'tags' => join(', ', @{$logtag_opts->{skipped_tags}}),
+                                                             'limit' => $uowner->get_cap('tags_max') } )
+            if @{$logtag_opts->{skipped_tags}};
     }
 
     ## copyright
@@ -2014,14 +2018,21 @@
     $req->{'props'}->{'revnum'} = ($curprops{$itemid}->{'revnum'} || 0) + 1;
     $req->{'props'}->{'revtime'} = time();
 
+    my $res = { 'itemid' => $itemid };
+
     # handle tags if they're defined
     if ($do_tags) {
         my $tagerr = "";
+        my $skipped_tags = [];
         my $rv = LJ::Tags::update_logtags($uowner, $itemid, {
                 set_string => $req->{props}->{taglist},
                 remote => $u,
                 err_ref => \$tagerr,
+                skipped_tags => $skipped_tags, # do all possible and report impossible
             });
+        push @{$res->{warnings} ||= []}, LJ::Lang::ml('/update.bml.tags.skipped', { 'tags' => join(', ', @$skipped_tags),
+                                                             'limit' => $uowner->get_cap('tags_max') } )
+            if @$skipped_tags;
     }
 
     if (LJ::is_enabled('default_copyright', $u)) {
@@ -2076,7 +2087,6 @@
 
     LJ::memcache_kill($ownerid, "dayct2");
 
-    my $res = { 'itemid' => $itemid };
     if (defined $oldevent->{'anum'}) {
         $res->{'anum'} = $oldevent->{'anum'};
         $res->{'url'} = LJ::item_link($uowner, $itemid, $oldevent->{'anum'});
@@ -4003,6 +4013,7 @@
     $res->{'itemid'} = $rs->{'itemid'};
     $res->{'anum'} = $rs->{'anum'} if defined $rs->{'anum'};
     $res->{'url'} = $rs->{'url'} if defined $rs->{'url'};
+    # we may not translate 'warnings' here, because it may contain \n characters
     return 1;
 }
 

Modified: trunk/cgi-bin/taglib.pl
===================================================================
--- trunk/cgi-bin/taglib.pl	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/cgi-bin/taglib.pl	2010-01-25 11:14:09 UTC (rev 16133)
@@ -70,7 +70,7 @@
     # spawn gearman jobs to get each of the users
     my $ts = $gc->new_task_set();
     foreach my $u (values %need) {
-        $ts->add_task(Gearman::Task->new("load_usertags", \"$u->{userid}",
+        $ts->add_task(Gearman::Task->new("load_usertags", "$u->{userid}",
             {
                 uniq => '-',
                 on_complete => sub {
@@ -768,14 +768,17 @@
         # and turn everything into ids
         $opts->{"${verb}_ids"} ||= [];
         foreach my $kw (@{$opts->{$verb} || []}) {
-            my $kwid = LJ::get_keyword_id($u, $kw, $can_control);
+            my $kwid = LJ::get_keyword_id($u, $kw, $can_control); # parameter 'autovivify(create-if-not-exist)' gets $can_control
             if ($can_control) {
                 # error if we failed to create
                 return undef unless $kwid;
             } else {
                 # if we're not creating, who cares, just skip; also skip if the keyword
                 # is not really a tag (don't promote it)
-                next unless $kwid && $utags->{$kwid};
+                unless ($kwid && $utags->{$kwid}) {
+                    push @{$opts->{skipped_tags}}, $kw if exists $opts->{skipped_tags} and ref $opts->{skipped_tags} eq 'ARRAY';
+                    next;
+                }
             }
 
             # add the ids to the list, and save to create later if needed
@@ -823,12 +826,29 @@
     my $max = $u->get_cap('tags_max');
     if (@to_create && $max && $max > 0) {
         my $total = scalar(keys %$utags) + scalar(@to_create);
-        return $err->(LJ::Lang::ml('taglib.error.toomany', { max => $max })) if $total > $max;
+        if (exists $opts->{skipped_tags} and ref $opts->{skipped_tags} eq 'ARRAY') { # will do possible and give warning on impossible
+            my $may = $max - scalar(keys %$utags);
+            $may = 0 if $may < 0;
+            my @skip = splice(@to_create, $may); # @to_create remains with first $may elements
+            push @{$opts->{skipped_tags}}, @skip;
+            # now @to_create is safe
+        } else { # old behavior requested
+            return $err->(LJ::Lang::ml('taglib.error.toomany', { max => $max })) if $total > $max;
+        }
     }
 
     # now we can create the new tags, since we know we're safe
-    LJ::Tags::create_usertag($u, $_, { display => 1 }) foreach @to_create;
+    my $created = LJ::Tags::create_usertag($u, join(', ', @to_create), { display => 1 });
+    my %created = reverse %{$created || {}}; # tag - kwid => kwid - tag
 
+    # we may not set skipped tags on entry, but now they are in 'add' ids list
+    # clean 'add' list
+    foreach my $id (keys %add) {
+        delete $add{$id} unless $utags->{$id} or $created{$id};
+    } 
+
+    return 1 unless %add || %delete; # again - we cleaned %add
+
     # %add and %delete are accurate, but we need to track necessary
     # security updates; this is a hash of keyword ids and a modification
     # value (a delta; +/-N) to be applied to that row later

Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/htdocs/editjournal.bml	2010-01-25 11:14:09 UTC (rev 16133)
@@ -199,9 +199,9 @@
             if (!$spellcheck_html && ($POST{'action:save'} || $POST{'action:saveunsuspend'} || $POST{'action:delete'} || $POST{'action:deletespam'})) {
                 return LJ::bad_input($ML{'error.invalidform'}) unless LJ::check_form_auth();
 
-                my %req = ( 'mode' => 'editevent',
+                my %req = (
                             'ver' => $LJ::PROTOCOL_VER,
-                            'user' => $u->{'user'},
+                            'username' => $u->{'user'},
                             'usejournal' => $usejournal,
                             'itemid' => $itemid,
                             );
@@ -224,17 +224,23 @@
                 }
 
                 # do editevent request
-                LJ::do_request(\%req, \%res, { 'noauth' => 1, 'u' => $u });
+                foreach my $k (keys %req) {
+                    next unless ($k =~ /^prop_(.+)/);
+                    $req{'props'}->{$1} = $req{$k};
+                    delete $req{$k};
+                }
+                my $err = 0;
+                my $res = LJ::Protocol::do_request('editevent', \%req, \$err, { 'noauth' => 1, 'u' => $u });
 
                 # check response
-                unless ($res{'success'} eq "OK") {
-                    return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.modify'} <ul><li><b>$res{'errmsg'}</b></li></ul> p?>";
+                unless ($res) {
+                    return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.modify'} <ul><li><b>" . LJ::Protocol::error_message($err) . "</b></li></ul> p?>";
                 }
 
                 my $deleted = $req{event} ? 0 : 1;
                 my $journalu = $usejournal ? $usejournal_u : $u;
                 my $j_base = $journalu->journal_base;
-                my $entry_url = LJ::item_link($journalu, $itemid, $res{anum});
+                my $entry_url = LJ::item_link($journalu, $itemid, $res->{anum});
 
                 my $result = "<?h1 $ML{'.success.head'} h1?>";
                 $result .= "<table border='0' width='100%'><tr valign='top'><td>";
@@ -272,6 +278,8 @@
                     }
                 }
 
+                $result .= join('<br>', @{$res->{warnings}} ) if $res->{warnings} and @{$res->{warnings}};
+
                 $result .= "<div id='fromhere'>$ML{'.success.fromhere'}<ul>";
                 $result .= "<li><a href='$entry_url'>$ML{'.success.fromhere.viewentry'}</a></li>" unless $deleted;
                 $result .= "<li><a href='$j_base'>$ML{'.success.fromhere.viewentries'}</a></li>";

Modified: trunk/htdocs/edittags.bml
===================================================================
--- trunk/htdocs/edittags.bml	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/htdocs/edittags.bml	2010-01-25 11:14:09 UTC (rev 16133)
@@ -53,12 +53,17 @@
             unless LJ::check_form_auth();
 
         my $tagerr = "";
+        my $skipped_tags = [];
         my $rv = LJ::Tags::update_logtags($u, $jitemid, {
             set_string => $POST{edittags},
             remote => $remote,
             err_ref => \$tagerr,
+            skipped_tags => $skipped_tags, # do all possible and report impossible
         });
         return $err->($tagerr) unless $rv;
+        return "<?h1 $ML{'.warning.title'} h1?><?p " . LJ::Lang::ml('/update.bml.tags.skipped', { 'tags' => join(', ', @$skipped_tags),
+                                                             'limit' => $u->get_cap('tags_max') } ) . " p?>"
+            if @$skipped_tags;
 
         BML::redirect( LJ::journal_base($u) . "/$ditemid.html" );
         #$msg = "<div class='update_good'>Tags successfully updated.</div>";

Modified: trunk/htdocs/edittags.bml.text
===================================================================
--- trunk/htdocs/edittags.bml.text	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/htdocs/edittags.bml.text	2010-01-25 11:14:09 UTC (rev 16133)
@@ -37,3 +37,4 @@
 
 .view=<a [[aopts]]>View</a> this entry.
 
+.warning.title=Warning

Modified: trunk/htdocs/update.bml
===================================================================
--- trunk/htdocs/update.bml	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/htdocs/update.bml	2010-01-25 11:14:09 UTC (rev 16133)
@@ -367,9 +367,9 @@
             $$body .= "<?p <strong>$ML{'.loggingin'}</strong> $ML{'.servermsg'} p?><div style='margin-left: 40px'><b>$login_message</b></div>";
         }
 
-        my %req = ( 'mode'        => 'postevent',
+        my %req = (
                     'ver'         => $LJ::PROTOCOL_VER,
-                    'user'        => $user,
+                    'username'    => $user,
                     'password'    => $POST{'password'},
                     'usejournal'  => $POST{'usejournal'},
                     'tz'          => 'guess',
@@ -388,23 +388,28 @@
         $req{prop_qotdid} = $qid;
         $req{prop_interface} = "web";
 
-        my %res;
-        LJ::do_request(\%req, \%res, $flags);
+        foreach my $k (keys %req) {
+            next unless ($k =~ /^prop_(.+)/);
+            $req{'props'}->{$1} = $req{$k};
+            delete $req{$k};
+        }
+        my $err = 0;
+        my $res = LJ::Protocol::do_request("postevent", \%req, \$err, $flags);
 
         if (!keys %$errors) {
             # examine response
             my $update_message;
-            if ($res{'success'} eq "OK" && $res{'message'}) {
-                $update_message = LJ::auto_linkify(LJ::ehtml($res{'message'}));
+            if ($res && $res->{'message'}) {
+                $update_message = LJ::auto_linkify(LJ::ehtml($res->{'message'}));
             }
 
             # report results
             $$body .= "<?p <strong>$ML{'.updating'}</strong> ";
 
-            if ($res{'success'} ne 'OK') {
+            unless ($res) {
                 # update failed?
                 $$body .= "<br /><?errorbar <strong>$ML{'.error.update'}</strong> ";
-                $$body .= LJ::ehtml($res{'errmsg'}) . " errorbar?>";
+                $$body .= LJ::ehtml(LJ::Protocol::error_message($err)) . " errorbar?>";
                 $$body .= "<br /> p?>";
             } else {
                 # Clear out a draft
@@ -422,8 +427,8 @@
 
                 my ($ju, $itemlink);
                 # short bail if this was posted moderated or some other special case (no itemid but a message)
-                if (!defined $res{itemid} && $res{message}) {
-                    $$body .= "<br />$res{message} p?>";
+                if (!defined $res->{itemid} && $res->{message}) {
+                    $$body .= "<br />$res->{message} p?>";
                 } else {
 
                     # update success
@@ -441,10 +446,12 @@
                     };
                     $$body .= BML::ml('.update.success2', {'aopts' => "href='" . $ju->journal_base . "/'"});
 
-                    $$body .= $res{extra_result_message};
-                    
+                    $$body .= $res->{extra_result_message};
+
+                    $$body .= join('<br>', @{$res->{warnings}} ) if $res->{warnings} and @{$res->{warnings}};
+
                     my $juser = $ju->{'user'};
-                    my ($itemid, $anum) = ($res{'itemid'}, $res{'anum'});
+                    my ($itemid, $anum) = ($res->{'itemid'}, $res->{'anum'});
                     $itemlink = LJ::item_link($ju, $itemid, $anum);
                     $itemid = $itemid * 256 + $anum;
 

Modified: trunk/htdocs/update.bml.text
===================================================================
--- trunk/htdocs/update.bml.text	2010-01-25 11:07:43 UTC (rev 16132)
+++ trunk/htdocs/update.bml.text	2010-01-25 11:14:09 UTC (rev 16133)
@@ -113,6 +113,8 @@
 
 .success.links.view=View the entry
 
+.tags.skipped=<p>The entry has been saved. However, some tags have not been added because you have exceeded your maximum tags limit of [[limit]] tags. The tags we couldn't add are as follows:<p><p><strong>[[tags]]</strong></p>
+
 .timeformat=24 hour time
 
 .title2=Post an Entry

Tags: bml, livejournal, pl, ssafronova, text
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments