Ejemplo n.º 1
0
def handle_text_request(req, rev_id, page_id, user_id, rev_time, page_title):
    global DB_PREFIX
    global sleep_time_sec
    global not_found_text_token
    global connection

    # First, tries to read the colored markup from the database.
    res = fetch_colored_markup(rev_id, page_id, user_id, rev_time, page_title)
    if res == not_found_text_token:
        # Ian -- Killing this to give the server a chance to catch up.
        # If the revision is not found among the colored ones, it marks it for coloring,
        # and it waits a bit, in the hope that it got colored.
        server_utils.mark_for_coloring(
            rev_id, page_id, user_id, rev_time, page_title, "coloring", connection, DB_PREFIX
        )
        time.sleep(sleep_time_sec)
    # Tries again to get it, to see if it has been colored.
    res = fetch_colored_markup(rev_id, page_id, user_id, rev_time, page_title)
    if res == not_found_text_token:
        # No: we will have to wait until it gets colored.  For now, we report not found.
        req.write(not_found_text_token)
    else:
        # req.write("found")
        # Found: we compress it and return it.
        compressed = compressBuf(res)
        req.content_type = "application/x-gzip"
        req.content_length = len(compressed)
        req.send_http_header()
        req.write(compressed)
Ejemplo n.º 2
0
def handle_edit(req, rev_id, page_id, user_id, v_time, page_title):

    global DB_PREFIX
    global connection

    server_utils.mark_for_coloring(rev_id, page_id, user_id, v_time, page_title, "edit", connection, DB_PREFIX)
    req.write("good")
Ejemplo n.º 3
0
def addEdit(rev_id, page_id, user_id, e_time, page_title):
  global DB_PREFIX
  global connection

  server_utils.mark_for_coloring(rev_id,
                                 page_id,
                                 user_id,
                                 e_time,
                                 page_title,
                                 "edit",
                                 connection,
                                 DB_PREFIX)
Ejemplo n.º 4
0
def addTextRequest(rev_id, page_id, user_id, rev_time, page_title):
  global DB_PREFIX
  global connection

  server_utils.mark_for_coloring(rev_id, 
                                 page_id, 
                                 user_id, 
                                 rev_time, 
                                 page_title,
                                 "coloring",
                                 connection,
                                 DB_PREFIX)
Ejemplo n.º 5
0
def addVote(rev_id, page_id, user_id, v_time, page_title):
  global DB_PREFIX
  global connection

  curs = connection.cursor()
  sql = """INSERT INTO """ + DB_PREFIX + """wikitrust_vote (revision_id, page_id, voter_id, voted_on) VALUES (%(rid)s, %(pid)s, %(vid)s, %(time)s) ON DUPLICATE KEY UPDATE voted_on = %(time)s"""
  args = {'rid':rev_id, 'pid':page_id, 'vid':user_id, 'time':v_time}
  numRows = curs.execute(sql, args)
  connection.commit()
  # Once a vote is inserted, we need to recolor the page.
  # Only do this though if the vote is not a repeat.
  if (numRows > 0):
     server_utils.mark_for_coloring(rev_id,
                                    page_id,
                                    user_id,
                                    v_time,
                                    page_title,
                                    "vote",
                                    connection,
                                    DB_PREFIX)
Ejemplo n.º 6
0
def handle_vote(req, rev_id, page_id, user_id, v_time, page_title):
    global DB_PREFIX
    global connection

    curs = connection.cursor()
    sql = (
        """INSERT INTO """
        + DB_PREFIX
        + """wikitrust_vote (revision_id, page_id, voter_id, voted_on) VALUES (%(rid)s, %(pid)s, %(vid)s, %(time)s) ON DUPLICATE KEY UPDATE voted_on = %(time)s"""
    )
    args = {"rid": rev_id, "pid": page_id, "vid": user_id, "time": v_time}
    numRows = curs.execute(sql, args)
    connection.commit()
    # Once a vote is inserted, we need to recolor the page.
    # Only do this though if the vote is not a repeat.
    if numRows > 0:
        server_utils.mark_for_coloring(rev_id, page_id, user_id, v_time, page_title, "vote", connection, DB_PREFIX)

    # Token saying things are ok
    # Votes do not return anything. This just sends back the ACK
    # that the vote was recorded.
    # We could change this to be the re-colored wiki-text, reflecting the
    # effect of the vote, if you like.
    req.write("good")