[dw-free] Strip out NavTag code
[commit: http://hg.dwscoalition.org/dw-free/rev/a1e932a98437]
http://bugs.dwscoalition.org/show_bug.cgi?id=4403
Remove files (committer's fault!)
Patch by
kaberett.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=4403
Remove files (committer's fault!)
Patch by
Files modified:
- cgi-bin/LJ/NavTag.pm
- htdocs/admin/navtag.bml
--------------------------------------------------------------------------------
diff -r d7d16ac3a92e -r a1e932a98437 cgi-bin/LJ/NavTag.pm
--- a/cgi-bin/LJ/NavTag.pm Thu Jul 12 17:48:09 2012 +0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,248 +0,0 @@
-# This code was forked from the LiveJournal project owned and operated
-# by Live Journal, Inc. The code has been modified and expanded by
-# Dreamwidth Studios, LLC. These files were originally licensed under
-# the terms of the license supplied by Live Journal, Inc, which can
-# currently be found at:
-#
-# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
-#
-# In accordance with the original license, this code and all its
-# modifications are provided under the GNU General Public License.
-# A copy of that license can be found in the LICENSE file included as
-# part of this distribution.
-
-############################################################################
-package LJ::NavTag;
-use strict;
-
-sub valid_types {
- return qw(LJUSER FAQ PAGE SSL);
-}
-
-sub is_valid_type {
- my $class = shift;
- my $type = shift;
- return grep { $_ eq $type } valid_types();
-}
-
-sub canonical_tag {
- shift @_ if $_[0] eq __PACKAGE__;
- my $tag = shift;
- die if @_;
-
- $tag =~ s/^\s+//;
- $tag =~ s/\s+$//;
- $tag =~ tr/A-Z/a-z/;
- return $tag;
-}
-
-sub tags_of_url {
- my ($type, $url) = @_;
- my $dest = LJ::NavTag::Dest->new_from_url($url);
- return undef unless $dest;
- return LJ::NavTag->tags_of_dest($dest);
-}
-
-sub tags_of_dest {
- my ($class, $dest) = @_;
- my @tags = ();
- my $dbr = LJ::get_db_reader();
- my $sth = $dbr->prepare("SELECT tag FROM navtag WHERE dest_type=? AND dest=?");
- $sth->execute($dest->type, $dest->dest);
- while (my ($tag) = $sth->fetchrow_array) {
- push @tags, $tag;
- }
-
- return @tags;
-}
-
-# returns hashref of { $tag => $count }
-sub tags_with_count {
- shift @_ if $_[0] eq __PACKAGE__;
- die if @_;
-
- my $dbr = LJ::get_db_reader();
- my $sth = $dbr->prepare("SELECT tag, count(*) FROM navtag GROUP BY tag");
- $sth->execute;
- my $tags = {};
- while (my ($tag, $count) = $sth->fetchrow_array) {
- $tags->{$tag} = $count;
- }
- return $tags;
-}
-
-# given a tag (scalar), returns an array of destination objects
-sub dests_of_tag {
- shift @_ if $_[0] eq __PACKAGE__;
- my $tag = shift;
- $tag = LJ::NavTag->canonical_tag($tag);
- die if @_;
-
- my $dbr = LJ::get_db_reader();
- my $sth = $dbr->prepare("SELECT dest_type, dest FROM navtag WHERE tag=?");
- $sth->execute($tag);
- my @dests;
- while (my $rec = $sth->fetchrow_hashref) {
- my $dest = LJ::NavTag::Dest->new(type => $rec->{dest_type},
- dest => $rec->{dest});
- push @dests, $dest;
- }
-
- return @dests;
-}
-
-############################################################################
-package LJ::NavTag::Dest;
-use strict;
-
-sub new {
- my ($class, %opts) = @_;
- my $self = {};
- $self->{type} = delete $opts{'type'};
- $self->{dest} = delete $opts{'dest'};
- die "Unknown arguments to constructor: " . join(", ", keys %opts) if %opts;
- die "Unknown type" unless LJ::NavTag->is_valid_type($self->{type});
- bless $self, "LJ::NavTag::Dest::$self->{type}";
- return $self;
-}
-
-# $destobj = LJ::NavTag::Dest->new_from_url("http://www.livejournal.com/profile.bml?user=brad");
-sub new_from_url {
- my ($class, $url) = @_;
- foreach my $type (LJ::NavTag->valid_types) {
- my $dest = "LJ::NavTag::Dest::$type"->dest_from_url($url);
- return $dest if $dest;
- }
- return undef;
-}
-
-sub dest_from_url { undef; }
-
-sub type { my $self = shift; return $self->{type}; }
-sub dest { my $self = shift; return $self->{dest}; }
-
-sub add_tag {
- my ($self, $tag) = @_;
- $tag = LJ::NavTag->canonical_tag($tag);
- my $dbh = LJ::get_db_writer();
- return $dbh->do("INSERT INTO navtag SET tag=?, dest_type=?, dest=?",
- undef, $tag, $self->type, $self->dest);
-}
-
-sub remove_tag {
- my ($self, $tag) = @_;
- $tag = LJ::NavTag->canonical_tag($tag);
- my $dbh = LJ::get_db_writer();
- return $dbh->do("DELETE FROM navtag WHERE tag=? AND dest_type=? AND dest=?",
- undef, $tag, $self->type, $self->dest);
-}
-
-sub title {
- my $self = shift;
- return "$self->{type} -- $self->{dest}";
-}
-
-sub ljuser { undef; }
-
-sub url { "about:"; }
-
-############################################################################
-package LJ::NavTag::Dest::LJUSER;
-use base "LJ::NavTag::Dest";
-
-sub ljuser {
- my $self = shift;
- return LJ::load_user($self->{dest});
-}
-
-sub title {
- my $self = shift;
- my $u = $self->ljuser;
- return $u ? $u->{name} : $self->SUPER::title;
-}
-
-sub url {
- my $self = shift;
- my $user = $self->{dest};
- my $u = LJ::load_user($user);
- return $u->profile_url if $u;
- return "$LJ::SITEROOT/profile.bml?user=$user";
-}
-
-sub dest_from_url {
- my ($class, $url) = @_;
- # FIXME: broken. wrong URL type
- return undef unless $url =~ m!/profile.bml\?user=(\w+)!;
- return LJ::NavTag::Dest->new(type => "LJUSER",
- dest => $1);
-}
-
-############################################################################
-package LJ::NavTag::Dest::PAGE;
-use base "LJ::NavTag::Dest";
-
-sub url { my $self = shift; "$LJ::SITEROOT" . $self->{dest} }
-
-sub dest_from_url {
- my ($class, $url) = @_;
- return undef unless $url =~ s!^\Q$LJ::SITEROOT\E!!;
- return LJ::NavTag::Dest->new(type => "PAGE",
- dest => $url || "/");
-}
-
-sub title {
- my $self = shift;
- my $curlang = BML::get_language();
- my $mld = LJ::Lang::get_dom("general");
- my $dest = $self->{dest};
- $dest .= "index.bml" unless $dest =~ /\.bml$/;
- return LJ::Lang::get_text($curlang, $dest . ".title", $mld->{'dmid'}) ||
- $self->{dest};
-}
-
-############################################################################
-package LJ::NavTag::Dest::SSL;
-use base "LJ::NavTag::Dest::PAGE";
-
-sub url { my $self = shift; "$LJ::SSLROOT" . $self->{dest} }
-
-sub dest_from_url {
- my ($class, $url) = @_;
- return undef unless $url =~ s!^\Q$LJ::SSLROOT\E!!;
- return LJ::NavTag::Dest->new(type => "PAGE",
- dest => $url || "/");
-}
-
-############################################################################
-package LJ::NavTag::Dest::FAQ;
-use base "LJ::NavTag::Dest";
-
-sub dest_from_url {
- my ($class, $url) = @_;
- return undef unless $url =~ m!/support/faqbrowse.bml\?faqid=(\d+)!;
- return LJ::NavTag::Dest->new(type => "FAQ",
- dest => $1);
-}
-
-sub _faqid { int($_[0]->{dest}) };
-
-sub url {
- my $self = shift;
- return "$LJ::SITEROOT/support/faqbrowse.bml?faqid=" . $self->_faqid;
-}
-
-sub title {
- my $self = shift;
- my $curlang = BML::get_language();
- my $deflang = BML::get_language_default();
- my $altlang = $curlang ne $deflang;
- my $mld = LJ::Lang::get_dom("faq");
- if ($altlang) {
- return LJ::Lang::get_text($curlang, $self->_faqid . ".1question", $mld->{'dmid'});
- }
-
- my $dbr = LJ::get_db_reader();
- return $dbr->selectrow_array("SELECT question FROM faq WHERE faqid=?", undef, $self->_faqid);
-}
-
-1;
diff -r d7d16ac3a92e -r a1e932a98437 htdocs/admin/navtag.bml
--- a/htdocs/admin/navtag.bml Thu Jul 12 17:48:09 2012 +0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,252 +0,0 @@
-<?_c
-# This code was forked from the LiveJournal project owned and operated
-# by Live Journal, Inc. The code has been modified and expanded by
-# Dreamwidth Studios, LLC. These files were originally licensed under
-# the terms of the license supplied by Live Journal, Inc, which can
-# currently be found at:
-#
-# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
-#
-# In accordance with the original license, this code and all its
-# modifications are provided under the GNU General Public License.
-# A copy of that license can be found in the LICENSE file included as
-# part of this distribution.
-_c?>
-<html>
-<head>
-<style>
- div.tagcloud a { text-decoration: none; }
- div.tagcloud a:visited { color: #00f; }
- div.tagcloud a:link { color: #00f; }
-</style>
-</head>
-<body>
-<?_code
-{
- use strict;
- use vars qw(%GET %POST);
-
- my $remote = LJ::get_remote();
- my @displayprivs = ( "siteadmin:navtag", "siteadmin:*" );
- my $numprivs = @displayprivs;
-
- return "<?needlogin?>" unless $remote;
-
- return BML::ml( "admin.noprivserror", { numprivs => $numprivs, needprivs => "<b>" . join(", ", @displayprivs) . "</b>"} )
- unless $remote->has_priv( 'siteadmin', 'navtag' );
-
- do "LJ/NavTag.pm";
- #use LJ::NavTag;
-
- my $view = $GET{'view'};
- my $viewtag = $GET{'tag'};
- my $viewdest = $GET{'dest'};
-
- my $body;
-
- if (LJ::did_post()) {
- return "<b>$ML{'Error'}</b> $ML{'error.invalidform'}" unless LJ::check_form_auth();
-
- foreach my $key (keys %POST) {
- if ($key eq 'add_tags') {
- my $tags = $POST{'add_tags'};
- my $url = $POST{'add_tags_url'};
-
- return "No tags specified" unless $tags;
- return "No URL specified" unless $url;
-
- my $dest = LJ::NavTag::Dest->new_from_url($url);
- foreach my $tag (split(',', $tags)) {
- $dest->add_tag(LJ::NavTag::canonical_tag($tag));
- }
-
- $view = 'dest';
- $viewdest = $url;
-
- } elsif ($key =~ /^del_(\w+)_(\w+):(.+)$/) {
- my ($tag, $type, $dest) = ($1, $2, $3);
-
- $dest =~ s/$LJ::SITEROOT//;
-
- my $destobj = LJ::NavTag::Dest->new(
- type => $type,
- dest => $dest,
- );
- return "Can't create dest object" unless $destobj;
-
- $destobj->remove_tag($tag);
-
- $view = 'dest';
- $viewdest = $LJ::SITEROOT . $dest;
- }
- }
- }
-
- if ($view eq 'tag') {
- $body .= "<a href='navtag'><< Home</a><br />";
- $body .= by_tag($viewtag);
- } elsif ($view eq 'dest') {
- $body .= "<a href='navtag'><< Home</a><br />";
- $body .= by_url($viewdest);
- } else {
- $body .= current_tags();
- $body .= add_tags();
- }
-
- return $body;
-
- sub add_tags {
- my $dest = shift;
-
- my $ret;
-
-
- $ret .= "<form action='navtag' method='POST'>";
- $ret .= LJ::form_auth();
- $ret .= "<br /><?h1 JFTI! h1?>";
-
- $ret .= "<?p To link to a user enter their profile URL. FAQ's should be the faqbrowse URL ending in the faqid. All others will be considered a normal page. Tags are comma-separated. p?>";
-
- if ($dest) {
- $ret .= "<b>Add Tags:</b> ";
- $ret .= LJ::html_text({ name => 'add_tags', size => 30 });
- $ret .= LJ::html_hidden('add_tags_url', $dest);
- } else {
- $ret .= "<table><thead><tr><th>Add Tags</th><th>URL</th></tr></thead>";
- $ret .= "<tr><td>";
- $ret .= LJ::html_text({ name => 'add_tags', size => 30 });
- $ret .= "</td><td>";
- $ret .= LJ::html_text({ name => 'add_tags_url', size => 40 });
- $ret .= "</td></tr></table>";
- }
-
- $ret .= LJ::html_submit('Save');
- $ret .= "</form>";
-
- return $ret;
- }
-
- sub current_tags {
- my $ret;
- $ret .= "<?h1 Current Resource Tags on $LJ::SITENAMESHORT h1?>";
-
- my $tags = LJ::NavTag::tags_with_count();
- my %cloud;
-
- foreach my $tag (keys %$tags) {
- $cloud{$tag} = {
- url => "navtag?view=tag&tag=" . LJ::eurl($tag),
- value => $tags->{$tag},
- };
- }
-
- $ret .= tag_cloud(\%cloud);
-
- return $ret;
- }
-
- sub by_url {
- my $url = shift;
- my $ret;
-
- $ret .= "<form action='navtag' method='POST'>";
- $ret .= LJ::form_auth();
- $ret .= "<?h1 Tags Pointing At " . LJ::ehtml($url) . " h1?>";
-
- $ret .= "<table><thead><tr><th>Tag</th><th>Remove</th></tr></thead>";
-
- my $dest = LJ::NavTag::Dest->new_from_url($url);
-
- return "No destination found" unless $dest;
-
- my @tags = LJ::NavTag->tags_of_dest($dest);
-
- foreach my $tag (@tags) {
- $ret .= "<tr><td><a href='navtag?view=tag&tag=" . LJ::eurl($tag) . "'>";
- $ret .= LJ::ehtml($tag) . "</a></td>";
-
- $ret .= "<td>" . LJ::html_submit("del_${tag}_PAGE:$url", 'X') . "</td>";
- }
-
- $ret .= "</table>";
- $ret .= "</form>";
-
- $ret .= add_tags($url);
-
- return $ret;
- }
-
- sub by_tag {
- my $tag = shift;
- my $ret;
-
- $ret .= "<?h1 Destinations Of Tag " . LJ::ehtml($tag) . " h1?>";
- $ret .= "<table><thead><tr><th>Title</th><th>Destination</th></tr></thead>";
-
- my @dests = LJ::NavTag->dests_of_tag($tag);
-
- foreach my $dest (@dests) {
- $ret .= "<tr><td>" . LJ::ehtml($dest->title) . "</td>";
-
- if (my $lju = $dest->ljuser) {
- $ret .= "<td><a href='navtag?view=dest&dest=";
- $ret .= LJ::eurl("$LJ::SITEROOT/profile?user=$lju->{user}") . "'>";
- $ret .= "$lju->{user}</a> (" . $lju->ljuser_display . ")</td>";
- } elsif (my $url = $dest->url) {
- $ret .= "<td><a href='navtag?view=dest&dest=" . LJ::eurl($url) . "'>";
- $ret .= LJ::ehtml($url) . "</a> (<a href='$url'>view</a>)</td>";
- }
-
- $ret .= "</tr>";
- }
-
- $ret .= "</table>";
-
- return $ret;
- }
-
- # Returns HTML of a dynamic tag could given passed in data
- # Requires hash-ref of tag => { url => url, value => value }
- sub tag_cloud {
- my $tags = shift;
-
- # find sizes of tags, sorted
- my @sizes = sort { $a <=> $b } map { $tags->{$_}->{'value'} } keys %$tags;
-
- # remove duplicates:
- my %sizes = map { $_, 1 } @sizes;
- @sizes = sort { $a <=> $b } keys %sizes;
-
- my @tag_names = sort keys %$tags;
-
- my $percentile = sub {
- my $n = shift;
- my $total = scalar @sizes;
- for (my $i = 0; $i < $total; $i++) {
- next if $n > $sizes[$i];
- return $i / $total;
- }
- };
-
- my $ret .= "<div id='tagcloud' class='tagcloud'>";
- my %tagdata = ();
- foreach my $tag (@tag_names) {
- my $tagurl = $tags->{$tag}->{'url'};
- my $ct = $tags->{$tag}->{'value'};
- my $pt = int(8 + $percentile->($ct) * 25);
- $ret .= "<a id='taglink_$tag' href='";
- $ret .= LJ::ehtml($tagurl) . "' style='color: <?altcolor2?>; font-size: ${pt}pt;'>";
- $ret .= LJ::ehtml($tag) . "</a>\n";
-
- # build hash of tagname => final point size for refresh
- $tagdata{$tag} = $pt;
- }
- $ret .= "</div>";
-
- return $ret;
- }
-
-}
-_code?>
-</body>
-</html>
--------------------------------------------------------------------------------
