Skip to content

Commit

Permalink
Work around an E_DEPRECATED in MW 1.37+ (#32)
Browse files Browse the repository at this point in the history
Introduces a new method to work around the deprecation warning in MW 1.37+.
The new method is essentially the same as ContentHandler#getContentText in core (master) as of today.

Closes #29.
  • Loading branch information
mary-kate authored Oct 27, 2024
1 parent bb17f7e commit d552225
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions LibertyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,13 @@ protected function parseNavbar() {
$skin = $this->getSkin();
$userName = $skin->getUser()->getName();
$userLang = $skin->getLanguage()->mCode;
$globalData = ContentHandler::getContentText( $this->getContentOfTitle(
$globalData = $this->getContentText( $this->getContentOfTitle(
Title::newFromText( 'Liberty-Navbar', NS_MEDIAWIKI )
) );
$globalLangData = ContentHandler::getContentText( $this->getContentOfTitle(
$globalLangData = $this->getContentText( $this->getContentOfTitle(
Title::newFromText( 'Liberty-Navbar/' . $userLang, NS_MEDIAWIKI )
) );
$userData = ContentHandler::getContentText( $this->getContentOfTitle(
$userData = $this->getContentText( $this->getContentOfTitle(
Title::newFromText( $userName . '/Liberty-Navbar', NS_USER )
) );
if ( !empty( $userData ) ) {
Expand Down Expand Up @@ -1241,6 +1241,25 @@ protected function buildAd( $position ) {
<?php
}

/**
* Helper function for parseNavbar() to not trigger deprecation warnings on MW 1.37+ and to continue
* functioning on MW 1.43+.
*
* @param Content|null $content
* @return string|null Textual form of the content, if available.
*/
private function getContentText( Content $content = null ) {
if ( $content === null ) {
return '';
}

if ( $content instanceof TextContent ) {
return $content->getText();
}

return null;
}

private function getContentOfTitle( Title $title ): ?Content {
$page = null;

Expand Down

0 comments on commit d552225

Please sign in to comment.