[SQL]

# Wiki Pages
GetWikiPageVersion=SELECT * FROM wikipage WHERE pagename=? AND version=?
GetWikiPage=SELECT * FROM wikipage WHERE pagename=? ORDER BY version DESC LIMIT 1
SaveWikiPage=INSERT INTO wikipage (pagename,version,userid,comment,content,createdate) VALUES (?,?,?,?,?,?)
GetWikiHistory=SELECT w.pagename,w.version,w.createdate,w.comment,w.locked,u.* FROM wikipage AS w \
    INNER JOIN users AS u ON w.userid=u.userid \
    WHERE w.pagename=? ORDER BY w.version DESC
CheckWikiPage=SELECT version FROM wikipage WHERE pagename=? LIMIT 1

GetWikiIndex=SELECT * FROM wikiindex WHERE pagename=?
UpdateWikiIndex=UPDATE wikiindex SET version=? WHERE pagename=?
InsertWikiIndex=INSERT INTO wikiindex (version,pagename) VALUES (?,?)
WikiRecentChanges=SELECT * FROM wikipage AS w \
    INNER JOIN users AS u ON w.userid=u.userid \
    ORDER BY w.createdate DESC $limit
DeleteWikiPage=DELETE FROM wikipage WHERE version>? AND pagename=?
DeleteWikiPages=DELETE FROM wikipage WHERE pagename=?
DeleteWikiIndex=DELETE FROM wikiindex WHERE pagename=?
SetWikiLock=UPDATE wikipage SET locked=? WHERE pagename=?

WikiSearch=SELECT * FROM wikiindex AS x \
    INNER JOIN wikipage AS w ON w.pagename=x.pagename AND w.version=x.version \
    INNER JOIN users AS u ON w.userid=u.userid \
    WHERE w.content LIKE ? \
    ORDER BY w.createdate LIMIT 100
WikiSearchFull=SELECT * FROM wikipage AS w \
    INNER JOIN users AS u ON w.userid=u.userid \
    WHERE w.content LIKE ? \
    ORDER BY w.createdate LIMIT 100
