mirror of
https://bitbucket.org/vertlach/iusethis.git
synced 2024-06-17 07:30:50 +03:00
fix code for MW 1.40
This commit is contained in:
parent
1af57d1518
commit
bb45bde09c
42
IUTClass.php
42
IUTClass.php
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
||||
/**
|
||||
* Vote class - class for handling vote-related functions (counting
|
||||
* the average score of a given page, inserting/updating/removing a vote etc.)
|
||||
|
@ -31,17 +34,19 @@ class IUT {
|
|||
* @return int Amount of votes
|
||||
*/
|
||||
function count() {
|
||||
global $wgMemc;
|
||||
$cache = MediaWikiServices::getInstance()->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',
|
||||
|
@ -168,6 +177,8 @@ class IUT {
|
|||
$output .= '<span id="iutcount" class="count">' . $this->count() . ' ' . wfMessage('people-count')->parse() . ' </span>';
|
||||
$output .= '<span id="iutaction" class="iut-action">';
|
||||
|
||||
$services = MediaWikiServices::getInstance();
|
||||
|
||||
if ( !$wgUser->isAllowed( 'iusethis' ) ) {
|
||||
// @todo FIXME: this is horrible. If we don't have enough
|
||||
// permissions to vote, we should tell the end-user /that/,
|
||||
|
@ -177,7 +188,8 @@ class IUT {
|
|||
htmlspecialchars( $login->getFullURL() ) . '" rel="nofollow">' .
|
||||
wfMessage('iusethis-link')->parse() . '</a>';
|
||||
} else {
|
||||
if ( !wfReadOnly() ) {
|
||||
$readonly = $services->getReadOnlyMode()->isReadOnly();
|
||||
if ( $readonly ) {
|
||||
if ( $voted === false ) {
|
||||
$output .= '<a href="javascript:void(0);" class="iut-vote-link">' .
|
||||
wfMessage('iusethis-link')->parse() . '</a>';
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* All hooked functions used by IUseThis extension.
|
||||
*
|
||||
|
@ -32,7 +34,7 @@ class IUTHooks {
|
|||
// Disable parser cache (sadly we have to do this, because the caching is
|
||||
// messing stuff up; we want to show an up-to-date rating instead of old
|
||||
// or totally wrong rating, i.e. another page's rating...)
|
||||
$parser->disableCache();
|
||||
$parser->getOutput()->updateCacheExpiry(0);
|
||||
|
||||
// Add CSS & JS
|
||||
// In order for us to do this *here* instead of having to do this in
|
||||
|
|
Loading…
Reference in a new issue