Exemplo n.º 1
0
    private void LoadWikiPage()
    {
        if (!IsFile)
        {
            wikiViewFile.Visible = false;
            wikiEditFile.Visible = false;

            if (WikiPage.Equals(string.Empty) || !Action.Equals(Action.View))
            {
                if (!Action.Equals(Action.View))
                {
                    wikiEditPage.Visible = true;
                }
                wikiViewPage.Visible = false;


                if (Action.Equals(Action.Edit))
                {
                    wikiEditPage.PageName = WikiPage;
                }
                else
                {
                    wikiEditPage.PageName = string.Empty;
                }


                Title = string.Format("WIKI - Edit/Add page");
            }
            else
            {
                wikiViewPage.Visible = true;
                wikiEditPage.Visible = false;

                wikiViewPage.PageName = WikiPage;
                Title = string.Format("WIKI - {0}", PageNameUtil.Decode(WikiPage));
            }
        }
        else
        {
            wikiViewPage.Visible = false;
            wikiEditPage.Visible = false;

            if (WikiPage.Equals(string.Empty) || !Action.Equals(Action.View))
            {
                if (!Action.Equals(Action.View))
                {
                    wikiEditFile.Visible = true;
                }
                wikiViewFile.Visible = false;


                if (Action.Equals(Action.Edit))
                {
                    wikiEditFile.FileName = WikiPage;
                }
                else
                {
                    wikiEditFile.FileName = string.Empty;
                }


                Title = string.Format("WIKI - Edit/Add file");
            }
            else
            {
                wikiViewFile.Visible = true;
                wikiEditFile.Visible = false;

                cmdEditFile.Visible = true;

                wikiViewFile.FileName = WikiPage;
                Title = string.Format("WIKI - {0}", PageNameUtil.Decode(WikiPage));
            }
        }
    }
Exemplo n.º 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;
                var  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;
                var isPageRename = pageName != PageNameUtil.Decode(PageName) && !string.IsNullOrEmpty(PageName);
                var 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.InvariantCultureIgnoreCase))
                {
                    page = Wiki.GetPage(currentPageName);
                    if (page != null)
                    {
                        SetWikiFCKEditorValue(currentPageName, Wiki_FCKEditor.Value);
                        return(SaveResult.SamePageExists);
                    }
                    page = new Page();
                }
                else
                {
                    page = Wiki.GetPage(currentPageName) ?? new Page();
                }

                page.PageName = currentPageName;
                var pageResult = PageSection < 0
                                     ? Wiki_FCKEditor.Value
                                     : 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);
                    }
                    return(SaveResult.SamePageExists);
                }
                return(SaveResult.Ok);
            }
            catch (Exception)
            {
                pageName = txtPageName.Text.Trim();
                return(SaveResult.Error);
            }
        }
Exemplo n.º 3
0
 private void BindHistoryList()
 {
     rptPageHistory.DataSource = Wiki.GetPageHistory(PageNameUtil.Decode(WikiPage));
     rptPageHistory.DataBind();
     cmdDiff.Visible = (rptPageHistory.DataSource as List <Page>).Count > 1;
 }
