Matt Ryall avatar Matt Ryall committed 2dc8a5f

Initial import from Subversion

Comments (0)

Files changed (32)

+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.atlassian.confluence.plugin.news</groupId>
+    <artifactId>confluence-news-plugin</artifactId>
+    <version>1.1-SNAPSHOT</version>
+
+    <organization>
+        <name>Atlassian</name>
+        <url>http://www.atlassian.com/</url>
+    </organization>
+
+    <name>Confluence News Plugin</name>
+    <description>Hacker News style UI for Confluence blog posts and comments.</description>
+    <packaging>atlassian-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.confluence</groupId>
+            <artifactId>confluence</artifactId>
+            <version>${confluence.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.activeobjects</groupId>
+            <artifactId>activeobjects-plugin</artifactId>
+            <version>${ao.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.sal</groupId>
+            <artifactId>sal-api</artifactId>
+            <version>${sal.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-confluence-plugin</artifactId>
+                <version>3.2.3</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>${confluence.version}</productVersion>
+                    <productDataVersion>${confluence.data.version}</productDataVersion>
+                    <pluginArtifacts>
+                        <pluginArtifact>
+                            <groupId>com.atlassian.activeobjects</groupId>
+                            <artifactId>activeobjects-plugin</artifactId>
+                            <version>${ao.version}</version>
+                        </pluginArtifact>
+                        <pluginArtifact>
+                            <groupId>com.atlassian.activeobjects</groupId>
+                            <artifactId>activeobjects-confluence-spi</artifactId>
+                            <version>${ao.version}</version>
+                        </pluginArtifact>
+                    </pluginArtifacts>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <confluence.version>3.5</confluence.version>
+        <confluence.data.version>3.5</confluence.data.version>
+        <ao.version>0.9.5</ao.version>
+        <sal.version>2.0.0</sal.version>
+    </properties>
+
+    <scm>
+        <connection>scm:svn:https://svn.atlassian.com/svn/private/atlassian/personal/mryall/confluence-news-plugin/trunk</connection>
+        <developerConnection>scm:svn:https://svn.atlassian.com/svn/private/atlassian/personal/mryall/confluence-news-plugin/trunk</developerConnection>
+        <url>https://svn.atlassian.com/svn/private/atlassian/personal/mryall/confluence-news-plugin/trunk</url>
+    </scm>
+
+    <distributionManagement>
+        <repository>
+            <id>atlassian-contrib</id>
+            <name>Atlassian repository of contributed code</name>
+            <url>davs://maven.atlassian.com/contrib</url>
+        </repository>
+        <snapshotRepository>
+            <id>atlassian-contrib-snapshot</id>
+            <name>Atlassian repository of contributed code snapshots</name>
+            <url>davs://maven.atlassian.com/contrib-snapshot</url>
+        </snapshotRepository>
+    </distributionManagement>
+</project>

src/main/java/com/atlassian/confluence/plugin/news/AbstractNewsAction.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.confluence.core.ConfluenceActionSupport;
+import com.atlassian.renderer.RenderContext;
+import com.atlassian.spring.container.ContainerManager;
+
+public class AbstractNewsAction extends ConfluenceActionSupport
+{
+    protected NewsService newsService;
+
+    public final void setNewsService(NewsService newsService)
+    {
+        this.newsService = newsService;
+    }
+
+    public final int getKarma()
+    {
+        return newsService.getUserKarma(getRemoteUser().getName());
+    }
+
+    public RenderContext getRenderContext()
+    {
+        return new RenderContext();
+    }
+
+    /** returns the 4.x renderer if it exists, otherwise null */
+    public final Object getViewRenderer()
+    {
+        try
+        {
+            return ContainerManager.getComponent("viewRenderer");
+        }
+        catch (Exception e)
+        {
+            return null;
+        }
+    }
+
+    /** returns the 3.x renderer if it exists, otherwise null */
+    public final Object getWikiStyleRenderer()
+    {
+        try
+        {
+            return ContainerManager.getComponent("wikiStyleRenderer");
+        }
+        catch (Exception e)
+        {
+            return null;
+        }
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/CommentSummary.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.confluence.pages.Comment;
+import com.google.common.collect.Lists;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+
+public class CommentSummary extends ItemSummary
+{
+    private final Object renderContent;
+    private final String replyUrl;
+    private final List<CommentSummary> children = Lists.newArrayList();
+    private final long parentId;
+    private final long itemId;
+    private final String itemTitle;
+
+    public CommentSummary(Comment comment, int score, boolean allowVote)
+    {
+        super(comment, score, allowVote);
+        this.replyUrl = "/pages/replycomment.action?commentId=" + comment.getId() + "&pageId=" + comment.getPage().getId();
+        this.parentId = comment.getParent() != null ? comment.getParent().getId() : 0;
+        this.itemId = comment.getOwner().getId();
+        this.itemTitle = comment.getOwner().getTitle();
+        String legacyContent = invokeGetContentMethod(comment, "getContent");
+        if (legacyContent != null)
+        {
+            this.renderContent = legacyContent;
+            return;
+        }
+        this.renderContent = comment; // need entire comment for rendering in 4.x
+    }
+
+    private String invokeGetContentMethod(Comment comment, String methodName)
+    {
+        try
+        {
+            Method legacyGetContentMethod = Comment.class.getMethod(methodName);
+            return (String) legacyGetContentMethod.invoke(comment);
+        }
+        catch (NoSuchMethodException e)
+        {
+            return null;
+        }
+        catch (IllegalAccessException e)
+        {
+            return null;
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new RuntimeException(e.getCause());
+        }
+    }
+
+    public Object getRenderContent()
+    {
+        return renderContent;
+    }
+
+    public String getReplyUrl()
+    {
+        return replyUrl;
+    }
+
+    public void addChild(CommentSummary commentSummary)
+    {
+        children.add(commentSummary);
+    }
+
+    public List<CommentSummary> getChildren()
+    {
+        List<CommentSummary> result = Lists.newArrayList(children);
+        Collections.sort(result, ItemSummaryRankComparator.getInstance());
+        return result;
+    }
+
+    public long getParentId()
+    {
+        return parentId;
+    }
+
+    public long getItemId()
+    {
+        return itemId;
+    }
+
+    public String getItemTitle()
+    {
+        return itemTitle;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/CommentsAction.java

+package com.atlassian.confluence.plugin.news;
+
+import java.util.List;
+
+public class CommentsAction extends AbstractNewsAction
+{
+    private List<CommentSummary> comments;
+
+    @Override
+    public String execute() throws Exception
+    {
+        comments = newsService.getNewestComments();
+        return SUCCESS;
+    }
+
+    public List<CommentSummary> getComments()
+    {
+        return comments;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/DefaultNewsService.java

+package com.atlassian.confluence.plugin.news;
+
+import bucket.core.persistence.hibernate.HibernateHandle;
+import com.atlassian.activeobjects.external.ActiveObjects;
+import com.atlassian.bonnie.Searchable;
+import com.atlassian.confluence.core.ContentEntityObject;
+import com.atlassian.confluence.pages.AbstractPage;
+import com.atlassian.confluence.pages.BlogPost;
+import com.atlassian.confluence.pages.Comment;
+import com.atlassian.confluence.pages.PageManager;
+import com.atlassian.confluence.renderer.PageContext;
+import com.atlassian.confluence.search.v2.ContentSearch;
+import com.atlassian.confluence.search.v2.InvalidSearchException;
+import com.atlassian.confluence.search.v2.SearchFilter;
+import com.atlassian.confluence.search.v2.SearchManager;
+import com.atlassian.confluence.search.v2.SearchResult;
+import com.atlassian.confluence.search.v2.SearchResults;
+import com.atlassian.confluence.search.v2.filter.SubsetResultFilter;
+import com.atlassian.confluence.search.v2.query.ContentTypeQuery;
+import com.atlassian.confluence.search.v2.searchfilter.ChainedSearchFilter;
+import com.atlassian.confluence.search.v2.searchfilter.ContentPermissionsSearchFilter;
+import com.atlassian.confluence.search.v2.searchfilter.SpacePermissionsSearchFilter;
+import com.atlassian.confluence.search.v2.sort.CreatedSort;
+import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
+import com.atlassian.hibernate.PluginHibernateSessionFactory;
+import com.atlassian.renderer.RenderContext;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Query;
+import net.sf.hibernate.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import static com.atlassian.confluence.search.service.ContentTypeEnum.BLOG;
+import static com.atlassian.confluence.search.service.ContentTypeEnum.COMMENT;
+import static com.atlassian.confluence.search.v2.SearchSort.Order.DESCENDING;
+
+public final class DefaultNewsService implements NewsService
+{
+    private static final Lock voteLock = new ReentrantLock();
+    private static final Logger log = LoggerFactory.getLogger(DefaultNewsService.class);
+    private static final int DISPLAY_COUNT = 30;
+
+    private ActiveObjects activeObjects;
+    private PluginHibernateSessionFactory sessionFactory;
+    private SearchManager searchManager;
+    private PageManager pageManager;
+
+    public DefaultNewsService(ActiveObjects activeObjects, PluginHibernateSessionFactory sessionFactory,
+        SearchManager searchManager, PageManager pageManager)
+    {
+        this.activeObjects = activeObjects;
+        this.sessionFactory = sessionFactory;
+        this.searchManager = searchManager;
+        this.pageManager = pageManager;
+    }
+
+    @Override
+    public List<ItemSummary> getTopRankedItems()
+    {
+        return getTopItemsBy(getRecentBlogPosts(), ItemSummaryRankComparator.getInstance());
+    }
+
+    @Override
+    public List<ItemSummary> getNewestItems()
+    {
+        return getTopItemsBy(getRecentBlogPosts(), ItemSummaryAgeComparator.getInstance());
+    }
+
+    @Override
+    public List<CommentSummary> getNewestComments()
+    {
+        List<CommentSummary> summaries = Lists.newArrayList();
+        for (Comment comment : getRecentComments())
+        {
+            if (!(comment.getOwner() instanceof BlogPost))
+                continue;
+            long id = comment.getId();
+            summaries.add(new CommentSummary(comment,
+                getItemVotes(id), canVote(id, comment.getCreatorName())));
+            if (summaries.size() >= 30) break;
+        }
+        Collections.sort(summaries, ItemSummaryAgeComparator.getInstance());
+        return summaries;
+    }
+
+    @Override
+    public ItemSummary getItemSummary(long contentId)
+    {
+        AbstractPage content = pageManager.getAbstractPage(contentId);
+        if (content == null || !(content instanceof BlogPost))
+            throw new IllegalStateException("No blog post with ID: " + contentId);
+
+        ItemSummary summary = new ItemSummary(content, getItemVotes(content.getId()),
+            canVote(content.getId(), content.getCreatorName()));
+        updateCommentCounts(Collections.singletonList(summary));
+        return summary;
+    }
+
+    private List<ItemSummary> getTopItemsBy(SearchResults results, Comparator<ItemSummary> sort)
+    {
+        List<ItemSummary> summaries = Lists.newArrayList();
+        for (SearchResult searchResult : results)
+        {
+            long id = ((HibernateHandle) searchResult.getHandle()).getId();
+            boolean allowVote = canVote(id, searchResult.getCreator());
+            summaries.add(new ItemSummary(searchResult, id, getItemVotes(id), allowVote));
+        }
+        Collections.sort(summaries, sort);
+        summaries = summaries.subList(0, Math.min(DISPLAY_COUNT, summaries.size()));
+        updateCommentCounts(summaries);
+        return summaries;
+    }
+
+    private List<Comment> getRecentComments()
+    {
+        try
+        {
+            // hide content that isn't permitted
+            SearchFilter filter = new ChainedSearchFilter(SpacePermissionsSearchFilter.getInstance(), ContentPermissionsSearchFilter.getInstance());
+            ContentSearch search = new ContentSearch(new ContentTypeQuery(COMMENT), new CreatedSort(DESCENDING),
+                filter, new SubsetResultFilter(100));
+            List<Comment> result = Lists.newArrayList();
+            for (Searchable searchable : searchManager.searchEntities(search))
+            {
+                result.add((Comment) searchable);
+            }
+            return result;
+        }
+        catch (InvalidSearchException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private SearchResults getRecentBlogPosts()
+    {
+        try
+        {
+            // hide content that isn't permitted
+            SearchFilter filter = new ChainedSearchFilter(SpacePermissionsSearchFilter.getInstance(), ContentPermissionsSearchFilter.getInstance());
+            ContentSearch search = new ContentSearch(new ContentTypeQuery(BLOG), new CreatedSort(DESCENDING),
+                filter, new SubsetResultFilter(200));
+            return searchManager.search(search);
+        }
+        catch (InvalidSearchException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public int getUserKarma(String user)
+    {
+        return activeObjects.count(VoteEntity.class, "AUTHOR = ?", user);
+    }
+
+    @Override
+    public int getItemVotes(long itemId)
+    {
+        return activeObjects.count(VoteEntity.class, "ITEMID = ?", itemId) + 1;
+    }
+
+    @Override
+    public boolean voteFor(long contentId)
+    {
+        ContentEntityObject content = pageManager.getById(contentId);
+        if (content == null)
+        {
+            log.error("Content not found: " + contentId);
+            return false;
+        }
+
+        String currentUser = AuthenticatedUserThreadLocal.getUsername();
+        voteLock.lock();
+        try
+        {
+            int existingVotes = activeObjects.count(VoteEntity.class, "ITEMID = ? AND VOTER = ?", content.getId(), currentUser);
+            if (existingVotes > 0) return false;
+
+            VoteEntity entity = activeObjects.create(VoteEntity.class);
+            entity.setItemId(content.getId());
+            entity.setAuthor(content.getCreatorName());
+            entity.setVoter(currentUser);
+            entity.save();
+        }
+        finally
+        {
+            voteLock.unlock();
+        }
+        return true;
+    }
+
+    @Override
+    public List<CommentSummary> getComments(long contentId)
+    {
+        ContentEntityObject content = pageManager.getById(contentId);
+        if (content == null)
+        {
+            log.error("Content not found: " + contentId);
+            return Collections.emptyList();
+        }
+
+        List<Comment> comments = content.getComments();
+        Map<Long, CommentSummary> commentsMap = Maps.newHashMap();
+        for (Comment comment : comments)
+        {
+            long id = comment.getId();
+            commentsMap.put(id, new CommentSummary(comment,
+                getItemVotes(id), canVote(id, comment.getCreatorName())));
+        }
+
+        List<CommentSummary> topLevelComments = Lists.newArrayList();
+        for (CommentSummary summary : commentsMap.values())
+        {
+            if (summary.getParentId() != 0)
+                commentsMap.get(summary.getParentId()).addChild(summary);
+            else
+                topLevelComments.add(summary);
+        }
+        Collections.sort(topLevelComments, ItemSummaryRankComparator.getInstance());
+        return topLevelComments;
+    }
+
+    @Override
+    public RenderContext getRenderContext(long contentId)
+    {
+        return new PageContext(pageManager.getById(contentId));
+    }
+
+    @Override
+    public List<UserKarma> getTopUsers()
+    {
+        Map<String, Long> allUsers = Maps.newHashMap();
+        VoteEntity[] votes = activeObjects.find(VoteEntity.class);
+        for (VoteEntity vote : votes)
+        {
+            String user = vote.getAuthor();
+            if (!allUsers.containsKey(user))
+                allUsers.put(user, 1L);
+            else
+                allUsers.put(user, allUsers.get(user) + 1);
+        }
+        List<UserKarma> topUsers = Lists.newArrayList();
+        for (Map.Entry<String, Long> entry : allUsers.entrySet())
+        {
+            topUsers.add(new UserKarma(entry.getKey(), entry.getValue()));
+        }
+        Collections.sort(topUsers);
+        topUsers = topUsers.subList(0, Math.min(DISPLAY_COUNT, topUsers.size()));
+        return topUsers;
+    }
+
+    @Override
+    public boolean canVote(long itemId, String author)
+    {
+        String currentUser = AuthenticatedUserThreadLocal.getUsername();
+        if (author.equalsIgnoreCase(currentUser))
+            return false;
+        return activeObjects.count(VoteEntity.class, "ITEMID = ? AND VOTER = ?", itemId, currentUser) == 0;
+    }
+
+    private void updateCommentCounts(List<ItemSummary> summaries)
+    {
+        Map<Long, ItemSummary> summaryMap = Maps.newLinkedHashMap(); /* preserve insertion order */
+        for (ItemSummary summary : summaries)
+        {
+            summaryMap.put(summary.getId(), summary);
+        }
+
+        Session session = sessionFactory.getSession();
+        try
+        {
+            final Query query = session.createQuery("select blog.id, count(comments) from BlogPost blog join blog.comments comments group by blog.id having blog.id in (:ids)");
+            query.setParameterList("ids", summaryMap.keySet());
+            //noinspection unchecked
+            for (Object[] idAndCount : (List<Object[]>) query.list())
+            {
+                long id = (Long) idAndCount[0];
+                int count = (Integer) idAndCount[1];
+                summaryMap.get(id).setComments(count);
+            }
+        }
+        catch (HibernateException e)
+        {
+            log.error("Couldn't retrieve comment count for news page", e);
+        }
+    }
+
+}

src/main/java/com/atlassian/confluence/plugin/news/ItemAction.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.renderer.RenderContext;
+
+import java.util.List;
+
+public class ItemAction extends AbstractNewsAction
+{
+    private long id;
+    private ItemSummary summary;
+    private List<CommentSummary> comments;
+
+    @Override
+    public String execute() throws Exception
+    {
+        summary = newsService.getItemSummary(id);
+        comments = newsService.getComments(id);
+
+        return SUCCESS;
+    }
+
+    public ItemSummary getSummary()
+    {
+        return summary;
+    }
+
+    public List<CommentSummary> getComments()
+    {
+        return comments;
+    }
+
+    public RenderContext getRenderContext()
+    {
+        return newsService.getRenderContext(id);
+    }
+
+    public void setId(long id)
+    {
+        this.id = id;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/ItemSummary.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.confluence.core.ContentEntityObject;
+import com.atlassian.confluence.pages.AbstractPage;
+import com.atlassian.confluence.search.v2.SearchResult;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class ItemSummary implements Comparable<ItemSummary>
+{
+    private static final long ONE_MINUTE_MILLIS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
+    private static final long ONE_HOUR_MILLIS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS);
+    private static final long ONE_DAY_MILLIS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
+    private static final double GRAVITY = 0.8;
+
+    private final long id;
+    private final String title;
+    private final String url;
+    private final long score;
+    private final String author;
+    private final long created;
+    private final boolean allowVote;
+    private String domain;
+    private int comments;
+
+    protected ItemSummary(long id, String title, String url, long score, String author, long created, boolean allowVote)
+    {
+        this.id = id;
+        this.title = checkNotNull(title, "title can't be null");
+        this.url = checkNotNull(url, "URL can't be null");
+        this.score = score;
+        this.author = checkNotNull(author, "author can't be null");
+        this.created = created;
+        this.allowVote = allowVote;
+    }
+
+    public ItemSummary(SearchResult searchResult, long id, int score, boolean allowVote)
+    {
+        this(id, searchResult.getDisplayTitle(), searchResult.getUrlPath(), score, searchResult.getCreator(), searchResult.getCreationDate().getTime(), allowVote);
+        this.domain = searchResult.getSpaceName();
+    }
+
+    public ItemSummary(AbstractPage content, int score, boolean allowVote)
+    {
+        this(content.getId(), content.getDisplayTitle(), content.getUrlPath(), score, content.getCreatorName(), content.getCreationDate().getTime(), allowVote);
+        this.domain = content.getSpace().getName();
+    }
+
+    public ItemSummary(ContentEntityObject content, int score, boolean allowVote)
+    {
+        this(content.getId(), content.getDisplayTitle(), content.getUrlPath(), score, content.getCreatorName(), content.getCreationDate().getTime(), allowVote);
+    }
+
+    public long getId()
+    {
+        return id;
+    }
+
+    public String getTitle()
+    {
+        return title;
+    }
+
+    public String getUrl()
+    {
+        return url;
+    }
+
+    public String getDomain()
+    {
+        return domain;
+    }
+
+    public long getScore()
+    {
+        return score;
+    }
+
+    public String getAuthor()
+    {
+        return author;
+    }
+
+    public long getCreated()
+    {
+        return created;
+    }
+
+    public boolean isAllowVote()
+    {
+        return allowVote;
+    }
+
+    public double getFrontPageRank()
+    {
+        return (score - 1) / Math.pow(getAgeInHours() + 2, GRAVITY);
+    }
+
+    public String getFriendlyAge()
+    {
+        long age = System.currentTimeMillis() - created;
+        if (age < ONE_HOUR_MILLIS) {
+            long ageInMinutes = age / ONE_MINUTE_MILLIS;
+            return ageInMinutes + (ageInMinutes == 1 ? " minute" : " minutes") + " ago";
+        }
+        if (age < ONE_DAY_MILLIS) {
+            long ageInHours = age / ONE_HOUR_MILLIS;
+            return ageInHours + (ageInHours == 1 ? " hour" : " hours") + " ago";
+        }
+        long ageInDays = age / ONE_DAY_MILLIS;
+        return ageInDays + (ageInDays == 1 ? " day" : " days") + " ago";
+    }
+
+    private long getAgeInHours()
+    {
+        return (System.currentTimeMillis() - created) / ONE_HOUR_MILLIS;
+    }
+
+    public int getComments()
+    {
+        return comments;
+    }
+
+    public void setComments(int comments)
+    {
+        this.comments = comments;
+    }
+
+    public int compareTo(ItemSummary other)
+    {
+        return Double.compare(other.getFrontPageRank(), getFrontPageRank());
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/ItemSummaryAgeComparator.java

+package com.atlassian.confluence.plugin.news;
+
+import java.util.Comparator;
+
+/**
+ * Newest items first.
+ */
+public class ItemSummaryAgeComparator implements Comparator<ItemSummary>
+{
+    private static final Comparator<ItemSummary> INSTANCE = new ItemSummaryAgeComparator();
+
+    public static Comparator<ItemSummary> getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private ItemSummaryAgeComparator() {}
+
+    @Override
+    public int compare(ItemSummary o1, ItemSummary o2)
+    {
+        return ((Long) o2.getCreated()).compareTo(o1.getCreated());
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/ItemSummaryRankComparator.java

+package com.atlassian.confluence.plugin.news;
+
+import java.util.Comparator;
+
+/**
+ * Sorts by descending values of {@link ItemSummary#getFrontPageRank()}.
+ */
+public class ItemSummaryRankComparator implements Comparator<ItemSummary>
+{
+    private static final Comparator<ItemSummary> INSTANCE = new ItemSummaryRankComparator();
+
+    public static Comparator<ItemSummary> getInstance()
+    {
+        return INSTANCE;
+    }
+
+    private ItemSummaryRankComparator() {}
+
+    @Override
+    public int compare(ItemSummary o1, ItemSummary o2)
+    {
+        return Double.compare(o2.getFrontPageRank(), o1.getFrontPageRank());
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/NewsAction.java

+package com.atlassian.confluence.plugin.news;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+public final class NewsAction extends AbstractNewsAction
+{
+    private List<ItemSummary> summaries = Lists.newArrayList();
+
+    public String showTopRanked() throws Exception
+    {
+        this.summaries = newsService.getTopRankedItems();
+        return SUCCESS;
+    }
+
+    public String showNewest() throws Exception
+    {
+        this.summaries = newsService.getNewestItems();
+        return SUCCESS;
+    }
+
+    public List<ItemSummary> getSummaries()
+    {
+        return summaries;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/NewsService.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.renderer.RenderContext;
+
+import java.util.List;
+import java.util.Map;
+
+public interface NewsService
+{
+    List<ItemSummary> getTopRankedItems();
+
+    List<ItemSummary> getNewestItems();
+
+    List<CommentSummary> getNewestComments();
+
+    ItemSummary getItemSummary(long contentId);
+
+    int getUserKarma(String user);
+        
+    boolean canVote(long itemId, String author);
+
+    int getItemVotes(long itemId);
+
+    boolean voteFor(long contentId);
+
+    List<CommentSummary> getComments(long contentId);
+
+    RenderContext getRenderContext(long id);
+
+    List<UserKarma> getTopUsers();
+}

src/main/java/com/atlassian/confluence/plugin/news/ResetVotesAction.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.activeobjects.external.ActiveObjects;
+import com.atlassian.confluence.core.ConfluenceActionSupport;
+
+public class ResetVotesAction extends ConfluenceActionSupport
+{
+    private ActiveObjects activeObjects;
+
+    @Override
+    public String execute() throws Exception
+    {
+        if (isNewsManager())
+        {
+            // may be slow, but there isn't a better way as far as I can tell
+            for (VoteEntity vote : activeObjects.find(VoteEntity.class))
+            {
+                activeObjects.delete(vote);
+            }
+        }
+        return SUCCESS;
+    }
+
+    private boolean isNewsManager()
+    {
+        final String currentUser = getRemoteUser().getName();
+        return "mryall".equals(currentUser) || "matt@atlassian.com".equals(currentUser) || "admin".equals(currentUser);
+    }
+
+    public void setActiveObjects(ActiveObjects activeObjects)
+    {
+        this.activeObjects = activeObjects;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/UserAction.java

+package com.atlassian.confluence.plugin.news;
+
+public class UserAction extends AbstractNewsAction
+{
+    private String name;
+
+    @Override
+    public String execute() throws Exception
+    {
+        return SUCCESS;
+    }
+
+    public int getUserKarma()
+    {
+        return newsService.getUserKarma(name);
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/UserKarma.java

+package com.atlassian.confluence.plugin.news;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class UserKarma implements Comparable<UserKarma>
+{
+    private final String name;
+    private final long karma;
+
+    public UserKarma(String name, long karma)
+    {
+        this.name = checkNotNull(name);
+        this.karma = karma;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public long getKarma()
+    {
+        return karma;
+    }
+
+    @Override
+    public int compareTo(UserKarma o)
+    {
+        return Long.valueOf(o.karma).compareTo(karma);
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/UsersAction.java

+package com.atlassian.confluence.plugin.news;
+
+import java.util.List;
+
+public class UsersAction extends AbstractNewsAction
+{
+    private List<UserKarma> users;
+
+    @Override
+    public String execute() throws Exception
+    {
+        users = newsService.getTopUsers();
+        return SUCCESS;
+    }
+
+    public List<UserKarma> getUsers()
+    {
+        return users;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/VoteAction.java

+package com.atlassian.confluence.plugin.news;
+
+import com.atlassian.confluence.core.ConfluenceActionSupport;
+
+public final class VoteAction extends AbstractNewsAction
+{
+    private long id;
+
+    public String execute() throws Exception
+    {
+        newsService.voteFor(id);
+        return SUCCESS;
+    }
+
+    public void setId(long id)
+    {
+        this.id = id;
+    }
+}

src/main/java/com/atlassian/confluence/plugin/news/VoteEntity.java

+package com.atlassian.confluence.plugin.news;
+
+import net.java.ao.Entity;
+import net.java.ao.schema.Indexed;
+
+public interface VoteEntity extends Entity
+{
+    @Indexed
+    long getItemId();
+    void setItemId(long id);
+
+    @Indexed
+    String getVoter();
+    void setVoter(String voter);
+
+    void setAuthor(String author);
+    String getAuthor();
+}

src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
+    </plugin-info>
+
+    <ao key="ao-entities" name="Active Objects Entities">
+        <entity>com.atlassian.confluence.plugin.news.VoteEntity</entity>
+    </ao>
+
+    <component-import key="activeObjects" interface="com.atlassian.activeobjects.external.ActiveObjects"/>
+    <component-import key="pageManager" interface="com.atlassian.confluence.pages.PageManager"/>
+
+    <component key="newsService" class="com.atlassian.confluence.plugin.news.DefaultNewsService" public="true">
+        <interface>com.atlassian.confluence.plugin.news.NewsService</interface>
+    </component>
+
+    <xwork key="news-plugin-actions" name="News Plugin Actions">
+        <package name="news" extends="default" namespace="/plugins/news">
+            <default-interceptor-ref name="defaultStack"/>
+            <action name="list" class="com.atlassian.confluence.plugin.news.NewsAction" method="showTopRanked">
+                <result name="success" type="velocity">/news/news.vm</result>
+            </action>
+            <action name="newest" class="com.atlassian.confluence.plugin.news.NewsAction" method="showNewest">
+                <result name="success" type="velocity">/news/news.vm</result>
+            </action>
+            <action name="item" class="com.atlassian.confluence.plugin.news.ItemAction">
+                <result name="success" type="velocity">/news/item.vm</result>
+            </action>
+            <action name="vote" class="com.atlassian.confluence.plugin.news.VoteAction">
+                <result name="success" type="redirect">/plugins/news/list.action</result>
+                <result name="error" type="velocity">/news/vote-failed.vm</result>
+            </action>
+            <action name="reset" class="com.atlassian.confluence.plugin.news.ResetVotesAction">
+                <result name="success" type="redirect">/plugins/news/list.action</result>
+            </action>
+            <action name="users" class="com.atlassian.confluence.plugin.news.UsersAction">
+                <result name="success" type="velocity">/news/users.vm</result>
+            </action>
+            <action name="user" class="com.atlassian.confluence.plugin.news.UserAction">
+                <result name="success" type="velocity">/news/user.vm</result>
+            </action>
+            <action name="comments" class="com.atlassian.confluence.plugin.news.CommentsAction">
+                <result name="success" type="velocity">/news/comments.vm</result>
+            </action>
+        </package>
+    </xwork>
+
+    <web-resource key="resources" name="News Plugin Web Resources">
+        <resource type="download" name="news.css" location="news/news.css"/>
+        <resource type="download" name="news.js" location="news/news.js"/>
+        <context>com.atlassian.confluence.plugin.news</context>
+    </web-resource>
+
+    <web-item key="global-menu-item" name="People Directory" section="system.browse/global" weight="15">
+        <label>Atlassian News</label>
+        <link linkId="atlassian-news-link">/plugins/news/list.action</link>
+    </web-item>
+
+    <resource type="download" name="an.gif" location="news/an.gif"/>
+    <resource type="download" name="an-blue.gif" location="news/an-blue.gif"/>
+
+</atlassian-plugin>
Add a comment to this file

src/main/resources/news/an-blue.gif

Added
New image
Add a comment to this file

src/main/resources/news/an.gif

Added
New image

src/main/resources/news/comment.vm

+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.ItemAction" *#
+#* @vtlvariable name="c" type="com.atlassian.confluence.plugin.news.CommentSummary" *#
+<div class="comment vote-target">
+    <div class="comment-header">
+            #if ($c.author.equalsIgnoreCase($action.remoteUser.name))
+                <span class="mine">*</span>
+            #else
+                <span class="vote-up">
+                    #if ($c.allowVote)
+                        <a href="${req.contextPath}/plugins/news/vote.action?id=$c.id">&#x25b2;</a>
+                    #else
+                        &nbsp;
+                    #end
+                </span>
+            #end
+        <span class="points">${c.score}#if($c.score == 1) point#else points#end</span>
+        <span class="author">by <a href="/display/~$c.author">$c.author</a></span>
+        <span class="age">$c.friendlyAge</span>
+        <span class="link">| <a href="$req.contextPath$c.url">link</a></span>
+        #if ($showItemLink)
+            <span class="item">| on <a href="$req.contextPath/plugins/news/item.action?id=$c.itemId">$!c.itemTitle</a></span>
+        #end
+    </div>
+    <div class="comment-body">
+        #if ($action.viewRenderer) ## 4.0 rendering
+            $action.viewRenderer.render($c.renderContent)
+        #else ## legacy 3.5 rendering
+            $action.wikiStyleRenderer.convertWikiToXHtml($action.renderContext, $c.renderContent)
+        #end
+    </div>
+    <div class="comment-footer">
+        <a href="$req.contextPath$c.replyUrl">reply</a>
+    </div>
+    #set ($children = $c.children)
+    #if (!$children.empty)
+        <div class="comment-children">
+            #foreach($c in $children)
+                #parse("/news/comment.vm") ## recursive - look out!
+            #end
+        </div>
+    #end
+</div>

src/main/resources/news/comments.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.CommentsAction" *#
+#htmlSafe()
+$webResourceManager.requireResourcesForContext("com.atlassian.confluence.plugin.news")
+<html>
+<head>
+    <title>Atlassian News - New Comments</title>
+    <meta name="decorator" content="atl.general">
+    <!-- HACK: find a better way of doing this -->
+    <content tag="breadcrumbs">
+        <ol id="breadcrumbs">
+            <li class="first"><a href="$req.contextPath/dashboard.action">Dashboard</a></li>
+            <li><a href="$req.contextPath/plugins/news/list.action">Atlassian News</a></li>
+            <li>New Comments</li>
+        </ol>
+    </content>
+    <content tag="bodyClass">atlassian-news</content><!-- TODO: restyle the header and footer to fit -->
+</head>
+<body>
+<div id="atlassian-news">
+    #parse("/news/header.vm")
+    <div class="body">
+        <div class="newest-comments">
+            #foreach ($c in $action.comments)
+                #set ($showItemLink = true)
+                #parse("/news/comment.vm")
+            #end
+        </div>
+    </div>
+</div>
+</body>
+</html>

src/main/resources/news/header.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.AbstractNewsAction" *#
+<div class="header">
+    <a href="$req.contextPath/plugins/news/list.action"><img class="logo" src="$req.contextPath/download/resources/com.atlassian.confluence.plugin.news/an-blue.gif"></a>
+    <h1><a href="$req.contextPath/plugins/news/list.action">Atlassian News</a></h1>
+    <ul class="operations">
+        <li><a href="${req.contextPath}/plugins/news/newest.action">new</a></li>
+        <li><a href="${req.contextPath}/plugins/news/comments.action">comments</a></li>
+        <li><a href="${req.contextPath}/plugins/news/users.action">leaders</a></li>
+        <li><a href="${req.contextPath}/pages/createblogpost.action?spaceKey=~$action.remoteUser.name">submit</a></li>
+    </ul>
+    <span class="current-user">
+        <a href="$req.contextPath/plugins/news/user.action?name=$action.remoteUser.name">$action.remoteUser.name</a>
+        ($action.karma)
+    </span>
+</div>

src/main/resources/news/item-summary.vm

+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.ItemAction" *#
+#* @vtlvariable name="s" type="com.atlassian.confluence.plugin.news.ItemSummary" *#
+#* @vtlvariable name="req" type="javax.servlet.http.HttpServletRequest" *#
+<div class="summary vote-target">
+    <div class="primary">
+        <span class="number">#if ($velocityCount) ${velocityCount}. #else &nbsp; #end</span>
+        #if ($s.author.equalsIgnoreCase($action.remoteUser.name))
+            <span class="mine">*</span>
+        #else
+            <span class="vote-up">
+                #if ($s.allowVote)
+                    <a href="${req.contextPath}/plugins/news/vote.action?id=$s.id">&#x25b2;</a>
+                #else
+                    &nbsp;
+                #end
+            </span>
+        #end
+        <span class="title"><a href="$!req.contextPath$!s.url">$!s.title</a></span>
+        <span class="domain">($s.domain)</span>
+        #if ($req.getParameter("r"))
+            <span class="rank">rank: $s.frontPageRank</span>
+        #end
+    </div>
+    <div class="secondary">
+        <span class="points">${s.score}#if($s.score == 1) point#else points#end</span>
+        <span class="author">by <a href="$req.contextPath/plugins/news/user.action?name=$s.author">$s.author</a></span>
+        <span class="age">$s.friendlyAge</span>
+        |
+        <span class="comment-count"><a href="${req.contextPath}/plugins/news/item.action?id=$s.id">$s.comments
+            #if($s.comments == 1) comment#else comments#end</a></span>
+    </div>
+</div>

src/main/resources/news/item.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.ItemAction" *#
+#htmlSafe()
+$webResourceManager.requireResourcesForContext("com.atlassian.confluence.plugin.news")
+<html>
+<head>
+    <title>Atlassian News - $action.summary.title</title>
+    <meta name="decorator" content="atl.general">
+    <!-- HACK: find a better way of doing this -->
+    <content tag="breadcrumbs">
+        <ol id="breadcrumbs">
+            <li class="first"><a href="$req.contextPath/dashboard.action">Dashboard</a></li>
+            <li><a href="$req.contextPath/plugins/news/list.action">Atlassian News</a></li>
+            <li>$action.summary.title</li>
+        </ol>
+    </content>
+    <content tag="bodyClass">atlassian-news</content><!-- TODO: restyle the header and footer to fit -->
+</head>
+<body>
+<div id="atlassian-news">
+    #parse("/news/header.vm")
+    <div class="body">
+        #set($s = $action.summary)
+        #parse("/news/item-summary.vm")
+
+        <div class="comments">
+            #foreach ($c in $action.comments)
+                #parse("/news/comment.vm")
+            #end
+        </div>
+    </div>
+</div>
+</body>
+</html>

src/main/resources/news/news.css

+#title-heading {
+    display: none;
+}
+#atlassian-news ol,
+#atlassian-news ul,
+#atlassian-news li {
+    list-style: none;
+    margin: 0;
+    padding: 0;
+}
+#atlassian-news {
+    font-family: Verdana, sans-serif;
+    font-size: 13px;
+    width: 85%;
+    margin: 0 auto; /* centre the box */
+}
+#atlassian-news a {
+    text-decoration: none;
+}
+#atlassian-news .domain {
+    font-size: 11px;
+}
+#atlassian-news .secondary,
+#atlassian-news .vote-up {
+    font-size: 9px;
+}
+#atlassian-news .secondary a:hover,
+#atlassian-news .comment-header a:hover {
+    text-decoration: underline;
+}
+#atlassian-news .header {
+    overflow: hidden;
+}
+#atlassian-news .logo {
+    float: left;
+    margin: 2px;
+    border: 1px solid #fff;
+}
+#atlassian-news .header h1 {
+    font-size: 13px;
+    font-weight: bold;
+    float: left;
+    margin: 0;
+    padding: 4px 8px 4px 4px;
+}
+#atlassian-news .header ul {
+    float: left;
+}
+#atlassian-news .header li {
+    float: left;
+    padding: 4px 2px;
+}
+#atlassian-news .header li:before {
+    content: "| ";
+}
+#atlassian-news .header li:first-child:before {
+    content: none;
+}
+#atlassian-news .current-user {
+    float: right;
+    padding: 3px 10px 3px 2px;
+}
+#atlassian-news .body {
+    padding: 10px 0;
+}
+#atlassian-news .body .summary {
+    margin-bottom: 5px;
+}
+#atlassian-news .empty {
+    margin: 10px;
+}
+
+#atlassian-news .vote-up,
+#atlassian-news .number {
+    display: inline-block;
+    text-align: right;
+}
+#atlassian-news .number {
+    width: 22px;
+}
+#atlassian-news .vote-up,
+#atlassian-news .mine {
+    width: 8px;
+    margin-left: -2px;
+}
+#atlassian-news .summary .secondary {
+    margin-left: 38px;
+}
+
+#atlassian-news .comments {
+    margin: 30px 38px 10px;
+}
+#atlassian-news .comment {
+    margin: 15px 0;
+}
+#atlassian-news .comment-header {
+    font-size: 11px;
+    margin-left: -11px;
+}
+#atlassian-news .comment-body {
+    margin: 5px 0;
+}
+#atlassian-news .comment-footer {
+    font-size: 9px;
+    margin-top: 5px;
+}
+#atlassian-news .comment-body a,
+#atlassian-news .comment-footer a {
+    text-decoration: underline;
+}
+#atlassian-news .comment-body,
+#atlassian-news .comment-body p,
+#atlassian-news .comment-body td,
+#atlassian-news .comment-body li {
+    font-size: 12px;
+}
+#atlassian-news .comment-body p,
+#atlassian-news .comment-body li {
+    margin: 0;
+}
+#atlassian-news .comment-children {
+    margin-left: 30px;
+}
+#atlassian-news .newest-comments {
+    margin: 10px 30px;
+}
+#atlassian-news .users .user {
+    width: 100px;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
+#atlassian-news .users .karma {
+    text-align: right;
+    width: 40px;
+}
+#atlassian-news table.user {
+    margin: 10px 20px;
+}
+#atlassian-news table.user th {
+    width: 60px;
+    font-weight: normal;
+}
+
+/* Colours */
+#atlassian-news .header {
+    background: #4466ff;
+    color: #000;
+}
+#atlassian-news .body {
+    background-color: #efeff6;
+    color: #828282;
+}
+#atlassian-news a:link,
+#atlassian-news a:visited,
+#atlassian-news .comment-body {
+    color: #000;
+}
+#atlassian-news .secondary a:link,
+#atlassian-news .secondary a:visited,
+#atlassian-news .comment-header a:link,
+#atlassian-news .comment-header a:visited,
+#atlassian-news .vote-up a:link,
+#atlassian-news .vote-up a:visited,
+#atlassian-news table.user td,
+#atlassian-news table.user th,
+#atlassian-news table.users td {
+    color: #828282;
+}
+#atlassian-news .mine {
+    color: #4466ff;
+    font-size: 13px;
+}
+#atlassian-news .vote-up a:hover {
+    text-decoration: none;
+}

