class Caramelize::InputWiki::MediaWiki

Constants

NAMESPACE_MAPPING
SQL_AUTHORS
SQL_PAGES

for Mediawiki v1.41

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/caramelize/input_wiki/media_wiki.rb, line 43
def initialize(options = {})
  super(options)
  @options[:markup] = :media_wiki
  @options[:filters] << Caramelize::AddNewlineToPageEnd
  @options[:filters] << ::Caramelize::MediawikiToMarkdown
end

Public Instance Methods

excluded_pages() click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 70
def excluded_pages
  []
end
read_authors() click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 60
def read_authors
  database.query(authors_query).each do |row|
    name = row['user_real_name'].empty? ? row['user_name'] : 'Anonymous'
    email = row['user_email'].empty? ? nil : row['user_email']
    authors[row['user_id']] = { name:, email: }
  end

  authors
end
read_pages() click to toggle source

after calling this action, titles and @revisions are expected to be filled

# File lib/caramelize/input_wiki/media_wiki.rb, line 51
def read_pages
  pages.each do |row|
    titles << row['page_title']
    revisions << Page.new(build_properties(row))
  end
  titles.uniq!
  revisions
end

Private Instance Methods

authors_query() click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 80
def authors_query
  SQL_AUTHORS
end
build_properties(row) click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 88
def build_properties(row)
  author = authors[row['actor_user']] || { name: 'Anonymous', email: 'anonymous@example.com' }
  {
    id: row['rev_id'],
    title: title_by_namespace(row),
    body: row['old_text'],
    markup: :media_wiki,
    latest: row['page_latest'] == row['rev_id'],
    time: Time.strptime(row['rev_timestamp'], '%Y%m%d%H%M%S'),
    message: row['comment_text'],
    author:
  }
end
namespace_matches?(namespace_id, expected_namespace) click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 109
def namespace_matches?(namespace_id, expected_namespace)
  NAMESPACE_MAPPING[namespace_id] == expected_namespace
end
pages() click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 84
def pages
  @pages ||= database.query(pages_query)
end
pages_query() click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 76
def pages_query
  SQL_PAGES
end
title_by_namespace(row) click to toggle source
# File lib/caramelize/input_wiki/media_wiki.rb, line 102
def title_by_namespace(row)
  return row['page_title'] if namespace_matches?(row['page_namespace'], :NS_MAIN)
  return "#{row['page_title']}_Discussion" if namespace_matches?(row['page_namespace'], :NS_TALK)

  row['page_title']
end