mediawiki-voteny/Vote_AjaxFunctions.php
Jack Phoenix a3c82a518b VoteNY: actually make this work under 1.18+, not just in ResourceLoader's debug mode.
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.
2012-01-04 19:51:44 +00:00

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();
}