Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaWiki 1.43 DBAL compatibility #5634

Open
osnard opened this issue May 4, 2024 · 2 comments
Open

MediaWiki 1.43 DBAL compatibility #5634

osnard opened this issue May 4, 2024 · 2 comments
Labels
bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error MW 1.43

Comments

@osnard
Copy link
Contributor

osnard commented May 4, 2024

Setup

  • SMW version: master branch at #f6b3855f
  • MW version: 1.43.0-wmf.2 (pre-release)
  • PHP version: 8.1.20 (fpm-fcgi)
  • DB system (MySQL, Blazegraph, etc.) and version: 10.11.4-MariaDB-1:10.11.4+maria~ubu2204

Issue

During the Wikimedia Hackathon 2024, I tried to run the latest version of Semantic MediaWiki on a pre-release version of MediaWiki 1.43 (upcomming LTS). The goal was to identify issues and maybe provide patches right away. Unfortunately, the available time will not allow to provide a fix, therefore I document the issue here.

First: Installation (running maintenance/run.php update) and activation of the extension ran smoothly, No immediate error.

But when trying to access Special:Browse the API call with the parameters

action: smwbrowse
format: json
browse: subject
params: {"subject":"Main_Page","ns":0,"iw":"","subobject":"","options":{"dir":null,"lang":"en","group":null,"printable":null,"offset":null,"including":false,"showInverse":false,"showAll":true,"showGroup":true,"showSort":false,"api":true,"valuelistlimit.out":"30","valuelistlimit.in":"20"},"type":"html"}

failed with the error

Exception caught: Table name component contains unexpected quote or dot character

"Wikimedia\\Rdbms\\DBLanguageError at /includes/libs/rdbms/platform/SQLPlatform.php(1051)
from /includes/libs/rdbms/platform/SQLPlatform.php(1051)
#0 /includes/libs/rdbms/platform/SQLPlatform.php(991): Wikimedia\\Rdbms\\Platform\\SQLPlatform->extractTableNameComponents(string)
#1 /includes/libs/rdbms/platform/SQLPlatform.php(957): Wikimedia\\Rdbms\\Platform\\SQLPlatform->qualifiedTableComponents(string)
#2 /includes/libs/rdbms/platform/SQLPlatform.php(936): Wikimedia\\Rdbms\\Platform\\SQLPlatform->tableName(string)
#3 /includes/libs/rdbms/platform/SQLPlatform.php(837): Wikimedia\\Rdbms\\Platform\\SQLPlatform->tableNameWithAlias(string, string)
#4 /includes/libs/rdbms/platform/SQLPlatform.php(666): Wikimedia\\Rdbms\\Platform\\SQLPlatform->tableNamesWithIndexClauseOrJOIN(array, array, array, array)
#5 /includes/libs/rdbms/database/Database.php(3335): Wikimedia\\Rdbms\\Platform\\SQLPlatform->selectSQLText(string, string, string, string, array, array)
#6 /includes/libs/rdbms/database/DatabaseMySQL.php(730): Wikimedia\\Rdbms\\Database->selectSQLText(string, string, string, string, array, array)
#7 /includes/libs/rdbms/database/Database.php(1342): Wikimedia\\Rdbms\\DatabaseMySQL->selectSQLText(string, string, string, string, array, array)
#8 /includes/libs/rdbms/database/DBConnRef.php(126): Wikimedia\\Rdbms\\Database->select(string, string, string, string, array, array)
#9 /includes/libs/rdbms/database/DBConnRef.php(358): Wikimedia\\Rdbms\\DBConnRef->__call(string, array)
#10 /extensions/SemanticMediaWiki/src/MediaWiki/Connection/Database.php(247): Wikimedia\\Rdbms\\DBConnRef->select(string, string, string, string, array, array)
#11 /extensions/SemanticMediaWiki/src/SQLStore/EntityStore/TraversalPropertyLookup.php(97): SMW\\MediaWiki\\Connection\\Database->select(string, string, string, string, array)
#12 /extensions/SemanticMediaWiki/src/SQLStore/EntityStore/EntityLookup.php(437): SMW\\SQLStore\\EntityStore\\TraversalPropertyLookup->fetchFromTable(SMW\\SQLStore\\PropertyTableDefinition, SMW\\DIWikiPage, SMW\\RequestOptions)
#13 /extensions/SemanticMediaWiki/src/SQLStore/SQLStore.php(289): SMW\\SQLStore\\EntityStore\\EntityLookup->getInProperties(SMW\\DIWikiPage, SMW\\RequestOptions)
#14 /extensions/SemanticMediaWiki/src/MediaWiki/Specials/Browse/HtmlBuilder.php(876): SMW\\SQLStore\\SQLStore->getInProperties(SMW\\DIWikiPage, SMW\\RequestOptions)
#15 /extensions/SemanticMediaWiki/src/MediaWiki/Specials/Browse/HtmlBuilder.php(355): SMW\\MediaWiki\\Specials\\Browse\\HtmlBuilder->getInData()
#16 /extensions/SemanticMediaWiki/src/MediaWiki/Specials/Browse/HtmlBuilder.php(263): SMW\\MediaWiki\\Specials\\Browse\\HtmlBuilder->createHTML()
#17 /extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/SubjectLookup.php(107): SMW\\MediaWiki\\Specials\\Browse\\HtmlBuilder->buildHTML()
#18 /extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse/SubjectLookup.php(69): SMW\\MediaWiki\\Api\\Browse\\SubjectLookup->buildHTML(array)
#19 /extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse.php(268): SMW\\MediaWiki\\Api\\Browse\\SubjectLookup->lookup(array)
#20 /extensions/SemanticMediaWiki/src/MediaWiki/Api/Browse.php(71): SMW\\MediaWiki\\Api\\Browse->callSubjectLookup(array)
#21 /includes/api/ApiMain.php(1948): SMW\\MediaWiki\\Api\\Browse->execute()
#22 /includes/api/ApiMain.php(924): ApiMain->executeAction()
#23 /includes/api/ApiMain.php(895): ApiMain->executeActionWithErrorHandling()
#24 /includes/api/ApiEntryPoint.php(158): ApiMain->execute()
#25 /includes/MediaWikiEntryPoint.php(199): MediaWiki\\Api\\ApiEntryPoint->execute()
#26 /api.php(44): MediaWiki\\MediaWikiEntryPoint->run()

