Skip to content

Commit

Permalink
1.39.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashank Atreya committed Jun 29, 2023
1 parent 53ef2f4 commit 2e177c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
7 changes: 6 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 14 additions & 7 deletions src/SpecialPage/SpecialNetworkNotice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
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;

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

Expand Down Expand Up @@ -337,7 +344,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 +356,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 +370,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 +393,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 +416,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 2e177c6

Please sign in to comment.