Example #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;
 } 
Example #2
0
        public Yield GetTaggedPages(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            string language = DreamContext.Current.GetParam("language", null);
            var    tagBL    = new TagBL();
            XDoc   doc      = tagBL.GetTagXml(tagBL.GetTagFromUrl(context), true, language);

            response.Return(DreamMessage.Ok(doc));
            yield break;
        }
Example #3
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;
        }
Example #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;
        }
Example #5
0
 public string[] GetTags(string prefixText, int count)
 {
     tagbl = new TagBL();
     return(tagbl.GetTags(prefixText, count));
 }
Example #6
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;
        }
Example #7
0
 public Yield GetTaggedPages(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
     string language = DreamContext.Current.GetParam("language", null);
     var tagBL = new TagBL();
     XDoc doc = tagBL.GetTagXml(tagBL.GetTagFromUrl(context), true, language);
     response.Return(DreamMessage.Ok(doc));
     yield break;
 } 
Example #8
0
 public Hashtable WikiGeTag(
     [DekiExtParam("tag name")] string tag
 ) {
     var tagBL = new TagBL();
     TagBE result = tagBL.ParseTag(tag);
     result = DbUtils.CurrentSession.Tags_GetByNameAndType(result.Name, result.Type);
     if(result != null) {
         return MakeTagObject(result);
     }
     return null;
 }
Example #9
0
 internal Hashtable SiteTags() {
     Hashtable result = new Hashtable(StringComparer.OrdinalIgnoreCase);
     var tagBL = new TagBL();
     foreach(TagBE tag in tagBL.GetTags(null, TagType.ALL, DateTime.MinValue, DateTime.MaxValue)) {
         result[tag.PrefixedName] = MakeTagObject(tag);
     }
     return result;
 }
Example #10
0
 internal Hashtable TagsProperty(uint pageid) {
     Hashtable result = new Hashtable(StringComparer.OrdinalIgnoreCase);
     PageBE page = GetPage(pageid, Permissions.READ, false);
     if(page != null) {
         var tagBL = new TagBL();
         foreach(TagBE tag in tagBL.GetTagsForPage(page)) {
             result[tag.PrefixedName] = MakeTagObject(tag);
         }
     }
     return result;
 }
Example #11
0
        public static void PostProcessTemplateInsertBody(ParserResult result, PageBE page) {

            // add nested template links
            XDoc body = result.MainBody;
            XDoc tree = PageSiteMapBL.BuildHtmlSiteMap(page, null, int.MaxValue, false);
            tree = tree[".//ul"];
            if(!tree.IsEmpty) {
                foreach(XDoc a in tree[".//a"]) {
                    a["@href"].ReplaceValue("#");
                    a.Attr("template", a["@title"].AsText);
                    a.Attr("class", "site");
                    a.RemoveAttr("rel");
                    a.RemoveAttr("pageid");
                }
                body.Add(tree);
            }

            // add tag inclusion hints
            var tagBL = new TagBL();
            IList<TagBE> tags = tagBL.GetTagsForPage(page);
            if(tags.Count > 0) {
                body.Start("p")
                    .Attr("class", "template:tag-insert")
                    .Elem("em", DekiContext.Current.Resources.Localize("Page.Tags.tags-inserted-from-template") + " ");
                bool first = true;
                foreach(TagBE tag in tags) {
                    if(!first) {
                        body.Elem("span", ", ");
                    }
                    first = false;
                    body.Start("a").Attr("href", "#").Value(tag.PrefixedName).End();
                }
                body.End();
            }
        }
Example #12
0
 private static void ImportPageTags(PageBE page, string[] tags) {
     var tagBL = new TagBL();
     tagBL.PutTags(page, tags);
 }
Example #13
0
        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;
        }
 /// <summary>
 /// Convert from MediaWiki categories to MindTouch tags
 /// </summary>
 public void ConvertCategories() {
     Console.Out.Write("Migrating categories... ");
     Dictionary<string, List<string>> pageToCategoryMap = MediaWikiDA.GetCategoryNamesByPage();
     var tagBL = new TagBL();
     foreach(KeyValuePair<string, List<string>> categoriesByPage in pageToCategoryMap) {
         TagBE[] tags = new TagBE[categoriesByPage.Value.Count];
         for(int i = 0; i < tags.Length; i++) {
             TagBE categoryTag = new TagBE();
             categoryTag.Type = TagType.TEXT;
             categoryTag.Name = categoriesByPage.Value[i];
             tags[i] = categoryTag;
         }
         ulong pageID;
         if(_MWToDWPageIDMap.TryGetValue(categoriesByPage.Key, out pageID)) {
             tagBL.InsertTags(pageID, tags);
         }
     }
     Console.Out.WriteLine("Done!");
 }