r91716 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91715‎ | r91716 | r91717 >
Date:07:03, 8 July 2011
Author:questpc
Status:deferred
Tags:
Comment:
MVC improvements. Applying showresults attribute in accordance with current user rights. Display default error message when interpretation script generated proposal errors but have not returned common error message.
Modified paths:
  • /trunk/extensions/QPoll/clientside (added) (history)
  • /trunk/extensions/QPoll/clientside/qp_results.css (added) (history)
  • /trunk/extensions/QPoll/clientside/qp_user.css (added) (history)
  • /trunk/extensions/QPoll/clientside/qp_user.js (added) (history)
  • /trunk/extensions/QPoll/clientside/qp_user_rtl.css (added) (history)
  • /trunk/extensions/QPoll/ctrl/qp_abstractpoll.php (modified) (history)
  • /trunk/extensions/QPoll/ctrl/qp_abstractquestion.php (modified) (history)
  • /trunk/extensions/QPoll/ctrl/qp_poll.php (modified) (history)
  • /trunk/extensions/QPoll/ctrl/qp_pollstats.php (modified) (history)
  • /trunk/extensions/QPoll/ctrl/qp_question.php (modified) (history)
  • /trunk/extensions/QPoll/ctrl/qp_questionstats.php (modified) (history)
  • /trunk/extensions/QPoll/qp_interpret.php (modified) (history)
  • /trunk/extensions/QPoll/qp_pollstore.php (modified) (history)
  • /trunk/extensions/QPoll/qp_results.css (deleted) (history)
  • /trunk/extensions/QPoll/qp_results.php (modified) (history)
  • /trunk/extensions/QPoll/qp_user.css (deleted) (history)
  • /trunk/extensions/QPoll/qp_user.js (deleted) (history)
  • /trunk/extensions/QPoll/qp_user.php (modified) (history)
  • /trunk/extensions/QPoll/qp_user_rtl.css (deleted) (history)
  • /trunk/extensions/QPoll/view/qp_questionstatsview.php (modified) (history)
  • /trunk/extensions/QPoll/view/qp_questionview.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/qp_user_rtl.css
