示例#1
0
 public Yield GetPageTags(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     PageBE page = PageBL_AuthorizePage(context, null, Permissions.READ, false);
     XUri href = DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "tags");
     var tagBL = new TagBL();
     XDoc doc = tagBL.GetTagListXml(tagBL.GetTagsForPage(page), "tags", href, false);
     response.Return(DreamMessage.Ok(doc));
     yield break;
 } 
示例#2
0
        public Yield GetPageTags(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PageBE page  = PageBL_AuthorizePage(context, null, Permissions.READ, false);
            XUri   href  = DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "tags");
            var    tagBL = new TagBL();
            XDoc   doc   = tagBL.GetTagListXml(tagBL.GetTagsForPage(page), "tags", href, false);

            response.Return(DreamMessage.Ok(doc));
            yield break;
        }
示例#3
0
        public Yield GetTags(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            string type        = DreamContext.Current.GetParam("type", "");
            string fromStr     = DreamContext.Current.GetParam("from", "");
            string toStr       = DreamContext.Current.GetParam("to", "");
            bool   showPages   = DreamContext.Current.GetParam("pages", false);
            string partialName = DreamContext.Current.GetParam("q", "");

            // parse type
            TagType tagType = TagType.ALL;

            if (!string.IsNullOrEmpty(type) && !SysUtil.TryParseEnum(type, out tagType))
            {
                throw new DreamBadRequestException("Invalid type parameter");
            }

            // check and validate from date
            DateTime from = (tagType == TagType.DATE) ? DateTime.Now : DateTime.MinValue;

            if (!string.IsNullOrEmpty(fromStr) && !DateTime.TryParse(fromStr, out from))
            {
                throw new DreamBadRequestException("Invalid from date parameter");
            }

            // check and validate to date
            DateTime to = (tagType == TagType.DATE) ? from.AddDays(30) : DateTime.MaxValue;

            if (!string.IsNullOrEmpty(toStr) && !DateTime.TryParse(toStr, out to))
            {
                throw new DreamBadRequestException("Invalid to date parameter");
            }

            // execute query
            var  tagBL = new TagBL();
            var  tags  = tagBL.GetTags(partialName, tagType, from, to);
            XDoc doc   = tagBL.GetTagListXml(tags, "tags", null, showPages);

            response.Return(DreamMessage.Ok(doc));
            yield break;
        }
示例#4
0
        public Yield GetTags(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
            string type = DreamContext.Current.GetParam("type", "");
            string fromStr = DreamContext.Current.GetParam("from", "");
            string toStr = DreamContext.Current.GetParam("to", "");
            bool showPages = DreamContext.Current.GetParam("pages", false);
            string partialName = DreamContext.Current.GetParam("q", "");

            // parse type
            TagType tagType = TagType.ALL;
            if(!string.IsNullOrEmpty(type) && !SysUtil.TryParseEnum(type, out tagType)) {
                throw new DreamBadRequestException("Invalid type parameter");
            }

            // check and validate from date
            DateTime from = (tagType == TagType.DATE) ? DateTime.Now : DateTime.MinValue;
            if(!string.IsNullOrEmpty(fromStr) && !DateTime.TryParse(fromStr, out from)) {
                throw new DreamBadRequestException("Invalid from date parameter");
            }

            // check and validate to date
            DateTime to = (tagType == TagType.DATE) ? from.AddDays(30) : DateTime.MaxValue;
            if(!string.IsNullOrEmpty(toStr) && !DateTime.TryParse(toStr, out to)) {
                throw new DreamBadRequestException("Invalid to date parameter");
            }

            // execute query
            var tagBL = new TagBL();
            var tags = tagBL.GetTags(partialName, tagType, from, to);
            XDoc doc = tagBL.GetTagListXml(tags, "tags", null, showPages);
            response.Return(DreamMessage.Ok(doc));
            yield break;
        }
