[dw-free] When importing already-OpenID comments, indicate what service they were imported from
[commit: http://hg.dwscoalition.org/dw-free/rev/2276c707d94f]
http://bugs.dwscoalition.org/show_bug.cgi?id=315
Indicate which service already-OpenID comments were imported from.
Patch by
exor674.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=315
Indicate which service already-OpenID comments were imported from.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/proplists.dat
- bin/upgrading/s2layers/core2.s2
- cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm
- cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm
- cgi-bin/LJ/S2/EntryPage.pm
- htdocs/talkread.bml
- htdocs/talkread.bml.text
-------------------------------------------------------------------------------- diff -r e410de8a0dd0 -r 2276c707d94f bin/upgrading/proplists.dat --- a/bin/upgrading/proplists.dat Sat Apr 04 07:50:56 2009 +0000 +++ b/bin/upgrading/proplists.dat Sun Apr 05 01:59:49 2009 +0000 @@ -1195,8 +1195,13 @@ talkproplist.guest_url: talkproplist.import_source: datatype: char - des: Where this entry was imported from + des: Where this comment was imported from prettyname: Import source + +talkproplist.imported_from: + datatype: char + des: The hostname of the site where this comment was imported from. + prettyname: Imported from talkproplist.opt_preformatted: datatype: bool diff -r e410de8a0dd0 -r 2276c707d94f bin/upgrading/s2layers/core2.s2 --- a/bin/upgrading/s2layers/core2.s2 Sat Apr 04 07:50:56 2009 +0000 +++ b/bin/upgrading/s2layers/core2.s2 Sun Apr 05 01:59:49 2009 +0000 @@ -1957,6 +1957,13 @@ property string text_poster_anonymous { } set text_poster_anonymous = "(Anonymous)"; +property string text_openid_from { + des = "Text to indicate which site this OpenID account originally posted a comment on"; + example = "from"; + noui = 1; +} +set text_openid_from = "from"; + property string text_reply_back { des = "Text to link back to the single entry view from the read comments page"; example = "Read Comments"; @@ -3161,6 +3168,8 @@ function Page::print_entry_poster(EntryL # For any given comment, print the commentor's name (local, anonymous, or openid) function Comment::print_poster() { var string poster = defined $this.poster ? $this.poster->as_string() : "<span class=\"anonymous\">$*text_poster_anonymous</span>"; + if ($this.metadata{"imported_from"}) { $poster = "$poster ($*text_openid_from " + $this.metadata{"imported_from"} + ")"; } + print safe "<span class=\"poster comment-poster\">$*text_comment_from $poster</span>\n"; } diff -r e410de8a0dd0 -r 2276c707d94f cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm --- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm Sat Apr 04 07:50:56 2009 +0000 +++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm Sun Apr 05 01:59:49 2009 +0000 @@ -88,7 +88,7 @@ sub try_work { if $url =~ m!/(\d+)\.html$!; $jitemid_map->{$jitemid} = $entry_map->{$url}; } - + # this will take a talk_map (old URL -> new jtalkid) and convert it to a jtalkid map (old jtalkid -> new jtalkid) my $talk_map = DW::Worker::ContentImporter::Local::Comments->get_comment_map( $u ) || {}; $log->( 'Loaded comment map with %d entries.', scalar( keys %$talk_map ) ); @@ -102,9 +102,9 @@ sub try_work { } # parameters for below - my ( %meta, @userids, $identity_map ); + my ( %meta, @userids, $identity_map, $was_external_user ); my ( $maxid, $server_max_id, $server_next_id, $lasttag ) = ( 0, 0, 1, '' ); - + # setup our parsing function my $meta_handler = sub { # this sub actually processes incoming meta information @@ -126,6 +126,8 @@ sub try_work { my ( $local_oid, $local_fid ) = $class->get_remapped_userids( $data, $temp{user} ); $identity_map->{$temp{id}} = $local_oid; + $was_external_user->{$temp{id}} = 1 + if $temp{user} =~ m/^ext_/; # If the remote username starts with ext_ flag it as external $log->( 'Mapped remote %s(%d) to local userid %d.', $temp{user}, $temp{id}, $local_oid ); } @@ -145,7 +147,7 @@ sub try_work { $server_max_id = $_[1] + 0 if $lasttag eq 'maxid'; $server_next_id = $_[1] + 0 if $lasttag eq 'nextid'; }; - + # hit up the server for metadata while ( defined $server_next_id && $server_next_id =~ /^\d+$/ ) { $log->( 'Fetching metadata; max_id = %d, next_id = %d.', $server_max_id || 0, $server_next_id || 0 ); @@ -155,9 +157,9 @@ sub try_work { ); return $temp_fail->( 'Error fetching comment metadata from server.' ) unless $content; - + $server_next_id = undef; - + # now we want to XML parse this my $parser = new XML::Parser( Handlers => { @@ -201,7 +203,7 @@ sub try_work { # that may or may not be in the data stream, and we won't know until we've already # gotten some data }; - + # start looping to fetch all of the comment bodies while ( $lastid < $server_max_id ) { $log->( 'Fetching bodydata; last_id = %d, max_id = %d.', $lastid || 0, $server_max_id || 0 ); @@ -221,13 +223,13 @@ sub try_work { } ); $parser->parse( $content ); - + # the exporter should always return the maximum number of items, so loop again. of course, # this will fail nicely as soon as some site we're importing from reduces the max items # they return due to load. http://community.livejournal.com/changelog/5907095.html $lastid += $COMMENTS_FETCH_BODY; } - + # now iterate over each comment and build the nearly final structure foreach my $comment ( values %meta ) { @@ -240,16 +242,19 @@ sub try_work { next; } + $comment->{source} = $data->{hostname} + if $was_external_user->{$comment->{posterid}}; + # basic mappings $comment->{posterid} = $identity_map->{$comment->{posterid}}; $comment->{jitemid} = $jitemid_map->{$comment->{jitemid}}; $comment->{orig_id} = $comment->{id}; - + # unresolved comments means we haven't got the parent in the database # yet so we can't post this one $comment->{unresolved} = 1 if $comment->{parentid}; - + # the reverse of unresolved, tell the parent it has visible children $meta{$comment->{parentid}}->{has_children} = 1 if $comment->{parentid} && $comment->{state} ne 'D'; @@ -265,7 +270,7 @@ sub try_work { $comment->{body} = encode_utf8( $comment->{body} ); $comment->{subject} = encode_utf8( $comment->{subject} ); } - + # variable setup for the database work my @to_import = sort { ( $a->{id}+0 ) <=> ( $b->{id}+0 ) } values %meta; my $had_unresolved = 1; @@ -342,7 +347,7 @@ sub try_work { return $fail->( 'Found unresolvable comment chain.' ); } } - + return $ok->(); } diff -r e410de8a0dd0 -r 2276c707d94f cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm --- a/cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm Sat Apr 04 07:50:56 2009 +0000 +++ b/cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm Sun Apr 05 01:59:49 2009 +0000 @@ -76,6 +76,7 @@ sub insert_comment { $errref ||= ''; # load the data we need to make this comment + # FIXME: What is the point of this? use Data::Dumper; warn Dumper( $cmt ) unless $cmt->{jitemid}; @@ -103,6 +104,7 @@ sub insert_comment { props => { import_source => $source, + imported_from => $cmt->{source}, }, no_urls => 1, diff -r e410de8a0dd0 -r 2276c707d94f cgi-bin/LJ/S2/EntryPage.pm --- a/cgi-bin/LJ/S2/EntryPage.pm Sat Apr 04 07:50:56 2009 +0000 +++ b/cgi-bin/LJ/S2/EntryPage.pm Sun Apr 05 01:59:49 2009 +0000 @@ -277,6 +277,9 @@ sub EntryPage ($remote->{'userid'} == $entry->posterid || LJ::can_manage($remote, $u) || $viewall)); + $s2com->{metadata}->{imported_from} = $com->{props}->{imported_from} + if $com->{props}->{imported_from}; + push @$destlist, $s2com; $self->($self, $s2com->{'replies'}, $com->{'children'}, $depth+1); diff -r e410de8a0dd0 -r 2276c707d94f htdocs/talkread.bml --- a/htdocs/talkread.bml Sat Apr 04 07:50:56 2009 +0000 +++ b/htdocs/talkread.bml Sun Apr 05 01:59:49 2009 +0000 @@ -555,6 +555,7 @@ my $old_url = 0; my $cleansubject = LJ::ehtml($post->{'subject'}); $ret .= "<span class='commentsubject'><b>$cleansubject</b></span> $icon"; $ret .= "<br />$user\n"; + $ret .= " " . BML::ml( '.from_external', {site=>$post->{props}->{imported_from}} ) if $post->{props}->{imported_from}; $ret .= "<br /><span class='datepost'>$datepost</span>\n"; if ($post->{'props'}->{'poster_ip'} && $remote && ($remote->{'user'} eq $up->{'user'} || diff -r e410de8a0dd0 -r 2276c707d94f htdocs/talkread.bml.text --- a/htdocs/talkread.bml.text Sat Apr 04 07:50:56 2009 +0000 +++ b/htdocs/talkread.bml.text Sun Apr 05 01:59:49 2009 +0000 @@ -12,6 +12,8 @@ .deleteduser=<i>(Deleted user: [[username]])</i> .edittime=Edited at [[edittime]] + +.from_external=(from [[site]]) .fromip=(from [[ip]]) --------------------------------------------------------------------------------