Example #1
0
        protected void cmdRevert_Click(object sender, EventArgs e)
        {
            if (CommunitySecurity.IsOutsider())
            {
                throw new SecurityException();
            }

            int ver;

            if (int.TryParse((sender as LinkButton).CommandName, out ver))
            {
                var page = Wiki.GetPage(PageNameUtil.Decode(WikiPage), ver);
                if (page != null)
                {
                    page.Date    = TenantUtil.DateTimeNow();
                    page.UserID  = SecurityContext.CurrentAccount.ID;
                    page.Version = Wiki.GetPageMaxVersion(page.PageName) + 1;

                    Wiki.SavePage(page);
                    Wiki.UpdateCategoriesByPageContent(page);

                    BindHistoryList();
                }
            }
        }
Example #2
0
        public SaveResult Save(Guid userId, out string pageName)
        {
            try
            {
                if (SetNewFCKMode != null)
                {
                    bool isSource;
                    bool.TryParse(hfFCKLastState.Value, out isSource);
                    SetNewFCKMode(!isSource);

                    IsWysiwygDefault = !isSource; //We need to update the variable if SetNewFCKMode is used only!!!
                }

                Page   page;
                string currentPageName = txtPageName.Text.Trim();
                if (currentPageName.Length > 240)
                {
                    currentPageName = currentPageName.Substring(0, 240).Trim();
                }
                currentPageName = PageNameUtil.Clean(currentPageName);
                if (pageSection >= 0)
                {
                    currentPageName = PageNameUtil.Decode(PageName);
                }

                pageName = currentPageName;
                bool   isPageRename = pageName != PageNameUtil.Decode(PageName) && !string.IsNullOrEmpty(PageName);
                string oldPageName  = PageName;

                if (currentPageName.Equals(string.Empty) && !txtPageName.ReadOnly)
                {
                    SetWikiFCKEditorValue(currentPageName, Wiki_FCKEditor.Value);
                    return(SaveResult.PageNameIsEmpty);
                }

                if (!IsSpecialName && IsNameReserved(currentPageName))
                {
                    SetWikiFCKEditorValue(currentPageName, Wiki_FCKEditor.Value);
                    return(SaveResult.PageNameIsIncorrect);
                }

                if (userId.Equals(Guid.Empty))
                {
                    SetWikiFCKEditorValue(currentPageName, Wiki_FCKEditor.Value);
                    return(SaveResult.UserIdIsEmpty);
                }

                if (!PageNameUtil.Decode(PageName).Equals(currentPageName, StringComparison.InvariantCulture))
                {
                    page = Wiki.GetPage(currentPageName);
                    if (page != null)
                    {
                        SetWikiFCKEditorValue(currentPageName, Wiki_FCKEditor.Value);
                        return(SaveResult.SamePageExists);
                    }
                    page = new Page();
                }
                else
                {
                    page = Wiki.GetPage(currentPageName);
                    if (page == null)
                    {
                        page = new Page();
                    }
                }

                page.PageName = currentPageName;
                string PageResult;
                if (pageSection < 0)
                {
                    PageResult = Wiki_FCKEditor.Value;
                }
                else
                {
                    PageResult = HtmlWikiUtil.SetWikiSectionBySectionNumber(page.Body, pageSection, Wiki_FCKEditor.Value);
                }

                if (PageResult.Equals(page.Body))
                {
                    SetWikiFCKEditorValue(page.PageName, Wiki_FCKEditor.Value);
                    return(SaveResult.NoChanges);
                }

                page.Body = PageResult;

                if (pageVersion > 0 && pageVersion < Wiki.GetPageMaxVersion(page.PageName))
                {
                    SetWikiFCKEditorValue(page.PageName, Wiki_FCKEditor.Value);
                    return(SaveResult.OldVersion);
                }
                page.Date   = TenantUtil.DateTimeNow();
                page.UserID = userId;

                page.Version++;
                Wiki.SavePage(page);

                var newCats = Wiki.UpdateCategoriesByPageContent(page);
                if (newCats.Count > 0 && SaveNewCategoriesAdded != null)
                {
                    SaveNewCategoriesAdded(this, newCats, page.PageName);
                }

                pageVersion = page.Version;
                RisePublishVersionInfo(page);

                SetWikiFCKEditorValue(page.PageName, Wiki_FCKEditor.Value);

                if (pageSection >= 0)
                {
                    return(SaveResult.SectionUpdate);
                }
                if (isPageRename)
                {
                    //create dumb page
                    var oldpage = Wiki.GetPage(PageNameUtil.Decode(oldPageName));
                    if (oldpage != null)
                    {
                        oldpage.Date   = TenantUtil.DateTimeNow();
                        oldpage.UserID = userId;
                        oldpage.Body   = string.Format(WikiUCResource.wikiPageMoved, pageName); //Dummy
                        oldpage.Version++;
                        Wiki.SavePage(oldpage);

                        return(SaveResult.OkPageRename);
                    }
                    else
                    {
                        return(SaveResult.SamePageExists);
                    }
                }
                return(SaveResult.Ok);
            }
            catch (Exception)
            {
                pageName = txtPageName.Text.Trim();
                return(SaveResult.Error);
            }
        }