<commit_before><?xml version="1.0" encoding="UTF-8"?>

<xwikidoc>
<web>XWiki</web>
<name>AllAttachmentsResults</name>
<language></language>
<defaultLanguage>en</defaultLanguage>
<translation>0</translation>
<parent>XWiki.AllAttachments</parent>
<creator>XWiki.Admin</creator>
<author>XWiki.Admin</author>
<customClass></customClass>
<contentAuthor>XWiki.Admin</contentAuthor>
<creationDate>1252454400000</creationDate>
<date>1254218569000</date>
<contentUpdateDate>1254218569000</contentUpdateDate>
<version>1.1</version>
<title>$msg.get("xe.index.attachments.results")</title>
<template></template>
<defaultTemplate></defaultTemplate>
<validationScript></validationScript>
<comment></comment>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.0</syntaxId>
<hidden>false</hidden>
<content>{{velocity}}
## ============================================================================================
## This page is called from live grids via Ajax with the argument xpage=plain. It returns a
## set of results serialized in JSON.
## @programming This service page needs to be saved by a user with the programming access level
## to work as expected
## ============================================================================================
#if ("$!request.get('xpage')" == 'plain')
  #set ($offset = $util.parseInt($request.get('offset')))
  ## offset starts from 0 in velocity and 1 in javascript
  #set ($off = $offset - 1)
  #set ($limit = $util.parseInt($request.get('limit')))
  #set ($title = $request.get('doc.name'))
  #set ($author = $request.get('doc.author'))
  #set ($space = $request.get('doc.space'))
  #set ($filename = $request.filename)
  #set ($formatDate = 'yyyy MMMM dd, HH:mm')
  #set ($sql = '')
  #if ($title)
    #set ($title = $title.trim().toLowerCase())
    #set ($sql = $sql + "and lower(doc.name) like '%${title}%' ")
  #end
  #if ($author)
    #set ($author = $author.trim().toLowerCase())
    #set ($sql = $sql + "and lower(attach.author) like '%${author}%' ")
  #end
  #if ($filename)
    #set ($filename = $filename.trim().toLowerCase())
    #set ($sql = $sql + "and lower(attach.filename) like '%${filename}%' ")
  #end
  #if ($space)
    #set ($space = $space.trim().toLowerCase())
    #set ($sql = $sql + "and lower(doc.space) like '%${space}%' ")
  #end
  ##
  ## Exclude Blacklisted spaces ($blacklistedSpaces is set in xwikivars.vm)
  ##
  #foreach ($blacklistedSpace in $blacklistedSpaces)
    #set ($sql = "${sql} and doc.space &lt;&gt; '$blacklistedSpace'")
  #end
  #if ("$!request.sort" != '')
    #set ($order = $request.sort)
  #else
    #set ($order = 'attach.filename')
  #end
  #if ($order == 'filename')
    #set ($order = 'attach.filename')
  #end
  #if ("$!request.dir" != '')
    #set ($dir = $request.dir)
  #else
    #set ($dir = 'asc')
  #end
  ##
  ## Compute the final query
  ##
  #set ($sql = "select doc.fullName, attach from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id " + $sql + " order by $order $dir")
  #set ($items = $xwiki.search($sql, $limit, $off))
  #set ($totalItems = $xwiki.search($sql).size())
  #set ($returnedItems = $items.size())
  ## ==============================================
  ## json starts
  ## ==============================================
{
"totalrows": $totalItems,
"returnedrows": #if($returnedItems &lt; $limit) $returnedItems #else $limit #end,
"offset": $offset,
"reqNo": $request.reqNo,
"rows": [
#foreach ($item in $items)
  #foreach ($element in $item)
    #if ($velocityCount == 1)
      #set ($docName = $element)
      #set ($hasAccess = $xwiki.hasAccessLevel('view', $context.user, $docName))
    #else
      #set ($attachment = $element)
    #end
  #end
  #if ($velocityCount &gt; 1) , #end
  { "acclev"    : $hasAccess,
  #if ($hasAccess)
    #set ($document = $xwiki.getDocument($docName))
    "page" : "$document.name",
    "space" : "$document.space",
    "fullname" : "$document.fullName",
    "filename" : "$attachment.filename",
    "fileurl" : "$document.getAttachmentURL($attachment.filename)",
    "url" : "$document.getURL('view')",
    "spaceurl" : '$xwiki.getURL("${document.space}.WebHome","view")',
    "date" : "$xwiki.formatDate($attachment.date,$formatDate)",
    "author" : "$attachment.author",
    "authorname" : "$xwiki.getDocument($attachment.author).name",
    "authorurl" : "$xwiki.getURL($attachment.author,'view')",
    "type" : "$attachment.getMimeType($context.context)"
  #else
    "fullname": "$docName"
  #end
  }
#end
]}
## ==============================================
## json ended
## ==============================================
#end
{{/velocity}}</content>
</xwikidoc>
<commit_msg>[misc] Added missing escapes.<commit_after><?xml version="1.0" encoding="UTF-8"?>

