From: Chad Horohoe Date: Mon, 26 Oct 2015 18:50:23 +0000 (-0700) Subject: PrefixSearch: avoid looking for titles that don't exist X-Git-Tag: 1.31.0-rc.0~9234^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=119a792d74d01e4eb897659e311eadad8ff30937;p=lhc%2Fweb%2Fwiklou.git PrefixSearch: avoid looking for titles that don't exist WikiPage::getRedirectTarget() can very easily return null. Don't blow up when that happens. Properly document PrefixSearch::getRedirectTarget() while we're here. Bug: T116029 Change-Id: Ib509e8e3e6ec04a787de3857a4b5ee9b01560559 --- diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index 430b4b8972..f36635be9d 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -258,12 +258,18 @@ abstract class PrefixSearch { return $array; } + /** + * Get a redirect's destination from a title + * @param Title $title A title to redirect. It may not redirect or even exist + * @return null|string If title exists and redirects, get the destination's prefixed name + */ private function getRedirectTarget( $title ) { $page = WikiPage::factory( $title ); if ( !$page->exists() ) { return null; } - return $page->getRedirectTarget()->getPrefixedText(); + $redir = $page->getRedirectTarget(); + return $redir ? $redir->getPrefixedText() : null; } /**