Apparently the code at

$result = $connection->select(
$from,
' smw_title,smw_sortkey,smw_iw',
$conditions,
__METHOD__,
$options
);

gets called with

$from = "`smw_object_ids` INNER JOIN ( SELECT p_id FROM `smw_di_wikipage`  WHERE o_id=0  GROUP BY p_id ) AS t1 ON t1.p_id=smw_id"

which is not allowed in the MediaWiki 1.43 DBAL anymore.

Wikimedia engineer Ladsgroup recommended to use the new "query builder" (in this particular case SelectQueryBuilder, see https://www.mediawiki.org/wiki/Manual:Database_access#SelectQueryBuilder) implementation of MediaWiki.

I can not tell how much code in Semantic MediaWiki is actually affected by this, but there are ~27 files that contain the INNER JOIN syntax.

@osnard osnard added the bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error label May 4, 2024
@krabina krabina added the MW 1.43 label May 4, 2024
@osnard
Copy link
Contributor Author

osnard commented May 5, 2024

I have created the draft PR #5636
It does not work yet, but roughly shows the direction. I believe the task contains two main items:

  1. Make new MW43 DBAL factory methods (new*QueryBuilder()) available from SMW\Connection\ConnectionRef or SMW\MediaWiki\Connection\Database
  2. Rewrite all problematic queries (most likely the ones with an INNER JOIN on a subquery) to MW43 DBAL

@Nikerabbit
Copy link
Contributor

FYI: SelectQueryBuilder was introduced long time ago: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/566127. It's only now that everything is getting migrated over. The other query builders or some special features have been introduced later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error MW 1.43
Projects
None yet
Development

No branches or pull requests

3 participants