Skip to content

Commit

Permalink
1.39 (#5)
Browse files Browse the repository at this point in the history
* 1.39.3

* 1.39.3

* version

---------

Co-authored-by: Shashank Atreya <satreya@liquipedia.net>
  • Loading branch information
godarkrai and Shashank Atreya committed Aug 2, 2023
1 parent 53ef2f4 commit f6a2950
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
9 changes: 7 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.35.3"
"MediaWiki": ">= 1.39.3"
},
"MessagesDirs": {
"NetworkNotice": [
Expand All @@ -36,7 +36,12 @@
"SiteNoticeAfter": "Main"
},
"SpecialPages": {
"NetworkNotice": "\\Liquipedia\\Extension\\NetworkNotice\\SpecialPage\\SpecialNetworkNotice"
"NetworkNotice": {
"class": "\\Liquipedia\\Extension\\NetworkNotice\\SpecialPage\\SpecialNetworkNotice",
"services": [
"DBLoadBalancer"
]
}
},
"ResourceModules": {
"ext.networknotice.Notice": {
Expand Down
10 changes: 6 additions & 4 deletions src/Hooks/MainHookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Liquipedia\Extension\NetworkNotice\NoticeHtml;
use MediaWiki\Hook\BeforePageDisplayHook;
use MediaWiki\Hook\SiteNoticeAfterHook;
use MWNamespace;
use MediaWiki\MediaWikiServices;
use OutputPage;
use Skin;

Expand Down Expand Up @@ -34,13 +34,15 @@ public function onSiteNoticeAfter( &$siteNotice, $skin ) {
$config = $skin->getConfig();
$title = $skin->getTitle();
$out = $skin->getOutput();

$dbr = wfGetDB( DB_REPLICA, [], $config->get( 'DBname' ) );
$services = MediaWikiServices::getInstance();
$loadBalancer = $services->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection( DB_REPLICA, [], $config->get( 'DBname' ) );

// Remove leading '/'
$wiki = substr( $config->get( 'ScriptPath' ), 1 );
$categories = $out->getCategories();
$namespace = MWNamespace::getCanonicalName( $title->getNamespace() );
$namespaceInfo = $services->getNamespaceInfo();
$namespace = $namespaceInfo->getCanonicalName( $title->getNamespace() );
$titleText = $title->getText();
$action = Action::getActionName( $skin );

Expand Down
24 changes: 17 additions & 7 deletions src/SpecialPage/SpecialNetworkNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@
use Liquipedia\Extension\NetworkNotice\Colors;
use Liquipedia\Extension\NetworkNotice\NoticeHtml;
use Status;
use Wikimedia\Rdbms\ILoadBalancer;

class SpecialNetworkNotice extends \SpecialPage {

public function __construct() {
/**
* @var ILoadBalancer
*/
private $loadBalancer;

/**
* @param ILoadBalancer $loadBalancer
*/
public function __construct( ILoadBalancer $loadBalancer ) {
$this->loadBalancer = $loadBalancer;
parent::__construct( 'NetworkNotice', 'usenetworknotice' );
}

Expand Down Expand Up @@ -337,7 +347,7 @@ public function createNetworkNoticeCB( $formData ) {
* @param array $vars
*/
private function createNetworkNotice( $vars ) {
$dbw = wfGetDB( DB_PRIMARY, [], $this->getConfig()->get( 'DBname' ) );
$dbw = $this->loadBalancer->getConnection( DB_PRIMARY, [], $this->getConfig()->get( 'DBname' ) );
$dbw->insert(
'networknotice',
$vars
Expand All @@ -349,7 +359,7 @@ private function createNetworkNotice( $vars ) {
* @param int $id
*/
private function updateNetworkNotice( $vars, $id ) {
$dbw = wfGetDB( DB_PRIMARY, [], $this->getConfig()->get( 'DBname' ) );
$dbw = $this->loadBalancer->getConnection( DB_PRIMARY, [], $this->getConfig()->get( 'DBname' ) );
$dbw->update(
'networknotice',
$vars,
Expand All @@ -363,7 +373,7 @@ private function updateNetworkNotice( $vars, $id ) {
* @return IResultWrapper
*/
private function getNetworkNotices() {
$dbr = wfGetDB( DB_REPLICA, [], $this->getConfig()->get( 'DBname' ) );
$dbr = $this->loadBalancer->getConnection( DB_REPLICA, [], $this->getConfig()->get( 'DBname' ) );
return $dbr->select(
'networknotice',
[
Expand All @@ -386,7 +396,7 @@ private function getNetworkNotices() {
* @return IResultWrapper
*/
private function getNetworkNoticeById( $id ) {
$dbr = wfGetDB( DB_REPLICA, [], $this->getConfig()->get( 'DBname' ) );
$dbr = $this->loadBalancer->getConnection( DB_REPLICA, [], $this->getConfig()->get( 'DBname' ) );
return $dbr->select(
'networknotice',
[
Expand All @@ -409,10 +419,10 @@ private function getNetworkNoticeById( $id ) {

/**
* @param int $id
* @return IResultWrapper
* @return bool
*/
private function deleteNetworkNotice( $id ) {
$dbw = wfGetDB( DB_PRIMARY, [], $this->getConfig()->get( 'DBname' ) );
$dbw = $this->loadBalancer->getConnection( DB_PRIMARY, [], $this->getConfig()->get( 'DBname' ) );
return $dbw->delete(
'networknotice',
[
Expand Down

0 comments on commit f6a2950

Please sign in to comment.