示例#5
0
文件: PageBL.cs 项目: heran/DekiWiki
        public static XDoc GetPageXmlVerbose(PageBE page, string relation, PageContentFilterSettings contentFilterSettings) {
            XDoc pageXml = GetPageXml(page, relation, true);
            pageXml.Add(GetMetricsXml(page, true));
            pageXml.Start("summary").Value(page.TIP).End();

            //Pages that are not editable dont allow permission changes. If permission changes aren't allowed, don't display the security info.
            if(page.Title.IsEditable) {
                pageXml.Add(GetSecurityXml(page));
            }

            // HACKHACKHACK (MaxM): Page Create timestamp and creator need to be tracked in the PageBE entity rather than queried
            DateTime? created = null;
            uint? creatorUserId = null;
            if(page.Revision == 1) {
                created = page.TimeStamp;
                creatorUserId = page.UserID;
            } else {
                var tailRev = GetOldRevisionForPage(page, 1);
                if(tailRev != null) {
                    created = tailRev.TimeStamp;
                    creatorUserId = tailRev.UserID;
                }
            }
            UserBE creator = null;
            if(creatorUserId != null) {
                creator = UserBL.GetUserById(creatorUserId.Value);
            }
            if(creator != null) {
                pageXml.Add(UserBL.GetUserXml(creator, "createdby", Utils.ShowPrivateUserInfo(creator)));
            }
            if(created != null) {
                pageXml.Start("date.created").Value(created.Value).End();
            }
            pageXml.Start("date.edited").Value(page.TimeStamp).End();
            pageXml.Start("date.modified").Value(page.Touched).End();
            UserBE author;
            if(page.Revision == 1) {
                author = creator;
            } else {
                author = UserBL.GetUserById(page.UserID);
            }
            if(author != null) {
                pageXml.Add(UserBL.GetUserXml(author, "author", Utils.ShowPrivateUserInfo(author)));
            }
            pageXml.Start("description").Value(page.Comment).End();
            pageXml.Elem("language", page.Language);
            pageXml.Add(BuildParentPageXmlTree(page, false));

            // page redirection information
            pageXml.Start("page.redirectedfrom");
            if(null != page.RedirectedFrom) {
                pageXml.Add(GetPageXml(page.RedirectedFrom, null, true));
            }
            pageXml.End();

            PageBE redirectedTo = GetTargetForRedirectPage(page);
            if(page.IsRedirect && redirectedTo != null) {
                pageXml.Add(GetPageXml(redirectedTo, "redirectedto", true));
            }

            // Embed page rating
            RatingBL.AppendRatingXml(pageXml, page, DekiContext.Current.User);
            pageXml.Start("subpages").Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "subpages")).End();

            // TODO (steveb): why is this commented out?
            //pageXml.Add(GetPageListXml("subpages", PageBL.GetChildren(this, true), DekiContext.Current.ApiUri.At("pages", ID.ToString(), "subpages")));

            if(!contentFilterSettings.ExcludeOutboundLinks) {
                pageXml.Add(GetLinksXml(DbUtils.CurrentSession.Links_GetOutboundLinks(page.ID), "outbound"));
            }
            if(!contentFilterSettings.ExcludeInboundLinks) {
                pageXml.Add(GetLinksXml(DbUtils.CurrentSession.Links_GetInboundLinks(page.ID), "inbound"));
            }
            pageXml.Start("aliases")
                //TODO (Max): .Attr("count", ????)
                .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "aliases"))
            .End();
            pageXml.Start("revisions")
                .Attr("count", page.Revision)
                .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "revisions"))
           .End();

            // Emit archive revision info
            if(PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN)) {
                pageXml.Start("revisions.archive")
                    .Attr("count", DbUtils.CurrentSession.Archive_GetCountByTitle(page.Title))
                    .Attr("href", DekiContext.Current.ApiUri.At("archive", "pages", page.Title.AsApiParam(), "revisions"))
                .End();
            }

            // Emit comment info
            pageXml.Start("comments")
                .Attr("count", DbUtils.CurrentSession.Comments_GetCountByPageId(page.ID).ToString())
                .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "comments"))
            .End();

            //Embed properties for the attachment
            IList<ResourceBE> props = PropertyBL.Instance.GetPageProperties(page.ID);
            pageXml = PropertyBL.Instance.GetPropertyXml(props, GetUri(page), null, null, pageXml);

            //Backwards compatibility: return the language within properties
            pageXml["/page/properties"].Start("language").Attr("deprecated", true).Value(page.Language).End();

            // Emit tags list
            XUri tagHref = DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "tags");
            var tagBL = new TagBL();
            pageXml.Add(tagBL.GetTagListXml(tagBL.GetTagsForPage(page), "tags", tagHref, false));

            //Page file attachments
            pageXml.Add(AttachmentBL.Instance.GetFileXml(AttachmentBL.Instance.GetPageAttachments(page.ID), false, null, null, null));
            if(contentFilterSettings.IncludeContents) {
                ParserResult parserResult;
                ResolvePageRev(page, contentFilterSettings.Revision);
                pageXml.Add(RetrievePageXDoc(page, (uint)page.ID, contentFilterSettings.ContentsMode, page.Language, false, -1, page.Title, contentFilterSettings.Xhtml, out parserResult)); // CESAR: finish
            } else {
                pageXml.Start("contents")
                    .Attr("type", page.ContentType)
                    .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "contents"))
                    .Attr("etag", page.Etag)
                    .End();
            if(DekiContext.Current.Deki.PrinceXmlPath != string.Empty)
                pageXml.Start("contents.alt").Attr("type", MimeType.PDF.FullType).Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "pdf")).End();
            }
            return pageXml;
        }