src/main/resources/news/news.js

+jQuery(function ($) {
+    $(".vote-up > a").click(function (e) {
+        var $link = $(this);
+        $.get($link.attr("href")); // load it in the background
+        var $points = $link.closest(".vote-target").find(".points:first");
+        var newPoints = +$points.text().replace(/(\d+).*/, "$1") + 1;
+        $points.text(newPoints + " points");
+        $link.remove();
+        return false;
+    });
+});

src/main/resources/news/news.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.NewsAction" *#
+#htmlSafe()
+$webResourceManager.requireResourcesForContext("com.atlassian.confluence.plugin.news")
+<html>
+<head>
+    <title>Atlassian News</title>
+    <meta name="decorator" content="atl.general">
+    <!-- HACK: find a better way of doing this -->
+    <content tag="breadcrumbs">
+        <ol id="breadcrumbs">
+            <li class="first"><a href="$req.contextPath/dashboard.action">Dashboard</a></li>
+            <li>Atlassian News</li>
+        </ol>
+    </content>
+    <content tag="bodyClass">atlassian-news</content><!-- TODO: restyle the header and footer to fit -->
+</head>
+<body>
+<div id="atlassian-news">
+    #parse("/news/header.vm")
+    <div class="body">
+        <ol class="summaries">
+            #foreach($s in $action.summaries)
+                <li>
+                    #parse("/news/item-summary.vm")
+                </li>
+            #end
+            #if ($action.summaries.empty)
+                <li class="empty">No news found.</li>
+            #end
+        </ol>
+    </div>
+</div>
+</body>
+</html>

