Permalink
Browse files

updated wmf mode to use latest WikiTrust.pm imple

  • Loading branch information...
Ian Pye
Ian Pye committed Dec 11, 2009
1 parent f477331 commit 56538a8d839fb6693b866b2aaa2cef1a9afb5be2
Showing with 150 additions and 92 deletions.
  1. +41 −21 WikiTrust.php
  2. +42 −33 includes/WikiTrustBase.php
  3. +67 −38 includes/WmfMode.php
View
@@ -20,35 +20,54 @@
if (!defined('MEDIAWIKI')) die();
-# There isn't a built in enum for php
-global $wgWikiTrustVersion;
-$wgWikiTrustVersion = "local"; ## This needs to be one of local, remote, wmf.
+# We use a lot of config vars.
+global $wgWikiTrustVersion, $wgWikiTrustGadget, $wgWikiTrustShowVoteButton, $wgWikiTrustContentServerURL;
+global $wgWikiTrustLog, $wgWikiTrustDebugLog, $wgWikiTrustDebugVerbosity;
+global $wgWikiTrustCmd, $wgWikiTrustCmdExtraArgs, $wgWikiTrustShowMouseOrigin,
+ $wgWikiTrustBlobPath, $wgWikiTrustRepSpeed, $wgWikiTrustApiURL, $wgWikiTrustRobots;
-global $wgWikiTrustGadget, $wgWikiTrustShowVoteButton, $wgWikiTrustContentServerURL;
-$wgWikiTrustGadget = NULL;
-$wgWikiTrustShowVoteButton = true; // If true, the vote button is shown.
-$wgWikiTrustContentServerURL = "http://localhost:10303/?";
+# There isn't a built in enum for php
+if (!$wgWikiTrustVersion)
+ $wgWikiTrustVersion = "local"; ## This needs to be one of local, remote, wmf.
+if (!$wgWikiTrustGadget)
+ $wgWikiTrustGadget = NULL;
+if (!$wgWikiTrustShowVoteButton)
+ $wgWikiTrustShowVoteButton = true; // If true, the vote button is shown.
+if (!$wgWikiTrustContentServerURL)
+ $wgWikiTrustContentServerURL = "http://localhost:10303/?";
// Debugging Verbosity
define(WIKITRUST_DEBUG, 0);
define(WIKITRUST_WARN, 10);
define(WIKITRUST_ERROR, 20);
-global $wgWikiTrustLog, $wgWikiTrustDebugLog, $wgWikiTrustDebugVerbosity;
+// HTML Handling
+define(WIKITRUST_HTML, "H");
+define(WIKITRUST_WIKI, "W");
+
#$wgWikiTrustLog = "/tmp/{$wgDBname}-trust.log";
#$wgWikiTrustDebugLog = "/tmp/{$wgDBname}-trust-debug.log";
-$wgWikiTrustDebugVerbosity = WIKITRUST_WARN; // how much information to write;
-$wgWikiTrustLog = "/dev/null";
-$wgWikiTrustDebugLog = "/dev/null";
-$wgWikiTrustShowMouseOrigin = false;
-global $wgWikiTrustCmd, $wgWikiTrustCmdExtraArgs,
- $wgWikiTrustBlobPath, $wgWikiTrustRepSpeed, $wgWikiTrustApiURL;
-$wgWikiTrustCmd = dirname(__FILE__) . "/eval_online_wiki";
-$wgWikiTrustCmdExtraArgs = "";
-$wgWikiTrustBlobPath = NULL;
-$wgWikiTrustRepSpeed = 1.0;
-$wgWikiTrustApiURL = "http://en.wikipedia.org/w/api.php?";
-$wgWikiTrustRobots = NULL;
+
+if (!$wgWikiTrustDebugVerbosity)
+ $wgWikiTrustDebugVerbosity = WIKITRUST_WARN; // how much information to write;
+if (!$wgWikiTrustLog)
+ $wgWikiTrustLog = "/dev/null";
+if (!$wgWikiTrustDebugLog)
+ $wgWikiTrustDebugLog = "/dev/null";
+if (!$wgWikiTrustShowMouseOrigin)
+ $wgWikiTrustShowMouseOrigin = false;
+if (!$wgWikiTrustCmd)
+ $wgWikiTrustCmd = dirname(__FILE__) . "/eval_online_wiki";
+if (!$wgWikiTrustCmdExtraArgs)
+ $wgWikiTrustCmdExtraArgs = "";
+if (!$wgWikiTrustBlobPath)
+ $wgWikiTrustBlobPath = NULL;
+if (!$wgWikiTrustRepSpeed)
+ $wgWikiTrustRepSpeed = 1.0;
+if (!$wgWikiTrustApiURL)
+ $wgWikiTrustApiURL = "http://en.wikipedia.org/w/api.php";
+if (!$wgWikiTrustRobots)
+ $wgWikiTrustRobots = NULL;
global $wgExtensionFunctions, $wgExtensionCredits;
$wgExtensionCredits['other'][] = array(
@@ -90,6 +109,7 @@ function wfWikiTrustSetup() {
global $wgAutoloadClasses, $wgHooks, $wgWikiTrustVersion;
$wgAutoloadClasses['WikiTrustBase'] = $dir . 'WikiTrustBase.php';
$wgAutoloadClasses['WikiTrustUpdate'] = $dir . 'WikiTrustUpdate.php';
+
switch ($wgWikiTrustVersion) {
case "local":
$wgAutoloadClasses['WikiTrust'] = $dir . 'LocalMode.php';
@@ -115,7 +135,7 @@ function wfWikiTrustSetup() {
}
# Is the user opting to use wikitrust?
- global $wgUser;
+ global $wgUser, $wgWikiTrustGadget;
if ($wgWikiTrustGadget && !$wgUser->getOption($wgWikiTrustGadget))
return;
View
@@ -25,6 +25,9 @@ class WikiTrustBase {
## Median Value of Trust
static $median = 1.0;
+ ## Already rendered HTML?
+ static $html_rendered = false;
+
## Don't close the first opening span tag
static $first_span = true;
@@ -154,7 +157,7 @@ static function ucscOutputBeforeHTML(&$out, &$text){
$options);
$text = $msg->getText() . $text;
} else {
- self::color_Wiki2Html($colored_text, $text);
+ self::color_Wiki2Html($colored_text, $text, $rev_id);
self::vote_showButton($text);
self::color_addTracker($text);
}
@@ -302,74 +305,80 @@ static function color_getColorData($page_title, $page_id=0, $rev_id=0)
return $colored_text;
}
- static function color_parseWiki($colored_text, &$options)
+ static function color_parseWiki($colored_text, $rev_id, &$options)
{
global $wgTitle, $wgParser;
$parsed = $wgParser->parse($colored_text, $wgTitle, $options);
return $parsed->getText();
}
- static function color_Wiki2Html(&$colored_text, &$text)
+ static function color_Wiki2Html(&$colored_text, &$text, $rev_id)
{
global $wgParser, $wgUser, $wgTitle;
$count = 0;
- // fix trust tags around links
- $colored_text = preg_replace_callback("/\{\{#t:(\d+),(\d+),([^}]+)\}\}\s*\[\[([^\]]+)\]\]\s*(?=\{\{#t:|$)/D",
+ if (self::$html_rendered){
+ $text = $colored_text;
+ } else {
+
+ // fix trust tags around links
+ $colored_text = preg_replace_callback("/\{\{#t:(\d+),(\d+),([^}]+)\}\}\s*\[\[([^\]]+)\]\]\s*(?=\{\{#t:|$)/D",
"WikiTrust::regex_fixBracketTrust",
$colored_text,
-1,
$count);
- // fix trust tags around semicolon lines
- $colored_text = preg_replace_callback("/^;\s*\{\{#t:(\d+),(\d+),([^}]+)\}\}(\s*[^\{<]*?)(?=\{|<|$)/m",
+ // fix trust tags around semicolon lines
+ $colored_text = preg_replace_callback("/^;\s*\{\{#t:(\d+),(\d+),([^}]+)\}\}(\s*[^\{<]*?)(?=\{|<|$)/m",
"WikiTrust::regex_fixTextTrust",
$colored_text,
-1,
$count);
- $options = ParserOptions::newFromUser($wgUser);
- $text = WikiTrust::color_parseWiki($colored_text, $options);
-
- // Fix broken dt tags -- caused by ;
- $text = preg_replace("/<dt>\{\{#t<\/dt>\n<dd>(.*?)<\/dd>/",
- "<dt>{{#t:$1</dt>",
- $text,
- -1,
- $count);
+ $options = ParserOptions::newFromUser($wgUser);
+ $text = WikiTrust::color_parseWiki($colored_text, $rev_id, $options);
+
+ // Fix broken dt tags -- caused by ;
+ $text = preg_replace("/<dt>\{\{#t<\/dt>\n<dd>(.*?)<\/dd>/",
+ "<dt>{{#t:$1</dt>",
+ $text,
+ -1,
+ $count);
- // Fix edit section links
- $text = preg_replace_callback(
- "/<span class=\"editsection\"([^>]*?)>(.*?) title=\"(.*?)\">/",
- "WikiTrust::regex_fixSectionEdit",
- $text,
- -1,
- $count);
-
- // Update the trust tags
- $text = preg_replace_callback("/\{\{#t:(\d+),(\d+),([^}]+)\}\}([^\{<]++[^<]*?)(?=\{\{#t:|<|$)/D",
+ // Fix edit section links
+ $text = preg_replace_callback(
+ "/<span class=\"editsection\"([^>]*?)>(.*?) title=\"(.*?)\">/",
+ "WikiTrust::regex_fixSectionEdit",
+ $text,
+ -1,
+ $count);
+
+ // Update the trust tags
+ $text = preg_replace_callback("/\{\{#t:(\d+),(\d+),([^}]+)\}\}([^\{<]++[^<]*?)(?=\{\{#t:|<|$)/D",
"WikiTrust::regex_fixTextTrust",
$text,
-1,
$count);
- // Remove all of the trust tags which we can not handle at the moment.
- $text = preg_replace("/\{\{#t:\d+,\d+,[^}]+\}\}/",
+ // Remove all of the trust tags which we can not handle at the moment.
+ $text = preg_replace("/\{\{#t:\d+,\d+,[^}]+\}\}/",
"",
$text,
-1,
$count);
- global $wgScriptPath;
- $text = '<script type="text/javascript" src="'
+ global $wgScriptPath;
+ $text = '<script type="text/javascript" src="'
.$wgScriptPath
.'/extensions/WikiTrust/js/wz_tooltip.js"></script>' . $text;
- $msg = $wgParser->parse(wfMsgNoTrans("wgTrustExplanation"),
+ $msg = $wgParser->parse(wfMsgNoTrans("wgTrustExplanation"),
$wgTitle,
$options);
- $text .= $msg->getText();
+ $text .= $msg->getText();
+ WikiTrust::color_shareHTML($text, $rev_id);
+ }
}
static function regex_fixSectionEdit($matches){
@@ -610,7 +619,7 @@ static function ajax_getColoredText($page_title,
$options);
$text = $msg->getText() . $text;
} else {
- self::color_Wiki2Html($colored_text, $text);
+ self::color_Wiki2Html($colored_text, $text, $rev_id);
self::vote_showButton($text);
self::color_addTracker($text);
// Save the finished text in the cache.
Oops, something went wrong.

0 comments on commit 56538a8

Please sign in to comment.