diff options
author | Mark A. Hershberger <mah@nichework.com> | 2022-07-04 14:08:09 -0400 |
---|---|---|
committer | Krinkle <krinkle@fastmail.com> | 2022-07-06 19:07:01 +0000 |
commit | c8586c88dc5e9e4c3d9a5594fdcb1d98a7017fe7 (patch) | |
tree | 593b6f8a7de3b6c4511373ddda791dddd540a3e3 /includes/site | |
parent | 6b3afa8ca3708751ba9b2aca0a5dc3c4a649b095 (diff) | |
download | mediawikicore-c8586c88dc5e9e4c3d9a5594fdcb1d98a7017fe7.tar.gz mediawikicore-c8586c88dc5e9e4c3d9a5594fdcb1d98a7017fe7.zip |
site: Consistently return null from Site::getDomain()
Note that null triggers the following for php 8.1:
PHP Deprecated: strrev(): Passing null to parameter #1 ($string) of
type string is deprecated
Got a few of these in WikiMapTest::testMakeForeignLink(), caused by a
single call in DBSiteStore.
Bug: T289926
Change-Id: I0b29963ec0e2e8a38a66e250e81fbc16e42465ab
Diffstat (limited to 'includes/site')
-rw-r--r-- | includes/site/DBSiteStore.php | 2 | ||||
-rw-r--r-- | includes/site/Site.php | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/includes/site/DBSiteStore.php b/includes/site/DBSiteStore.php index b06e794c8486..ee4497789391 100644 --- a/includes/site/DBSiteStore.php +++ b/includes/site/DBSiteStore.php @@ -200,7 +200,7 @@ class DBSiteStore implements SiteStore { 'site_source' => $site->getSource(), 'site_language' => $site->getLanguageCode() ?? '', 'site_protocol' => $site->getProtocol(), - 'site_domain' => strrev( $site->getDomain() ) . '.', + 'site_domain' => strrev( $site->getDomain() ?? '' ) . '.', 'site_data' => serialize( $site->getExtraData() ), // Site config diff --git a/includes/site/Site.php b/includes/site/Site.php index e84f1c7ce1ea..f93ed15dd52b 100644 --- a/includes/site/Site.php +++ b/includes/site/Site.php @@ -261,20 +261,26 @@ class Site implements Serializable { /** * Returns the domain of the site, ie en.wikipedia.org - * Or false if it's not known. + * Or null if it's not known. * * @since 1.21 * * @return string|null */ - public function getDomain() { + public function getDomain(): ?string { $path = $this->getLinkPath(); if ( $path === null ) { return null; } - return parse_url( $path, PHP_URL_HOST ); + $domain = parse_url( $path, PHP_URL_HOST ); + + if ( $domain === false ) { + $domain = null; + } + + return $domain; } /** |