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

Work around an E_DEPRECATED in MW 1.37+ #32

Merged
merged 1 commit into from
Oct 27, 2024
Merged
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
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
Loading