예제 #1
0
        /// <summary>
        /// Hides Unformatted text (nowiki, pre, math, html comments, timelines), source tags
        /// Also hides images and external links if set on call to constructor
        /// </summary>
        /// <param name="articleText">The wiki text of the article.</param>
        /// <returns></returns>
        public string Hide(string articleText)
        {
            HiddenTokens.Clear();
            cachedOriginalArticleTextBeforeHide = articleText;

            // performance: get all tags in format <tag...> in article, apply Replace only if needed
            List <string> AnyTagList = (from Match m in AnyTag.Matches(articleText)
                                        select m.Groups[1].Value.Trim().ToLower()).ToList();

            if (AnyTagList.Any(t => t.Equals("tt") || t.StartsWith("syntaxhighlight") || t.Equals("code") || t.StartsWith("source")))
            {
                Replace(WikiRegexes.SourceCode.Matches(articleText), ref articleText);
            }
            Replace(MathCodeTypoTemplates.Matches(articleText), ref articleText);

            var matches = (from Match m in WikiRegexes.UnformattedText.Matches(articleText) where !LeaveMetaHeadings || !NoWikiIgnoreRegex.IsMatch(m.Value) select m).ToList();

            Replace(matches, ref articleText);

            if (HideExternalLinks)
            {
                Replace(WikiRegexes.ExternalLinks.Matches(articleText), ref articleText);

                List <Match> matches2 = (from Match m in WikiRegexes.PossibleInterwikis.Matches(articleText) where SiteMatrix.Languages.Contains(m.Groups[1].Value.ToLower()) select m).ToList();
                Replace(matches2, ref articleText);
            }

            if (HideImages)
            {
                Replace(WikiRegexes.Images.Matches(articleText), ref articleText);
                if (AnyTagList.Any(t => t.Contains("imagemap")))
                {
                    Replace(WikiRegexes.ImageMap.Matches(articleText), ref articleText);
                }
                Replace(CiteTitle.Matches(articleText), ref articleText);

                // gallery tag does not require Image: namespace link before image in gallery, so hide anything before pipe
                if (AnyTagList.Any(t => t.Contains("gallery")))
                {
                    articleText = WikiRegexes.GalleryTag.Replace(articleText, m => {
                        string res = m.Value;
                        Replace(ImageToBar.Matches(res), ref res);
                        return(res);
                    });
                }
            }

            cachedArticleTextAfterHide = articleText;
            return(articleText);
        }
예제 #2
0
        /// <summary>
        /// Hides Unformatted text (nowiki, pre, math, html comments, timelines), source tags
        /// Also hides images and external links if set on call to constructor
        /// </summary>
        /// <param name="articleText">The wiki text of the article.</param>
        /// <returns></returns>
        public string Hide(string articleText)
        {
            HiddenTokens.Clear();
            cachedOriginalArticleTextBeforeHide = articleText;

            // performance: get all tags in format <tag...> in article, apply Replace only if needed
            List <string> AnyTagList = (from Match m in AnyTag.Matches(articleText)
                                        select m.Groups[1].Value.Trim().ToLower()).ToList();

            if (AnyTagList.Any(t => t.Equals("tt") || t.StartsWith("syntaxhighlight") || t.Equals("code") || t.StartsWith("source")))
            {
                Replace(WikiRegexes.SourceCode.Matches(articleText), ref articleText);
            }
            Replace(MathCodeTypoTemplates.Matches(articleText), ref articleText);

            var matches = (from Match m in WikiRegexes.UnformattedText.Matches(articleText) where !LeaveMetaHeadings || !NoWikiIgnoreRegex.IsMatch(m.Value) select m).ToList();

            Replace(matches, ref articleText);

            if (HideExternalLinks)
            {
                Replace(WikiRegexes.ExternalLinks.Matches(articleText), ref articleText);

                List <Match> matches2 = (from Match m in WikiRegexes.PossibleInterwikis.Matches(articleText) where SiteMatrix.Languages.Contains(m.Groups[1].Value.ToLower()) select m).ToList();
                Replace(matches2, ref articleText);
            }

            if (HideImages)
            {
                // hide all image links but retain any braces at either end
                articleText = WikiRegexes.Images.Replace(articleText, m => {
                    string res = m.Value;

                    // don't hide URL parameter starting www as FixCitationTemplates will fix these
                    if (res.TrimStart().StartsWith("www.", StringComparison.OrdinalIgnoreCase))
                    {
                        return(res);
                    }

                    if (res.StartsWith("[["))
                    {
                        if (res.EndsWith("]]"))
                        {
                            Replace(RetainBraces.Matches(res), ref res);
                        }
                        else
                        {
                            Replace(RetainStartBraces.Matches(res), ref res);
                        }
                    }
                    else if (res.EndsWith("]]"))
                    {
                        Replace(RetainEndBraces.Matches(res), ref res);
                    }
                    else
                    {
                        Replace(All.Matches(res), ref res);
                    }
                    return(res);
                });

                if (AnyTagList.Any(t => t.Contains("imagemap")))
                {
                    Replace(WikiRegexes.ImageMap.Matches(articleText), ref articleText);
                }

                // Hide any title or trans_title parameters with dates in them
                Replace(CiteTitleYear.Matches(articleText), ref articleText);

                // gallery tag does not require Image: namespace link before image in gallery, so hide anything before pipe
                if (AnyTagList.Any(t => t.Contains("gallery")))
                {
                    articleText = WikiRegexes.GalleryTag.Replace(articleText, m => {
                        string res = m.Value;
                        Replace(ImageToBar.Matches(res), ref res);
                        return(res);
                    });
                }
            }

            cachedArticleTextAfterHide = articleText;
            return(articleText);
        }