MediaWiki扩展:投票与评分
天下维客,你可以修改的网络知识库
| MediaWiki扩展简明教程 | Inputbox帮助文档 | 使用Spam黑名单 | 内容折叠隐藏 | 动态文章列表 | 指定图片链接 |
| 代码高亮处理 | 预置初始编辑文本 | 页面访问限制 | 所见即所得编辑器 | QQ在线信息 | |
| 交流:扩展使用 | 投票与评分 | 内容随机展示 | wikitex | 改进设想 | ...更多 |
| 加入google地图和51地图标注功能 | Ajax五颗星评分插件 |
本文取自元维基,欢迎共同翻译、整理与大家共享,促进中文wiki发展^_^
This page is undergoing development, as i have changed my username.
Rate is as an extension developed for use on sites using MediaWiki. This extension realizes the ability for several pages to contain a rate.
To install it, put the file in your extensions/ directory, and addinclude("extensions/intersection/DynamicPageList.php"); to your LocalSettings.php file. -->
目录 |
How to use Rate
Rate is a MediaWiki extension. For using, just include the following HTML-like syntax in your page:
<Rate> ...parameters... </Rate>
The parameters given to the rate, besides Question, the multiple Answers and Explanation, start all with a # and are optional. You can choose for the next: #ID, #REVOKE, #STYLE, #CLOSED, #RESULT, #BUTTON, [[Rate:Result]] and [[Rate:Revoke]]
For example the next Rate:
with its result:
is made as the following:
<rate>
#RESULT EACH ANSWER
#ID :mainRate
#STYLE {{my PollTemplate}}
#REVOKE ON
;Is this wiki any good?
What do you think?
- Yes
= Maybe
- No
[[Poll:Result|result]]
$1 is the result
#BUTTON Rate
</rate>
Question
Purpose:
To make clear to the user which question they are answering.
Example:
Is this wiki any good?
There should only be one Question be defined.
QuestionElaboration
Purpose:
To make the question more clear, or more precisely defined.
Example:
What do you think?This parameter is being represented in relation and order to the Question; so, it can be given before or after. By use of a double ; (
;;), this line will not be mentioned in the result of the rate. Instead, Explanation will be included, on the end of the complete question-part.
Answers
Purpose:
To offer a choice to be made for the visitor, regarding the question.
Example:
- YesIt is also possible to start the answer with
-(100%)or another percentage. In this case the percentage will be used. For example, used in calculating the average vote by use of #RESULT AVERAGE PERCENT. Also possible is
-(4)for giving the answer predeterment value. This comes in handy when the order of answers change. In combination with #RESULT AVERAGE MARK all these numbers will be interpreted as a meaningful row for a higher vote, a higher result. To define a default selection is made by using
= Yesfor example.
Explanation
Purpose:
To give meaning to the result of the rate.
Example:
:$1 is the result.
Note: This should be used in combination with #RESULT AVERAGE-option. Else the default result will be represented... $1 will be replaced with the result: the average.
ID
Purpose:
To identify this rating. In the database a table collects all the votes. And because MediaWiki should support multiple ratings -I say- it also should ensure the vote be part of the correct rating.
After the #ID comes the identifying key. By default, this one is a derivable of the entry containing the rating. (This is the reason why a page can only contain one rating [without ID]!).
When an #ID is part of the rating, then will the identifying key be derived of the value following it.
Example of identification by reference to an other page:
#ID[[other page]]
In this way, you should also be able to direct to a translation of the rating, standing on a translated page. Could be useful when you want the opinion of all your visitors on a multi-lingual site.
Example of identification by an existing identification key:
#ID:0123456789ABCDEF0123456789ABCDEF
This last variant uses the same key used in the table, to identify this rating. This key is already derived from an existing -or not- article by use of the MD5-function.
REVOKE
Purpose:
Define if it is allowed for the visitor to revoke their vote.
Example:
#REVOKE ON
By default this parameter is OFF.
STYLE
Purpose:
To make it possible for use of your own style, even for each rating. It comes in handy within a MediaWiki which knows several different types of rating (e.g.: Normal rating and a Article Quality rating).
Example:
#STYLE {{my RateTemplate}}
CLOSED
Purpose:
As it says: to close the rating. No visitor is/should be able to add an other vote.
Example:
#CLOSED
RESULT
Purpose:
To determine how to deal with the result of the rating. The rate can be defined so it will result into a percentage and an amount/total, per Answer by use of EACH ANSWER. Or as only 1(!) result with: AVERAGE PERCENT en AVERAGE MARK.
Example:
#RESULT AVERAGE PERCENT; DOUBLE 4,1
By default it is EACH ANSWER.
For both AVERAGE-options will the results being ordered (if possible). In the general example, the order will be maintained: in this case you first have option 1, followed by 0. To maintain the order of the Yes/No question.
Both options EACH ANSWER and AVERAGE PERCENT are allowed to be followed with ; DOUBLE x,y - to determine how the number should be formatted. By the default of 4,1, it results into '100,0%' and '
7,3%' for example.
Note: AVERAGE PERCENT works only when the collection of answers starts with 0% and ends with 100%, in each order (DESC/ASC).
BUTTON
Purpose:
To reset the default of Rate! to its new setting.
Example:
#BUTTON Rate!
Rate:Result
Purpose:
To insert the correct link to the result of this rating.
Example:
[[Rate:Result|result]]
Rate:Revoke
Purpose: To insert the correct link to change the vote made by the current visitor.
Example:
[[Rate:Revoke|change your vote]]
Source Code
Rate.php: Template:User-Foobie-Rate-SourceCode
rate.sql
CREATE TABLE `rate` (
`rate_id` VARCHAR(32) NOT NULL DEFAULT '',
`rate_user` INT(5) NOT NULL DEFAULT '0',
`rate_user_text` VARCHAR(255) BINARY NOT NULL DEFAULT '',
`rate_cur_id` INT(8) unsigned NOT NULL DEFAULT '0',
`rate_answer` DOUBLE(3,1) NOT NULL DEFAULT '0.0',
`rate_percent` ENUM('Y','N') NOT NULL DEFAULT 'N',
`rate_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`rate_id`,`rate_user_text`)
);
Installation
- Upload the Rate.php the extensions-directory.
- Add the table rate into the database of MediaWiki (rate.sql).
- Add the following code -
include("extensions/Rate.php");- at the end of yourLocalSettings.php
file. - (Optional) Add the following Templates.
Template:Rate
When a template doesn't exist in the MediaWiki database, it uses the default in the source.
<RateTemplate>
<table border="0" cellSpacing="0" cellPadding="0">
;<form name="rate" method="POST">
<input type="hidden" name="ID" value="{{ID}}"/>
<tr><td>{{QuestionLines}}</td></tr>
;<tr><td>{{Answers}}</td></tr>
;<tr><td align="right">{{BUTTON}}</td></tr>
:<tr><td>{{Explaination}}</td></tr>
:<tr><td>{{REVOKE}}</td></tr>
;</form>
</table>
----
Question=<b>$i</b>
QuestionElaboration=<i>$i</i>
QuestionNewLine=<br/>
Answer=<input type="radio" name="rate_{{ID}}" value="{{value}}" id="{{label}}"{{checked}}/><label for="{{label}}">$1</label>
AnswerNewLine=</td></tr><tr><td>
Checked= CHECKED="true"
Explaination=<i>$1</>
REVOKE=I changed my mind, I want to [[Rate:Revoke|revoke]] my vote.
BUTTON=<input type="submit" value="$1"/>
</RateTemplate>
ToDo List
- Support for #STYLE. There is still an →StyleOpen()-handler missing. The way to interpreted the template already works!
- Support for #RESULT. At this moment this parameter is being ignored. And is momentarily replaced with testing if Explanation exists and is valid.
- Cleanup the source of Rate.php.
- To implement the correct method to communicate with the database, in the way MediaWiki is used to.
- Detecting if the current visitor already had voted; If so, view result.
- Extend the extension in a way it -temporary- disables the document-caching for the current visitor-document-relation.
- Add a functionality like
TOC
/Sections-Menu (the menu with all documents paragraphs, when there are more than 3) and<nowiki>__NOTOC__</nowiki>
to disable this function. To add the Article Quality Rate by default to each new contribution. - Test, debug, develop MORE!
Modifications
- Here is the new function I added to mediawiki_rate class :
function update_timestamp() {
global $wgTitle;
// met à jour le timestamp
$dbr =& wfGetDB( DB_SLAVE );
$cur = $dbr->tableName( 'cur' );
$timestamp = wfTimestampNow();
$invTimestamp = wfInvertTimestamp( $timestamp );
$sql = "UPDATE `cur` SET `cur_timestamp` = '".$timestamp."', `inverse_timestamp` = '".$invTimestamp."', "
."`cur_touched` = '".$timestamp."' \tWHERE `cur_id` = '".$wgTitle->mArticleID."' ;";
$wgTitle->invalidateCache();
return $dbr->query( $sql );
}
..and I call it in this way :
# The callback function for converting the input text to HTML output
function renderRate( $input, $argv=array() ) {
global $wgRateTemplate;
$mediawiki_rate = new mediawiki_rate($input);
$input = $mediawiki_rate->build($wgRateTemplate);
$mediawiki_rate->update_timestamp();
# $argv is an array containing any arguments passed to the extension like <example argument="foo" bar>..
$output = "<!-- rate=\"start\" -->$input<!-- rate=\"finish\" -->";
return $output;
}
Full source code
Rate.php: Template:User-Foobie-Rate-SourceCode CacheVersion
原文参见: Poll and Rate
| MediaWiki扩展简明教程 | Inputbox帮助文档 | 使用Spam黑名单 | 内容折叠隐藏 | 动态文章列表 | 指定图片链接 |
| 代码高亮处理 | 预置初始编辑文本 | 页面访问限制 | 所见即所得编辑器 | QQ在线信息 | |
| 交流:扩展使用 | 投票与评分 | 内容随机展示 | wikitex | 改进设想 | ...更多 |
| 加入google地图和51地图标注功能 | Ajax五颗星评分插件 |



