Skip to content

Commit

Permalink
fix: use MediaWikiServices to working with REL1_41
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoto-Cocoa committed Jan 22, 2024
1 parent 3362a4e commit a38316e
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions LibertyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Permissions\RestrictionStore;

class LibertyTemplate extends BaseTemplate {
/**
Expand Down Expand Up @@ -622,7 +623,7 @@ protected function contentsToolbox() {
<div class="dropdown-divider"></div>
<?php
// different labels depending on whether the page is or isn't protected
$protectionMsg = $title->isProtected() ? 'unprotect' : 'protect';
$protectionMsg = $this->isProtectedTitle( $title ) ? 'unprotect' : 'protect';
echo $linkRenderer->makeKnownLink(
$title,
$skin->msg( $protectionMsg )->plain(),
Expand Down Expand Up @@ -882,15 +883,15 @@ protected function parseNavbar() {
$skin = $this->getSkin();
$userName = $skin->getUser()->getName();
$userLang = $skin->getLanguage()->mCode;
$globalData = ContentHandler::getContentText( WikiPage::factory(
$globalData = ContentHandler::getContentText( $this->getContentOfTitle(
Title::newFromText( 'Liberty-Navbar', NS_MEDIAWIKI )
)->getContent( RevisionRecord::RAW ) );
$globalLangData = ContentHandler::getContentText( WikiPage::factory(
) );
$globalLangData = ContentHandler::getContentText( $this->getContentOfTitle(
Title::newFromText( 'Liberty-Navbar/' . $userLang, NS_MEDIAWIKI )
)->getContent( RevisionRecord::RAW ) );
$userData = ContentHandler::getContentText( WikiPage::factory(
) );
$userData = ContentHandler::getContentText( $this->getContentOfTitle(
Title::newFromText( $userName . '/Liberty-Navbar', NS_USER )
)->getContent( RevisionRecord::RAW ) );
) );
if ( !empty( $userData ) ) {
$data = $userData;
} elseif ( !empty( $globalLangData ) ) {
Expand Down Expand Up @@ -1238,4 +1239,26 @@ protected function buildAd( $position ) {
</div>
<?php
}

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

if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
$page = $wikiPageFactory->newFromTitle( $title );
} else {
$page = WikiPage::factory( $title );
}

return $page->getContent( RevisionRecord::RAW );
}

private function isProtectedTitle( Title $title ): bool {
if ( method_exists( RestrictionStore::class, 'isProtected' ) ) {
return MediaWikiServices::getInstance()->getRestrictionStore()->isProtected( $title );
} else {
return $title->isProtected();
}
}
}

0 comments on commit a38316e

Please sign in to comment.