mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-23 15:56:55 +00:00
ScribuntoContentHandler: Fix Phan suppressions
Title::castFromPageReference() and similar methods can return null instead of Title when the parameter is null. Although that could not happen in this code, there is no way to tell that to Phan, so suppressions were required to avoid its warnings about possible nulls. Instead, since MW 1.41, we can just use Title::newFromPageReference(), which can't return null (and doesn't accept null as the parameter). See also Ida4da75953cf3bca372a40dc88022443109ca0cb in MediaWiki core. Change-Id: Ia3c415cdd68fe4b19869aa8eb8e816e707bb5ad6
This commit is contained in:
parent
09f92105ed
commit
ae8c68b051
|
@ -96,11 +96,10 @@ class ScribuntoContentHandler extends CodeContentHandler {
|
|||
public function validate( TextContent $content, PageIdentity $page ) {
|
||||
if ( !( $page instanceof Title ) ) {
|
||||
$titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
|
||||
$page = $titleFactory->castFromPageIdentity( $page );
|
||||
$page = $titleFactory->newFromPageIdentity( $page );
|
||||
}
|
||||
|
||||
$engine = Scribunto::newDefaultEngine();
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgument
|
||||
$engine->setTitle( $page );
|
||||
return $engine->validate( $content->getText(), $page->getPrefixedDBkey() );
|
||||
}
|
||||
|
@ -115,13 +114,12 @@ class ScribuntoContentHandler extends CodeContentHandler {
|
|||
) {
|
||||
'@phan-var ScribuntoContent $content';
|
||||
$page = $cpoParams->getPage();
|
||||
$title = Title::castFromPageReference( $page );
|
||||
$title = Title::newFromPageReference( $page );
|
||||
$parserOptions = $cpoParams->getParserOptions();
|
||||
$revId = $cpoParams->getRevId();
|
||||
$generateHtml = $cpoParams->getGenerateHtml();
|
||||
$parser = MediaWikiServices::getInstance()->getParserFactory()->getInstance();
|
||||
$sourceCode = $content->getText();
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgument
|
||||
$docTitle = Scribunto::getDocPage( $title );
|
||||
$docMsg = $docTitle ? wfMessage(
|
||||
$docTitle->exists() ? 'scribunto-doc-page-show' : 'scribunto-doc-page-does-not-exist',
|
||||
|
@ -172,7 +170,6 @@ class ScribuntoContentHandler extends CodeContentHandler {
|
|||
|
||||
// Validate the script, and include an error message and tracking
|
||||
// category if it's invalid
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgument
|
||||
$status = $this->validate( $content, $title );
|
||||
if ( !$status->isOK() ) {
|
||||
// FIXME: This uses a Status object, which in turn uses global RequestContext
|
||||
|
@ -198,7 +195,6 @@ class ScribuntoContentHandler extends CodeContentHandler {
|
|||
}
|
||||
|
||||
$engine = Scribunto::newDefaultEngine();
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgument
|
||||
$engine->setTitle( $title );
|
||||
$codeLang = $engine->getGeSHiLanguage();
|
||||
$html .= $this->highlight( $sourceCode, $parserOutput, $codeLang );
|
||||
|
|
Loading…
Reference in a new issue