mirror of
https://bitbucket.org/vertlach/voteny.git
synced 2024-05-20 14:38:13 +03:00
a3c82a518b
Changelist: *removed backwards-compatibility code *used HTML5 data attributes to store various information that we access in the JS file *incremented the extension's version number *removed ancient vote key stuff (the "vote key" was being passed to the AJAX function but it wasn't used in any of the functions) *updated Linker class, that class is now static *killd $wgTitle Some things are now a bit slower, i.e. if you click on the green voting box, then click again when the unvote link appears, it doesn't seem to change back to "vote" again...but at least it should work now.
88 lines
1.5 KiB
PHP
88 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* AJAX functions used by Vote extension.
|
|
*/
|
|
$wgAjaxExportList[] = 'wfVoteClick';
|
|
|
|
function wfVoteClick( $voteValue, $pageId ) {
|
|
global $wgUser;
|
|
|
|
if ( !$wgUser->isAllowed( 'vote' ) ) {
|
|
return '';
|
|
}
|
|
|
|
if( is_numeric( $pageId ) && ( is_numeric( $voteValue ) ) ) {
|
|
$vote = new Vote( $pageId );
|
|
$vote->insert( $voteValue );
|
|
|
|
return $vote->count( 1 );
|
|
} else {
|
|
return 'error';
|
|
}
|
|
}
|
|
|
|
$wgAjaxExportList[] = 'wfVoteDelete';
|
|
function wfVoteDelete( $pageId ) {
|
|
global $wgUser;
|
|
|
|
if ( !$wgUser->isAllowed( 'vote' ) ) {
|
|
return '';
|
|
}
|
|
|
|
if( is_numeric( $pageId ) ) {
|
|
$vote = new Vote( $pageId );
|
|
$vote->delete();
|
|
|
|
return $vote->count( 1 );
|
|
} else {
|
|
return 'error';
|
|
}
|
|
}
|
|
|
|
$wgAjaxExportList[] = 'wfVoteStars';
|
|
function wfVoteStars( $voteValue, $pageId ) {
|
|
global $wgUser;
|
|
|
|
if ( !$wgUser->isAllowed( 'vote' ) ) {
|
|
return '';
|
|
}
|
|
|
|
$vote = new VoteStars( $pageId );
|
|
if( $vote->UserAlreadyVoted() ) {
|
|
$vote->delete();
|
|
}
|
|
$vote->insert( $voteValue );
|
|
|
|
return $vote->display( $voteValue );
|
|
}
|
|
|
|
$wgAjaxExportList[] = 'wfVoteStarsMulti';
|
|
function wfVoteStarsMulti( $voteValue, $pageId ) {
|
|
global $wgUser;
|
|
|
|
if ( !$wgUser->isAllowed( 'vote' ) ) {
|
|
return '';
|
|
}
|
|
|
|
$vote = new VoteStars( $pageId );
|
|
if( $vote->UserAlreadyVoted() ) {
|
|
$vote->delete();
|
|
}
|
|
$vote->insert( $voteValue );
|
|
|
|
return $vote->displayScore();
|
|
}
|
|
|
|
$wgAjaxExportList[] = 'wfVoteStarsDelete';
|
|
function wfVoteStarsDelete( $pageId ) {
|
|
global $wgUser;
|
|
|
|
if ( !$wgUser->isAllowed( 'vote' ) ) {
|
|
return '';
|
|
}
|
|
|
|
$vote = new VoteStars( $pageId );
|
|
$vote->delete();
|
|
|
|
return $vote->display();
|
|
} |