Class: MediaWiki::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/mediawiki/utils.rb

Overview

Util class similar to MediaWiki’s non-API JavaScript util methods.

To use this class it must be explicitly required. Including mediawiki/butt does not automatically include this class.

Its methods are class methods, not instance methods. They are not executed on your Butt instance.

Examples:

require 'mediawiki/utils'
encoded_url = MediaWiki::Utils.encode_url(url)

Class Method Summary collapse

Class Method Details

.encode_url(str) ⇒ String

Encodes the URL like mw.util.rawurlencode JS.

Parameters:

  • str (String)

    The string to replace (typically a page title).

Returns:

  • (String)

    The encoded string.



15
16
17
18
19
20
21
22
23
24
# File 'lib/mediawiki/utils.rb', line 15

def self.encode_url(str)
  str.gsub!(/!/, '%21')
  str.gsub!(/'/, '%27')
  str.gsub!(/\(/, '%28')
  str.gsub!(/\)/, '%29')
  str.gsub!(/\*/, '%2A')
  str.gsub!(/~/, '%7E')

  str
end