Exemplo n.º 4
0
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            SaveResult result;
            string     pageName;

            if (IsFile || Action.Equals(ActionOnPage.AddNewFile))
            {
                result = wikiEditFile.Save(SecurityContext.CurrentAccount.ID, out pageName);
            }
            else
            {
                result = wikiEditPage.Save(SecurityContext.CurrentAccount.ID, out pageName);
            }

            PrintResultBySave(result, pageName);
            if (result == SaveResult.OkPageRename)
            {
                //Redirect
                Response.RedirectLC(ActionHelper.GetViewPagePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode(pageName)), this);
            }
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                return;
            }

            _mobileVer = MobileDetector.IsMobile;


            //fix for IE 10
            var browser = HttpContext.Current.Request.Browser.Browser;

            var userAgent  = Context.Request.Headers["User-Agent"];
            var regExp     = new Regex("MSIE 10.0", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var regExpIe11 = new Regex("(?=.*Trident.*rv:11.0).+", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);

            if (browser == "IE" && regExp.Match(userAgent).Success || regExpIe11.Match(userAgent).Success)
            {
                _mobileVer = true;
            }

            Wiki_FCKEditor.BasePath   = VirtualPathUtility.ToAbsolute(BaseFCKRelPath);
            Wiki_FCKEditor.ToolbarSet = "WikiPanel";

            if (PageName != null && Visible)
            {
                var page      = Wiki.GetPage(PageNameUtil.Decode(PageName));
                var isPageNew = (page == null || IsNew);

                RiseWikiPageLoaded(isPageNew, page);

                if (!isPageNew)
                {
                    txtPageName.Text = page.PageName;
                    if (PageSection < 0)
                    {
                        SetWikiFCKEditorValue(page.PageName, page.Body);
                    }
                    else
                    {
                        SetWikiFCKEditorValue(page.PageName, HtmlWikiUtil.GetWikiSectionBySectionNumber(page.Body, PageSection));
                        txtPageName.ReadOnly = true;
                        txtPageName.Text    += string.Format(WikiUCResource.wikiPageEditSectionCaptionFormat, HtmlWikiUtil.GetWikiSectionNameBySectionNumber(page.Body, PageSection));
                    }

                    //Check for 'help' and 'main' page
                    if (IsStandartName(page))
                    {
                        txtPageName.ReadOnly = true;
                    }
                    PageVersion = page.Version;

                    //if (page.PageName.Equals(string.Empty))
                    //txtPageName.ReadOnly = true; //We need to disable any changes for the one time saved page.

                    RisePublishVersionInfo(page);
                }
                else if (!string.IsNullOrEmpty(PageName))
                {
                    txtPageName.Text = PageNameUtil.Decode(PageName);
                    if (IsSpecialName)
                    {
                        txtPageName.ReadOnly = true;
                    }
                }

                phPageName.Visible = !txtPageName.ReadOnly;
            }

            hfFCKLastState.Value = (!IsWysiwygDefault).ToString().ToLower();
        }
Exemplo n.º 6
0
        protected void On_PublishVersionInfo(object sender, VersionEventArgs e)
        {
            if (!e.UserID.Equals(Guid.Empty))
            {
                litAuthorInfo.Text = GetPageInfo(PageNameUtil.Decode(WikiPage), e.UserID, e.Date);
            }
            else
            {
                litAuthorInfo.Text = string.Empty;
            }

            hlVersionPage.Text        = string.Format(WikiResource.cmdVersionTemplate, e.Version);
            hlVersionPage.NavigateUrl = ActionHelper.GetViewPagePath(this.ResolveUrlLC("PageHistoryList.aspx"), PageNameUtil.Decode(WikiPage));
            hlVersionPage.Visible     = Action.Equals(ActionOnPage.View) || Action.Equals(ActionOnPage.CategoryView);
            //litVersionSeparator.Visible = hlEditPage.Visible;
        }
Exemplo n.º 7
0
 protected void cmdCancel_Click(object sender, EventArgs e)
 {
     if (!IsFile)
     {
         Response.RedirectLC(ActionHelper.GetViewPagePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode(WikiPage)), this);
     }
     else
     {
         Response.RedirectLC(ActionHelper.GetViewFilePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode(WikiPage)), this);
     }
 }
Exemplo n.º 8
0
        private void UpdateBreadCrumb()
        {
            if (OldVer == 0 || NewVer == 0 || OldVer == NewVer)
            {
                Response.RedirectLC(ActionHelper.GetViewPagePath(this.ResolveUrlLC("PageHistoryList.aspx"), PageNameUtil.Decode(WikiPage)), this);
            }

            WikiMaster.CurrentPageCaption = string.Format(WikiResource.wikiDiffDescriptionFormat, OldVer, NewVer);
        }
