From 4febfe9e6ae2a0bdfb281b4a7f8e662145813c8f Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 5 May 2026 11:33:42 -0600 Subject: [PATCH 1/4] Support imagelinks migration --- includes/Query.php | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/includes/Query.php b/includes/Query.php index 4590759aa..09e51da78 100644 --- a/includes/Query.php +++ b/includes/Query.php @@ -151,8 +151,9 @@ public function buildAndSelect( bool $calcRows, string $profilingContext ): arra if ( $this->parameters->getParameter( 'openreferences' ) ) { if ( $this->parameters->getParameter( 'imagecontainer' ) ) { - $this->queryBuilder->select( 'il_to' ); $this->queryBuilder->table( 'imagelinks', 'ic' ); + $ilToField = $this->getImageLinksTitleField( 'ic', 'ic_lt' ); + $this->queryBuilder->select( [ 'lt_title' => $ilToField ] ); } else { $this->queryBuilder->table( 'pagelinks', 'pl' ); $this->queryBuilder->join( 'linktarget', 'lt', 'pl.pl_target_id = lt.lt_id' ); @@ -1037,13 +1038,15 @@ private function _hiddencategories( string $option ): never { */ private function _imagecontainer( array $option ): void { $this->queryBuilder->table( 'imagelinks', 'ic' ); - $this->queryBuilder->select( [ 'sortkey' => 'ic.il_to' ] ); + + $ilToField = $this->getImageLinksTitleField( 'ic', 'ic_lt' ); + $this->queryBuilder->select( [ 'sortkey' => $ilToField ] ); $where = []; if ( !$this->parameters->getParameter( 'openreferences' ) ) { $where = [ 'p.page_namespace = ' . NS_FILE, - 'p.page_title = ic.il_to', + "p.page_title = $ilToField", ]; } @@ -1067,7 +1070,9 @@ private function _imageused( array $option ): void { } $this->queryBuilder->table( 'imagelinks', 'il' ); - $this->queryBuilder->select( [ 'image_sel_title' => 'il.il_to' ] ); + + $ilToField = $this->getImageLinksTitleField( 'il', 'il_lt' ); + $this->queryBuilder->select( [ 'image_sel_title' => $ilToField ] ); $where = [ 'p.page_id = il.il_from' ]; @@ -1075,14 +1080,12 @@ private function _imageused( array $option ): void { foreach ( $option as $linkGroup ) { foreach ( $linkGroup as $link ) { $dbkey = $link->getDBkey(); - $fieldExpr = 'il.il_to'; - if ( $this->ignoreCase ) { - $ors[] = $this->caseInsensitiveComparison( $fieldExpr, '=', $dbkey ); + $ors[] = $this->caseInsensitiveComparison( $ilToField, '=', $dbkey ); continue; } - $ors[] = $this->dbr->expr( $fieldExpr, '=', $dbkey ); + $ors[] = $this->dbr->expr( $ilToField, '=', $dbkey ); } } @@ -2362,4 +2365,30 @@ private function getCategoryTitleFieldForAlias( string $clAlias, string $ltAlias return "$clAlias.cl_to"; } + + /** + * Add a linktarget join for imagelinks and return the title field expression. + * For MW 1.46+ adds linktarget join, for MW 1.45 returns empty (uses il_to directly). + * + * @param string $ilAlias Alias for the imagelinks table (e.g. 'il', 'ic') + * @param string $ltAlias Alias to use for the joined linktarget row + * @return string The field expression for the image file title + */ + private function getImageLinksTitleField( string $ilAlias, string $ltAlias ): string { + // LinksMigration covers imagelinks starting in MW 1.45/1.46. + // Check if the new schema is active (il_target_id column present). + $queryInfo = $this->linksMigration->getQueryInfo( 'imagelinks' ); + if ( in_array( 'linktarget', $queryInfo['tables'], true ) ) { + // MW 1.46+: join linktarget via il_target_id + $this->queryBuilder->join( 'linktarget', $ltAlias, [ + "$ilAlias.il_target_id = $ltAlias.lt_id", + "$ltAlias.lt_namespace" => NS_FILE, + ] ); + + return "$ltAlias.lt_title"; + } + + // MW 1.45: il_to is still the direct title column + return "$ilAlias.il_to"; + } } From 60f31da54b1668d9c94f7e53d928b0cd69a5ed5f Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 5 May 2026 11:35:27 -0600 Subject: [PATCH 2/4] Update --- includes/Parse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Parse.php b/includes/Parse.php index 3e466786d..c52ef2142 100644 --- a/includes/Parse.php +++ b/includes/Parse.php @@ -378,7 +378,7 @@ private function processQueryResults( array $rows, Parser $parser ): array { $imageContainer = $this->parameters->getParameter( 'imagecontainer' ) ?? []; if ( $imageContainer !== [] ) { $pageNamespace = NS_FILE; - $pageTitle = $row->il_to; + $pageTitle = $row->lt_title; } else { // Maybe non-existing title $pageNamespace = (int)$row->lt_namespace; From bc07f61f5ee020243b693618adf772ebd4f7472e Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 5 May 2026 12:06:39 -0600 Subject: [PATCH 3/4] Fix for older versions --- includes/Query.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/Query.php b/includes/Query.php index 09e51da78..014f0ce78 100644 --- a/includes/Query.php +++ b/includes/Query.php @@ -4,6 +4,7 @@ namespace MediaWiki\Extension\DynamicPageList4; +use InvalidArgumentException; use MediaWiki\Extension\DynamicPageList4\Exceptions\QueryException; use MediaWiki\ExternalLinks\LinkFilter; use MediaWiki\Linker\LinksMigration; @@ -2377,8 +2378,15 @@ private function getCategoryTitleFieldForAlias( string $clAlias, string $ltAlias private function getImageLinksTitleField( string $ilAlias, string $ltAlias ): string { // LinksMigration covers imagelinks starting in MW 1.45/1.46. // Check if the new schema is active (il_target_id column present). - $queryInfo = $this->linksMigration->getQueryInfo( 'imagelinks' ); - if ( in_array( 'linktarget', $queryInfo['tables'], true ) ) { + try { + $queryInfo = $this->linksMigration->getQueryInfo( 'imagelinks' ); + $isNew = in_array( 'linktarget', $queryInfo['tables'], true ); + } catch ( InvalidArgumentException ) { + // Pre-1.46 MW where LinksMigration doesn't know imagelinks + $isNew = false; + } + + if ( $isNew ) { // MW 1.46+: join linktarget via il_target_id $this->queryBuilder->join( 'linktarget', $ltAlias, [ "$ilAlias.il_target_id = $ltAlias.lt_id", From ed6c99af641a9a8cc4ff84d7eed48d4409ef0ea5 Mon Sep 17 00:00:00 2001 From: CosmicAlpha Date: Tue, 5 May 2026 12:10:21 -0600 Subject: [PATCH 4/4] Update --- includes/Query.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/Query.php b/includes/Query.php index 014f0ce78..c90e3ac9d 100644 --- a/includes/Query.php +++ b/includes/Query.php @@ -2376,9 +2376,10 @@ private function getCategoryTitleFieldForAlias( string $clAlias, string $ltAlias * @return string The field expression for the image file title */ private function getImageLinksTitleField( string $ilAlias, string $ltAlias ): string { - // LinksMigration covers imagelinks starting in MW 1.45/1.46. - // Check if the new schema is active (il_target_id column present). + // LinksMigration covers imagelinks starting in MW 1.46. It will throw an + // InvalidArgumentException on earlier versions where it is not covered. try { + // Check if the new schema is active (il_target_id column present). $queryInfo = $this->linksMigration->getQueryInfo( 'imagelinks' ); $isNew = in_array( 'linktarget', $queryInfo['tables'], true ); } catch ( InvalidArgumentException ) {