src/main/resources/news/user.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.UserAction" *#
+#htmlSafe()
+$webResourceManager.requireResourcesForContext("com.atlassian.confluence.plugin.news")
+<html>
+<head>
+    <title>Atlassian News - Profile: $action.name</title>
+    <meta name="decorator" content="atl.general">
+    <!-- HACK: find a better way of doing this -->
+    <content tag="breadcrumbs">
+        <ol id="breadcrumbs">
+            <li class="first"><a href="$req.contextPath/dashboard.action">Dashboard</a></li>
+            <li><a href="$req.contextPath/plugins/news/list.action">Atlassian News</a></li>
+            <li>Profile: $action.name</li>
+        </ol>
+    </content>
+    <content tag="bodyClass">atlassian-news</content><!-- TODO: restyle the header and footer to fit -->
+</head>
+<body>
+<div id="atlassian-news">
+    #parse("/news/header.vm")
+    <div class="body">
+        <table class="user">
+            <tr>
+                <th>user:</th>
+                <td class="name">$action.name</td>
+            </tr>
+            <tr>
+                <th>karma:</th>
+                <td class="karma">$action.userKarma</td>
+            </tr>
+        </table>
+    </div>
+</div>
+</body>
+</html>

src/main/resources/news/users.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#* @vtlvariable name="action" type="com.atlassian.confluence.plugin.news.UsersAction" *#
+#htmlSafe()
+$webResourceManager.requireResourcesForContext("com.atlassian.confluence.plugin.news")
+<html>
+<head>
+    <title>Atlassian News - Users</title>
+    <meta name="decorator" content="atl.general">
+    <!-- HACK: find a better way of doing this -->
+    <content tag="breadcrumbs">
+        <ol id="breadcrumbs">
+            <li class="first"><a href="$req.contextPath/dashboard.action">Dashboard</a></li>
+            <li><a href="$req.contextPath/plugins/news/list.action">Atlassian News</a></li>
+            <li>Leaders</li>
+        </ol>
+    </content>
+    <content tag="bodyClass">atlassian-news</content><!-- TODO: restyle the header and footer to fit -->
+</head>
+<body>
+<div id="atlassian-news">
+    #parse("/news/header.vm")
+    <div class="body">
+        <table class="users">
+        #foreach($u in $action.users)
+            <tr>
+                <td class="number">$velocityCount.</td>
+                <td class="user"><a href="$req.contextPath/plugins/news/user.action?name=$u.name">$u.name</a></td>
+                <td class="karma">$u.karma</td>
+            </tr>
+        #end
+        </table>
+    </div>
+</div>
+</body>
+</html>

src/main/resources/news/vote-failed.vm

+#* @vtlvariable name="webResourceManager" type="com.atlassian.plugin.webresource.WebResourceManager" *#
+#htmlSafe()
+$webResourceManager.requireResourcesForContext("com.atlassian.confluence.plugin.news")
+<html>
+<head>
+    <title>Vote failed - Atlassian News</title>
+    <meta name="decorator" content="atl.general">
+</head>
+<body>
+<div id="atlassian-news">
+    <p>Sorry, your vote failed to register. Try again later.</p>
+</div>
+</body>
+</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.