Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions includes/ProgressTableProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DOMDocument;
use DOMElement;
use DOMException;
use DOMXPath;
use Exception;
use MediaWiki\Html\Html;
Expand Down Expand Up @@ -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
*
Expand All @@ -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();
}

Expand Down Expand Up @@ -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 <td> 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 );

Expand Down
Loading