"""
Mediawiki oauth glue

    http://pythonhosted.org/mwoauth
    https://www.mediawiki.org/wiki/Extension:OAuth
"""

from mwoauth import ConsumerToken, Handshaker
from flickipedia.config import settings


def getMWIdentity():
    consumer_token = ConsumerToken(settings.MW_CLIENT_KEY, settings.MW_CLIENT_SECRET)

    # Construct handshaker with wiki URI and consumer
    handshaker = Handshaker("http://commons.wikimedia.org/wiki/Main_Page",
                            consumer_token)

    # Step 1: Initialize -- ask MediaWiki for a temporary key/secret for user
    redirect, request_token = handshaker.initiate()

    # Step 2: Authorize -- send user to MediaWiki to confirm authorization
    print("Point your browser to: %s" % redirect) #
    response_qs = input("Response query string: ")

    # Step 3: Complete -- obtain authorized key/secret for "resource owner"
    access_token = handshaker.complete(request_token, response_qs)

    # Step 4: Identify -- (optional) get identifying information about the user
    identity = handshaker.identify(access_token)

    return identity
@@ -1076,16 +1076,651 @@
  return identity
+%0A%0A%0Adef api_upload_url(url, token, async=True):%0A    %22%22%22 Wrapper around mediawiki api upload functionality%0A%0A    :param url:     photo url%0A    :param token:   edit token%0A    :param async:   flag for asynchronous upload%0A%0A    api.php?action=upload&url=http://www.google.com/intl/en_ALL/images/logo.gif&token=+%5C&asyncdownload=1%0A%0A    :return:    success flag%0A    %22%22%22%0A    call_url = 'https://en.wikipedia.org/w/api.php?action=upload&url=%25s&token=%25s'%0A    if async:%0A        call_url += '&asyncdownload=1'%0A%0A%0Adef api_upload_status():%0A    %22%22%22%0A    api.php?action=upload&checkstatus=true&filekey=somekey1234.jpg&token=+%5C%0A    :return:%0A    %22%22%22%0A    pass

add - method to upload photo by url