Exemplo n.º 9
0
        private string PrepereEmptyString(string format, bool isFile, bool isSearchResultExists)
        {
            commentList.Visible = false;
            var mainOptions         = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant;
            var rxLinkCreatePlace   = new Regex(@"{0([\s\S]+?)}", mainOptions);
            var rxLinkSearchResult  = new Regex(@"{1([\s\S]+?)}", mainOptions);
            var rxSearchResultParth = new Regex(@"\[\[([\s\S]+?)\]\]", mainOptions);
            var result = format;

            foreach (Match match in rxLinkCreatePlace.Matches(format))
            {
                if (isFile)
                {
                    if (CommunitySecurity.CheckPermissions(Common.Constants.Action_UploadFile) && !MobileDetector.IsMobile)
                    {
                        result = result.Replace(match.Value, string.Format(@"<a href=""{0}"">{1}</a>", ActionHelper.GetEditFilePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode(WikiPage)), match.Groups[1].Value));
                    }
                }
                else
                {
                    if (CommunitySecurity.CheckPermissions(Common.Constants.Action_AddPage))
                    {
                        result = result.Replace(match.Value, string.Format(@"<a href=""{0}"">{1}</a>", ActionHelper.GetEditPagePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode(WikiPage)), match.Groups[1].Value));
                    }
                    else
                    {
                        result = result.Replace(match.Value, match.Groups[1].Value);
                    }
                }
            }

            if (isSearchResultExists && !isFile)
            {
                result = rxSearchResultParth.Replace(result, SearchResultParthMatchEvaluator);

                foreach (Match match in rxLinkSearchResult.Matches(format))
                {
                    result = result.Replace(match.Value, string.Format(@"<a href=""{0}"">{1}</a>", this.ResolveUrlLC(string.Format("Search.aspx?Search={0}&pn=", HttpUtility.UrlEncode(PageNameUtil.Decode(WikiPage)))), match.Groups[1].Value));
                }
            }
            else
            {
                result = rxSearchResultParth.Replace(result, string.Empty);
            }

            return(result);
        }
