action: 'raw' 在 MediawikiApi 中的 Faraday 是什么意思?

What does the action: 'raw' means in Faraday in MediawikiApi?

Class: MediawikiApi::Client, there is a method called get_wikitext。查看该方法的源代码,我看到

def get_wikitext(title)
  @conn.get '/w/index.php', action: 'raw', title: title
end

好像用的是法拉第gem所以我在Faraday code base里找了找Faraday::Connection的get方法也看不懂

谁能解释一下

1) 这个方法是做什么的,这个方法的每个部分是什么意思,它是如何工作的?

特别是:

2) action: 'raw'中的'raw'是什么意思?

3) 为什么我们有 '/w/' 以及为什么索引页面? /w/index.php 是一个惯例吗?索引页是否意味着包含某些内容,这就是此方法始终指向 /w/index.php 的原因?如果是的话,你能简单地解释一下吗?或者给我指出一个解释它的来源?如果我要使用的 wiki 没有 /w/index.php 而只有 /index.php 怎么办?在这种情况下我该怎么办?

在此先致谢。

所有的http verbs方法都是在Faraday中动态生成的,你可以找到get here的定义:

%w[get head delete].each do |method|
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def #{method}(url = nil, params = nil, headers = nil)
      run_request(:#{method}, url, nil, headers) { |request|
        request.params.update(params) if params
        yield(request) if block_given?
      }
    end
  RUBY
end

签名是def get(url = nil, params = nil, headers = nil),所以在你的例子中action: 'raw', title: title是参数的Hash。 由于这是一个GET请求,参数被添加到URL,所以gem正在调用GET .../w/index.php?action=raw&title=title