2012-02-19 19:31:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AJAX Poll class
|
|
|
|
* Created by Dariusz Siedlecki, based on the work by Eric David.
|
|
|
|
* Licensed under the GFDL.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @author Dariusz Siedlecki <datrio@gmail.com>
|
|
|
|
* @author Jack Phoenix <jack@countervandalism.net>
|
|
|
|
* @author Thomas Gries
|
|
|
|
* @maintainer Thomas Gries
|
|
|
|
* @link http://www.mediawiki.org/wiki/Extension:AJAX_Poll Documentation
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AJAXPoll {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register <poll> tag with the parser
|
|
|
|
*
|
|
|
|
* @param $parser Object: instance of Parser (not necessarily $wgParser)
|
|
|
|
* @return Boolean: true
|
|
|
|
*/
|
2012-03-14 20:19:16 +00:00
|
|
|
static function onParserInit( $parser ) {
|
2012-03-13 22:31:46 +00:00
|
|
|
global $wgOut;
|
2012-02-19 19:31:24 +00:00
|
|
|
$parser->setHook( 'poll', array( __CLASS__, 'AJAXPollRender' ) );
|
2012-03-13 22:31:46 +00:00
|
|
|
$wgOut->addModules( 'ext.ajaxpoll' );
|
2012-02-19 19:31:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# The callback function for converting the input text to HTML output
|
2012-03-09 23:24:38 +00:00
|
|
|
static function AJAXPollRender( $input, $params = array(), Parser $parser ) {
|
2012-03-19 18:45:57 +00:00
|
|
|
global $wgUser, $wgOut, $wgTitle, $wgScriptPath, $wgUseAjax;
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-09 23:24:38 +00:00
|
|
|
$parser->disableCache();
|
2012-03-19 18:45:57 +00:00
|
|
|
$parser->addTrackingCategory( 'ajaxpoll-tracking-category' );
|
2012-03-09 19:23:28 +00:00
|
|
|
|
2012-02-19 19:31:24 +00:00
|
|
|
if ( $wgUser->getName() == '' ) {
|
|
|
|
$user = wfGetIP();
|
|
|
|
} else {
|
|
|
|
$user = $wgUser->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID of the poll
|
2012-03-12 22:13:51 +00:00
|
|
|
$id = strtoupper( md5( $input ) );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
$par = new Parser();
|
|
|
|
$input = $par->parse( $input, $wgTitle, $wgOut->parserOptions() );
|
|
|
|
$input = trim( strip_tags( $input->getText() ) );
|
|
|
|
$lines = explode( "\n", trim( $input ) );
|
|
|
|
|
2012-03-17 21:13:10 +00:00
|
|
|
// compatibility for non-ajax requests - just in case
|
|
|
|
if ( !$wgUseAjax ) {
|
|
|
|
$responseId = "ajaxpoll-post-id";
|
|
|
|
$responseAnswer = "ajaxpoll-post-answer-$id";
|
|
|
|
|
|
|
|
if ( isset( $_POST[$responseId] ) && isset( $_POST[$responseAnswer] ) && $_POST[$responseId] == $id ) {
|
|
|
|
AJAXPoll::submitVote( $id, intval( $_POST[$responseAnswer] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 19:31:24 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2012-03-09 19:26:20 +00:00
|
|
|
$dbw->begin( __METHOD__ );
|
2012-03-12 22:13:51 +00:00
|
|
|
|
2012-02-19 19:31:24 +00:00
|
|
|
/**
|
|
|
|
* Register poll in the database
|
|
|
|
*/
|
2012-03-12 22:13:51 +00:00
|
|
|
|
2012-02-19 19:31:24 +00:00
|
|
|
$row = $dbw->selectRow(
|
2012-03-14 20:28:16 +00:00
|
|
|
array( 'ajaxpoll_info' ),
|
2012-02-19 19:31:24 +00:00
|
|
|
array( 'COUNT(poll_id) AS count' ),
|
2012-03-12 22:13:51 +00:00
|
|
|
array( 'poll_id' => $id ),
|
2012-02-19 19:31:24 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
|
|
|
|
if( empty( $row->count ) ) {
|
|
|
|
$dbw->insert(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_info',
|
2012-02-19 19:31:24 +00:00
|
|
|
array(
|
2012-03-12 22:13:51 +00:00
|
|
|
'poll_id' => $id,
|
2012-02-19 19:31:24 +00:00
|
|
|
'poll_txt' => $input,
|
|
|
|
'poll_date' => wfTimestampNow(),
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
}
|
2012-03-09 19:27:55 +00:00
|
|
|
$dbw->commit( __METHOD__ );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
switch( $lines[0] ) {
|
|
|
|
case 'STATS':
|
2012-03-12 22:13:51 +00:00
|
|
|
$retVal = AJAXPoll::buildStats( $id, $user );
|
2012-02-19 19:31:24 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$retVal = '
|
2012-03-12 22:13:51 +00:00
|
|
|
<div id="ajaxpoll-container-' . $id . '">' . AJAXPoll::buildHTML( $id, $user, $lines ) . '</div>';
|
2012-02-19 19:31:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $retVal;
|
|
|
|
}
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
private static function buildStats( $id, $user ) {
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$res = $dbr->select(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-02-19 19:31:24 +00:00
|
|
|
array(
|
|
|
|
'COUNT(*)',
|
|
|
|
'COUNT(DISTINCT poll_id)',
|
|
|
|
'COUNT(DISTINCT poll_user)',
|
|
|
|
'TIMEDIFF(NOW(), MAX(poll_date))'
|
|
|
|
),
|
|
|
|
array(),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2012-03-12 22:13:51 +00:00
|
|
|
$tab = $dbr->fetchRow( $res );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
$clock = explode( ':', $tab[3] );
|
|
|
|
|
|
|
|
if ( $clock[0] == '00' && $clock[1] == '00' ) {
|
|
|
|
$x = $clock[2];
|
|
|
|
$y = 'second';
|
|
|
|
} elseif( $clock[0] == '00' ) {
|
|
|
|
$x = $clock[1];
|
|
|
|
$y = 'minute';
|
|
|
|
} else {
|
|
|
|
if ( $clock[0] < 24 ) {
|
|
|
|
$x = $clock[0];
|
|
|
|
$y = 'hour';
|
|
|
|
} else {
|
|
|
|
$x = floor( $hr / 24 );
|
|
|
|
$y = 'day';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$clockago = $x . ' ' . $y . ( $x > 1 ? 's' : '' );
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$res = $dbr->select(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-02-19 19:31:24 +00:00
|
|
|
'COUNT(*)',
|
|
|
|
array( 'DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= poll_date' ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2012-03-12 22:13:51 +00:00
|
|
|
$tab2 = $dbr->fetchRow( $res );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
return "There are $tab[1] polls and $tab[0] votes given by $tab[2] different people.<br />
|
|
|
|
The last vote has been given $clockago ago.<br/>
|
|
|
|
During the last 48 hours, $tab2[0] votes have been given.";
|
|
|
|
}
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
public static function submitVote( $id, $answer ) {
|
2012-02-19 19:31:24 +00:00
|
|
|
global $wgUser,$wgOut;
|
2012-03-17 21:13:10 +00:00
|
|
|
// echo "id: $id ans $answer<br/>";
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
if ( $wgUser->getName() == '' ) {
|
|
|
|
$user = wfGetIP();
|
|
|
|
} else {
|
|
|
|
$user = $wgUser->getName();
|
|
|
|
}
|
|
|
|
|
2012-03-10 11:36:01 +00:00
|
|
|
if ( !$wgUser->isAllowed( 'ajaxpoll-vote' ) || $wgUser->isAllowed( 'bot' ) ) {
|
2012-03-12 22:13:51 +00:00
|
|
|
return AJAXPoll::buildHTML( $id, $user );
|
2012-02-19 19:31:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 23:56:59 +00:00
|
|
|
if ( $answer != 0 ) {
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 23:56:59 +00:00
|
|
|
$answer = ++$answer;
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 23:56:59 +00:00
|
|
|
$q = $dbw->select(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-03-12 23:56:59 +00:00
|
|
|
'COUNT(*) AS count',
|
2012-02-19 19:31:24 +00:00
|
|
|
array(
|
2012-03-12 22:13:51 +00:00
|
|
|
'poll_id' => $id,
|
2012-02-19 19:31:24 +00:00
|
|
|
'poll_user' => $user
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
2012-03-12 23:56:59 +00:00
|
|
|
$row = $dbw->fetchRow( $q );
|
|
|
|
|
|
|
|
if ( $row['count'] > 0 ) {
|
|
|
|
|
|
|
|
$updateQuery = $dbw->update(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-03-12 23:56:59 +00:00
|
|
|
array(
|
|
|
|
'poll_answer' => $answer,
|
|
|
|
'poll_date' => wfTimestampNow()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'poll_id' => $id,
|
|
|
|
'poll_user' => $user,
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$dbw->commit();
|
|
|
|
$pollContainerText = ( $updateQuery ) ? 'ajaxpoll-vote-update' : 'ajaxpoll-vote-error';
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 23:56:59 +00:00
|
|
|
} else {
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 23:56:59 +00:00
|
|
|
$insertQuery = $dbw->insert(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-03-12 23:56:59 +00:00
|
|
|
array(
|
|
|
|
'poll_id' => $id,
|
|
|
|
'poll_user' => $user,
|
|
|
|
'poll_ip' => wfGetIP(),
|
|
|
|
'poll_answer' => $answer,
|
|
|
|
'poll_date' => wfTimestampNow()
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$dbw->commit();
|
|
|
|
$pollContainerText = ( $insertQuery ) ? 'ajaxpoll-vote-add' : 'ajaxpoll-vote-error';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // revoking a vote
|
|
|
|
|
|
|
|
$deleteQuery = $dbw->delete(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-02-19 19:31:24 +00:00
|
|
|
array(
|
2012-03-12 22:13:51 +00:00
|
|
|
'poll_id' => $id,
|
2012-02-19 19:31:24 +00:00
|
|
|
'poll_user' => $user,
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$dbw->commit();
|
2012-03-12 23:56:59 +00:00
|
|
|
$pollContainerText = ( $deleteQuery ) ? 'ajaxpoll-vote-revoked' : 'ajaxpoll-vote-error';
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
return AJAXPoll::buildHTML( $id, $user, '', $pollContainerText );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
private static function buildHTML( $id, $user, $lines = '', $extra_from_ajax = '' ) {
|
2012-03-10 09:26:52 +00:00
|
|
|
global $wgTitle, $wgUser, $wgLang, $wgUseAjax;
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$q = $dbr->select(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_info',
|
2012-02-19 19:31:24 +00:00
|
|
|
array( 'poll_txt', 'poll_date' ),
|
2012-03-12 22:13:51 +00:00
|
|
|
array( 'poll_id' => $id ),
|
2012-02-19 19:31:24 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
2012-03-12 22:13:51 +00:00
|
|
|
$row = $dbr->fetchRow( $q );
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
if ( empty( $lines ) ) {
|
|
|
|
$lines = explode( "\n", trim( $row['poll_txt'] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$start_date = $row['poll_date'];
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$q = $dbr->select(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-02-19 19:31:24 +00:00
|
|
|
array( 'poll_answer', 'COUNT(*)' ),
|
2012-03-12 22:13:51 +00:00
|
|
|
array( 'poll_id' => $id ),
|
2012-02-19 19:31:24 +00:00
|
|
|
__METHOD__,
|
|
|
|
array( 'GROUP BY' => 'poll_answer' )
|
|
|
|
);
|
|
|
|
|
|
|
|
$poll_result = array();
|
|
|
|
|
|
|
|
while ( $row = $q->fetchRow() ) {
|
|
|
|
$poll_result[$row[0]] = $row[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
$amountOfVotes = array_sum( $poll_result );
|
|
|
|
|
|
|
|
// Did we vote?
|
2012-03-12 22:13:51 +00:00
|
|
|
$q = $dbr->select(
|
2012-03-14 20:28:16 +00:00
|
|
|
'ajaxpoll_vote',
|
2012-02-19 19:31:24 +00:00
|
|
|
array( 'poll_answer', 'poll_date' ),
|
|
|
|
array(
|
2012-03-12 22:13:51 +00:00
|
|
|
'poll_id' => $id,
|
2012-02-19 19:31:24 +00:00
|
|
|
'poll_user' => $user
|
|
|
|
),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
if ( $row = $dbr->fetchRow( $q ) ) {
|
2012-02-19 19:31:24 +00:00
|
|
|
$ourLastVoteDate = wfMsg(
|
|
|
|
'ajaxpoll-your-vote',
|
|
|
|
$lines[$row[0] - 1],
|
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $row[1] ), true /* adjust? */ )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_object( $wgTitle ) ) {
|
|
|
|
if( !empty( $extra_from_ajax ) ) {
|
2012-02-22 19:07:58 +00:00
|
|
|
$attributes = ' style="display:block;"';
|
2012-02-19 19:31:24 +00:00
|
|
|
$ajaxMessage = wfMsg( $extra_from_ajax );
|
|
|
|
} else {
|
2012-02-22 19:07:58 +00:00
|
|
|
$attributes = ' style="display:none;"';
|
2012-02-19 19:31:24 +00:00
|
|
|
$ajaxMessage = '';
|
|
|
|
}
|
|
|
|
// HTML output has to be on one line thanks to a MediaWiki bug
|
|
|
|
// @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319
|
2012-03-17 21:13:10 +00:00
|
|
|
$ret = '<script>var useAjax='. ( !empty($wgUseAjax) ? "true" : "false" ) . ';</script>
|
|
|
|
<div id="ajaxpoll-id-' . $id . '" class="ajaxpoll">
|
2012-03-12 22:13:51 +00:00
|
|
|
<div id="ajaxpoll-ajax-' . $id . '" class="ajaxpoll-ajax"' . $attributes . '>' . $ajaxMessage . '</div>
|
2012-02-19 19:31:24 +00:00
|
|
|
<div class="ajaxpoll-question">' . strip_tags( $lines[0] ) . '</div>';
|
|
|
|
|
2012-03-12 18:26:50 +00:00
|
|
|
// Different message depending on if the user has already voted or not, or is entitled to vote
|
2012-03-10 09:26:52 +00:00
|
|
|
|
2012-03-13 01:04:59 +00:00
|
|
|
$canRevoke = false;
|
|
|
|
|
2012-03-10 09:26:52 +00:00
|
|
|
if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
|
2012-03-12 23:56:59 +00:00
|
|
|
if ( isset( $row[0] ) ) {
|
|
|
|
$message = $ourLastVoteDate;
|
2012-03-13 01:04:59 +00:00
|
|
|
$canRevoke = true;
|
2012-03-12 23:56:59 +00:00
|
|
|
$lines[] = wfMsg( 'ajaxpoll-revoke-vote' );
|
|
|
|
} else {
|
|
|
|
$message = wfMsg( 'ajaxpoll-no-vote' );
|
|
|
|
}
|
2012-03-10 09:26:52 +00:00
|
|
|
} else {
|
|
|
|
$message = wfMsg( 'ajaxpoll-vote-permission' );
|
|
|
|
}
|
|
|
|
|
2012-02-19 19:31:24 +00:00
|
|
|
$ret .= '<div class="ajaxpoll-misc">' . $message . '
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
$ret .= '<form method="post" action="' . $wgTitle->getLocalURL() .
|
2012-03-12 22:13:51 +00:00
|
|
|
'" id="ajaxpoll-answer-id-' . $id . '"><input type="hidden" name="ajaxpoll-post-id" value="' . $id . '" />';
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
for ( $i = 1; $i < count( $lines ); $i++ ) {
|
2012-03-12 23:56:59 +00:00
|
|
|
|
2012-03-13 01:04:59 +00:00
|
|
|
$vote = !( $canRevoke && ( $i == count( $lines ) - 1 ) );
|
|
|
|
|
2012-03-15 07:46:55 +00:00
|
|
|
// answers are counted from 1 ... n
|
|
|
|
// last answer is pseudo-answer for "I want to revoke vote"
|
|
|
|
// and becomes answer number 0
|
|
|
|
|
|
|
|
$answer = ( $vote ) ? $i : 0;
|
|
|
|
$xid = $id . "-" . $answer;
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
if ( $amountOfVotes == 0 ) {
|
|
|
|
$percent = 0;
|
|
|
|
} else {
|
|
|
|
$percent = $wgLang->formatNum( round( ( isset( $poll_result[$i + 1] ) ? $poll_result[$i + 1] : 0 ) * 100 / $amountOfVotes, 2 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
$our = ( isset( $row[0] ) && ( $row[0] - 1 == $i ) );
|
|
|
|
|
|
|
|
// If AJAX is enabled, as it is by default in modern MWs, we can
|
|
|
|
// just use sajax library function here for that AJAX-y feel.
|
|
|
|
// If not, we'll have to submit the form old-school way...
|
2012-03-10 09:26:52 +00:00
|
|
|
|
|
|
|
if ( $wgUser->isAllowed( 'ajaxpoll-vote' ) ) {
|
|
|
|
|
2012-03-12 23:56:59 +00:00
|
|
|
// HTML output has to be on one line thanks to a MediaWiki bug
|
|
|
|
// @see https://bugzilla.wikimedia.org/show_bug.cgi?id=1319
|
|
|
|
|
|
|
|
if ( $vote ) {
|
|
|
|
$ret .= "
|
2012-03-17 21:13:10 +00:00
|
|
|
<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer' poll='$id' answer='$answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-$xid'><input type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$id' value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
|
2012-03-13 22:31:46 +00:00
|
|
|
"</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' ajaxpoll-our-vote' : '' ) ."'><span title='" . wfMsg( 'ajaxpoll-percent-votes', sprintf( $percent ) ) . "'>" . ( ( isset( $poll_result ) && !empty( $poll_result[$i + 1] ) ) ? $poll_result[$i + 1] : 0 ) . "</span><div style='width: " . $percent . "%;" . ( $percent == 0 ? ' border:0;' : '' ) . "'></div></div>
|
2012-02-19 19:31:24 +00:00
|
|
|
</div>
|
|
|
|
";
|
2012-03-12 23:56:59 +00:00
|
|
|
} else {
|
|
|
|
$ret .= "
|
2012-03-17 21:13:10 +00:00
|
|
|
<div id='ajaxpoll-answer-$xid' class='ajaxpoll-answer' poll='$id' answer='$answer'><div class='ajaxpoll-answer-name ajaxpoll-answer-name-revoke'><label for='ajaxpoll-post-answer-$xid'><input type='radio' id='ajaxpoll-post-answer-$xid' name='ajaxpoll-post-answer-$id' value='" . $answer . "' " . ( $our ? 'checked=true ' : '' ) . "/>" . strip_tags( $lines[$i] ) .
|
2012-03-12 23:56:59 +00:00
|
|
|
"</label></div>
|
|
|
|
</div>
|
|
|
|
";
|
|
|
|
}
|
2012-03-10 09:26:52 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$ret .= "
|
2012-03-17 21:13:10 +00:00
|
|
|
<div id='ajaxpoll-answer-" . $xid . "' class='ajaxpoll-answer' poll='$id' answer='$answer'><div class='ajaxpoll-answer-name'><label for='ajaxpoll-post-answer-" . $xid . "' onclick='$(\"#ajaxpoll-ajax-" . $xid . "\").html(\"" . wfMsg( 'ajaxpoll-vote-permission' ) . "\").css(\"display\",\"block\");'><input disabled='disabled' type='radio' id='ajaxpoll-post-answer-" . $xid . "' name='ajaxpoll-post-answer-" . $id . "' value='" . $answer . "'/>" . strip_tags( $lines[$i] ) .
|
2012-03-13 22:31:46 +00:00
|
|
|
"</label></div><div class='ajaxpoll-answer-vote" . ( $our ? ' ajaxpoll-our-vote' : '' ) ."'><span title='" . wfMsg( 'ajaxpoll-percent-votes', sprintf( $percent ) ) . "'>" . ( ( isset( $poll_result ) && !empty( $poll_result[$i + 1] ) ) ? $poll_result[$i + 1] : 0 ) . "</span><div style='width: " . $percent . "%;" . ( $percent == 0 ? ' border:0;' : '' ) . "'></div></div>
|
2012-03-10 09:26:52 +00:00
|
|
|
</div>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-02-19 19:31:24 +00:00
|
|
|
|
|
|
|
$ret .= '</form>';
|
|
|
|
|
|
|
|
// Display information about the poll (creation date, amount of votes)
|
|
|
|
$pollSummary = wfMsgExt(
|
|
|
|
'ajaxpoll-info',
|
|
|
|
'parsemag', // parse PLURAL
|
|
|
|
$amountOfVotes, // amount of votes
|
|
|
|
$wgLang->timeanddate( wfTimestamp( TS_MW, $start_date ), true /* adjust? */ )
|
|
|
|
);
|
|
|
|
|
2012-03-12 22:13:51 +00:00
|
|
|
$ret .= '<div id="ajaxpoll-info-' . $id . '" class="ajaxpoll-info">' . $pollSummary . '<div class="ajaxpoll-id-info">poll-id ' . $id . '</div></div></div>';
|
2012-02-19 19:31:24 +00:00
|
|
|
} else {
|
|
|
|
$ret = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2012-03-14 20:19:16 +00:00
|
|
|
public static function onLoadExtensionSchemaUpdates( $updater = null ) {
|
|
|
|
if ( $updater === null ) {
|
|
|
|
// no < 1.17 support
|
|
|
|
} else {
|
|
|
|
// >= 1.17 support
|
2013-01-01 08:42:59 +00:00
|
|
|
$db = $updater->getDB();
|
2012-03-14 20:19:16 +00:00
|
|
|
|
2013-01-01 08:42:59 +00:00
|
|
|
if ( $db->tableExists( 'poll_info' ) ) {
|
2012-03-14 21:43:56 +00:00
|
|
|
# poll_info.poll_title field was dropped in AJAXPoll version 1.72
|
|
|
|
$updater->dropExtensionField(
|
|
|
|
'poll_info',
|
|
|
|
'poll_title',
|
|
|
|
dirname( __FILE__ ) . '/patches/drop-field--poll_info-poll_title.sql'
|
|
|
|
);
|
|
|
|
$updater->addExtensionTable(
|
|
|
|
'ajaxpoll_info',
|
|
|
|
dirname( __FILE__ ) . '/patches/rename-table--poll_info.sql'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$updater->addExtensionTable(
|
|
|
|
'ajaxpoll_info',
|
|
|
|
dirname( __FILE__ ) . '/patches/create-table--ajaxpoll_info.sql'
|
|
|
|
);
|
|
|
|
}
|
2012-03-14 20:19:16 +00:00
|
|
|
|
2013-01-01 08:42:59 +00:00
|
|
|
if ( $db->tableExists( 'poll_vote' ) ) {
|
2012-03-14 21:43:56 +00:00
|
|
|
$updater->addExtensionTable(
|
|
|
|
'ajaxpoll_vote',
|
|
|
|
dirname( __FILE__ ) . '/patches/rename-table--poll_vote.sql'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$updater->addExtensionTable(
|
|
|
|
'ajaxpoll_vote',
|
|
|
|
dirname( __FILE__ ) . '/patches/create-table--ajaxpoll_vote.sql'
|
|
|
|
);
|
|
|
|
}
|
2012-03-14 20:19:16 +00:00
|
|
|
|
|
|
|
}
|
2012-03-14 21:43:56 +00:00
|
|
|
|
2012-03-14 20:19:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-19 19:31:24 +00:00
|
|
|
} /* class AJAXPoll */
|