Exemplo n.º 10
0
        private void InitActions()
        {
            niMainPage.Name        = WikiResource.menu_MainPage;
            niAllCategories.Name   = WikiResource.menu_ListCategories;
            niAllPages.Name        = WikiResource.menu_ListPages;
            niNewPages.Name        = WikiResource.menu_NewPages;
            niFreshEditsPages.Name = WikiResource.menu_FreshEditPages;
            niAllFiles.Name        = WikiResource.menu_ListFiles;
            niHelp.Name            = WikiResource.menu_Help;

            string mainPath = this.ResolveUrlLC("Default.aspx");

            niMainPage.URL        = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalHomeKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));
            niAllCategories.URL   = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalCategoriesKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));
            niAllPages.URL        = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalIndexKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));
            niNewPages.URL        = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalNewPagesKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));
            niFreshEditsPages.URL = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalRecentlyKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));
            niAllFiles.URL        = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalFilesKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));
            niHelp.URL            = this.ResolveUrlLC(ActionHelper.GetViewPagePath(mainPath, ASC.Web.UserControls.Wiki.Constants.WikiInternalHelpKey, ASC.Web.UserControls.Wiki.Constants.WikiInternalKeyCaption));

            niaAddNewPage.Name    = WikiResource.menu_AddNewPage;
            niaCreateThePage.Name = WikiResource.menu_CreateThePage;
            niaUploadFile.Name    = WikiResource.menu_AddNewFile;
            niaEditThePage.Name   = WikiResource.menu_EditThePage;
            niaShowVersions.Name  = WikiResource.menu_ShowVersions;
            niaPrintPage.Name     = WikiResource.menu_PrintThePage;
            niaDeleteThePage.Name = WikiResource.menu_DeleteThePage;

            if (SecurityContext.IsAuthenticated)
            {
                ASC.Web.Studio.Controls.Common.MenuItem item = GetNewPageSubscription();
                if (item == null)
                {
                    niaSubscriptionOnNewPage.Visible = false;
                }
                else
                {
                    NewsActions.Controls.AddAt(NewsActions.Controls.IndexOf(niaSubscriptionOnNewPage), item);
                    NewsActions.Controls.Remove(niaSubscriptionOnNewPage);
                    niaSubscriptionOnNewPage = item;
                }

                item = GetThePageSubscription();
                if (item == null)
                {
                    niaSubscriptionThePage.Visible = false;
                }
                else
                {
                    NewsActions.Controls.AddAt(NewsActions.Controls.IndexOf(niaSubscriptionThePage), item);
                    NewsActions.Controls.Remove(niaSubscriptionThePage);
                    niaSubscriptionThePage = item;
                }

                item = GetTheCategorySubscription();
                if (item == null)
                {
                    niaSubscriptionOnCategory.Visible = false;
                }
                else
                {
                    NewsActions.Controls.AddAt(NewsActions.Controls.IndexOf(niaSubscriptionOnCategory), item);
                    NewsActions.Controls.Remove(niaSubscriptionOnCategory);
                    niaSubscriptionOnCategory = item;
                }
            }
            else
            {
                NewsActions.Visible = false;
            }

            niaAddNewPage.URL = ActionHelper.GetAddPagePath(this.ResolveUrlLC("Default.aspx"));
            niaUploadFile.URL = "javascript:ShowUploadFileBox();";

            try
            {
                niaCreateThePage.URL = ActionHelper.GetEditPagePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode((this.Page as WikiBasePage).WikiPage));
            }
            catch (SystemException)
            {
                niaCreateThePage.Visible = false;
            }

            try
            {
                niaEditThePage.URL = ActionHelper.GetEditPagePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode((this.Page as WikiBasePage).WikiPage));
            }
            catch (SystemException)
            {
                niaEditThePage.Visible = false;
            }

            try
            {
                niaShowVersions.URL = ActionHelper.GetViewPagePath(this.ResolveUrlLC("PageHistoryList.aspx"), PageNameUtil.Decode((this.Page as WikiBasePage).WikiPage));
            }
            catch (SystemException)
            {
                niaShowVersions.Visible = false;
            }

            LinkButton cmdDelete = new LinkButton();

            niaPrintPage.URL = @"javascript:window.print();";
            string delUniqId = GetDeleteUniqueId();

            if (!string.IsNullOrEmpty(delUniqId))
            {
                niaDeleteThePage.URL = string.Format(@"javascript:if(confirm('{0}')) __doPostBack('{1}', '');", WikiResource.cfmDeletePage, delUniqId);
            }
            else
            {
                niaDeleteThePage.Visible = false;
            }

            cmdPageGoButton.Text          = WikiResource.wiki_PageContGoButton;
            cmdPageGoButton.OnClientClick = string.Format(@"javascript: var txt =  document.getElementById('{0}'); if(txt.value.replace(/\s/g, '') == '') {{txt.focus(); return false;}} return true;",
                                                          txtSearchPage.ClientID);

            SetVisibleActions();

            //NotifyOnNews();
        }
Exemplo n.º 11
0
 protected void cmdCancel_Click(object sender, EventArgs e)
 {
     Response.RedirectLC(ActionHelper.GetViewPagePath(this.ResolveUrlLC("PageHistoryList.aspx"), PageNameUtil.Decode(WikiPage)), this);
 }
Exemplo n.º 12
0
 public static string GetEditFilePath(string mainPath, string pageName)
 {
     return(string.Format("{0}?file={1}&action=Edit", mainPath, PageNameUtil.Encode(pageName)));
 }
Exemplo n.º 13
0
 public static string GetViewPagePathWithVersion(string mainPath, string pageName, int version)
 {
     return(string.Format("{0}?page={1}&ver={2}", mainPath, PageNameUtil.Encode(pageName), version));
 }