@@ -1,8 +0,0 @@
2 -.qpoll .attempts_counter { border: 1px solid gray; padding: 0.1em 0.5em 0.1em 0.5em; color: black; background-color: lightblue; margin-right: 1em; }
3 -.qpoll .question { margin-right:2em; }
4 -.qpoll .margin { padding-right:20px; }
5 -.qpoll .header .questionId {font-size: 1.1em; font-weight: bold; float: right;}
6 -.qpoll .header .questionId { *padding-left: 0.5em; } /* applies to IE7 and below */
7 -.qpoll a.input em { color:black; background-color:#DFDFDF; margin-left:1px; }
8 -.qpoll a.input input { padding-right:2px; border:0; }
9 -.qpoll .error_mark { border-right: 3px solid #D700D7; }
Index: trunk/extensions/QPoll/qp_results.css
@@ -1,10 +0,0 @@
2 -.qpoll .head {font-weight:bold; color:gray;}
3 -.qpoll table.pollresults {border-collapse: collapse;}
4 -.qpoll table.pollresults th {border: 1px gray solid; background-color:lightgray; padding: 3px;}
5 -.qpoll table.pollresults tr.spans { color:Navy; }
6 -.qpoll table.pollresults td {border: 1px gray solid; text-align: center; padding: 3px;}
7 -.qpoll table.pollresults td.stats {background-color: Azure;}
8 -.qpoll table.pollresults td.spaneven {background-color: Aquamarine;}
9 -.qpoll table.pollresults td.spanodd {background-color: Moccasin;}
10 -.qpoll .interp_answer { border: 1px solid gray; padding: 0; margin: 0; color: black; background-color: lightgray; font-weight:bold; line-height:2em; }
11 -.qpoll .interp_answer_body { border: none; border-top: 1px solid gray; padding: 0.5em; margin-top: 0; color: black; background-color: Azure; font-weight: normal; line-height:normal; }
Index: trunk/extensions/QPoll/qp_user.js
@@ -1,132 +0,0 @@
2 -/**
3 - * ***** BEGIN LICENSE BLOCK *****
4 - * This file is part of QPoll.
5 - * Uses parts of code from Quiz extension (c) 2007 Louis-Rémi BABE. All rights reserved.
6 - *
7 - * QPoll is free software; you can redistribute it and/or modify
8 - * it under the terms of the GNU General Public License as published by
9 - * the Free Software Foundation; either version 2 of the License, or
10 - * (at your option) any later version.
11 - *
12 - * QPoll is distributed in the hope that it will be useful,
13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 - * GNU General Public License for more details.
16 - *
17 - * You should have received a copy of the GNU General Public License
18 - * along with QPoll; if not, write to the Free Software
19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 - *
21 - * ***** END LICENSE BLOCK *****
22 - *
23 - * QPoll is a poll tool for MediaWiki.
24 - *
25 - * To activate this extension :
26 - * * Create a new directory named QPoll into the directory "extensions" of MediaWiki.
27 - * * Place the files from the extension archive there.
28 - * * Add this line at the end of your LocalSettings.php file :
29 - * require_once "$IP/extensions/QPoll/qp_user.php";
30 - *
31 - * @version 0.8.0a
32 - * @link http://www.mediawiki.org/wiki/Extension:QPoll
33 - * @author QuestPC <questpc@rambler.ru>
34 - */
35 -
36 -(function() {
37 - function uniqueRadioButtonColumn() {
38 -// uq1c2p2
39 - var propId, inp;
40 - var id = new String( this.getAttribute('id') );
41 -// IE split is really buggy, so we have to search for p letter instead, was:
42 -// var params = id.split('/(uq\d{1,}?c\d{1,}?p)(\d{1,}?)/g');
43 -// if ( params !== null && params[1] !== null && params[2] != null ) {
44 -// var currPropId = parseInt( params[2] );
45 -// var basepart = params[1];
46 - var p = id.indexOf( 'p' ) + 1;
47 - var currPropId = parseInt( id.substring( p ) );
48 - var basepart = id.substring( 0, p );
49 - if ( p != 0) {
50 - for ( propId = 0; ( inp = document.getElementById( basepart + propId ) ) !== null; propId++ ) {
51 - if ( propId != currPropId) {
52 - inp.checked = false;
53 - }
54 - }
55 - }
56 - }
57 -
58 - function clickMixedRow() {
59 -// mx1p2c2
60 - var catId, inp;
61 - var id = new String( this.getAttribute('id') );
62 - var c = id.indexOf( 'c' ) + 1;
63 - var currCatId = parseInt( id.substring( c ) );
64 - var basepart = id.substring( 0, c );
65 - if ( c != 0) {
66 - for ( catId = 0; ( inp = document.getElementById( basepart + catId ) ) !== null; catId++ ) {
67 - if ( catId != currCatId ) {
68 - if ( this.type == 'radio' ) {
69 - if (inp.type == 'text' ) {
70 - inp.value = '';
71 - } else {
72 - inp.checked = false;
73 - }
74 - } else {
75 - if (inp.type == 'radio' ) {
76 - inp.checked = false;
77 - }
78 - }
79 - }
80 - }
81 - }
82 - }
83 - /**
84 - * Prepare the Poll for "javascriptable" browsers
85 - */
86 - function preparePoll() {
87 - var bodyContentDiv = document.getElementById('bodyContent').getElementsByTagName('div');
88 - var inputFuncId;
89 - for(var i=0; i<bodyContentDiv.length; ++i) {
90 - if(bodyContentDiv[i].className == 'qpoll') {
91 - var input = bodyContentDiv[i].getElementsByTagName('input');
92 - for(var j=0; j<input.length; ++j) {
93 - if ( input[j].id ) {
94 - inputFuncId = new String( input[j].id ).slice( 0, 2 );
95 - switch ( inputFuncId ) {
96 - case "uq":
97 - if ( input[j].type == "radio" ) {
98 - // unset the column of radiobuttons in case of unique proposal
99 - addEvent( input[j], "click", uniqueRadioButtonColumn );
100 - }
101 - break;
102 - case "mx":
103 - // unset the row of checkboxes in case of "mixed" question type
104 - addEvent( input[j], "click", clickMixedRow );
105 - break;
106 - }
107 - } else {
108 - // Add the possibility of unchecking radio buttons
109 - addEvent(input[j],"dblclick", function() { this.checked = false; });
110 - }
111 - }
112 - }
113 - }
114 - }
115 -
116 - function addEvent( obj, type, fn ) {
117 - if (obj.addEventListener) {
118 - obj.addEventListener( type, fn, false );
119 - }
120 - else if (obj.attachEvent) {
121 - obj["e"+type+fn] = fn;
122 - obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
123 - obj.attachEvent( "on"+type, obj[type+fn] );
124 - }
125 - else {
126 - obj["on"+type] = obj["e"+type+fn];
127 - }
128 - }
129 -
130 - if (document.getElementById && document.createTextNode) {
131 - addEvent(window,"load",preparePoll);
132 - }
133 -})();
\ No newline at end of file
Index: trunk/extensions/QPoll/qp_user.css
@@ -1,52 +0,0 @@
2 -.qpoll .error { background-color: LightYellow; }
3 -.qpoll .fatalerror { border: 1px solid gray; padding: 4px; background-color: LightYellow; }
4 -.qpoll .settings input.numerical { width:2em; }
5 -.qpoll .header {font-weight: bold;}
6 -*>.qpoll .header .questionId {text-indent: -1.5em; } /* *> prevent ie6 to interprate it. */
7 -.qpoll table.object { background-color:transparent; border-collapse:collapse; }
8 -.qpoll table.object .proposaltext { }
9 -.qpoll table.object th { padding-left: 5px; padding-right: 5px; vertical-align:bottom; }
10 -.qpoll table.object .spans { color:gray; }
11 -.qpoll table.object .categories { color:#444455; }
12 -.qpoll table.object .proposal { }
13 -.qpoll .proposalerror { color:red; font-weight:600; }
14 -.qpoll .settings td { padding: 0.1em 0.4em 0.1em 0.4em }
15 -.qpoll table.settings { background-color:transparent; }
16 -/* Part for the basic types's inputs. */
17 -.qpoll table.stats td { text-align:center; margin:2px; padding:0px; border:none; border-collapse:collapse; }
18 -.qpoll div.stats { text-align:center; font-size:7pt; color:green; padding-left: 2px; padding-right: 2px;}
19 -.qpoll div.stats1 { text-align:center; font-size:7pt; color:green; width:162px; margin:0px auto; margin-top:2px; }
20 -.qpoll div.stats2 { text-align:center; font-size:7pt; height:20px; font-weight:bold; color:green; width:105px; margin:0px auto; padding-left:3px; padding-bottom:1px; margin-top:1px; margin-bottom:2px; }
21 -.qpoll div.stats2 div { height:20px; }
22 -.qpoll div.bar0 { float:left; width:30px; }
23 -.qpoll div.bar1 { float:left; background-color:gainsboro; border-left: 1px solid gray; border-top: 1px solid gray; border-bottom: 1px solid gray; }
24 -.qpoll div.bar2 { float:left; background-color:linen; border-right: 1px solid gray; border-top: 1px solid gray; border-bottom: 1px solid gray; }
25 -.qpoll div.bar3 { width:100px; left:0px; top:-20px; position:relative; z-index:10; }
26 -.qpoll .sign { text-align:center; }
27 -.qpoll .signl { text-align:center; border-bottom:1px solid gray; border-top: 1px solid gray; border-left: 1px solid gray; }
28 -.qpoll .signc { text-align:center; border-bottom:1px solid gray; border-top: 1px solid gray; }
29 -.qpoll .signr { text-align:center; border-bottom:1px solid gray; border-top: 1px solid gray; border-right: 1px solid gray; }
30 -.qpoll .signt { text-align:center; border-left: 1px solid gray; border-right: 1px solid gray; border-top: 1px solid gray; }
31 -.qpoll .signm { text-align:center; border-left: 1px solid gray; border-right: 1px solid gray; }
32 -.qpoll .signb { text-align:center; border-left: 1px solid gray; border-right: 1px solid gray; border-bottom:1px solid gray; }
33 -/* Part for the inputfields */
34 -.qpoll a.input, .qpoll a.input:hover, .qpoll a.input:active, .qpoll a.input:visited { text-decoration:none; color:black; outline: 0 }
35 -.qpoll a.input span { outline:#7F9DB9 solid 1px; border:1px solid #7F9DB9; } /* *border is for IE6/7 star is removed due to ff console error */
36 -.qpoll .interp_error { border: 2px solid gray; padding: 0.5em; color: white; background-color: red; }
37 -.qpoll .interp_answer { border: 2px solid gray; padding: 0.5em; color: black; background-color: lightblue; }
38 -
39 -.qpoll .cell_errror { background-color: #D700D7; }
40 -
41 -/* script view */
42 -.qpoll .line_numbers { font-family: monospace, "Courier New"; white-space:pre; color:green; background-color: lightgray; float:left; border-left: 1px solid darkgray; border-top: 1px solid darkgray; border-bottom: 1px solid darkgray; padding: 0.5em; }
43 -.qpoll .script_view { font-family: monospace, "Courier New"; white-space:pre; overflow:auto; color:black; background-color: lightgray; border-right: 1px solid darkgray; border-top: 1px solid darkgray; border-bottom: 1px solid darkgray; padding: 0.5em; }
44 -
45 -/* LTR part (RTL is included from separate file */
46 -.qpoll .attempts_counter{ border: 1px solid gray; padding: 0.1em 0.5em 0.1em 0.5em; color: black; background-color: lightblue; margin-left: 1em; }
47 -.qpoll .question { margin-left:2em; }
48 -.qpoll .margin { padding-left:20px; }
49 -.qpoll .header .questionId { font-size: 1.1em; font-weight: bold; float: left; }
50 -.qpoll .header .questionId { *padding-right: 0.5em; } /* applies to IE7 and below */
51 -.qpoll a.input em { color:black; background-color:#DFDFDF; margin-right:1px; }
52 -.qpoll a.input input { padding-left:2px; border:0; }
53 -.qpoll .error_mark { border-left: 3px solid #D700D7; }
Index: trunk/extensions/QPoll/qp_interpret.php
@@ -106,7 +106,7 @@
107107 }
108108 # if there were question/proposal errors, return them;
109109 if ( $interpAnswer->isError() ) {
110 - return $interpAnswer;
 110+ return $interpAnswer->setDefaultErrorMessage();
111111 }
112112 if ( !isset( $result['short'] ) || !isset( $result['long'] ) ) {
113113 return $interpAnswer->setError( wfMsg( 'qp_error_interpretation_no_return' ) );
Index: trunk/extensions/QPoll/clientside/qp_user.css
@@ -0,0 +1,52 @@
 2+.qpoll .error { background-color: LightYellow; }
 3+.qpoll .fatalerror { border: 1px solid gray; padding: 4px; background-color: LightYellow; }
 4+.qpoll .settings input.numerical { width:2em; }
 5+.qpoll .header {font-weight: bold;}
 6+*>.qpoll .header .questionId {text-indent: -1.5em; } /* *> prevent ie6 to interprate it. */
 7+.qpoll table.object { background-color:transparent; border-collapse:collapse; }
 8+.qpoll table.object .proposaltext { }
 9+.qpoll table.object th { padding-left: 5px; padding-right: 5px; vertical-align:bottom; }
 10+.qpoll table.object .spans { color:gray; }
 11+.qpoll table.object .categories { color:#444455; }
 12+.qpoll table.object .proposal { }
 13+.qpoll .proposalerror { color:red; font-weight:600; }
 14+.qpoll .settings td { padding: 0.1em 0.4em 0.1em 0.4em }
 15+.qpoll table.settings { background-color:transparent; }
 16+/* Part for the basic types's inputs. */
 17+.qpoll table.stats td { text-align:center; margin:2px; padding:0px; border:none; border-collapse:collapse; }
 18+.qpoll div.stats { text-align:center; font-size:7pt; color:green; padding-left: 2px; padding-right: 2px;}
 19+.qpoll div.stats1 { text-align:center; font-size:7pt; color:green; width:162px; margin:0px auto; margin-top:2px; }
 20+.qpoll div.stats2 { text-align:center; font-size:7pt; height:20px; font-weight:bold; color:green; width:105px; margin:0px auto; padding-left:3px; padding-bottom:1px; margin-top:1px; margin-bottom:2px; }
 21+.qpoll div.stats2 div { height:20px; }
 22+.qpoll div.bar0 { float:left; width:30px; }
 23+.qpoll div.bar1 { float:left; background-color:gainsboro; border-left: 1px solid gray; border-top: 1px solid gray; border-bottom: 1px solid gray; }
 24+.qpoll div.bar2 { float:left; background-color:linen; border-right: 1px solid gray; border-top: 1px solid gray; border-bottom: 1px solid gray; }
 25+.qpoll div.bar3 { width:100px; left:0px; top:-20px; position:relative; z-index:10; }
 26+.qpoll .sign { text-align:center; }
 27+.qpoll .signl { text-align:center; border-bottom:1px solid gray; border-top: 1px solid gray; border-left: 1px solid gray; }
 28+.qpoll .signc { text-align:center; border-bottom:1px solid gray; border-top: 1px solid gray; }
 29+.qpoll .signr { text-align:center; border-bottom:1px solid gray; border-top: 1px solid gray; border-right: 1px solid gray; }
 30+.qpoll .signt { text-align:center; border-left: 1px solid gray; border-right: 1px solid gray; border-top: 1px solid gray; }
 31+.qpoll .signm { text-align:center; border-left: 1px solid gray; border-right: 1px solid gray; }
 32+.qpoll .signb { text-align:center; border-left: 1px solid gray; border-right: 1px solid gray; border-bottom:1px solid gray; }
 33+/* Part for the inputfields */
 34+.qpoll a.input, .qpoll a.input:hover, .qpoll a.input:active, .qpoll a.input:visited { text-decoration:none; color:black; outline: 0 }
 35+.qpoll a.input span { outline:#7F9DB9 solid 1px; border:1px solid #7F9DB9; } /* *border is for IE6/7 star is removed due to ff console error */
 36+.qpoll .interp_error { border: 2px solid gray; padding: 0.5em; color: white; background-color: red; }
 37+.qpoll .interp_answer { border: 2px solid gray; padding: 0.5em; color: black; background-color: lightblue; }
 38+
 39+.qpoll .cell_errror { background-color: #D700D7; }
 40+
 41+/* script view */
 42+.qpoll .line_numbers { font-family: monospace, "Courier New"; white-space:pre; color:green; background-color: lightgray; float:left; border-left: 1px solid darkgray; border-top: 1px solid darkgray; border-bottom: 1px solid darkgray; padding: 0.5em; }
 43+.qpoll .script_view { font-family: monospace, "Courier New"; white-space:pre; overflow:auto; color:black; background-color: lightgray; border-right: 1px solid darkgray; border-top: 1px solid darkgray; border-bottom: 1px solid darkgray; padding: 0.5em; }
 44+
 45+/* LTR part (RTL is included from separate file */
 46+.qpoll .attempts_counter{ border: 1px solid gray; padding: 0.1em 0.5em 0.1em 0.5em; color: black; background-color: lightblue; margin-left: 1em; }
 47+.qpoll .question { margin-left:2em; }
 48+.qpoll .margin { padding-left:20px; }
 49+.qpoll .header .questionId { font-size: 1.1em; font-weight: bold; float: left; }
 50+.qpoll .header .questionId { *padding-right: 0.5em; } /* applies to IE7 and below */
 51+.qpoll a.input em { color:black; background-color:#DFDFDF; margin-right:1px; }
 52+.qpoll a.input input { padding-left:2px; border:0; }
 53+.qpoll .error_mark { border-left: 3px solid #D700D7; }
Property changes on: trunk/extensions/QPoll/clientside/qp_user.css
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: trunk/extensions/QPoll/clientside/qp_user_rtl.css
@@ -0,0 +1,8 @@
 2+.qpoll .attempts_counter { border: 1px solid gray; padding: 0.1em 0.5em 0.1em 0.5em; color: black; background-color: lightblue; margin-right: 1em; }
 3+.qpoll .question { margin-right:2em; }
 4+.qpoll .margin { padding-right:20px; }
 5+.qpoll .header .questionId {font-size: 1.1em; font-weight: bold; float: right;}
 6+.qpoll .header .questionId { *padding-left: 0.5em; } /* applies to IE7 and below */
 7+.qpoll a.input em { color:black; background-color:#DFDFDF; margin-left:1px; }
 8+.qpoll a.input input { padding-right:2px; border:0; }
 9+.qpoll .error_mark { border-right: 3px solid #D700D7; }
Property changes on: trunk/extensions/QPoll/clientside/qp_user_rtl.css
___________________________________________________________________
Added: svn:eol-style
110 + native
Index: trunk/extensions/QPoll/clientside/qp_results.css
@@ -0,0 +1,10 @@
 2+.qpoll .head {font-weight:bold; color:gray;}
 3+.qpoll table.pollresults {border-collapse: collapse;}
 4+.qpoll table.pollresults th {border: 1px gray solid; background-color:lightgray; padding: 3px;}
 5+.qpoll table.pollresults tr.spans { color:Navy; }
 6+.qpoll table.pollresults td {border: 1px gray solid; text-align: center; padding: 3px;}
 7+.qpoll table.pollresults td.stats {background-color: Azure;}
 8+.qpoll table.pollresults td.spaneven {background-color: Aquamarine;}
 9+.qpoll table.pollresults td.spanodd {background-color: Moccasin;}
 10+.qpoll .interp_answer { border: 1px solid gray; padding: 0; margin: 0; color: black; background-color: lightgray; font-weight:bold; line-height:2em; }
 11+.qpoll .interp_answer_body { border: none; border-top: 1px solid gray; padding: 0.5em; margin-top: 0; color: black; background-color: Azure; font-weight: normal; line-height:normal; }
Property changes on: trunk/extensions/QPoll/clientside/qp_results.css
___________________________________________________________________
Added: svn:eol-style
112 + native
Index: trunk/extensions/QPoll/clientside/qp_user.js
@@ -0,0 +1,132 @@
 2+/**
 3+ * ***** BEGIN LICENSE BLOCK *****
 4+ * This file is part of QPoll.
 5+ * Uses parts of code from Quiz extension (c) 2007 Louis-Rémi BABE. All rights reserved.
 6+ *
 7+ * QPoll is free software; you can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version.
 11+ *
 12+ * QPoll is distributed in the hope that it will be useful,
 13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15+ * GNU General Public License for more details.
 16+ *
 17+ * You should have received a copy of the GNU General Public License
 18+ * along with QPoll; if not, write to the Free Software
 19+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20+ *
 21+ * ***** END LICENSE BLOCK *****
 22+ *
 23+ * QPoll is a poll tool for MediaWiki.
 24+ *
 25+ * To activate this extension :
 26+ * * Create a new directory named QPoll into the directory "extensions" of MediaWiki.
 27+ * * Place the files from the extension archive there.
 28+ * * Add this line at the end of your LocalSettings.php file :
 29+ * require_once "$IP/extensions/QPoll/qp_user.php";
 30+ *
 31+ * @version 0.8.0a
 32+ * @link http://www.mediawiki.org/wiki/Extension:QPoll
 33+ * @author QuestPC <questpc@rambler.ru>
 34+ */
 35+
 36+(function() {
 37+ function uniqueRadioButtonColumn() {
 38+// uq1c2p2
 39+ var propId, inp;
 40+ var id = new String( this.getAttribute('id') );
 41+// IE split is really buggy, so we have to search for p letter instead, was:
 42+// var params = id.split('/(uq\d{1,}?c\d{1,}?p)(\d{1,}?)/g');
 43+// if ( params !== null && params[1] !== null && params[2] != null ) {
 44+// var currPropId = parseInt( params[2] );
 45+// var basepart = params[1];
 46+ var p = id.indexOf( 'p' ) + 1;
 47+ var currPropId = parseInt( id.substring( p ) );
 48+ var basepart = id.substring( 0, p );
 49+ if ( p != 0) {
 50+ for ( propId = 0; ( inp = document.getElementById( basepart + propId ) ) !== null; propId++ ) {
 51+ if ( propId != currPropId) {
 52+ inp.checked = false;
 53+ }
 54+ }
 55+ }
 56+ }
 57+
 58+ function clickMixedRow() {
 59+// mx1p2c2
 60+ var catId, inp;
 61+ var id = new String( this.getAttribute('id') );
 62+ var c = id.indexOf( 'c' ) + 1;
 63+ var currCatId = parseInt( id.substring( c ) );
 64+ var basepart = id.substring( 0, c );
 65+ if ( c != 0) {
 66+ for ( catId = 0; ( inp = document.getElementById( basepart + catId ) ) !== null; catId++ ) {
 67+ if ( catId != currCatId ) {
 68+ if ( this.type == 'radio' ) {
 69+ if (inp.type == 'text' ) {
 70+ inp.value = '';
 71+ } else {
 72+ inp.checked = false;
 73+ }
 74+ } else {
 75+ if (inp.type == 'radio' ) {
 76+ inp.checked = false;
 77+ }
 78+ }
 79+ }
 80+ }
 81+ }
 82+ }
 83+ /**
 84+ * Prepare the Poll for "javascriptable" browsers
 85+ */
 86+ function preparePoll() {
 87+ var bodyContentDiv = document.getElementById('bodyContent').getElementsByTagName('div');
 88+ var inputFuncId;
 89+ for(var i=0; i<bodyContentDiv.length; ++i) {
 90+ if(bodyContentDiv[i].className == 'qpoll') {
 91+ var input = bodyContentDiv[i].getElementsByTagName('input');
 92+ for(var j=0; j<input.length; ++j) {
 93+ if ( input[j].id ) {
 94+ inputFuncId = new String( input[j].id ).slice( 0, 2 );
 95+ switch ( inputFuncId ) {
 96+ case "uq":
 97+ if ( input[j].type == "radio" ) {
 98+ // unset the column of radiobuttons in case of unique proposal
 99+ addEvent( input[j], "click", uniqueRadioButtonColumn );
 100+ }
 101+ break;
 102+ case "mx":
 103+ // unset the row of checkboxes in case of "mixed" question type
 104+ addEvent( input[j], "click", clickMixedRow );
 105+ break;
 106+ }
 107+ } else {
 108+ // Add the possibility of unchecking radio buttons
 109+ addEvent(input[j],"dblclick", function() { this.checked = false; });
 110+ }
 111+ }
 112+ }
 113+ }
 114+ }
 115+
 116+ function addEvent( obj, type, fn ) {
 117+ if (obj.addEventListener) {
 118+ obj.addEventListener( type, fn, false );
 119+ }
 120+ else if (obj.attachEvent) {
 121+ obj["e"+type+fn] = fn;
 122+ obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
 123+ obj.attachEvent( "on"+type, obj[type+fn] );
 124+ }
 125+ else {
 126+ obj["on"+type] = obj["e"+type+fn];
 127+ }
 128+ }
 129+
 130+ if (document.getElementById && document.createTextNode) {
 131+ addEvent(window,"load",preparePoll);
 132+ }
 133+})();
\ No newline at end of file
Property changes on: trunk/extensions/QPoll/clientside/qp_user.js
___________________________________________________________________
Added: svn:eol-style
1134 + native
Index: trunk/extensions/QPoll/ctrl/qp_abstractpoll.php
@@ -91,8 +91,8 @@
9292 $this->view = $view;
9393 # reset the unique index number of the question in the current poll (used to instantiate the questions)
9494 $this->mQuestionId = 0; // ( correspons to 'question_id' DB field )
95 - $this->username = self::currentUserName();
96 -
 95+ $this->username = qp_Setup::getCurrUserName();
 96+ # setup poll view showresults
9797 if ( array_key_exists( 'showresults', $argv ) && qp_Setup::$global_showresults != 0 ) {
9898 if ( $argv['showresults'] == 'showresults' ) {
9999 # default showresults for the empty value of xml attribute
@@ -100,6 +100,13 @@
101101 }
102102 $this->view->showResults = self::parseShowResults( $argv['showresults'] );
103103 }
 104+ # check whether current user has rights for showresults
 105+ $user = User::newFromName( $this->username );
 106+ if ( !$user->isAllowed( 'showresults' ) ) {
 107+ $this->view->showResults = false;
 108+ }
 109+ unset( $user );
 110+
104111 # every poll on the page should have unique poll id, to minimize the risk of collisions
105112 # it is required to be set manually via id="value" parameter
106113 # ( used only in "declaration" mode )
@@ -166,47 +173,6 @@
167174 return !in_array( $pollId, self::$sPrevPollIDs );
168175 }
169176
170 - static function currentUserName() {
171 - global $wgUser, $wgSquidServers;
172 - global $wgUsePrivateIPs;
173 - if ( qp_Setup::$anon_forwarded_for === true && $wgUser->isAnon() ) {
174 - /* collect the originating IPs
175 - borrowed from ProxyTools::wfGetIP
176 - bypass trusted proxies list check */
177 - # Client connecting to this webserver
178 - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
179 - $ipchain = array( IP::canonicalize( $_SERVER['REMOTE_ADDR'] ) );
180 - } else {
181 - # Running on CLI?
182 - $ipchain = array( '127.0.0.1' );
183 - }
184 - $ip = $ipchain[0];
185 -
186 - # Append XFF on to $ipchain
187 - $forwardedFor = wfGetForwardedFor();
188 - if ( isset( $forwardedFor ) ) {
189 - $xff = array_map( 'trim', explode( ',', $forwardedFor ) );
190 - $xff = array_reverse( $xff );
191 - $ipchain = array_merge( $ipchain, $xff );
192 - }
193 - $username = "";
194 - foreach ( $ipchain as $i => $curIP ) {
195 - if( $wgUsePrivateIPs || IP::isPublic( $curIP ) ) {
196 - $username .= IP::canonicalize( $curIP ) . '/';
197 - }
198 - }
199 - if ( $username != "" ) {
200 - # remove trailing slash
201 - $username = substr( $username, 0, strlen( $username ) - 1 );
202 - } else {
203 - $username .= IP::canonicalize( $ipchain[0] );
204 - }
205 - } else {
206 - $username = $wgUser->getName();
207 - }
208 - return $username;
209 - }
210 -
211177 // @input $addr - source poll address (possibly the short one) in the string or array form
212178 // @return array[0] - title where the poll is located
213179 // array[1] - pollId string
Index: trunk/extensions/QPoll/ctrl/qp_abstractquestion.php
@@ -7,12 +7,12 @@
88 abstract class qp_AbstractQuestion {
99
1010 var $mState = ''; // current state of question parsing (no error)
11 - # default type and subtype of the question; should always be properly initialized in $this->parseParameters();
 11+ # default type and subtype of the question; should always be properly initialized in derived $this->parseMainHeader();
1212 var $mType = 'unknown';
13 - var $mSubType = ''; // some questions has a subtype, see $this->parseParameters()
 13+ var $mSubType = ''; // some questions has a subtype, see derived $this->parseMainHeader()
1414 var $mCategories = Array();
1515 var $mCategorySpans = Array();
16 - var $mCommonQuestion = ''; // GET common question of the poll
 16+ var $mCommonQuestion = ''; // common question of this question
1717 var $mProposalText = Array(); // an array of question proposals
1818 var $alreadyVoted = false; // whether the selected user has already voted this question ?
1919
Index: trunk/extensions/QPoll/ctrl/qp_pollstats.php
@@ -45,10 +45,6 @@
4646 function __construct( $argv, qp_PollStatsView $view ) {
4747 parent::__construct( $argv, $view );
4848 $this->pollAddr = trim( $argv['address'] );
49 - # statistical mode is active, but qp_Setup::$global_showresults still can be false
50 - if ( qp_Setup::$global_showresults == 0 ) {
51 - $this->view->showResults = false;
52 - }
5349 }
5450
5551 # prepare qp_PollStore object
@@ -113,8 +109,7 @@
114110 # check for showresults attribute
115111 $questions_set = array();
116112 foreach ( $this->questions as &$question ) {
117 - if ( $question->view->showResults['type'] != 0 &&
118 - method_exists( $question->view, 'addShowResults' . $question->view->showResults['type'] ) ) {
 113+ if ( $question->view->hasShowResults() ) {
119114 $questions_set[] = $question->mQuestionId;
120115 }
121116 }
Index: trunk/extensions/QPoll/ctrl/qp_poll.php
@@ -295,8 +295,7 @@
296296 # check for showresults attribute
297297 $questions_set = array();
298298 foreach( $this->questions as &$question ) {
299 - if ( $question->view->showResults['type'] != 0 &&
300 - method_exists( $question->view, 'addShowResults' . $question->view->showResults['type'] ) ) {
 299+ if ( $question->view->hasShowResults() ) {
301300 $questions_set[] = $question->mQuestionId;
302301 }
303302 }
Index: trunk/extensions/QPoll/ctrl/qp_questionstats.php
@@ -98,7 +98,7 @@
9999 QP_Renderer::addClass( $row[ $catId ], $spanState->className );
100100 if ( $this->view->showResults['type'] != 0 ) {
101101 # there ars some stat in row (not necessarily all cells, because size of question table changes dynamically)
102 - $row[ $catId ][ 0 ] = $this->view->{'addShowResults' . $this->view->showResults['type']}( $proposalId, $catId );
 102+ $row[ $catId ][ 0 ] = $this->view->addShowResults( $proposalId, $catId );
103103 } else {
104104 $row[ $catId ][ 0 ] = '';
105105 }
Index: trunk/extensions/QPoll/ctrl/qp_question.php
@@ -250,7 +250,7 @@
251251 $inp[ 'value' ] = $value;
252252 if ( $this->view->showResults['type'] != 0 ) {
253253 # there ars some stat in row (not necessarily all cells, because size of question table changes dynamically)
254 - $row[ $catId ][ 0 ] = $this->view->{'addShowResults' . $this->view->showResults['type']}( $inp, $proposalId, $catId );
 254+ $row[ $catId ][ 0 ] = $this->view->addShowResults( $inp, $proposalId, $catId );
255255 } else {
256256 $row[ $catId ][ 0 ] = $inp;
257257 }
@@ -376,7 +376,7 @@
377377 }
378378 if ( $this->view->showResults['type'] != 0 ) {
379379 # there ars some stat in row (not necessarily all cells, because size of question table changes dynamically)
380 - $row[ $catId ][ 0 ] = $this->view->{'addShowResults' . $this->view->showResults['type']}( $inp, $proposalId, $catId );
 380+ $row[ $catId ][ 0 ] = $this->view->addShowResults( $inp, $proposalId, $catId );
381381 } else {
382382 $row[ $catId ][ 0 ] = $inp;
383383 }
Index: trunk/extensions/QPoll/qp_user.php
@@ -66,13 +66,13 @@
6767
6868 if ( isset( $wgResourceModules ) ) {
6969 $wgResourceModules['ext.qpoll'] = array(
70 - 'scripts' => 'qp_user.js',
71 - 'styles' => 'qp_user.css',
 70+ 'scripts' => 'clientside/qp_user.js',
 71+ 'styles' => 'clientside/qp_user.css',
7272 'localBasePath' => dirname( __FILE__ ),
7373 'remoteExtPath' => 'QPoll'
7474 );
7575 $wgResourceModules['ext.qpoll.special.pollresults'] = array(
76 - 'styles' => 'qp_results.css',
 76+ 'styles' => 'clientside/qp_results.css',
7777 'localBasePath' => dirname( __FILE__ ),
7878 'remoteExtPath' => 'QPoll'
7979 );
@@ -309,9 +309,10 @@
310310 }
311311
312312 # groups which has permission to access poll results by default
313 - $wgGroupPermissions['sysop']['showresults'] = true;
314 - $wgGroupPermissions['bureaucrat']['showresults'] = true;
315 - $wgGroupPermissions['polladmin']['showresults'] = true;
 313+ $wgGroupPermissions['user']['showresults'] = true;
 314+ $wgGroupPermissions['sysop']['pollresults'] = true;
 315+ $wgGroupPermissions['bureaucrat']['pollresults'] = true;
 316+ $wgGroupPermissions['polladmin']['pollresults'] = true;
316317 # groups which can edit interpretation scripts by default
317318 # please minimize the number of groups as low as you can
318319 # that is security measure against inserting of malicious code
@@ -325,6 +326,47 @@
326327 return version_compare( $wgVersion, $version, $operator );
327328 }
328329
 330+ static function getCurrUserName() {
 331+ global $wgUser, $wgSquidServers;
 332+ global $wgUsePrivateIPs;
 333+ if ( self::$anon_forwarded_for === true && $wgUser->isAnon() ) {
 334+ /* collect the originating IPs
 335+ borrowed from ProxyTools::wfGetIP
 336+ bypass trusted proxies list check */
 337+ # Client connecting to this webserver
 338+ if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
 339+ $ipchain = array( IP::canonicalize( $_SERVER['REMOTE_ADDR'] ) );
 340+ } else {
 341+ # Running on CLI?
 342+ $ipchain = array( '127.0.0.1' );
 343+ }
 344+ $ip = $ipchain[0];
 345+
 346+ # Append XFF on to $ipchain
 347+ $forwardedFor = wfGetForwardedFor();
 348+ if ( isset( $forwardedFor ) ) {
 349+ $xff = array_map( 'trim', explode( ',', $forwardedFor ) );
 350+ $xff = array_reverse( $xff );
 351+ $ipchain = array_merge( $ipchain, $xff );
 352+ }
 353+ $username = "";
 354+ foreach ( $ipchain as $i => $curIP ) {
 355+ if( $wgUsePrivateIPs || IP::isPublic( $curIP ) ) {
 356+ $username .= IP::canonicalize( $curIP ) . '/';
 357+ }
 358+ }
 359+ if ( $username != "" ) {
 360+ # remove trailing slash
 361+ $username = substr( $username, 0, strlen( $username ) - 1 );
 362+ } else {
 363+ $username .= IP::canonicalize( $ipchain[0] );
 364+ }
 365+ } else {
 366+ $username = $wgUser->getName();
 367+ }
 368+ return $username;
 369+ }
 370+
329371 static function onLoadAllMessages() {
330372 if ( !self::$messagesLoaded ) {
331373 self::$messagesLoaded = true;
@@ -421,11 +463,11 @@
422464 # MW < 1.17
423465 global $wgJsMimeType, $wgContLang;
424466 # Ouput the style and the script to the header once for all.
425 - $head = '<script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/qp_user.js"></script>' . "\n";
 467+ $head = '<script type="' . $wgJsMimeType . '" src="' . self::$ScriptPath . '/clientside/qp_user.js"></script>' . "\n";
426468 $wgOut->addScript( $head );
427 - $wgOut->addExtensionStyle( self::$ScriptPath . '/qp_user.css' );
 469+ $wgOut->addExtensionStyle( self::$ScriptPath . '/clientside/qp_user.css' );
428470 if ( $wgContLang->isRTL() ) {
429 - $wgOut->addExtensionStyle( self::$ScriptPath . '/qp_user_rtl.css' );
 471+ $wgOut->addExtensionStyle( self::$ScriptPath . '/clientside/qp_user_rtl.css' );
430472 }
431473 }
432474 global $wgQPollFunctionsHook;
@@ -761,7 +803,7 @@
762804 if ( is_numeric( $this->question_id ) ) {
763805 $this->question_id = intval( $this->question_id );
764806 $this->pollStore->loadQuestions();
765 - $this->pollStore->setLastUser( qp_AbstractPoll::currentUserName(), false );
 807+ $this->pollStore->setLastUser( qp_Setup::getCurrUserName(), false );
766808 $this->pollStore->loadUserVote();
767809 $this->error_message = 'missing_question_id';
768810 if ( array_key_exists( $this->question_id, $this->pollStore->Questions ) ) {
Index: trunk/extensions/QPoll/qp_results.php
@@ -48,7 +48,7 @@
4949 }
5050 }
5151
52 - static $accessPermissions = array( 'read', 'showresults' );
 52+ static $accessPermissions = array( 'read', 'pollresults' );
5353
5454 static $skin = null;
5555 static $UsersLink = "";
@@ -90,7 +90,7 @@
9191 $wgOut->addModules( 'ext.qpoll.special.pollresults' );
9292 } else {
9393 # MW < 1.17
94 - $wgOut->addExtensionStyle( qp_Setup::$ScriptPath . '/qp_results.css' );
 94+ $wgOut->addExtensionStyle( qp_Setup::$ScriptPath . '/clientside/qp_results.css' );
9595 }
9696 if ( self::$skin == null ) {
9797 self::$skin = $wgUser->getSkin();
Index: trunk/extensions/QPoll/qp_pollstore.php
@@ -161,6 +161,13 @@
162162 $this->qpErrors[$qidx][$pidx] = $msg;
163163 }
164164
 165+ function setDefaultErrorMessage() {
 166+ if ( is_array( $this->qpErrors ) && $this->error == '' ) {
 167+ $this->error = wfMsg( 'qp_interpetation_wrong_answer' );
 168+ }
 169+ return $this;
 170+ }
 171+
165172 function isError() {
166173 return $this->error != '' || is_array( $this->qpErrors );
167174 }
Index: trunk/extensions/QPoll/view/qp_questionstatsview.php
@@ -64,6 +64,10 @@
6565
6666 /*** cell templates ***/
6767
 68+ function addShowResults( $proposalId, $catId ) {
 69+ return $this->{'addShowResults' . $this->showResults['type']}( $proposalId, $catId );
 70+ }
 71+
6872 # cell templates for the selected showresults
6973 var $cellTemplate = Array();
7074 var $cellTemplateParam = Array( 'percents'=>'', 'bar1style'=>'', 'bar2style'=>'' );
Index: trunk/extensions/QPoll/view/qp_questionview.php
@@ -429,6 +429,15 @@
430430
431431 /*** cell templates ***/
432432
 433+ function hasShowResults() {
 434+ return $this->showResults['type'] != 0 &&
 435+ method_exists( $this, 'addShowResults' . $this->showResults['type'] );
 436+ }
 437+
 438+ function addShowResults( $inp, $proposalId, $catId ) {
 439+ return $this->{'addShowResults' . $this->showResults['type']}( $inp, $proposalId, $catId );
 440+ }
 441+
433442 # cell templates for the selected showresults
434443 var $cellTemplate = Array();
435444 var $cellTemplateParam = Array( 'inp'=>'', 'percents'=>'', 'bar1style'=>'', 'bar2style'=>'' );

Status & tagging log