class MyMediaWiki

Public Class Methods

new(media_type: 'wiki', config: nil, newpg_url: '', log: nil, debug: false) click to toggle source
Calls superclass method MyMediaWikiBase::new
# File lib/mymedia-wiki.rb, line 134
def initialize(media_type: 'wiki', config: nil, newpg_url: '', log: nil,
               debug: false)

  @url4new = newpg_url
  super(media_type: media_type, config: config, log: log, debug: debug)
end

Public Instance Methods

writecopy_publish(raws) click to toggle source
Calls superclass method MyMediaWikiBase#writecopy_publish
# File lib/mymedia-wiki.rb, line 141
def writecopy_publish(raws)

  # The content to be published might contain 1 or more wiki link
  #    e.g. [[topic2022]] or [[topic2022url|topic2022
  # Here, the link will be transformed to an actual hyperlink which points
  # to a valid wiki page

  s = raws.gsub(/\[\[([^\]]+)\]\]/) do |x|

    puts 'x: ' + x.inspect if @debug
    title = $1
    puts 'searching for title ' + title.inspect  if @debug

    # does the title exist?
    r = find_title(title)

    puts 'r: ' + r.inspect  if @debug

    if r then
      '<a href="' + '/wiki/' + r.title[/^#{title}/i] + '">' + title +'</a>'
    else
      '<a href="' + @url4new + escape(title) + '" class="new" title="' \
          + title + ' (page does not exist)">' + title + '</a>'
    end

  end

  super(s)

end

Private Instance Methods

find_title(s) click to toggle source
# File lib/mymedia-wiki.rb, line 174
def find_title(s)
  find /^#{s} (?=#)/i
end