Exemplo n.º 14
0
 public static string GetViewPagePath(string mainPath, string pageName, string spetial)
 {
     return(string.Format("{0}?page={1}", mainPath, string.IsNullOrEmpty(spetial) ? PageNameUtil.Encode(pageName) : string.Format(@"{0}:{1}", spetial, PageNameUtil.Encode(pageName))));
 }
Exemplo n.º 15
0
        private void FindDiff()
        {
            string pageName = PageNameUtil.Decode(WikiPage);

            //Page oldPage = PagesProvider.PagesHistGetByNameVersion(pageName, OldVer, TenantId);
            //Page newPage = PagesProvider.PagesHistGetByNameVersion(pageName, NewVer, TenantId);
            var oldPage = Wiki.GetPage(pageName, OldVer);
            var newPage = Wiki.GetPage(pageName, NewVer);

            string oldVersion, newVersion;

            if (oldPage == null)
            {
                oldVersion = string.Empty;
            }
            else
            {
                oldVersion = oldPage.Body;
            }

            if (newPage == null)
            {
                newVersion = string.Empty;
            }
            else
            {
                newVersion = newPage.Body;
            }


            DiffHelper.Item[] f      = DiffHelper.DiffText(oldVersion, newVersion, true, true, false);
            string[]          aLines = oldVersion.Split('\n');
            string[]          bLines = newVersion.Split('\n');

            int           n  = 0;
            StringBuilder sb = new StringBuilder();

            foreach (DiffHelper.Item aItem in f)
            {
                // write unchanged lines
                while ((n < aItem.StartB) && (n < bLines.Length))
                {
                    WriteLine(n, null, bLines[n], sb);
                    n++;
                } // while

                // write deleted lines
                for (int m = 0; m < aItem.deletedA; m++)
                {
                    WriteLine(-1, "d", aLines[aItem.StartA + m], sb);
                } // for

                // write inserted lines
                while (n < aItem.StartB + aItem.insertedB)
                {
                    WriteLine(n, "i", bLines[n], sb);
                    n++;
                } // while
            }     // while

            if (f.Length > 0 || (from bline in bLines where !bline.Trim().Equals(string.Empty) select bline).Count() > 0)
            {
                // write rest of unchanged lines
                while (n < bLines.Length)
                {
                    WriteLine(n, null, bLines[n], sb);
                    n++;
                } // while
            }
            litDiff.Text = sb.ToString();
        }
Exemplo n.º 16
0
        private void UpdateBreadCrumb()
        {
            if (OldVer == 0 || NewVer == 0 || OldVer == NewVer)
            {
                Response.RedirectLC(ActionHelper.GetViewPagePath(this.ResolveUrlLC("PageHistoryList.aspx"), PageNameUtil.Decode(WikiPage)), this);
            }

            string pageName = PageNameUtil.Decode(WikiPage);

            if (string.IsNullOrEmpty(pageName))
            {
                pageName = WikiResource.MainWikiCaption;
            }

            BreadCrumb.Clear();
            BreadCrumb.Add(new ASC.Web.Controls.BreadCrumb()
            {
                Caption = pageName, NavigationUrl = ActionHelper.GetViewPagePath(this.ResolveUrlLC("Default.aspx"), PageNameUtil.Decode(WikiPage))
            });
            BreadCrumb.Add(new ASC.Web.Controls.BreadCrumb()
            {
                Caption = WikiResource.wikiHistoryCaption, NavigationUrl = ActionHelper.GetViewPagePath(this.ResolveUrlLC("PageHistoryList.aspx"), PageNameUtil.Decode(WikiPage))
            });
            BreadCrumb.Add(new ASC.Web.Controls.BreadCrumb()
            {
                Caption = string.Format(WikiResource.wikiDiffDescriptionFormat, OldVer, NewVer)
            });
        }