/// <summary> /// Retrieves the title as a path consumable by the editor. The relative path is used if possible. /// Ex. "User:Admin/MyPage/" /// </summary> public static string AsEditorUriPath(this Title title) { // URL encode ?'s so they don't get confused for the query and add the filename, anchor and query return Utils.MKS_PATH + title.AppendFilenameQueryAnchor(title.AsPrefixedDbPath().Replace("?", "%3f"), false); }
/// <summary> /// Retrieves the user-friendly display name of this title. /// Used to always build a display name, either from localized resources or the last segment in the path. /// </summary> public static string AsUserFriendlyDisplayName(this Title title) { string result = title.AsPrefixedDbPath().Replace('_', ' '); // Check if there is a translated name for the page string resourceResult = title.GetTranslatedName(); if(resourceResult != null) { return resourceResult; } // replace '//' with '%2f' ('//' was used as encoding for '/' in titles) result = result.Trim('/').Replace("//", "%2f"); // split path into segments string[] segments = result.Split('/'); result = segments[segments.Length - 1]; return title.AppendFilenameQueryAnchor(XUri.Decode(result.Replace("%2f", "/")), false); }
public static string AsPrefixedUserFriendlyPath(this Title title) { if(!title.IsFile && !title.HasAnchor && !title.HasQuery) { // this is a special/admin page, we check if there is a translated name for the page string resourceResult = title.GetTranslatedName(); if(resourceResult != null) { return resourceResult; } } return title.AppendFilenameQueryAnchor(XUri.Decode(title.AsPrefixedDbPath()), false); }
/// <summary> /// Retrieves the user-friendly name of this title /// </summary> public static string AsUserFriendlyName(this Title title) { if(title.IsFile) { return title.AppendFilenameQueryAnchor(String.Empty, false); } else { string result = title.AsPrefixedDbPath().Replace('_', ' '); if(!title.HasAnchor && !title.HasQuery) { // Check if there is a translated name for the page string resourceResult = title.GetTranslatedName(); if(resourceResult != null) { return resourceResult; } // check if page has a display name (always the case for new pages after Olympic) if(!string.IsNullOrEmpty(title.DisplayName)) { return title.DisplayName; } } // replace '//' with '%2f' ('//' was used as encoding for '/' in titles) result = result.Trim('/').Replace("//", "%2f"); // split path into segments string[] segments = result.Split('/'); result = segments[segments.Length - 1]; return title.AppendFilenameQueryAnchor(XUri.Decode(result.Replace("%2f", "/")), false); } }