Wiki source code of Status on Extension Pages
Last modified by Eleni Cojocariu on 2026/11/16 18:08
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{cache timeToLive="3600" id="extensions-details-1-{{velocity}}#set($cacheKey = $stringtool.defaultString($request.get('scope')))#if($cacheKey.matches('^(noid|withid|project)$'))$cacheKey#end{{/velocity}}"}} | ||
| 2 | {{velocity}} | ||
| 3 | #* | ||
| 4 | Why this page is wrapped in a cache macro. | ||
| 5 | |||
| 6 | Every row here costs a lookup that the search index cannot do - the backlink count comes from the | ||
| 7 | link store, one call per page - so the cost of a view grows with the size of the tree being | ||
| 8 | listed. Measured as a guest before this cache was added: 5 s for 'noid', 1.4 s for 'withid' and 10 to 30 s for 'project' (611 rows). These are public pages, so | ||
| 9 | that was paid again on every visit, including every crawl. | ||
| 10 | |||
| 11 | Nothing about the queries changed; they now run at most once an hour per scope. | ||
| 12 | |||
| 13 | The id has to carry the scope, because the cached content is the same source text for all of | ||
| 14 | them: without an id, every scope would be served whichever one was computed first. It is | ||
| 15 | matched against the list of valid values rather than taken as given, so a crawler passing | ||
| 16 | ?scope=anything cannot mint a new cache entry - and a new computation - per request. | ||
| 17 | |||
| 18 | An id also means the page's own content is no longer part of the cache key, so editing anything | ||
| 19 | below does NOT invalidate what is already cached. Bump the number in the id when changing this | ||
| 20 | page, or the old output is what is served for the next hour - including a cached error block, | ||
| 21 | which is what a macro that fails in here leaves behind. | ||
| 22 | *# | ||
| 23 | #set ($Q = '"') | ||
| 24 | #set ($idField = 'property.ExtensionCode.ExtensionClass.id_string') | ||
| 25 | #set ($extBase = "type:DOCUMENT AND wiki:extensions AND hidden:false AND class:${Q}ExtensionCode.ExtensionClass${Q}") | ||
| 26 | ## Only the fields the table actually reads. Without this, Solr ships every stored field of every | ||
| 27 | ## extension page -- the whole rendered content and every object property -- which is where most of | ||
| 28 | ## the page's time went. The first five are mandatory whatever the table shows: SolrQueryExecutor | ||
| 29 | ## resolves each result to a DocumentReference to check view rights, and a result it cannot resolve | ||
| 30 | ## is dropped, so an incomplete 'fl' empties the table while the total still looks right. | ||
| 31 | ## 'website' is a TextArea, so it is NOT indexed under a '_string' field like the id: TypedValue.TEXT | ||
| 32 | ## is null, so DocumentSolrMetadataExtractor suffixes it with the document's locale instead | ||
| 33 | ## (website_en here). A glob in 'fl' asks for it whatever that locale turns out to be, and the row | ||
| 34 | ## loop finds it back by prefix -- the sort twin website_sortString is stored="false" and never comes. | ||
| 35 | #set ($websitePrefix = 'property.ExtensionCode.ExtensionClass.website_') | ||
| 36 | #set ($fields = "wiki,spaces,name,type,doclocale,fullname,title_,${idField},${websitePrefix}*") | ||
| 37 | |||
| 38 | ## The project/pom scope reads a different population: pages carrying an ExtensionCode.ProjectClass | ||
| 39 | ## object (a project groups the modules of one codebase and is NOT an extension page -- it holds no | ||
| 40 | ## ExtensionClass object, so it appears in neither of the two scopes above) and pages carrying an | ||
| 41 | ## ExtensionCode.ExtensionProxyClass object (their fields are imported from a Maven repository, i.e. | ||
| 42 | ## they come from the pom). 19 pages are both, so the query ORs the two classes instead of summing. | ||
| 43 | ## 'class' is the multi-valued field holding every class the page has an object of -- it is what the | ||
| 44 | ## two check-mark columns are read from, so it has to be in 'fl' like any other field the table uses. | ||
| 45 | #set ($projIdField = 'property.ExtensionCode.ProjectClass.id_string') | ||
| 46 | #set ($pomBase = "type:DOCUMENT AND wiki:extensions AND hidden:false AND (class:${Q}ExtensionCode.ProjectClass${Q} OR class:${Q}ExtensionCode.ExtensionProxyClass${Q})") | ||
| 47 | #set ($pomFields = "wiki,spaces,name,type,doclocale,fullname,title_,class,${idField},${projIdField}") | ||
| 48 | |||
| 49 | ## Scopes, in display order; the first one is the default, so the page has something to show when it | ||
| 50 | ## is opened without a parameter -- same contract as the sibling 'details' page and its tree switcher. | ||
| 51 | #set ($scopes = []) | ||
| 52 | #set ($discard = $scopes.add({'key': 'noid', 'label': 'Without id', 'heading': 'Extension pages without id'})) | ||
| 53 | #set ($discard = $scopes.add({'key': 'withid', 'label': 'With id', 'heading': 'Extension pages with id, grouped by id prefix'})) | ||
| 54 | #set ($discard = $scopes.add({'key': 'project', 'label': 'Project / pom pages', 'heading': 'Project pages and pom-imported extension pages'})) | ||
| 55 | #set ($requested = "$!request.get('scope')") | ||
| 56 | #set ($scope = '') | ||
| 57 | #foreach ($candidate in $scopes) | ||
| 58 | #if ($candidate.key == $requested) | ||
| 59 | #set ($scope = $candidate) | ||
| 60 | #end | ||
| 61 | #end | ||
| 62 | #if ($scope == '') | ||
| 63 | #set ($scope = $scopes.get(0)) | ||
| 64 | #end | ||
| 65 | #set ($links = []) | ||
| 66 | #foreach ($candidate in $scopes) | ||
| 67 | #if ($candidate.key == $scope.key) | ||
| 68 | #set ($discard = $links.add("**$candidate.label**")) | ||
| 69 | #else | ||
| 70 | #set ($url = $doc.getURL('view', "scope=$candidate.key")) | ||
| 71 | #set ($discard = $links.add("[[$candidate.label>>path:$url]]")) | ||
| 72 | #end | ||
| 73 | #end | ||
| 74 | Scope: $stringtool.join($links, ' | ') | ||
| 75 | |||
| 76 | ## Groups, in display order. "others" receives whatever matches no prefix. | ||
| 77 | #set ($groups = []) | ||
| 78 | #set ($discard = $groups.add({'key': 'platform', 'heading': 'org.xwiki.platform extensions', 'prefix': 'org.xwiki.platform'})) | ||
| 79 | #set ($discard = $groups.add({'key': 'contrib', 'heading': 'org.xwiki.contrib extensions', 'prefix': 'org.xwiki.contrib'})) | ||
| 80 | #set ($discard = $groups.add({'key': 'rendering', 'heading': 'org.xwiki.rendering extensions', 'prefix': 'org.xwiki.rendering'})) | ||
| 81 | #set ($discard = $groups.add({'key': 'commons', 'heading': 'org.xwiki.commons extensions', 'prefix': 'org.xwiki.commons'})) | ||
| 82 | #set ($discard = $groups.add({'key': 'others', 'heading': 'Other extensions', 'prefix': ''})) | ||
| 83 | |||
| 84 | ## Table of contents for the two scopes that render one section per group. Each entry points at an | ||
| 85 | ## explicit {{id}} placed on the group's heading rather than at the heading's generated id, because | ||
| 86 | ## that id is derived from the heading text -- which carries a count that changes at every import, so | ||
| 87 | ## a link written against it would rot silently. An anchor inside the SAME page (empty reference) is | ||
| 88 | ## also the one ||anchor= form that reliably emits its fragment: a cross-page one loses it whenever | ||
| 89 | ## the request carries no session cookie (XWIKI-24993). | ||
| 90 | #macro (groupToc $tocGroups $tocCounts) | ||
| 91 | (% class="box" %) | ||
| 92 | ((( | ||
| 93 | **Jump to:** | ||
| 94 | |||
| 95 | #foreach ($tocGroup in $tocGroups) | ||
| 96 | * [[$tocGroup.heading>>||anchor="group-$tocGroup.key"]]: $tocCounts.get($tocGroup.key) | ||
| 97 | #end | ||
| 98 | * [[Total>>||anchor="group-total"]] | ||
| 99 | ))) | ||
| 100 | |||
| 101 | #end | ||
| 102 | |||
| 103 | = $scope.heading = | ||
| 104 | |||
| 105 | ## Every extension page has the id field indexed; the ones "without an id" hold the empty string. | ||
| 106 | ## Splitting here rather than in Velocity means a scope only pays for the rows it shows. | ||
| 107 | ## The 'withid' scope fetches nothing at all here -- each of its groups is a Live Data that loads its | ||
| 108 | ## own rows from the results page -- so this block only runs for the two scopes that still render a | ||
| 109 | ## table built in Velocity. | ||
| 110 | #if ($scope.key != 'withid') | ||
| 111 | #if ($scope.key == 'project') | ||
| 112 | #set ($statement = $pomBase) | ||
| 113 | #set ($fl = $pomFields) | ||
| 114 | #else | ||
| 115 | #set ($statement = "${extBase} AND ${idField}:${Q}${Q}") | ||
| 116 | #set ($fl = $fields) | ||
| 117 | #end | ||
| 118 | #set ($query = $services.query.createQuery($statement, 'solr')) | ||
| 119 | #set ($discard = $query.setLimit(2000)) | ||
| 120 | #set ($discard = $query.bindValue('fl', $fl)) | ||
| 121 | ## Alphabetical by the title the Page column shows. title_sort is the schema's dedicated sort field | ||
| 122 | ## for it (a copyField of title_*, of the case-insensitive 'lowercase' type); title_ itself is | ||
| 123 | ## analysed and cannot be sorted on. Solr sorts before the rights filter removes rows, so the order | ||
| 124 | ## survives filtering, and the buckets below keep it. | ||
| 125 | #set ($discard = $query.bindValue('sort', 'title_sort asc')) | ||
| 126 | #set ($results = $query.execute().get(0).results) | ||
| 127 | #end | ||
| 128 | |||
| 129 | #if ($scope.key == 'noid') | ||
| 130 | (% class="table" %) | ||
| 131 | |=Page|=Website | ||
| 132 | #set ($withWebsite = 0) | ||
| 133 | #foreach ($solrDoc in $results) | ||
| 134 | #set ($title = "$!solrDoc.getFirstValue('title_')") | ||
| 135 | #if ($title == '') | ||
| 136 | #set ($title = "$!solrDoc.getFirstValue('name')") | ||
| 137 | #end | ||
| 138 | #set ($title = $title.replace('|', '~|')) | ||
| 139 | #set ($docWebsite = '') | ||
| 140 | #foreach ($fieldName in $solrDoc.getFieldNames()) | ||
| 141 | #if ($docWebsite == '' && $fieldName.startsWith($websitePrefix)) | ||
| 142 | #set ($docWebsite = "$!solrDoc.getFirstValue($fieldName)") | ||
| 143 | #end | ||
| 144 | #end | ||
| 145 | #if ($docWebsite == '') | ||
| 146 | #set ($website = '-') | ||
| 147 | #else | ||
| 148 | #set ($withWebsite = $withWebsite + 1) | ||
| 149 | #set ($website = $docWebsite.replace('|', '~|')) | ||
| 150 | #end | ||
| 151 | |[[$title>>doc:extensions:$solrDoc.getFirstValue('fullname')]]|$website | ||
| 152 | #end | ||
| 153 | |**Total: $results.size()**|**$withWebsite with a website** | ||
| 154 | #elseif ($scope.key == 'project') | ||
| 155 | ## Same buckets as the 'withid' scope, on the id resolved below. Sorting is done here rather than | ||
| 156 | ## in Solr because the id comes from either of two fields depending on the page, which no single | ||
| 157 | ## Solr 'sort' can express -- the bound 'title_sort' only decides the order inside a bucket when | ||
| 158 | ## two rows share an id. | ||
| 159 | #set ($buckets = {}) | ||
| 160 | #foreach ($g in $groups) | ||
| 161 | #set ($discard = $buckets.put($g.key, [])) | ||
| 162 | #end | ||
| 163 | #set ($bothCount = 0) | ||
| 164 | #foreach ($solrDoc in $results) | ||
| 165 | ## The project object's id when there is one, the extension object's otherwise. Both classes | ||
| 166 | ## index an unset id as the empty string rather than leaving the field out, so the first | ||
| 167 | ## non-empty value is what has to be looked for, not the first value. | ||
| 168 | #set ($extId = '') | ||
| 169 | #foreach ($values in [$solrDoc.getFieldValues($projIdField), $solrDoc.getFieldValues($idField)]) | ||
| 170 | #if ($values) | ||
| 171 | #foreach ($v in $values) | ||
| 172 | #if ($extId == '' && "$!v" != '') | ||
| 173 | #set ($extId = "$v") | ||
| 174 | #end | ||
| 175 | #end | ||
| 176 | #end | ||
| 177 | #end | ||
| 178 | ## The first matching prefix wins | ||
| 179 | #set ($docKey = 'others') | ||
| 180 | #foreach ($g in $groups) | ||
| 181 | #if ($docKey == 'others' && $g.key != 'others' && $extId.startsWith($g.prefix)) | ||
| 182 | #set ($docKey = $g.key) | ||
| 183 | #end | ||
| 184 | #end | ||
| 185 | ## 'class' is multi-valued: it holds every class the page carries an object of. Resolved to two | ||
| 186 | ## booleans here so the render loop below stays a straight render. | ||
| 187 | #set ($classes = $solrDoc.getFieldValues('class')) | ||
| 188 | #set ($isProject = false) | ||
| 189 | #set ($isPom = false) | ||
| 190 | #if ($classes) | ||
| 191 | #set ($isProject = $classes.contains('ExtensionCode.ProjectClass')) | ||
| 192 | #set ($isPom = $classes.contains('ExtensionCode.ExtensionProxyClass')) | ||
| 193 | #end | ||
| 194 | #if ($isProject && $isPom) | ||
| 195 | #set ($bothCount = $bothCount + 1) | ||
| 196 | #end | ||
| 197 | ## Sorted on 'sortid', not on 'id': $collectiontool.sort compares Strings case-sensitively, so a | ||
| 198 | ## single upper-case group id would otherwise sort ahead of every lower-case one. | ||
| 199 | #set ($discard = $buckets.get($docKey).add({'doc': $solrDoc, 'id': $extId, 'sortid': $extId.toLowerCase(), 'project': $isProject, 'pom': $isPom})) | ||
| 200 | #end | ||
| 201 | #set ($counts = {}) | ||
| 202 | #foreach ($g in $groups) | ||
| 203 | #set ($discard = $counts.put($g.key, $buckets.get($g.key).size())) | ||
| 204 | #end | ||
| 205 | #groupToc($groups $counts) | ||
| 206 | #set ($projectCount = 0) | ||
| 207 | #set ($pomCount = 0) | ||
| 208 | #foreach ($g in $groups) | ||
| 209 | #set ($list = $collectiontool.sort($buckets.get($g.key), 'sortid')) | ||
| 210 | |||
| 211 | {{id name="group-$g.key"/}} | ||
| 212 | |||
| 213 | == $g.heading: $list.size() == | ||
| 214 | |||
| 215 | (% class="table" %) | ||
| 216 | |=Extension|=Id|=Project page|=Pom page | ||
| 217 | #foreach ($item in $list) | ||
| 218 | #set ($title = "$!item.doc.getFirstValue('title_')") | ||
| 219 | #if ($title == '') | ||
| 220 | #set ($title = "$!item.doc.getFirstValue('name')") | ||
| 221 | #end | ||
| 222 | #set ($title = $title.replace('|', '~|')) | ||
| 223 | #if ($item.id == '') | ||
| 224 | #set ($extId = '-') | ||
| 225 | #else | ||
| 226 | #set ($extId = $item.id.replace('|', '~|')) | ||
| 227 | #end | ||
| 228 | #if ($item.project) | ||
| 229 | #set ($projectCell = '✅') | ||
| 230 | #set ($projectCount = $projectCount + 1) | ||
| 231 | #else | ||
| 232 | #set ($projectCell = '') | ||
| 233 | #end | ||
| 234 | #if ($item.pom) | ||
| 235 | #set ($pomCell = '✅') | ||
| 236 | #set ($pomCount = $pomCount + 1) | ||
| 237 | #else | ||
| 238 | #set ($pomCell = '') | ||
| 239 | #end | ||
| 240 | |[[$title>>doc:extensions:$item.doc.getFirstValue('fullname')]]|$extId|$projectCell|$pomCell | ||
| 241 | #end | ||
| 242 | #end | ||
| 243 | |||
| 244 | {{id name="group-total"/}} | ||
| 245 | |||
| 246 | == Total == | ||
| 247 | |||
| 248 | **$results.size()** pages: **$projectCount** project pages and **$pomCount** pom pages, **$bothCount** of them both. | ||
| 249 | #else | ||
| 250 | ## Each group is a Live Data rather than a table built here, so that the columns can be filtered and | ||
| 251 | ## sorted without reloading the page. Nothing is fetched in this branch: the rows are loaded by the | ||
| 252 | ## Live Data itself from the sibling 'livedata-results' page -- which is where the Solr query, the | ||
| 253 | ## filters and the author display names now live -- and the only thing computed here is the number | ||
| 254 | ## in each heading, one count-only query per group. | ||
| 255 | ## | ||
| 256 | ## The group is passed as a source parameter; the liveTable source copies every source parameter it | ||
| 257 | ## does not recognise into the fake live table request, which is how 'group' reaches the results page | ||
| 258 | ## next to 'offset', 'limit', 'sort'/'dir' and one parameter per column filter. | ||
| 259 | #set ($resultPage = 'XWikiOrg.documentation-scripts-queries.migration-progress.extensions.extensions-details.livedata-results.WebHome') | ||
| 260 | ## 'page', 'authors' and 'website' are rendered as HTML by the results page (links to the extension | ||
| 261 | ## page, to the author profiles and to the website), so they need the html displayer -- the default | ||
| 262 | ## one would print the markup. 'authors' and 'website' are not sortable: the first is multi-valued, | ||
| 263 | ## which Solr refuses to sort on, and both would sort by the stored value rather than by what the | ||
| 264 | ## column shows. | ||
| 265 | #set ($descriptors = []) | ||
| 266 | #set ($discard = $descriptors.add({'id': 'page', 'name': 'Page', 'type': 'String', 'visible': true, | ||
| 267 | 'filterable': true, 'sortable': true, 'displayer': {'id': 'html'}, 'filter': {'id': 'text'}})) | ||
| 268 | #set ($discard = $descriptors.add({'id': 'id', 'name': 'Id', 'type': 'String', 'visible': true, | ||
| 269 | 'filterable': true, 'sortable': true, 'displayer': {'id': 'text'}, 'filter': {'id': 'text'}})) | ||
| 270 | #set ($discard = $descriptors.add({'id': 'authors', 'name': 'Developed by', 'type': 'String', 'visible': true, | ||
| 271 | 'filterable': true, 'sortable': false, 'displayer': {'id': 'html'}, 'filter': {'id': 'text'}})) | ||
| 272 | ## The last column is not the raw 'website' field but what that field means: the extension page's | ||
| 273 | ## //Documentation// button, i.e. whether the page has been converted to the new documentation. | ||
| 274 | ## Its filter is therefore a two-option list, not free text -- nobody would guess they have to type | ||
| 275 | ## "ExtensionLD" to find the converted ones. Only 'equals' is offered: declaring the 'empty' | ||
| 276 | ## operator would make the widget add an "empty" option of its own next to the two below. | ||
| 277 | #set ($discard = $descriptors.add({'id': 'documentation', 'name': 'Documentation', 'type': 'String', | ||
| 278 | 'visible': true, 'filterable': true, 'sortable': false, 'displayer': {'id': 'html'}, | ||
| 279 | 'filter': {'id': 'list', 'defaultOperator': 'equals', | ||
| 280 | 'operators': [{'id': 'equals', 'name': 'Equals'}], | ||
| 281 | 'options': [{'value': 'converted', 'label': 'Converted'}, | ||
| 282 | {'value': 'not-converted', 'label': 'Not converted yet'}]}})) | ||
| 283 | |||
| 284 | ## The counts, taken with setLimit(0) so only the total travels. The clauses must be written exactly | ||
| 285 | ## as the results page writes them, or a heading and the Live Data under it disagree. | ||
| 286 | #set ($counts = {}) | ||
| 287 | #set ($total = 0) | ||
| 288 | #foreach ($g in $groups) | ||
| 289 | #set ($countClauses = []) | ||
| 290 | #set ($discard = $countClauses.add($extBase)) | ||
| 291 | #set ($discard = $countClauses.add("-${idField}:${Q}${Q}")) | ||
| 292 | #if ($g.key == 'others') | ||
| 293 | #foreach ($other in $groups) | ||
| 294 | #if ($other.key != 'others') | ||
| 295 | #set ($discard = $countClauses.add("-${idField}:${other.prefix}*")) | ||
| 296 | #end | ||
| 297 | #end | ||
| 298 | #else | ||
| 299 | #set ($discard = $countClauses.add("${idField}:${g.prefix}*")) | ||
| 300 | #end | ||
| 301 | #set ($countQuery = $services.query.createQuery($stringtool.join($countClauses, ' AND '), 'solr')) | ||
| 302 | #set ($discard = $countQuery.setLimit(0)) | ||
| 303 | #set ($groupCount = $countQuery.execute().get(0).results.getNumFound()) | ||
| 304 | #set ($discard = $counts.put($g.key, $groupCount)) | ||
| 305 | #set ($total = $total + $groupCount) | ||
| 306 | #end | ||
| 307 | #groupToc($groups $counts) | ||
| 308 | #foreach ($g in $groups) | ||
| 309 | |||
| 310 | {{id name="group-$g.key"/}} | ||
| 311 | |||
| 312 | == $g.heading: $counts.get($g.key) == | ||
| 313 | |||
| 314 | {{liveData id="extensions-$g.key"}} | ||
| 315 | $jsontool.serialize({ | ||
| 316 | 'query': { | ||
| 317 | 'properties': ['page', 'id', 'authors', 'documentation'], | ||
| 318 | 'source': {'id': 'liveTable', 'resultPage': $resultPage, 'group': $g.key}, | ||
| 319 | 'sort': [{'property': 'page', 'descending': false}], | ||
| 320 | 'limit': 15 | ||
| 321 | }, | ||
| 322 | 'meta': {'propertyDescriptors': $descriptors} | ||
| 323 | }) | ||
| 324 | {{/liveData}} | ||
| 325 | #end | ||
| 326 | |||
| 327 | {{id name="group-total"/}} | ||
| 328 | |||
| 329 | == Total == | ||
| 330 | |||
| 331 | **$total** extension pages with an id. | ||
| 332 | #end | ||
| 333 | {{/velocity}} | ||
| 334 | {{/cache}} |