Module | MediaWiki |
In: |
lib/media_wiki/config.rb
lib/media_wiki/utils.rb lib/media_wiki/gateway.rb |
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
# File lib/media_wiki/utils.rb, line 11 11: def get_path_to_subpage(title) 12: return nil unless title and title.include? '/' 13: parts = title.split(/\/([^\/]*)$/).first 14: 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"
# File lib/media_wiki/utils.rb, line 23 23: def get_subpage(title) 24: title.split('/').last if title 25: end
Convert URL-ized page name ("getting_there_%26_away") into Wiki display format page name ("getting there & away"). Also strips out any illegal characters (#<>[]|{}, cf. meta.wikimedia.org/wiki/Help:Page_name#Restrictions).
# File lib/media_wiki/utils.rb, line 31 31: def uri_to_wiki(uri) 32: CGI.unescape(uri).tr('_', ' ').tr('#<>[]|{}', '') if uri 33: end
Return current version of MediaWiki::Gateway
# File lib/media_wiki/utils.rb, line 43 43: def version 44: MediaWiki::VERSION 45: 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
# File lib/media_wiki/utils.rb, line 38 38: def wiki_to_uri(wiki) 39: wiki.to_s.split('/').map {|chunk| CGI.escape(chunk.tr(' ', '_')) }.join('/').gsub('%3A', ':') if wiki 40: end