<xwikidoc>
<web>XWiki</web>
<name>AllAttachmentsResults</name>
<language></language>
<defaultLanguage>en</defaultLanguage>
<translation>0</translation>
<parent>XWiki.AllAttachments</parent>
<creator>XWiki.Admin</creator>
<author>XWiki.Admin</author>
<customClass></customClass>
<contentAuthor>XWiki.Admin</contentAuthor>
<creationDate>1252454400000</creationDate>
<date>1254218569000</date>
<contentUpdateDate>1254218569000</contentUpdateDate>
<version>1.1</version>
<title>$msg.get("xe.index.attachments.results")</title>
<template></template>
<defaultTemplate></defaultTemplate>
<validationScript></validationScript>
<comment></comment>
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.0</syntaxId>
<hidden>false</hidden>
<content>{{velocity}}
## ============================================================================================
## This page is called from live grids via Ajax with the argument xpage=plain. It returns a
## set of results serialized in JSON.
## @programming This service page needs to be saved by a user with the programming access level
## to work as expected
## ============================================================================================
#if ("$!request.get('xpage')" == 'plain')
  #set ($offset = $util.parseInt($request.get('offset')))
  ## offset starts from 0 in velocity and 1 in javascript
  #set ($off = $offset - 1)
  #set ($limit = $util.parseInt($request.get('limit')))
  #set ($title = $request.get('doc.name'))
  #set ($author = $request.get('doc.author'))
  #set ($space = $request.get('doc.space'))
  #set ($filename = $request.filename)
  #set ($formatDate = 'yyyy MMMM dd, HH:mm')
  #set ($query = '')
  #set ($queryParameters = [])
  #if ($title)
    #set ($title = $title.trim().toLowerCase())
    #set ($query = $query + " and lower(doc.name) like ?")
    #set ($discard = $queryParameters.add("%${title}%"))
  #end
  #if ($author)
    #set ($author = $author.trim().toLowerCase())
    #set ($query = $query + " and lower(attach.author) like ?")
    #set ($discard = $queryParameters.add("%${author}%"))
  #end
  #if ($filename)
    #set ($filename = $filename.trim().toLowerCase())
    #set ($query = $query + " and lower(attach.filename) like ?")
    #set ($discard = $queryParameters.add("%${filename}%"))
  #end
  #if ($space)
    #set ($space = $space.trim().toLowerCase())
    #set ($query = $query + " and lower(doc.space) like ?")
    #set ($discard = $queryParameters.add("%${space}%"))
  #end
  ##
  ## Exclude Blacklisted spaces ($blacklistedSpaces is set in xwikivars.vm)
  ##
  #foreach ($blacklistedSpace in $blacklistedSpaces)
    #set ($query = "${query} and doc.space &lt;&gt; ?")
    #set ($discard = $queryParameters.add($blacklistedSpace))
  #end
  #if ("$!request.sort" != '')
    #set ($order = $escapetool.sql($request.sort))
  #else
    #set ($order = 'attach.filename')
  #end
  #if ($order == 'filename')
    #set ($order = 'attach.filename')
  #end
  #if ("$!request.dir" == 'desc')
    #set ($dir = 'desc')
  #else
    #set ($dir = 'asc')
  #end
  ##
  ## Compute the final query
  ##
  #set ($countQuery = "select count(*) from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id" + $query)
  #set ($query = "select doc.fullName, attach from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id" + $query + " order by $order $dir")
  #set ($items = $xwiki.search($query, $limit, $off, $queryParameters))
  #set ($totalItems = $xwiki.search($countQuery, 0, 0, $queryParameters).get(0))
  #set ($returnedItems = $items.size())
  ## ==============================================
  ## json starts
  ## ==============================================
{
"totalrows": $totalItems,
"returnedrows": #if($returnedItems &lt; $limit) $returnedItems #else $limit #end,
"offset": $offset,
"reqNo": $request.reqNo,
"rows": [
#foreach ($item in $items)
  #foreach ($element in $item)
    #if ($velocityCount == 1)
      #set ($docName = $element)
      #set ($hasAccess = $xwiki.hasAccessLevel('view', $context.user, $docName))
    #else
      #set ($attachment = $element)
    #end
  #end
  #if ($velocityCount &gt; 1) , #end
  { "acclev"    : $hasAccess,
  #if ($hasAccess)
    #set ($document = $xwiki.getDocument($docName))
    "page" : "$document.name",
    "space" : "$document.space",
    "fullname" : "$document.fullName",
    "filename" : "$attachment.filename",
    "fileurl" : "$document.getAttachmentURL($attachment.filename)",
    "url" : "$document.getURL('view')",
    "spaceurl" : '$xwiki.getURL("${document.space}.WebHome","view")',
    "date" : "$xwiki.formatDate($attachment.date,$formatDate)",
    "author" : "$attachment.author",
    "authorname" : "$xwiki.getDocument($attachment.author).name",
    "authorurl" : "$xwiki.getURL($attachment.author,'view')",
    "type" : "$attachment.getMimeType($context.context)"
  #else
    "fullname": "$docName"
  #end
  }
#end
]}
## ==============================================
## json ended
## ==============================================
#end
{{/velocity}}</content>
</xwikidoc>

{'fraction_non_alphanumeric': 0.2625191228964814, 'fraction_numerical': 0.010912799592044876, 'mean_word_length': 5.004898958971219, 'pattern_counts': {'":': 12, '<': 101, '<?xml version=': 2, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6885534', 'n_tokens_mistral': 3287, 'n_tokens_neox': 3153, 'n_words': 700}