Skip to content

Commit

Permalink
1.39.3 (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Shashank Atreya <satreya@liquipedia.net>
  • Loading branch information
godarkrai and Shashank Atreya committed Aug 2, 2023
1 parent 8bcafe4 commit 9b99d69
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion extension.json
Expand Up @@ -11,7 +11,7 @@
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.35.0"
"MediaWiki": ">= 1.39.3"
},
"ExtensionMessagesFiles": {
"WikiListAlias": "i18n/WikiListAlias.php"
Expand Down
10 changes: 5 additions & 5 deletions resources/scripts/trendingmenu.js
@@ -1,6 +1,6 @@
( function( window, document, mw ) {
'use strict';
var trendingmenu = {
const trendingmenu = {
init: function() {
if ( document.readyState === 'loading' ) {
window.addEventListener( 'DOMContentLoaded', trendingmenu.run );
Expand All @@ -10,16 +10,16 @@
},
run: function() {
mw.loader.using( [ 'mediawiki.util', 'mediawiki.api' ] ).then( function() {
var menuItem = document.getElementById( 'trending-pages-menu' );
const menuItem = document.getElementById( 'trending-pages-menu' );
if ( menuItem !== null ) {
var api = new mw.Api();
const api = new mw.Api();
api.get( {
action: 'trendingmenu',
uselang: 'content',
format: 'json'
} ).done( function( data ) {
var html = '';
for ( var i = 0; i < 5; i++ ) {
let html = '';
for ( let i = 0; i < 5; i++ ) {
if ( data.trendingmenu[ i ] ) {
html += '<a class="dropdown-item" href="' + data.trendingmenu[ i ].href + '">' + data.trendingmenu[ i ].text + '</a>';
}
Expand Down
16 changes: 8 additions & 8 deletions resources/scripts/wikilistdragsort.js
@@ -1,20 +1,20 @@
( function( document, mw ) {
var button = document.getElementById( 'wikilist-submit-button' );
var p = document.getElementById( 'wikilist-button-click-notification' );
const button = document.getElementById( 'wikilist-submit-button' );
const p = document.getElementById( 'wikilist-button-click-notification' );
button.addEventListener( 'click', function() {
var wikiTypes = [ 'mainWiki', 'alphaWiki', 'preAlphaWiki' ];
var json = { };
const wikiTypes = [ 'mainWiki', 'alphaWiki', 'preAlphaWiki' ];
const json = { };
wikiTypes.forEach( function( type ) {
var wikiList = document.getElementById( type ).getElementsByTagName( 'li' );
var totalWikis = wikiList.length;
const wikiList = document.getElementById( type ).getElementsByTagName( 'li' );
const totalWikis = wikiList.length;
if ( totalWikis > 0 ) {
json[ type ] = [ ];
for ( var i = 0; i < totalWikis; i++ ) {
for ( let i = 0; i < totalWikis; i++ ) {
json[ type ].push( { name: wikiList[ i ].innerText, slug: wikiList[ i ].getAttribute( 'slug-name' ) } );
}
}
} );
var api = new mw.Api();
const api = new mw.Api();
api.post( {
action: 'updatewikilist',
data: JSON.stringify( json )
Expand Down
5 changes: 3 additions & 2 deletions src/Api/TrendingPages.php
Expand Up @@ -3,6 +3,7 @@
namespace Liquipedia\Extension\TrendingMenu\Api;

use ApiBase;
use MediaWiki\MediaWikiServices;

class TrendingPages extends ApiBase {

Expand All @@ -15,8 +16,8 @@ public function execute() {
$trendingArticles = [];

$wiki = substr( $this->getConfig()->get( 'ScriptPath' ), 1 );

$dbr = wfGetDB( DB_REPLICA, '', $TL_DB );
$loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection( DB_REPLICA, '', $TL_DB );
$res = $dbr->select(
'wiki_hot', '*', [
'wiki' => $wiki
Expand Down
14 changes: 3 additions & 11 deletions src/Api/UpdateWikiList.php
Expand Up @@ -4,6 +4,7 @@

use ApiBase;
use Liquipedia\Extension\TrendingMenu\Helper;
use Wikimedia\ParamValidator\ParamValidator;

class UpdateWikiList extends ApiBase {

Expand Down Expand Up @@ -38,24 +39,15 @@ public function getParamDescription() {
return parent::getParamDescription();
}

/**
* @return array
*/
public function getExamplesMessages() {
return [
'action=updatewikilist&data={json_format_data_goes_here}' => 'updatewikilist-example',
];
}

/**
* @return array
*/
public function getAllowedParams() {
return [
'data' => [
ApiBase::PARAM_TYPE => 'string',
ParamValidator::PARAM_TYPE => 'string',
ParamValidator::PARAM_REQUIRED => true,
ApiBase::PARAM_HELP_MSG => 'updatewikilist-data',
ApiBase::PARAM_REQUIRED => true,
]
];
}
Expand Down
5 changes: 3 additions & 2 deletions src/Api/WikiList.php
Expand Up @@ -4,6 +4,7 @@

use ApiBase;
use Liquipedia\Extension\TrendingMenu\Helper;
use Wikimedia\ParamValidator\ParamValidator;

class WikiList extends ApiBase {

Expand Down Expand Up @@ -55,9 +56,9 @@ public function getExamplesMessages() {
public function getAllowedParams() {
return [
'data' => [
ApiBase::PARAM_TYPE => 'string',
ParamValidator::PARAM_TYPE => 'string',
ParamValidator::PARAM_REQUIRED => true,
ApiBase::PARAM_HELP_MSG => 'wikilist-data',
ApiBase::PARAM_REQUIRED => true,
]
];
}
Expand Down
44 changes: 29 additions & 15 deletions src/Helper.php
Expand Up @@ -10,8 +10,10 @@ class Helper {
* @return array
*/
public static function getWikiList() {
$config = MediaWikiServices::getInstance()->getMainConfig();
$dbr = wfGetDB( DB_REPLICA,
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$loadBalancer = $services->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection( DB_REPLICA,
[],
$config->get( 'DBname' ) );
$res = $dbr->select(
Expand Down Expand Up @@ -44,7 +46,9 @@ public static function getWikiList() {
* @return array
*/
public static function getWikiHotList() {
$dbr = wfGetDB(
$services = MediaWikiServices::getInstance();
$loadBalancer = $services->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection(
DB_REPLICA,
[],
'liquid-'
Expand Down Expand Up @@ -77,9 +81,11 @@ public static function getWikiHotList() {
*/
public static function update( $jsonData ) {
$data = json_decode( $jsonData );
$config = MediaWikiServices::getInstance()->getMainConfig();
$dbw = wfGetDB(
DB_MASTER,
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$loadBalancer = $services->getDBLoadBalancer();
$dbw = $loadBalancer->getConnection(
DB_PRIMARY,
[],
$config->get( 'DBname' )
);
Expand All @@ -106,9 +112,11 @@ public static function update( $jsonData ) {
* @param string $wiki
*/
public static function add( $wiki ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
$dbw = wfGetDB(
DB_MASTER,
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$loadBalancer = $services->getDBLoadBalancer();
$dbw = $loadBalancer->getConnection(
DB_PRIMARY,
[],
$config->get( 'DBname' )
);
Expand All @@ -124,8 +132,10 @@ public static function add( $wiki ) {
* @return bool
*/
public static function exists( $wiki ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
$dbr = wfGetDB(
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$loadBalancer = $services->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection(
DB_REPLICA,
[],
$config->get( 'DBname' )
Expand All @@ -148,8 +158,10 @@ public static function exists( $wiki ) {
* @return array
*/
public static function getWikiNamesForDropList() {
$config = MediaWikiServices::getInstance()->getMainConfig();
$dbr = wfGetDB( DB_REPLICA,
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$loadBalancer = $services->getDBLoadBalancer();
$dbr = $loadBalancer->getConnection( DB_REPLICA,
[],
$config->get( 'DBname' ) );
$res = $dbr->select(
Expand All @@ -172,8 +184,10 @@ public static function getWikiNamesForDropList() {
* @param string $slug
*/
public static function delete( $slug ) {
$config = MediaWikiServices::getInstance()->getMainConfig();
$dbw = wfGetDB( DB_MASTER,
$services = MediaWikiServices::getInstance();
$config = $services->getMainConfig();
$loadBalancer = $services->getDBLoadBalancer();
$dbw = $loadBalancer->getConnection( DB_PRIMARY,
[],
$config->get( 'DBname' ) );
$dbw->delete( 'wiki_list',
Expand Down

0 comments on commit 9b99d69

Please sign in to comment.