From 6456374249567892acfa4d6a98eef60c9410a3f7 Mon Sep 17 00:00:00 2001 From: OriginalAuthority Date: Fri, 20 Mar 2026 01:00:48 +0000 Subject: [PATCH 1/5] Add ability to sort table rows --- includes/ProgressTableProcessor.php | 5 ++++- resources/index.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/ProgressTableProcessor.php b/includes/ProgressTableProcessor.php index 96ee2a0..348117e 100644 --- a/includes/ProgressTableProcessor.php +++ b/includes/ProgressTableProcessor.php @@ -174,7 +174,7 @@ private function validateDataRowIds(): bool { foreach ( $dataRows as $row ) { $rowId = $this->extractDataRowId( $row ); if ( empty( $rowId ) ) { - $this->errorMessage = 'When unique-column-index is not provided, + $this->errorMessage = 'When unique-column-index is not provided, all data rows must have a data-row-id attribute.'; return false; } @@ -348,6 +348,9 @@ private function addCheckboxCellToRow( DOMElement $row, int $rowIndex ): void { $cell = $this->dom->createElement( 'td' ); $cell->setAttribute( 'class', self::CHECKBOX_CELL_CLASS ); + // set the initial sortable value to 0 (does nothing if the table isn't sortable) + // when the JS runs, it will change this to 1 for tracked cells + $cell->setAttribute( 'data-sort-value', 0 ); $cell->appendChild( $checkboxDiv ); $row->insertBefore( $cell, $row->firstChild ); diff --git a/resources/index.js b/resources/index.js index 82ac3ce..46eadc4 100644 --- a/resources/index.js +++ b/resources/index.js @@ -152,8 +152,19 @@ var ProgressTracker = { // remove the disable attribute from the checkbox so that it can be actioned // this happens irrespective of whether the checkbox is checked or not checkbox.disabled = false; + + // if this row is tracked, change the sortable value to 1 to allow sorting + // (even if the table isn't sortable) + let sortVal = isChecked ? 1 : 0; + let $cell = $( checkbox ).closest( 'td' ); + + if ($cell.length) { + $cell.attr( 'data-sort-value', sortVal ); + $cell.data( 'sortValue', sortVal ); + } } }.bind( this ) ); + $( table ).trigger('update'); }, /** From cd98eac629d8be7e045e806d89aa29599ca90160 Mon Sep 17 00:00:00 2001 From: OriginalAuthority Date: Fri, 20 Mar 2026 01:02:09 +0000 Subject: [PATCH 2/5] CI: lint to MW Standards --- resources/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/index.js b/resources/index.js index 46eadc4..7bdefd4 100644 --- a/resources/index.js +++ b/resources/index.js @@ -158,7 +158,7 @@ var ProgressTracker = { let sortVal = isChecked ? 1 : 0; let $cell = $( checkbox ).closest( 'td' ); - if ($cell.length) { + if ( $cell.length ) { $cell.attr( 'data-sort-value', sortVal ); $cell.data( 'sortValue', sortVal ); } From 4125dff31db96d42d8620227db4eb7cc2561d566 Mon Sep 17 00:00:00 2001 From: OriginalAuthority Date: Fri, 20 Mar 2026 01:15:18 +0000 Subject: [PATCH 3/5] Add ability to define location of checkboxes --- includes/ProgressTableProcessor.php | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/includes/ProgressTableProcessor.php b/includes/ProgressTableProcessor.php index 348117e..12aecd9 100644 --- a/includes/ProgressTableProcessor.php +++ b/includes/ProgressTableProcessor.php @@ -4,6 +4,7 @@ use DOMDocument; use DOMElement; +use DOMException; use DOMXPath; use Exception; use MediaWiki\Html\Html; @@ -58,6 +59,15 @@ class ProgressTableProcessor { */ private ?string $errorMessage = null; + /** + * Whether the checkbox row should go on the left (first column) or the right + * (last column). Accepted values are "last" or anything else which will default to first + * (hence the 'first' here actually does nothing) + * @TODO: maybe we need to automatically decide this from rtl lang also + * @var string + */ + private string $checkboxLocation = 'first'; + /** * Constructor * @@ -84,6 +94,10 @@ public function __construct( string $wikitext, array $args, Parser $parser, PPFr return; } + if ( isset( $this->args['location'] ) ) { + // maybe don't need htmlspecialchars here but paranoia + $this->checkboxLocation = htmlspecialchars( $this->args['location'] ); + } $this->loadAndValidateHtml(); } @@ -270,7 +284,11 @@ private function addProgressHeader(): void { $progressHeader->appendChild( $headerDiv ); - $headerRow->insertBefore( $progressHeader, $headerRow->firstChild ); + if ( $this->checkboxLocation === 'last' ) { + $headerRow->appendChild( $progressHeader ); + } else { + $headerRow->insertBefore( $progressHeader, $headerRow->firstChild ); + } } } @@ -291,9 +309,12 @@ private function processDataRows(): void { /** * Creates and adds a progress tracking checkbox cell to a single data row. + * * @param DOMElement $row the row we are currently working on * @param int $rowIndex the index we are applying to the row + * * @return void + * @throws DOMException */ private function addCheckboxCellToRow( DOMElement $row, int $rowIndex ): void { $rowId = $this->getUniqueRowId( $row, $rowIndex ); @@ -313,6 +334,7 @@ private function addCheckboxCellToRow( DOMElement $row, int $rowIndex ): void { $checkBoxInput->setAttribute( 'class', 'cdx-checkbox__input' ); $checkBoxInput->setAttribute( 'data-row-id', $rowId ); $checkBoxInput->setAttribute( 'id', $rowId ); + // disable the checkbox by default, when the JS runs, it will remove the disabled attribute. // this is to ensure that no checkbox is selected before the JS initialises (or in the case of an unregistered // user, the checkbox will remain disabled) @@ -353,7 +375,11 @@ private function addCheckboxCellToRow( DOMElement $row, int $rowIndex ): void { $cell->setAttribute( 'data-sort-value', 0 ); $cell->appendChild( $checkboxDiv ); - $row->insertBefore( $cell, $row->firstChild ); + if ( $this->checkboxLocation === 'last' ) { + $row->appendChild( $cell ); + } else { + $row->insertBefore( $cell, $row->firstChild ); + } } /** From 61c1bbe335e666b643b6cfab71f77f6939f76140 Mon Sep 17 00:00:00 2001 From: OriginalAuthority Date: Fri, 20 Mar 2026 01:31:17 +0000 Subject: [PATCH 4/5] Add background for checked off items --- resources/index.less | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/index.less b/resources/index.less index 294a48f..36a7c73 100644 --- a/resources/index.less +++ b/resources/index.less @@ -1,5 +1,9 @@ @import "mediawiki.skin.variables.less"; +:root { + --tpt-checked-background: @color-success; +} + .progress-tracking-table .header_icon { display: flex; margin: 0; @@ -8,3 +12,7 @@ .ext-tableProgressTracking-icon-check { .cdx-mixin-css-icon( @cdx-icon-check ); } + +td.progress-tracker-checkbox-cell:has(input[type="checkbox"]:checked) { + background: var(--tpt-checked-background); +} From 6a2f9f26349f2462ab9f2e3de33ee663b69b864b Mon Sep 17 00:00:00 2001 From: OriginalAuthority Date: Fri, 20 Mar 2026 01:32:54 +0000 Subject: [PATCH 5/5] bugfix: centre checkboxes in the column --- resources/index.less | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/index.less b/resources/index.less index 36a7c73..f4ab3d1 100644 --- a/resources/index.less +++ b/resources/index.less @@ -16,3 +16,12 @@ td.progress-tracker-checkbox-cell:has(input[type="checkbox"]:checked) { background: var(--tpt-checked-background); } + +// Center checkboxes +// https://dev.miraheze.org/wiki/User:Splatched/TPTTweaks.js +.progress-tracker-checkbox-cell .cdx-checkbox { + margin-left: auto; + margin-right: auto; + width: max-content; + display: flex; +}