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

Fix deprecations for MediaWiki 1.43 #301

Merged
merged 7 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
'MediaWikiNoEmptyIfDefined',
'SecurityCheck-LikelyFalsePositive',
'PhanAccessMethodInternal',

'PhanDeprecatedFunction',
'PhanDeprecatedProperty',
];

return $cfg;
24 changes: 14 additions & 10 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use MediaWiki\Extension\DynamicPageList3\Maintenance\CreateView;
use MediaWiki\Installer\DatabaseUpdater;
use MediaWiki\Parser\Parser;
use MediaWiki\Parser\ParserOutputLinkTypes;
use MediaWiki\Parser\PPFrame;
use MediaWiki\Registration\ExtensionRegistry;

Expand Down Expand Up @@ -211,15 +212,15 @@
}

$text = $parse->parse( $input, $parser, $reset, $eliminate, true );
$parserOutput = $parser->getOutput();

// we can remove the templates by save/restore
if ( $reset['templates'] ?? false ) {
$saveTemplates = $parser->getOutput()->getTemplates();
$saveTemplates = $parserOutput->getLinkList( ParserOutputLinkTypes::TEMPLATE );
}

// we can remove the categories by save/restore
if ( $reset['categories'] ?? false ) {
$parserOutput = $parser->getOutput();
$saveCategories = array_combine(
$parserOutput->getCategoryNames(),
array_map( fn ( $value ) => $parserOutput->getCategorySortKey( $value ), $parserOutput->getCategoryNames() )
Expand All @@ -228,7 +229,7 @@

// we can remove the images by save/restore
if ( $reset['images'] ?? false ) {
$saveImages = $parser->getOutput()->getImages();
$saveImages = $parserOutput->getLinkList( ParserOutputLinkTypes::MEDIA );
}

$parsedDPL = $parser->recursiveTagParse( $text );
Expand Down Expand Up @@ -594,28 +595,30 @@
// called during the final output phase; removes links created by DPL
if ( isset( self::$createdLinks ) ) {
if ( array_key_exists( 0, self::$createdLinks ) ) {
foreach ( $parser->getOutput()->getLinks() as $nsp => $link ) {
$parserLinks = $parser->getOutput()->getLinkList( ParserOutputLinkTypes::LOCAL );
foreach ( $parserLinks as $nsp => $link ) {

Check notice

Code scanning / Phpmd (reported by Codacy)

Prohibit the definition or assignment of unused local variables Note

Avoid unused local variables such as '$link'.
if ( !array_key_exists( $nsp, self::$createdLinks[0] ) ) {
continue;
}

$parser->getOutput()->mLinks[$nsp] = array_diff_assoc( $parser->getOutput()->getLinks()[$nsp], self::$createdLinks[0][$nsp] );
$parser->getOutput()->mLinks[$nsp] = array_diff_assoc( $parserLinks[$nsp], self::$createdLinks[0][$nsp] );

if ( count( $parser->getOutput()->getLinks()[$nsp] ) == 0 ) {
if ( count( $parserLinks[$nsp] ) == 0 ) {
unset( $parser->getOutput()->mLinks[$nsp] );
}
}
}

if ( isset( self::$createdLinks ) && array_key_exists( 1, self::$createdLinks ) ) {
foreach ( $parser->getOutput()->getTemplates() as $nsp => $tpl ) {
$parserTemplates = $parser->getOutput()->getLinkList( ParserOutputLinkTypes::TEMPLATE );
foreach ( $parserTemplates as $nsp => $tpl ) {

Check notice

Code scanning / Phpmd (reported by Codacy)

Prohibit the definition or assignment of unused local variables Note

Avoid unused local variables such as '$tpl'.
if ( !array_key_exists( $nsp, self::$createdLinks[1] ) ) {
continue;
}

$parser->getOutput()->mTemplates[$nsp] = array_diff_assoc( $parser->getOutput()->getTemplates()[$nsp], self::$createdLinks[1][$nsp] );
$parser->getOutput()->mTemplates[$nsp] = array_diff_assoc( $parserTemplates[$nsp], self::$createdLinks[1][$nsp] );

if ( count( $parser->getOutput()->getTemplates()[$nsp] ) == 0 ) {
if ( count( $parserTemplates[$nsp] ) == 0 ) {
unset( $parser->getOutput()->mTemplates[$nsp] );
}
}
Expand All @@ -634,7 +637,8 @@
}

if ( isset( self::$createdLinks ) && array_key_exists( 3, self::$createdLinks ) ) {
$parser->getOutput()->mImages = array_diff_assoc( $parser->getOutput()->getImages(), self::$createdLinks[3] );
$parserMedia = $parser->getOutput()->getLinkList( ParserOutputLinkTypes::MEDIA );
$parser->getOutput()->mImages = array_diff_assoc( $parserMedia, self::$createdLinks[3] );
}
}
}
Expand Down
Loading