当前位置: 首页>>代码示例>>C#>>正文


C# PageBE.GetText方法代码示例

本文整理汇总了C#中MindTouch.Deki.Data.PageBE.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# PageBE.GetText方法的具体用法?C# PageBE.GetText怎么用?C# PageBE.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MindTouch.Deki.Data.PageBE的用法示例。


在下文中一共展示了PageBE.GetText方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MWToDWContent

        public void MWToDWContent(Site site, PageBE page, bool isOld) {
            try {

                // check for template content overrides
                if (OverrideTemplate(site, page)) {
                    return;
                }

                Plug converterUri = MediaWikiConverterContext.Current.MWConverterUri;
                if (null != converterUri) {
                    string interwikiInfo = String.Empty;
                    if (null != _MWInterwikiBySite) {
                        _MWInterwikiBySite.TryGetValue(site, out interwikiInfo);
                    }
                    XDoc xml = converterUri.With("title", page.Title.AsPrefixedDbPath()).With("lang", site.Language).With("site", site.Name).With("interwiki", interwikiInfo).With("text", page.GetText(DbUtils.CurrentSession)).PostAsForm().ToDocument();
                    xml.UsePrefix("mediawiki", "#mediawiki");

                    // if this is a redirect, set the page text accordingly]
                    if (page.IsRedirect) {
                        ParserResult result = DekiXmlParser.Parse(page, ParserMode.SAVE, -1, false);
                        if (result.RedirectsToTitle != null) {
                            page.SetText(String.Format(REDIRECT_TEXT, MWToDWTitle(site, Title.FromUIUri(null, xml["//mediawiki:link/@href"].Contents, true)).AsPrefixedDbPath().Replace("&", "&")));
                        } else {
                            page.SetText(String.Format(REDIRECT_TEXT, xml["//mediawiki:link/@href"].Contents.Replace("&", "&"), true));
                        }
                        page.ContentType = DekiMimeType.DEKI_XML0805;
                        return;
                    }

                    // remove extra paragraph tags from templates
                    if (page.Title.IsTemplate) {
                        List<XDoc> topLevelParagraphs = xml["/html/body/p"].ToList();
                        if (1 == topLevelParagraphs.Count) {
                            topLevelParagraphs[0].ReplaceWithNodes(topLevelParagraphs[0]);
                        }
                    }

                    // Map MediaWiki titles to MindTouch
                    MWToDWTitles(site, page, isOld, xml);

                    // Convert from MediaWiki output to MindTouch
                    WikiTextProcessor.Convert(site, xml, page.Title.IsTemplate);

                    // If the page is available in other languages, insert wiki.languages 
                    List<XDoc> languageList = xml["//mediawiki:meta[@type='language']"].ToList();
                    if (0 < languageList.Count) {
                        StringBuilder languageData = new StringBuilder("{{ wiki.languages( { ");
                        for (int i = 0; i < languageList.Count; i++) {
                            if (0 < i) {
                                languageData.Append(", ");
                            }
                            string relatedLanguage = languageList[i]["@language"].AsText;
                            Title relatedTitle = Title.FromUIUri(null, languageList[i].Contents, false);
                            Site relatedSite = MediaWikiConverterContext.Current.GetMWSite(relatedLanguage);
                            languageData.AppendFormat("{0}: {1}", StringUtil.QuoteString(relatedLanguage), StringUtil.QuoteString(MWToDWTitle(relatedSite, relatedTitle).AsPrefixedDbPath()));
                            languageList[i].Remove();
                        }
                        languageData.Append(" } ) }}");
                        xml["//body"].Value(languageData.ToString());
                    }

                    string contents = xml.ToString();
                    int first = contents.IndexOf("<body>");
                    int last = contents.LastIndexOf("</body>");
                    if ((first >= 0) && (last >= 0)) {
                        page.SetText(contents.Substring(first + 6, last - (first + 6)));
                        page.ContentType = DekiMimeType.DEKI_TEXT;
                    }
                }
            } catch (Exception e) {
                Console.Out.WriteLine("An unexpected exception has occurred:");
                Console.Out.WriteLine(e.GetCoroutineStackTrace());
                Console.Out.WriteLine("MediaWiki page text that produced the exception:");
                Console.Out.WriteLine(page.GetText(DbUtils.CurrentSession));
            }
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:76,代码来源:MediaWikiConverterService.cs

示例2: Save

        public static OldBE Save(PageBE page, OldBE previous, string userComment, string text, string contentType, string displayName, string language, int section, string xpath, DateTime timeStamp, ulong restoredPageId, bool loggingEnabled, bool removeIllegalElements, Title relToTitle, bool overwrite, uint authorId, out bool conflict) {

            // NOTE (steveb):
            //  page: most recent page about to be overwritten
            //  previous: (optional) possible earlier page on which the current edit is based upon

            conflict = false;
            bool isNewForEventContext = page.ID == 0 || page.IsRedirect;

            // check save permissions
            IsAccessAllowed(page, 0 == page.ID ? Permissions.CREATE : Permissions.UPDATE, false);

            // validate the save
            if((0 == page.ID) && ((-1 != section) || (null != xpath))) {
                throw new ArgumentException(DekiResources.SECTION_EDIT_EXISTING_PAGES_ONLY);
            }

            // displaynames entered by user are trimmed
            if(displayName != null) {
                displayName = displayName.Trim();
            }

            if(!Title.FromDbPath(page.Title.Namespace, page.Title.AsUnprefixedDbPath(), displayName).IsValid) {
                throw new DreamAbortException(DreamMessage.Conflict(DekiResources.INVALID_TITLE));
            }

            // load old contents into current page when a section is edited
            ParserResult alternate = new ParserResult();
            ParserResult original = new ParserResult();
            if(previous != null) {

                // parse most recent version as alternate
                alternate = DekiXmlParser.Parse(page, ParserMode.RAW);

                // parse base version for three way diff
                string pageContentType = page.ContentType;
                string pageText = page.GetText(DbUtils.CurrentSession);
                page.ContentType = previous.ContentType;
                page.SetText(previous.Text);
                original = DekiXmlParser.Parse(page, ParserMode.RAW);
                page.ContentType = pageContentType;
                page.SetText(pageText);
            }

            // ensure the parent exists
            PageBE parent = EnsureParent(DekiXmlParser.REDIRECT_REGEX.IsMatch(text), page.Title);
            if(null != parent) {
                page.ParentID = parent.Title.IsRoot ? 0 : parent.ID;
            }

            // Explicitly setting the language of a talk page is not valid
            if(page.Title.IsTalk && !string.IsNullOrEmpty(language)) {
                throw new Exceptions.TalkPageLanguageCannotBeSet();
            }

            // Language is set in this order: explicitly given, already set, language of parent
            language = language ?? page.Language ?? (null != parent ? parent.Language : String.Empty);

            // talk pages always get their language from their corresponding front page
            if(page.Title.IsTalk) {
                PageBE frontPage = PageBL.GetPageByTitle(page.Title.AsFront());
                if(frontPage != null && frontPage.ID != 0) {
                    language = frontPage.Language;
                }
            }

            string nativeName = ValidatePageLanguage(language);

            // parse the content
            ParserResult parserResult = DekiXmlParser.ParseSave(page, contentType, language, text, section, xpath, removeIllegalElements, relToTitle);
            OldBE old = null;
            string comment = userComment ?? string.Empty;

            // check if this is a new page
            if(0 == page.ID) {
                AuthorizePage(DekiContext.Current.User, Permissions.CREATE, parent, false);

                if(0 == restoredPageId) {
                    if(!string.IsNullOrEmpty(comment)) {
                        comment += "; ";
                    }
                    comment += string.Format(DekiResources.PAGE_CREATED);
                    if((null == parserResult.RedirectsToTitle) && (null == parserResult.RedirectsToUri)) {
                        comment += string.Format(", " + DekiResources.PAGE_DIFF_SUMMARY_ADDED, Utils.GetPageWordCount(parserResult.MainBody));
                    }
                    page.MinorEdit = false;
                    page.IsNew = true;
                }
            }

            // if this is an existing page, ensure the content has changed and save the current page information 
            else {

                // prevent creating a redirect on a page that has non-redirect children
                if((null != parserResult.RedirectsToTitle) || (null != parserResult.RedirectsToUri)) {
                    IList<PageBE> children = DbUtils.CurrentSession.Pages_GetChildren((uint)page.ID, page.Title.Namespace, true);
                    if(0 < children.Count) {
                        throw new DreamAbortException(DreamMessage.Conflict(DekiResources.INVALID_REDIRECT));
                    }
                }
//.........这里部分代码省略.........
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:101,代码来源:PageBL.cs

示例3: OverrideTemplate

        public bool OverrideTemplate(Site site, PageBE page) {
            if (page.Title.IsTemplate && !String.IsNullOrEmpty(MediaWikiConverterContext.Current.MWTemplatePath)) {
                string templateFilename = GetTemplateFilename(page.Title);
                string templateOriginal = Path.Combine(OriginalTemplateDir, site.Language + "-" + templateFilename);

                // check the template against its base version to see if it's changed
                if (!File.Exists(templateOriginal)) {
                    #region logging
                    if (MediaWikiConverterContext.Current.LoggingEnabled) {
                        log["/html/body/table[@id='outdatedtemplates']"].Add(new XDoc("tr").Elem("td", MWToDWTitle(site, page.Title).AsPrefixedDbPath()));
                    }
                    #endregion
                    File.WriteAllLines(templateOriginal, new string[] { page.TimeStamp.ToString() });
                    File.AppendAllText(templateOriginal, page.GetText(DbUtils.CurrentSession));
                } else {
                    DateTime baseTimestamp = DateTime.MinValue;
                    string[] lines = File.ReadAllLines(templateOriginal);
                    if (0 < lines.Length) {
                        DateTime.TryParse(lines[0], out baseTimestamp);
                    }
                    if (DateTime.MinValue == baseTimestamp || baseTimestamp < page.TimeStamp) {
                        #region logging
                        if (MediaWikiConverterContext.Current.LoggingEnabled) {
                            log["/html/body/table[@id='outdatedtemplates']"].Add(new XDoc("tr").Elem("td", MWToDWTitle(site, page.Title).AsPrefixedDbPath()));
                        }
                        #endregion
                        File.WriteAllLines(templateOriginal, new string[] { page.TimeStamp.ToString() });
                        File.AppendAllText(templateOriginal, page.GetText(DbUtils.CurrentSession));

                    }
                }

                // check if the template's content has been overriden
                string templateOverride = Path.Combine(OverrideTemplateDir, templateFilename);
                if (File.Exists(templateOverride)) {
                    page.SetText(File.ReadAllText(templateOverride));
                    page.ContentType = DekiMimeType.DEKI_TEXT;
                    ParserResult parserResult = DekiXmlParser.Parse(page, ParserMode.SAVE, -1, false);
                    page.IsRedirect = (null != parserResult.RedirectsToTitle) || (null != parserResult.RedirectsToUri);
                    return true;
                }
            }
            return false;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:44,代码来源:MediaWikiConverterService.cs

示例4: MovePageProcessRedirects

        private static void MovePageProcessRedirects(List<PageBE> pagesToMove, Dictionary<ulong, Title> newTitlesByPageId, List<PageBE> childRedirectsToRecreate) {

            //Update redirects pointing to the old locations to point to the new
            Dictionary<ulong, IList<PageBE>> redirectsByPages =
                DbUtils.CurrentSession.Pages_GetRedirects(new List<ulong>(from p in pagesToMove select p.ID));

            foreach(PageBE pageToMove in pagesToMove) {
                IList<PageBE> redirects = null;
                if(redirectsByPages.TryGetValue(pageToMove.ID, out redirects)) {
                    foreach(PageBE redirect in redirects) {
                        redirect.SetText("#REDIRECT [[" + newTitlesByPageId[pageToMove.ID].AsPrefixedDbPath() + "]]");
                        DbUtils.CurrentSession.Pages_Update(redirect);
                    }
                }
            }

            // redirects that are children of the moved root page are deleted by Pages_UpdateTitlesForMove and need to be recreated
            pagesToMove.AddRange(childRedirectsToRecreate);

            //NOTE: Pages are sorted before creating redirects to intermediate parent pages arent automatically created
            pagesToMove = pagesToMove.OrderBy(p => p.Title).ToList();
 
            foreach(PageBE movedPage in pagesToMove) {
                string text = string.Empty;
                if(movedPage.IsRedirect) {
                    //This redirect is simply recreated any may be a direct link or in the case when it's pointing to a page that was just moved,
                    //it will point to the previous title for which there's a new redirect.
                    text = movedPage.GetText(DbUtils.CurrentSession);
                } else {
                    text = "#REDIRECT [[" + newTitlesByPageId[movedPage.ID].AsPrefixedDbPath() + "]]";
                }
                PageBE oldPageRedirect = new PageBE();
                oldPageRedirect.Title = movedPage.Title;
                oldPageRedirect.SetText(text);
                PageBL.Save(oldPageRedirect, oldPageRedirect.GetText(DbUtils.CurrentSession), DekiMimeType.DEKI_TEXT, null);
                DbUtils.CurrentSession.Grants_CopyToPage(movedPage.ID, oldPageRedirect.ID);
                DekiContext.Current.Instance.EventSink.PageAliasCreate(DreamContext.Current.StartTime, oldPageRedirect, DekiContext.Current.User);
            }
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:39,代码来源:PageBL.cs

示例5: CopyPageToOld

 public static void CopyPageToOld(PageBE page, OldBE old) {
     old.Text = page.GetText(DbUtils.CurrentSession);
     old.ContentType = page.ContentType;
     old.UserID = page.UserID;
     old.TimeStamp = page.TimeStamp;
     old.MinorEdit = page.MinorEdit;
     old.Comment = page.Comment;
     old.Language = page.Language;
     old.IsHidden = page.IsHidden;
     old.Meta = page.Meta;
     old.Revision = page.Revision;
     old.PageID = page.ID;
     old.DisplayName = page.Title.DisplayName;
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:14,代码来源:PageBL.cs

示例6: Parse

 public static ParserResult Parse(PageBE page, ParserMode mode) {
     return Parse(page, page.ContentType, page.Language, page.GetText(DbUtils.CurrentSession), mode, false, -1, null, null);
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:3,代码来源:DekiXmlParser.cs

示例7: CreateParserDocument

 public static XDoc CreateParserDocument(PageBE page, ParserMode mode) {
     return CreateParserDocument(page, page.ContentType, page.Language, page.GetText(DbUtils.CurrentSession), mode);
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:3,代码来源:DekiXmlParser.cs

示例8: ParseSave


//.........这里部分代码省略.........
                    bool hasLocalPrefix = true;
                    if(link.StartsWithInvariantIgnoreCase(Utils.MKS_PATH)) {
                        link = link.Substring(Utils.MKS_PATH.Length);
                    } else if(link.StartsWithInvariantIgnoreCase(DekiContext.Current.UiUri.Uri.SchemeHostPort + "/")) {
                        link = link.Substring(DekiContext.Current.UiUri.Uri.SchemeHostPort.Length + 1);
                    } else {
                        hasLocalPrefix = false;
                    }
                    if(hasLocalPrefix) {
                        if(!link.StartsWith("/")) {
                            link = "/" + link;
                        }
                        addr.Attr(attrName, link);
                    }
                }
            }

            // pass the input through the xml validator
            DekiScriptLibrary.ValidateXHtml(contentDoc["body"], DekiContext.Current.Instance.SafeHtml && !PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.UNSAFECONTENT), removeIllegalElements);
            XDoc validatedDoc = CreateParserDocument(page, contentType, language, string.Empty, ParserMode.SAVE);
            validatedDoc["content/@type"].ReplaceValue(DekiMimeType.DEKI_TEXT);
            validatedDoc[".//body"].Replace(contentDoc[".//body"]);

            // check if we need to remove a trailing <br /> element from <body>
            XDoc body = validatedDoc[".//body"];
            if(!body.IsEmpty) {
                XmlNode last = body.AsXmlNode.LastChild;

                // check if last node is a <table> or <pre> element
                if((last != null) && (last.NodeType == XmlNodeType.Element)) {
                    if(last.LocalName.EqualsInvariant("br")) {

                        // remove <br /> element
                        body[last].Remove();
                    } else if(
                            last.LocalName.EqualsInvariant("p") && (
                                (last.ChildNodes.Count == 0) || (
                                    (last.ChildNodes.Count == 1) && (
                                        ((last.ChildNodes[0].NodeType == XmlNodeType.Text) && (last.ChildNodes[0].Value.Trim().Length == 0)) ||
                                        (last.ChildNodes[0].NodeType == XmlNodeType.SignificantWhitespace) ||
                                        (last.ChildNodes[0].NodeType == XmlNodeType.Whitespace)
                                    )
                                )
                            )
                    ) {

                        // remove <p></p> element
                        body[last].Remove();
                    }
                }
            }

            // if section is negative, update the entire page contents
            if((section < 0) && (null == xpath)) {
                result = validatedDoc;
            } else {

                // convert the existing page and new section contents to a consistent format
                result = CreateParserDocument(page, page.ContentType, page.Language, page.GetText(DbUtils.CurrentSession), ParserMode.RAW);
                XDoc headingDoc = validatedDoc;
                if(DekiMimeType.DEKI_TEXT == contentType) {
                    WikiConverter_TextToXml.Convert(headingDoc);
                }

                if(section < 0) {

                    // if no section was specified, replace the node identified by the xpath
                    if(xpath.StartsWith("/")) {
                        xpath = "." + xpath;
                    }
                    try {
                        result[MAIN_BODY_XPATH][xpath].ReplaceWithNodes(headingDoc[MAIN_BODY_XPATH]);
                    } catch {
                        throw new DekiXmlParserInvalidXPathException();
                    }
                } else if(0 == section) {

                    // append the section to the end of the document
                    result[MAIN_BODY_XPATH].AddNodes(headingDoc[MAIN_BODY_XPATH]);
                } else {

                    // find the specified section number
                    XmlNode startNode, endNode;
                    FindSection(result, section, out startNode, out endNode);
                    if(null == startNode) {
                        throw new SectionParamInvalidArgumentException();
                    }

                    // replace the section contents
                    AddChildrenBefore(startNode, headingDoc[MAIN_BODY_XPATH].AsXmlNode);
                    XmlNode currentNode = startNode;
                    while(currentNode != null && currentNode != endNode) {
                        XmlNode nodeToDelete = currentNode;
                        currentNode = currentNode.NextSibling;
                        nodeToDelete.ParentNode.RemoveChild(nodeToDelete);
                    }
                }
            }
            return Parse(page, result, ParserMode.SAVE, false, null, relToTitle);
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:101,代码来源:DekiXmlParser.cs

示例9: ParseGlobalTemplate

        public static ParserResult ParseGlobalTemplate(PageBE contextPage, PageBE templatePage) {

            // update the parse state to indicate the page is in the process of being parsed
            ParserState parseState = GetParseState();
            string parseStateKey = GetParserCacheKey(contextPage, ParserMode.VIEW_NO_EXECUTE);
            parseState.ProcessedPages[parseStateKey] = null;
            parseState.ProcessingStack.Add(contextPage);

            // set current page in context
            DreamContext context = DreamContext.Current;
            PageBE prevBasePage = context.GetState<PageBE>("CurrentPage");
            CultureInfo prevCulture = context.Culture;
            context.SetState("CurrentPage", contextPage);
            context.Culture = HttpUtil.GetCultureInfoFromHeader(contextPage.Language, context.Culture);

            // parse the page
            ParserResult result = Parse(templatePage, templatePage.ContentType, templatePage.Language, templatePage.GetText(DbUtils.CurrentSession), ParserMode.VIEW, true, -1, DekiScriptNil.Value, null);

            // restore previous page context
            context.SetState("CurrentPage", prevBasePage);
            context.Culture = prevCulture;

            // update the parse state to indicate the page as been successfully parsed
            parseState.ProcessedPages.Remove(parseStateKey);
            parseState.ProcessingStack.RemoveAt(parseState.ProcessingStack.Count - 1);

            // return result
            return result;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:29,代码来源:DekiXmlParser.cs

示例10: UpdateDWPageData

 public static void UpdateDWPageData(PageBE page) {
     MediaWikiConverterContext.Current.DWCatalog.NewQuery(String.Format("UPDATE pages set page_usecache={0}, page_tip='{1}', page_content_type='{2}', page_text='{3}' where page_id={4}", page.UseCache, DataCommand.MakeSqlSafe(page.TIP), DataCommand.MakeSqlSafe(page.ContentType), DataCommand.MakeSqlSafe(page.GetText(DbUtils.CurrentSession)), page.ID)).Execute();
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:3,代码来源:MediaWikiDA.cs

示例11: RetrievePageXDoc

        public static XDoc RetrievePageXDoc(PageBE page, uint pageId, ParserMode mode, string language, bool isInclude, int section, Title relToTitle, bool xhtml, out ParserResult parserResult) {
            uint contextPageId = pageId;
            if((mode == ParserMode.VIEW) && (contextPageId != uint.MaxValue) && page.Title.IsTemplate) {

                // NOTE (steveb): page being rendered is a template and a contextual page was specified; this means we're rendering a global template page
                PageBE contextPage = GetPageById(contextPageId);
                if(contextPage == null) {
                    parserResult = new ParserResult();
                    return null;
                }
                parserResult = DekiXmlParser.ParseGlobalTemplate(contextPage, page);
            } else {
                parserResult = DekiXmlParser.Parse(page, page.ContentType, language ?? page.Language, page.GetText(DbUtils.CurrentSession), mode, isInclude, section, null, relToTitle);
            }
            if(page.Title.IsTemplate && isInclude) {
                DekiXmlParser.PostProcessTemplateInsertBody(parserResult, page);
            }

            // post process tail element
            DekiXmlParser.PostProcessParserResults(parserResult);

            // BUGBUGBUG (steveb): we cannot properly restore an old title unless it had a display title set

            // wrap the result in a content tag and return it to the user
            XDoc result = new XDoc("content")
                    .Attr("type", parserResult.ContentType)
                    .Attr("etag", page.Etag)
                    .Attr("title", page.CustomTitle ?? page.Title.AsUserFriendlyName());

            // check if page contains unsafe content
            if(mode == ParserMode.EDIT) {
                result.Attr("unsafe", !DekiScriptLibrary.VerifyXHtml(parserResult.MainBody, true));
            }

            if(xhtml) {
                result.AddNodes(parserResult.Content);
            } else {

                // encode the result as nodes of text
                foreach(XDoc entry in parserResult.Content.Elements) {
                    if(entry.HasName("body")) {
                        result.Start("body").Attr("target", entry["@target"].AsText).Value(entry.ToInnerXHtml()).End();
                    } else {
                        result.Elem(entry.Name, entry.ToInnerXHtml());
                    }
                }
            }
            return result;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:49,代码来源:PageBL.cs


注:本文中的MindTouch.Deki.Data.PageBE.GetText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。