Class: MyMediaWiki

Inherits:
MyMediaWikiBase show all
Defined in:
lib/mymedia-wiki.rb

Instance Method Summary collapse

Methods inherited from MyMediaWikiBase

#copy_publish, #delete

Constructor Details

#initialize(media_type: 'wiki', config: nil, newpg_url: '', log: nil, debug: false) ⇒ MyMediaWiki

Returns a new instance of MyMediaWiki.



134
135
136
137
138
139
# 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

Instance Method Details

#writecopy_publish(raws) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# 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