/// <summary> /// Converts a MediaWiki title to its MindTouch format /// </summary> /// <param name="mwTitle">The title to convert</param> /// <param name="replaceSeparator">If true, replace ":" with "/"</param> /// <returns>The converted title</returns> public Title MWToDWTitle(Site site, Title mwTitle, bool useNewFormat) { string dbPrefix = null; string dbPath = mwTitle.AsUnprefixedDbPath(); string displayName = mwTitle.DisplayName; // create a language heirarchy in the main namespaces if (CreateLanguageHierarchyForNS(mwTitle.Namespace)) { dbPrefix = site.DWRootPage + "/"; if (site.MWRootPage == mwTitle.Path && useNewFormat) { displayName = displayName ?? mwTitle.AsUserFriendlyName(); dbPath = String.Empty; } } // prefix template pages with language to make unique accross langauges else if (mwTitle.IsTemplate || NS.TEMPLATE_TALK == mwTitle.Namespace || mwTitle.IsSpecial) { return mwTitle; } // if this is a user page that corresponds to a renamed user, rename the page. else if (mwTitle.IsUser || NS.USER_TALK == mwTitle.Namespace) { string parentSegment = mwTitle.AsUnprefixedDbSegments()[0]; string newParentSegment; if (_MWToDWUserNameMap.TryGetValue(parentSegment, out newParentSegment)) { dbPath = newParentSegment + mwTitle.Path.Substring(newParentSegment.Length - 1); } } if ('/' != MediaWikiConverterContext.Current.MWPageSeparator) { dbPath = dbPath.Replace("/", "//"); // If desired, replace the page separator with "/" if (useNewFormat && 0 < MediaWikiConverterContext.Current.MWPageSeparator) { String[] segments = dbPath.Split(MediaWikiConverterContext.Current.MWPageSeparator); if (1 < segments.Length) { StringBuilder result = new StringBuilder(); for (int i = 0; i < segments.Length; i++) { if ((0 < i && !String.IsNullOrEmpty(segments[i - 1])) && !(i == segments.Length - 1 && String.IsNullOrEmpty(segments[i]))) { result.Append("/"); } if (String.IsNullOrEmpty(segments[i])) { result.Append(MediaWikiConverterContext.Current.MWPageSeparator); } else { result.Append(segments[i].Trim(new char[] { '_' })); } } dbPath = result.ToString(); } } } dbPath = dbPrefix + dbPath; return Title.FromDbPath(mwTitle.Namespace, dbPath.Trim('/'), displayName, mwTitle.Filename, mwTitle.Anchor, mwTitle.Query); }