diff --git a/includes/ProgressTableProcessor.php b/includes/ProgressTableProcessor.php index 96ee2a0..4efa39e 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,12 @@ class ProgressTableProcessor { */ private ?string $errorMessage = null; + /** + * Row indexes that should not contain checkboxes if exclude-row-indexes is set + * @var array + */ + private array $skipRows = []; + /** * Constructor * @@ -84,6 +91,17 @@ public function __construct( string $wikitext, array $args, Parser $parser, PPFr return; } + if ( isset( $this->args['exclude-row-indexes'] ) ) { + $indexes = explode( ";" , $this->args['exclude-row-indexes'] ); + + // DOMDocument and XPath are 0-based, therefore, as above, we need to minus 1 from each of + // the user-provided args to ensure we are targeting the correct row + $this->skipRows = array_map( + fn( $i ) => max( 0, intval( $i ) - 1 ), + $indexes + ); + } + $this->loadAndValidateHtml(); } @@ -291,11 +309,23 @@ 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 { + // user did not want a checkbox for this cell. We still need to add the or else + // the remainder of the content is shifted left 1 place + if ( in_array( $rowIndex, $this->skipRows, true ) ) { + $emptyCell = $this->dom->createElement( 'td' ); + $emptyCell->setAttribute( 'class', self::CHECKBOX_CELL_CLASS ); + $row->insertBefore( $emptyCell, $row->firstChild ); + return; + } + $rowId = $this->getUniqueRowId( $row, $rowIndex ); $row->setAttribute( 'data-row-id', $rowId );