[completed: 572] RSS.aspx now displays the full user name, when available, instead of username.

This commit is contained in:
Dario Solera 2011-07-12 08:48:19 +02:00
parent 1feca4c025
commit 2b453bdf38
2 changed files with 65 additions and 105 deletions

View file

@ -16,5 +16,5 @@ using System.Reflection;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.4.577")] [assembly: AssemblyVersion("3.0.4.578")]
[assembly: AssemblyFileVersion("3.0.4.577")] [assembly: AssemblyFileVersion("3.0.4.578")]

View file

@ -70,17 +70,14 @@ namespace ScrewTurn.Wiki {
PageContent content = Content.GetPageContent(page, true); PageContent content = Content.GetPageContent(page, true);
if(Request["Discuss"] == null) { if(Request["Discuss"] == null) {
// Check permission for the page // Check permission for the page
bool canReadPage = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage, bool canReadPage = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage, currentUsername, currentGroups);
currentUsername, currentGroups);
if(!canReadPage) { if(!canReadPage) {
Response.StatusCode = 401; Response.StatusCode = 401;
return; return;
} }
// Start an XML writer for the output stream // Start an XML writer for the output stream
using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) using(XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
{
// Build an RSS header // Build an RSS header
BuildRssHeader(rss); BuildRssHeader(rss);
@ -97,21 +94,22 @@ namespace ScrewTurn.Wiki {
rss.WriteEndElement(); rss.WriteEndElement();
rss.WriteElementString("link", Settings.MainUrl + page.FullName + Settings.PageExtension); rss.WriteElementString("link", Settings.MainUrl + page.FullName + Settings.PageExtension);
UserInfo user = Users.FindUser(content.User);
string username = user != null ? Users.GetDisplayName(user) : content.User;
// Create the description tag // Create the description tag
rss.WriteStartElement("description"); rss.WriteStartElement("description");
if (rssFeedsMode == RssFeedsMode.Summary) if(rssFeedsMode == RssFeedsMode.Summary) {
{
rss.WriteCData(Formatter.StripHtml(content.Title) + ": " + Properties.Messages.ThePageHasBeenUpdatedBy + " " + rss.WriteCData(Formatter.StripHtml(content.Title) + ": " + Properties.Messages.ThePageHasBeenUpdatedBy + " " +
content.User + (content.Comment.Length > 0 ? ".<br />" + content.Comment : ".")); username + (content.Comment.Length > 0 ? ".<br />" + content.Comment : "."));
} }
else else {
{
rss.WriteCData(Content.GetFormattedPageContent(page, false)); rss.WriteCData(Content.GetFormattedPageContent(page, false));
} }
rss.WriteEndElement(); rss.WriteEndElement();
// Write the remaining elements // Write the remaining elements
BuildAuthorTag(rss, content.User); rss.WriteElementString("author", username);
rss.WriteElementString("pubDate", content.LastModified.ToUniversalTime().ToString("R")); rss.WriteElementString("pubDate", content.LastModified.ToUniversalTime().ToString("R"));
rss.WriteStartElement("guid"); rss.WriteStartElement("guid");
rss.WriteAttributeString("isPermaLink", "false"); rss.WriteAttributeString("isPermaLink", "false");
@ -130,14 +128,11 @@ namespace ScrewTurn.Wiki {
// Finish off // Finish off
rss.Flush(); rss.Flush();
rss.Close(); rss.Close();
} }
} }
else { else {
// Check permission for the discussion // Check permission for the discussion
bool canReadDiscussion = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadDiscussion, bool canReadDiscussion = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);
currentUsername, currentGroups);
if(!canReadDiscussion) { if(!canReadDiscussion) {
Response.StatusCode = 401; Response.StatusCode = 401;
return; return;
@ -150,9 +145,7 @@ namespace ScrewTurn.Wiki {
messages.Sort(new MessageDateTimeComparer(true)); messages.Sort(new MessageDateTimeComparer(true));
// Start an XML writer for the output stream // Start an XML writer for the output stream
using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) using(XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
{
// Build an RSS header // Build an RSS header
BuildRssHeader(rss); BuildRssHeader(rss);
@ -162,9 +155,7 @@ namespace ScrewTurn.Wiki {
Settings.MainUrl + UrlTools.BuildUrl("RSS.aspx?Page=", page.FullName, "&Discuss=1"), Settings.MainUrl + UrlTools.BuildUrl("RSS.aspx?Page=", page.FullName, "&Discuss=1"),
Settings.WikiTitle + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)) + " - Discussion Updates"); Settings.WikiTitle + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)) + " - Discussion Updates");
for (int i = 0; i < messages.Count; i++) for(int i = 0; i < messages.Count; i++) {
{
// Write the item element // Write the item element
rss.WriteStartElement("item"); rss.WriteStartElement("item");
rss.WriteStartElement("title"); rss.WriteStartElement("title");
@ -172,20 +163,21 @@ namespace ScrewTurn.Wiki {
rss.WriteEndElement(); rss.WriteEndElement();
rss.WriteElementString("link", Settings.MainUrl + page.FullName + Settings.PageExtension + "?Discuss=1"); rss.WriteElementString("link", Settings.MainUrl + page.FullName + Settings.PageExtension + "?Discuss=1");
UserInfo user = Users.FindUser(messages[i].Username);
string username = user != null ? Users.GetDisplayName(user) : messages[i].Username;
// Create the description tag // Create the description tag
rss.WriteStartElement("description"); rss.WriteStartElement("description");
if (rssFeedsMode == RssFeedsMode.Summary) if(rssFeedsMode == RssFeedsMode.Summary) {
{ rss.WriteCData(Properties.Messages.AMessageHasBeenPostedBy.Replace("##SUBJECT##", messages[i].Subject) + " " + username + ".");
rss.WriteCData(Properties.Messages.AMessageHasBeenPostedBy.Replace("##SUBJECT##", messages[i].Subject) + " " + messages[i].Username + ".");
} }
else else {
{
rss.WriteCData(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(messages[i].Body, false, FormattingContext.MessageBody, page), FormattingContext.MessageBody, page)); rss.WriteCData(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(messages[i].Body, false, FormattingContext.MessageBody, page), FormattingContext.MessageBody, page));
} }
rss.WriteEndElement(); rss.WriteEndElement();
// Write the remaining elements // Write the remaining elements
BuildAuthorTag(rss, messages[i].Username); rss.WriteElementString("author", username);
rss.WriteElementString("pubDate", messages[i].DateTime.ToUniversalTime().ToString("R")); rss.WriteElementString("pubDate", messages[i].DateTime.ToUniversalTime().ToString("R"));
rss.WriteStartElement("guid"); rss.WriteStartElement("guid");
rss.WriteAttributeString("isPermaLink", "false"); rss.WriteAttributeString("isPermaLink", "false");
@ -194,7 +186,6 @@ namespace ScrewTurn.Wiki {
// Complete the item element // Complete the item element
CompleteCurrentElement(rss); CompleteCurrentElement(rss);
} }
// Complete the channel element // Complete the channel element
@ -206,12 +197,9 @@ namespace ScrewTurn.Wiki {
// Finish off // Finish off
rss.Flush(); rss.Flush();
rss.Close(); rss.Close();
}
} }
} }
}
else { else {
if(Request["Discuss"] == null) { if(Request["Discuss"] == null) {
// All page updates // All page updates
@ -242,7 +230,7 @@ namespace ScrewTurn.Wiki {
// Suppress this entry if we've already reported this page (so we don't create duplicate entries in the feed page) // Suppress this entry if we've already reported this page (so we don't create duplicate entries in the feed page)
bool duplicateFound = false; bool duplicateFound = false;
for(int j = 0; j < i; j++) { for(int j = 0; j < i; j++) {
if (ch[j].Page == ch[i].Page) { if(ch[j].Page == ch[i].Page) {
duplicateFound = true; duplicateFound = true;
break; break;
} }
@ -255,8 +243,7 @@ namespace ScrewTurn.Wiki {
PageInfo p = Pages.FindPage(ch[i].Page); PageInfo p = Pages.FindPage(ch[i].Page);
if(p != null) { if(p != null) {
// Check permissions for every page // Check permissions for every page
bool canReadThisPage = AuthChecker.CheckActionForPage(p, Actions.ForPages.ReadPage, bool canReadThisPage = AuthChecker.CheckActionForPage(p, Actions.ForPages.ReadPage, currentUsername, currentGroups);
currentUsername, currentGroups);
if(!canReadThisPage) continue; if(!canReadThisPage) continue;
if(useCat) { if(useCat) {
@ -286,11 +273,16 @@ namespace ScrewTurn.Wiki {
rss.WriteStartElement("title"); rss.WriteStartElement("title");
rss.WriteCData(Formatter.StripHtml(FormattingPipeline.PrepareTitle(ch[i].Title, false, FormattingContext.PageContent, p))); rss.WriteCData(Formatter.StripHtml(FormattingPipeline.PrepareTitle(ch[i].Title, false, FormattingContext.PageContent, p)));
rss.WriteEndElement(); rss.WriteEndElement();
if (ch[i].Change != Change.PageDeleted && p != null)
if(ch[i].Change != Change.PageDeleted && p != null) {
rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension); rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension);
else }
rss.WriteElementString("link", Settings.MainUrl); else rss.WriteElementString("link", Settings.MainUrl);
BuildAuthorTag(rss, ch[i].User);
UserInfo user = Users.FindUser(ch[i].User);
string username = user != null ? Users.GetDisplayName(user) : ch[i].User;
rss.WriteElementString("author", username);
// Create the description tag // Create the description tag
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -309,7 +301,7 @@ namespace ScrewTurn.Wiki {
sb.Append(Properties.Messages.ThePageHasBeenRolledBackBy); sb.Append(Properties.Messages.ThePageHasBeenRolledBackBy);
break; break;
} }
sb.Append(" " + ch[i].User + (ch[i].Description.Length > 0 ? ".<br />" + ch[i].Description : ".")); sb.Append(" " + username + (ch[i].Description.Length > 0 ? ".<br />" + ch[i].Description : "."));
} }
else { else {
// p != null // p != null
@ -328,7 +320,6 @@ namespace ScrewTurn.Wiki {
// Complete the item element // Complete the item element
rss.WriteEndElement(); rss.WriteEndElement();
} }
// Complete the channel element // Complete the channel element
@ -340,23 +331,20 @@ namespace ScrewTurn.Wiki {
// Finish off // Finish off
rss.Flush(); rss.Flush();
rss.Close(); rss.Close();
} }
} }
else { else {
// All discussion updates // All discussion updates
// Start an XML writer for the output stream // Start an XML writer for the output stream
using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) using(XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
{
// Build an RSS header // Build an RSS header
BuildRssHeader(rss); BuildRssHeader(rss);
bool useCat = false; bool useCat = false;
string cat = ""; string cat = "";
if (Request["Category"] != null) if(Request["Category"] != null) {
{
useCat = true; useCat = true;
cat = Request["Category"]; cat = Request["Category"];
} }
@ -369,41 +357,33 @@ namespace ScrewTurn.Wiki {
RecentChange[] ch = RecentChanges.GetAllChanges(); RecentChange[] ch = RecentChanges.GetAllChanges();
Array.Reverse(ch); Array.Reverse(ch);
for (int i = 0; i < ch.Length; i++) for(int i = 0; i < ch.Length; i++) {
{
// Skip page-related entries // Skip page-related entries
if (!IsMessageChange(ch[i].Change)) continue; if(!IsMessageChange(ch[i].Change)) continue;
PageInfo p = Pages.FindPage(ch[i].Page); PageInfo p = Pages.FindPage(ch[i].Page);
if (p != null) if(p != null) {
{
// Check permissions for every page // Check permissions for every page
bool canReadThisPageDiscussion = AuthChecker.CheckActionForPage(p, Actions.ForPages.ReadDiscussion, bool canReadThisPageDiscussion = AuthChecker.CheckActionForPage(p, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);
currentUsername, currentGroups); if(!canReadThisPageDiscussion) continue;
if (!canReadThisPageDiscussion) continue;
if (useCat) if(useCat) {
{
CategoryInfo[] infos = Pages.GetCategoriesForPage(p); CategoryInfo[] infos = Pages.GetCategoriesForPage(p);
if (infos.Length == 0 && cat != "-") continue; if(infos.Length == 0 && cat != "-") continue;
else if (infos.Length != 0) else if(infos.Length != 0) {
{
bool found = false; bool found = false;
for (int k = 0; k < infos.Length; k++) for(int k = 0; k < infos.Length; k++) {
{ if(infos[k].FullName == cat) {
if (infos[k].FullName == cat)
{
found = true; found = true;
break; break;
} }
} }
if (!found) continue; if(!found) continue;
} }
} }
// Check namespace // Check namespace
if (NameTools.GetNamespace(p.FullName) != currentNamespace) continue; if(NameTools.GetNamespace(p.FullName) != currentNamespace) continue;
// Write the item element // Write the item element
rss.WriteStartElement("item"); rss.WriteStartElement("item");
@ -412,21 +392,20 @@ namespace ScrewTurn.Wiki {
rss.WriteEndElement(); rss.WriteEndElement();
string id = Tools.GetMessageIdForAnchor(ch[i].DateTime); string id = Tools.GetMessageIdForAnchor(ch[i].DateTime);
if (ch[i].Change != Change.MessageDeleted) if(ch[i].Change != Change.MessageDeleted) {
{
rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension + "?Discuss=1#" + id); rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension + "?Discuss=1#" + id);
} }
else rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension + "?Discuss=1"); else rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension + "?Discuss=1");
string messageContent = FindMessageContent(ch[i].Page, id); string messageContent = FindMessageContent(ch[i].Page, id);
UserInfo user = Users.FindUser(ch[i].User);
string username = user != null ? Users.GetDisplayName(user) : ch[i].User;
// Create the description tag // Create the description tag
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (rssFeedsMode == RssFeedsMode.Summary || messageContent == null) if(rssFeedsMode == RssFeedsMode.Summary || messageContent == null) {
{ switch(ch[i].Change) {
switch (ch[i].Change)
{
case Change.MessagePosted: case Change.MessagePosted:
sb.Append(Properties.Messages.AMessageHasBeenPostedBy.Replace("##SUBJECT##", ch[i].MessageSubject)); sb.Append(Properties.Messages.AMessageHasBeenPostedBy.Replace("##SUBJECT##", ch[i].MessageSubject));
break; break;
@ -437,10 +416,9 @@ namespace ScrewTurn.Wiki {
sb.Append(Properties.Messages.AMessageHasBeenDeletedBy.Replace("##SUBJECT##", ch[i].MessageSubject)); sb.Append(Properties.Messages.AMessageHasBeenDeletedBy.Replace("##SUBJECT##", ch[i].MessageSubject));
break; break;
} }
sb.Append(" " + ch[i].User + (ch[i].Description.Length > 0 ? ".<br />" + ch[i].Description : ".")); sb.Append(" " + username + (ch[i].Description.Length > 0 ? ".<br />" + ch[i].Description : "."));
} }
else else {
{
sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(messageContent, false, FormattingContext.MessageBody, null), FormattingContext.MessageBody, null)); sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(messageContent, false, FormattingContext.MessageBody, null), FormattingContext.MessageBody, null));
} }
rss.WriteStartElement("description"); rss.WriteStartElement("description");
@ -448,7 +426,7 @@ namespace ScrewTurn.Wiki {
rss.WriteEndElement(); rss.WriteEndElement();
// Write the remaining elements // Write the remaining elements
BuildAuthorTag(rss, ch[i].User); rss.WriteElementString("author", username);
rss.WriteElementString("pubDate", ch[i].DateTime.ToUniversalTime().ToString("R")); rss.WriteElementString("pubDate", ch[i].DateTime.ToUniversalTime().ToString("R"));
rss.WriteStartElement("guid"); rss.WriteStartElement("guid");
rss.WriteAttributeString("isPermaLink", "false"); rss.WriteAttributeString("isPermaLink", "false");
@ -457,7 +435,6 @@ namespace ScrewTurn.Wiki {
// Complete the item element // Complete the item element
rss.WriteEndElement(); rss.WriteEndElement();
} }
} }
@ -470,7 +447,6 @@ namespace ScrewTurn.Wiki {
// Finish off // Finish off
rss.Flush(); rss.Flush();
rss.Close(); rss.Close();
} }
} }
} }
@ -566,8 +542,7 @@ namespace ScrewTurn.Wiki {
/// <param name="selfLink">The self link (atom).</param> /// <param name="selfLink">The self link (atom).</param>
/// <param name="description">The description.</param> /// <param name="description">The description.</param>
/// <returns>The complete channel head.</returns> /// <returns>The complete channel head.</returns>
private void BuildChannelHead(XmlWriter rss, string title, string link, string selfLink, string description) private void BuildChannelHead(XmlWriter rss, string title, string link, string selfLink, string description) {
{
rss.WriteStartElement("channel"); rss.WriteStartElement("channel");
rss.WriteStartElement("title"); rss.WriteStartElement("title");
rss.WriteCData(title); rss.WriteCData(title);
@ -593,21 +568,6 @@ namespace ScrewTurn.Wiki {
rss.WriteEndElement(); rss.WriteEndElement();
} }
/// <summary>
/// Sends an author tag to the output stream.
/// </summary>
/// <param name="rss">The output stream.</param>
/// <param name="userName">The author's user name.</param>
private void BuildAuthorTag(XmlWriter rss, string userName) {
UserInfo author = Users.FindUser(userName);
if(author == null) {
rss.WriteElementString("author", userName);
}
else {
rss.WriteElementString("author", string.Format("{0} ({1})", Formatter.StripHtml(author.DisplayName), userName));
}
}
} }
} }