lib/media_wiki/gateway.rb in mediawiki-gateway-0.3.2 vs lib/media_wiki/gateway.rb in mediawiki-gateway-0.3.3

- old
+ new

@@ -50,15 +50,15 @@ make_api_request(form_data) @password = password @username = username end - # Fetch MediaWiki page in MediaWiki format + # Fetch MediaWiki page in MediaWiki format. Does not follow redirects. # # [page_title] Page title to fetch # - # Returns content of page as string, nil if the page does not exist + # Returns content of page as string, nil if the page does not exist. def get(page_title) form_data = {'action' => 'query', 'prop' => 'revisions', 'rvprop' => 'content', 'titles' => page_title} page = make_api_request(form_data).first.elements["query/pages/page"] if ! page or page.attributes["missing"] nil @@ -305,9 +305,20 @@ 'action' => 'upload', 'token' => get_token('edit', options['filename']) ) make_api_request(form_data) + end + + # Checks if page is a redirect. + # + # [page_title] Page title to fetch + # + # Returns true if the page is a redirect, false if it is not or the page does not exist. + def redirect?(page_title) + form_data = {'action' => 'query', 'prop' => 'info', 'titles' => page_title} + page = make_api_request(form_data).first.elements["query/pages/page"] + !!(page and page.attributes["redirect"]) end # Requests image info from MediaWiki. Follows redirects. # # _file_name_or_page_id_ should be either: