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 all 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
6 changes: 6 additions & 0 deletions includes/LST.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ class LST {
*/
public static function open( $parser, $part1 ) {
// Infinite loop test
// @phan-suppress-next-line PhanDeprecatedProperty
if ( isset( $parser->mTemplatePath[$part1] ) ) {
wfDebug( __METHOD__ . ": template loop broken at '$part1'\n" );

return false;
} else {
// @phan-suppress-next-line PhanDeprecatedProperty
if ( !isset( $parser->mTemplatePath ) ) {
// @phan-suppress-next-line PhanDeprecatedProperty
$parser->mTemplatePath = [];
}

// @phan-suppress-next-line PhanDeprecatedProperty
$parser->mTemplatePath[$part1] = 1;

return true;
Expand All @@ -71,7 +75,9 @@ public static function open( $parser, $part1 ) {
*/
public static function close( $parser, $part1 ) {
// Infinite loop test
// @phan-suppress-next-line PhanDeprecatedProperty
if ( isset( $parser->mTemplatePath[$part1] ) ) {
// @phan-suppress-next-line PhanDeprecatedProperty
unset( $parser->mTemplatePath[$part1] );
} else {
wfDebug( __METHOD__ . ": close unopened template loop at '$part1'\n" );
Expand Down
7 changes: 5 additions & 2 deletions includes/Lister/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MediaWiki\Extension\DynamicPageList3\LST;
use MediaWiki\Extension\DynamicPageList3\Parameters;
use MediaWiki\Extension\DynamicPageList3\UpdateArticle;
use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Parser\Parser;
use MediaWiki\Parser\Sanitizer;
Expand Down Expand Up @@ -652,8 +653,10 @@ public function formatItem( Article $article, $pageText = null ) {

if ( $article->mCounter > 0 ) {
$contLang = MediaWikiServices::getInstance()->getContentLanguage();

$item .= ' ' . $contLang->getDirMark() . '(' . wfMessage( 'hitcounters-nviews', $lang->formatNum( $article->mCounter ) )->escaped() . ')';
$item .= ' ' . Html::rawElement( 'bdi',
Dismissed Show dismissed Hide dismissed
[ 'dir' => $contLang->getDir() ],
'(' . wfMessage( 'hitcounters-nviews', $lang->formatNum( $article->mCounter ) )->escaped() . ')'
);
}

if ( $article->mUserLink ) {
Expand Down
6 changes: 4 additions & 2 deletions includes/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use MediaWiki\Extension\DynamicPageList3\Lister\Lister;
use MediaWiki\MediaWikiServices;
use MediaWiki\Parser\Parser;
use MediaWiki\Parser\ParserOutputLinkTypes;
use MediaWiki\Request\WebRequest;
use MediaWiki\Title\Title;

Expand Down Expand Up @@ -108,6 +109,7 @@ public function parse( $input, Parser $parser, &$reset, &$eliminate, $isParserTa
$title = Title::castFromPageReference( $parser->getPage() );

// Check that we are not in an infinite transclusion loop
// @phan-suppress-next-line PhanDeprecatedProperty
if ( isset( $parser->mTemplatePath[$title->getPrefixedText()] ) ) {
$this->logger->addMessage( Hooks::WARN_TRANSCLUSIONLOOP, $title->getPrefixedText() );

Expand Down Expand Up @@ -970,15 +972,15 @@ private function triggerEndResets( $output, &$reset, &$eliminate, $isParserTag,
// Trigger the mediawiki parser to find links, images, categories etc. which are contained in the DPL output. This allows us to remove these links from the link list later. If the article containing the DPL statement itself uses one of these links they will be thrown away!
Hooks::$createdLinks[0] = [];

foreach ( $parserOutput->getLinks() as $nsp => $link ) {
foreach ( $parserOutput->getLinkList( ParserOutputLinkTypes::LOCAL ) as $nsp => $link ) {
Hooks::$createdLinks[0][$nsp] = $link;
}
}

if ( $parserOutput && isset( $eliminate['templates'] ) && $eliminate['templates'] ) {
Hooks::$createdLinks[1] = [];

foreach ( $parserOutput->getTemplates() as $nsp => $tpl ) {
foreach ( $parserOutput->getLinkList( ParserOutputLinkTypes::TEMPLATE ) as $nsp => $tpl ) {
Hooks::$createdLinks[1][$nsp] = $tpl;
}
}
Expand Down
21 changes: 13 additions & 8 deletions includes/UpdateArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use MediaWiki\CommentStore\CommentStoreComment;
use MediaWiki\Context\RequestContext;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Title\Title;
use ReadOnlyError;
Expand Down Expand Up @@ -403,9 +404,12 @@ private static function doUpdateArticle( $title, $text, $summary ) {
}

$titleX = Title::newFromText( $title );
$permission_errors = MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors( 'edit', $user, $titleX );
$permissionStatus = MediaWikiServices::getInstance()
->getPermissionManager()->getPermissionStatus(
'edit', $user, $titleX, PermissionManager::RIGOR_SECURE
);

if ( count( $permission_errors ) == 0 ) {
if ( $permissionStatus->isGood() ) {
$services = MediaWikiServices::getInstance();
$wikiPageFactory = $services->getWikiPageFactory();
$page = $wikiPageFactory->newFromTitle( $titleX );
Expand All @@ -424,8 +428,7 @@ private static function doUpdateArticle( $title, $text, $summary ) {

return '';
} else {
$out->showPermissionsErrorPage( $permission_errors );

$out->showPermissionStatus( $permissionStatus, 'edit' );
return 'permission error';
}
}
Expand Down Expand Up @@ -751,12 +754,14 @@ public static function deleteArticleByRule( $title, $text, $rulesText ) {
$user = $context->getUser();

# Check permissions
$permission_errors = MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors( 'delete', $user, $titleX );
$isReadOnly = MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly();
$permissionStatus = MediaWikiServices::getInstance()
->getPermissionManager()->getPermissionStatus(
'delete', $user, $titleX, PermissionManager::RIGOR_SECURE
);

if ( count( $permission_errors ) > 0 ) {
$out->showPermissionsErrorPage( $permission_errors );

if ( !$permissionStatus->isGood() ) {
$out->showPermissionStatus( $permissionStatus, 'delete' );
return 'permission error';
} elseif ( $isReadOnly ) {
throw new ReadOnlyError;
Expand Down
Loading