From bb45bde09cbff329f592038fdcc255e076e446d0 Mon Sep 17 00:00:00 2001 From: Aleksandr Yakovlev Date: Sun, 6 Aug 2023 11:32:35 +0600 Subject: [PATCH] fix code for MW 1.40 --- IUTClass.php | 42 +++++++++++++++++++++++++++--------------- IUTHooks.php | 4 +++- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/IUTClass.php b/IUTClass.php index a5397b6..15ea4e3 100644 --- a/IUTClass.php +++ b/IUTClass.php @@ -1,4 +1,7 @@ getMainWANObjectCache(); + $logger = LoggerFactory::getInstance( 'VoteNY' ); - $key = wfMemcKey( 'iusethis', 'count', $this->PageID ); - $data = $wgMemc->get( $key ); + $key = 'iusethis_count_'.$this->PageID; + $data = $cache->get( $key ); // Try cache if ( $data ) { - wfDebug( "Loading vote count for page {$this->PageID} from cache\n" ); + $logger->debug( "Loading vote count for page {$this->PageID} from cache\n" ); $vote_count = $data; } else { - $dbr = wfGetDB( DB_SLAVE ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $dbr = $lb->getConnection( DB_PRIMARY ); $vote_count = 0; $res = $dbr->select( 'IUseThis', @@ -49,11 +54,11 @@ class IUT { array( 'vote_page_id' => $this->PageID ), __METHOD__ ); - $row = $dbr->fetchObject( $res ); + $row = $res->fetchRow(); if ( $row ) { $vote_count = $row->votecount; } - $wgMemc->set( $key, $vote_count ); + $cache->set( $key, $vote_count ); } return $vote_count; @@ -63,11 +68,12 @@ class IUT { * Clear caches - memcached, parser cache and Squid cache */ function clearCache() { - global $wgUser, $wgMemc; + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + global $wgUser; // Kill internal cache - $wgMemc->delete( wfMemcKey( 'iusethis', 'count', $this->PageID ) ); - $wgMemc->delete( wfMemcKey( 'iusethis', 'avg', $this->PageID ) ); + $cache->delete( 'iusethis_count_'.$this->PageID ); + $cache->delete( 'iusethis_avg_'.$this->PageID ); // Purge squid $pageTitle = Title::newFromID( $this->PageID ); @@ -79,7 +85,7 @@ class IUT { $article = new Article( $pageTitle, /* oldid */0 ); $parserCache = ParserCache::singleton(); $parserKey = $parserCache->getKey( $article, $wgUser ); - $wgMemc->delete( $parserKey ); + $cache->delete( $parserKey ); } } @@ -87,7 +93,8 @@ class IUT { * Delete the user's vote from the database, purges normal caches. */ function delete() { - $dbw = wfGetDB( DB_MASTER ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $dbw = $lb->getConnection( DB_PRIMARY ); $dbw->delete( 'IUseThis', array( @@ -105,7 +112,8 @@ class IUT { */ function insert() { global $wgRequest; - $dbw = wfGetDB( DB_MASTER ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $dbw = $lb->getConnection( DB_PRIMARY ); wfSuppressWarnings(); // E_STRICT whining $voteDate = date( 'Y-m-d H:i:s' ); wfRestoreWarnings(); @@ -133,7 +141,8 @@ class IUT { * value of 'vote_value' column from Vote DB table */ function UserAlreadyVoted() { - $dbr = wfGetDB( DB_SLAVE ); + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); + $dbr = $lb->getConnection( DB_PRIMARY ); $s = $dbr->selectRow( 'IUseThis', 'COUNT(*) as count', @@ -167,6 +176,8 @@ class IUT { $output = "
"; $output .= '' . $this->count() . ' ' . wfMessage('people-count')->parse() . ' '; $output .= ''; + + $services = MediaWikiServices::getInstance(); if ( !$wgUser->isAllowed( 'iusethis' ) ) { // @todo FIXME: this is horrible. If we don't have enough @@ -177,7 +188,8 @@ class IUT { htmlspecialchars( $login->getFullURL() ) . '" rel="nofollow">' . wfMessage('iusethis-link')->parse() . ''; } else { - if ( !wfReadOnly() ) { + $readonly = $services->getReadOnlyMode()->isReadOnly(); + if ( $readonly ) { if ( $voted === false ) { $output .= '' . wfMessage('iusethis-link')->parse() . ''; diff --git a/IUTHooks.php b/IUTHooks.php index 1903eb5..3b01d7f 100644 --- a/IUTHooks.php +++ b/IUTHooks.php @@ -1,4 +1,6 @@ disableCache(); + $parser->getOutput()->updateCacheExpiry(0); // Add CSS & JS // In order for us to do this *here* instead of having to do this in