From 9244518b26c8fee3434c007b7d5820e26918ab7c Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Mon, 16 Oct 2017 20:16:33 +0200 Subject: [PATCH 1/3] Use different query for SQLite databases. - Fix: Avoid errors with SQLite database. Closes #35. --- includes/Config.php | 17 ++++++++++++++ includes/Targets.php | 53 +++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/includes/Config.php b/includes/Config.php index 0940cd2..f5c77d0 100644 --- a/includes/Config.php +++ b/includes/Config.php @@ -169,9 +169,24 @@ class Config { */ public $sameNamespace; + /** + * Caches the global $wgDBtype variable. + * @var string $dbType; + */ + private $dbType; + public $enableConsoleOutput; public $enableDebugConsoleOutput; + /** + * Determines whether the MediaWiki database is SQLITE by inspecting the + * $wgDBtype variable (which is cached in $this->dbType). + * @return bool True if the database is SQLITE. + */ + public function sqliteDatabase() { + return $this->dbType === 'sqlite'; + } + /** * Constructs a new Config object. * @@ -197,6 +212,7 @@ class Config { global $wgLinkTitlesEnableNoTargetMagicWord; global $wgLinkTitlesCheckRedirect; global $wgLinkTitlesSpecialPageReloadAfter; + global $wgDBtype; $this->parseOnEdit = $wgLinkTitlesParseOnEdit; $this->parseOnRender = $wgLinkTitlesParseOnRender; $this->preferShortTitles = $wgLinkTitlesPreferShortTitles; @@ -217,5 +233,6 @@ class Config { $this->specialPageReloadAfter = $wgLinkTitlesSpecialPageReloadAfter; $this->enableConsoleOutput = false; $this->enableDebugConsoleOutput = false; + $this->dbType = $wgDBtype; } } diff --git a/includes/Targets.php b/includes/Targets.php index d129d72..e88d042 100644 --- a/includes/Targets.php +++ b/includes/Targets.php @@ -74,6 +74,12 @@ class Targets { private $config; + /** + * Stores the CHAR_LENGTH function to be used with the database connection. + * @var string $charLengthFunction + */ + private $charLengthFunction; + /** * The constructor is private to enforce using the singleton pattern. * @param \Title $title @@ -129,34 +135,25 @@ class Targets { // = 0) are returned. Since the db may be sqlite, we need a try..catch // structure because sqlite does not support the CHAR_LENGTH function. $dbr = wfGetDB( DB_SLAVE ); - try { - $this->queryResult = $dbr->select( - 'page', - array( 'page_title', 'page_namespace' , "weight" => $weightSelect), - array_filter( - array( - 'page_namespace IN ' . $namespacesClause, - 'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength, - $blackList, - ) - ), - __METHOD__, - array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sortOrder ) - ); - } catch (Exception $e) { - $this->queryResult = $dbr->select( - 'page', - array( 'page_title', 'page_namespace' , "weight" => $weightSelect ), - array_filter( - array( - 'page_namespace IN ' . $namespacesClause, - 'LENGTH(page_title) >= ' . $this->config->minimumTitleLength, - $blackList, - ) - ), - __METHOD__, - array( 'ORDER BY' => 'weight ASC, LENGTH(page_title) ' . $sortOrder ) - ); + $this->queryResult = $dbr->select( + 'page', + array( 'page_title', 'page_namespace' , "weight" => $weightSelect), + array_filter( + array( + 'page_namespace IN ' . $namespacesClause, + 'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength, + $blackList, + ) + ), + __METHOD__, + array( 'ORDER BY' => 'weight ASC, ' . $this->charLength() . '(page_title) ' . $sortOrder ) + ); + } + + private function charLength() { + if ($this->charLengthFunction === null) { + $this->charLengthFunction = $this->config->sqliteDatabase() ? 'LENGTH' : 'CHAR_LENGTH'; } + return $this->charLengthFunction; } } From 9f1c5a655e20e5b7f6a873c444ffa0111821bd0b Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Tue, 17 Oct 2017 19:59:45 +0200 Subject: [PATCH 2/3] Substitute other CHAR_LENGTH occurrence. Addresses #35. --- includes/Targets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Targets.php b/includes/Targets.php index e88d042..bcb4d43 100644 --- a/includes/Targets.php +++ b/includes/Targets.php @@ -141,7 +141,7 @@ class Targets { array_filter( array( 'page_namespace IN ' . $namespacesClause, - 'CHAR_LENGTH(page_title) >= ' . $this->config->minimumTitleLength, + $this->charLength() . '(page_title) >= ' . $this->config->minimumTitleLength, $blackList, ) ), From 03f99fd9fff1abd7783a32d8f0ef06993cf7ab5f Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Tue, 17 Oct 2017 21:03:46 +0200 Subject: [PATCH 3/3] Prepare release 5.0.5. --- NEWS | 8 ++++++++ extension.json | 2 +- gh-pages | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 9a29dfd..03bc3c6 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Version 5.0.5 (2017-10-17) +------------------------------------------------------------------------ + +- Fix: Avoid errors with SQLite database. + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + Version 5.0.4 (2017-09-23) ------------------------------------------------------------------------ diff --git a/extension.json b/extension.json index bdfe5d8..ada0bdc 100644 --- a/extension.json +++ b/extension.json @@ -9,7 +9,7 @@ ], "type": "parserhook", "url": "https://www.mediawiki.org/wiki/Extension:LinkTitles", - "version": "5.0.4", + "version": "5.0.5", "license-name": "GPL-2.0+", "descriptionmsg": "linktitles-desc", "requires": { diff --git a/gh-pages b/gh-pages index 570fcaa..7161033 160000 --- a/gh-pages +++ b/gh-pages @@ -1 +1 @@ -Subproject commit 570fcaa3c59f534884a227fbfd34c328410f91a4 +Subproject commit 7161033535b0a0624b92cc85a116c64229cd05a2