module MediaWiki::Utils
Constants
- NO_UNICODE_SUPPORT
Public Instance Methods
Extract base name. If there are no subpages, return page name.
Examples: get_base_name
(“Namespace:Foo/Bar/Baz”) -> “Namespace:Foo” get_base_name
(“Namespace:Foo”) -> “Namespace:Foo”
- title
-
Page name string in Wiki format
# File lib/media_wiki/utils.rb 12 def get_base_name(title) 13 title.split('/').first if title 14 end
Extract path leading up to subpage. If title does not contain a subpage, returns nil.
Examples: get_path_to_subpage
(“Namespace:Foo/Bar/Baz”) -> “Namespace:Foo/Bar” get_path_to_subpage
(“Namespace:Foo”) -> nil
- title
-
Page name string in Wiki format
# File lib/media_wiki/utils.rb 23 def get_path_to_subpage(title) 24 title.split(/\/([^\/]*)$/).first if title && title.include?('/') 25 end
Extract subpage name. If there is no hierarchy above, return page name.
Examples: get_subpage
(“Namespace:Foo/Bar/Baz”) -> “Baz” get_subpage
(“Namespace:Foo”) -> “Namespace:Foo”
- title
-
Page name string in Wiki format
# File lib/media_wiki/utils.rb 34 def get_subpage(title) 35 title.split('/').last if title 36 end
Convert URL-ized page name (“getting_there_%26_away”) into Wiki display format page name (“Getting there & away”). Also capitalizes first letter, replaces underscores with spaces and strips out any illegal characters (#<>[]|{}, cf. meta.wikimedia.org/wiki/Help:Page_name#Restrictions).
- wiki
-
Page name string in URL
# File lib/media_wiki/utils.rb 42 def uri_to_wiki(uri) 43 upcase_first_char(CGI.unescape(uri).tr('_', ' ').tr('#<>[]|{}', '')) if uri 44 end
Return current version of MediaWiki::Gateway
# File lib/media_wiki/utils.rb 56 def version 57 MediaWiki::VERSION 58 end
Convert a Wiki page name (“Getting there & away”) to URI-safe format (“Getting_there_%26_away”), taking care not to mangle slashes or colons
- wiki
-
Page name string in Wiki format
# File lib/media_wiki/utils.rb 49 def wiki_to_uri(wiki) 50 wiki.to_s.split('/').map { |chunk| 51 CGI.escape(CGI.unescape(chunk).tr(' ', '_')) 52 }.join('/').gsub('%3A', ':') if wiki 53 end