Permalink
Browse files

Add group-invite/disinvite table to "manage wiki" form

  • Loading branch information...
1 parent d7cc885 commit 7b2e18bea80f03b9cb13e79ae2a25d339a19d4eb @tomclegg tomclegg committed Sep 11, 2010
Showing with 86 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. BIN DataTables-1.7.1.zip
  3. +14 −0 WikifarmDriver.php
  4. +53 −7 WikifarmPageMachine.php
  5. +1 −0 index.php
  6. +2 −0 install
  7. +6 −0 js/wikifarm-ui.js
  8. +9 −4 style.css
View
1 .gitignore
@@ -1 +1,2 @@
*~
+DataTables-1.7.1
View
BIN DataTables-1.7.1.zip
Binary file not shown.
View
14 WikifarmDriver.php
@@ -182,6 +182,12 @@ function getMyWikis() {
$wikis[] = $w;
return $wikis;
}
+
+ function getWiki ($wikiid) {
+ foreach ($this->getAllWikis() as $w)
+ if ($w["wikiid"] == $wikiid)
+ return $w;
+ }
# returns a list of wikis selected by the focus user as favorites TODO - invent this table
function getFavoriteWikis() {
@@ -235,6 +241,14 @@ function createWiki($wikiname, $realname, $mwusername, $groups) {
return true;
}
+ function inviteGroup ($wikiid, $groupid) {
+ $this->DB->exec ("INSERT OR IGNORE INTO wikipermission (wikiid, userid_or_groupname) values ('$wikiid', '".SQLite3::escapeString($groupid)."')");
+ }
+
+ function disinviteGroup ($wikiid, $groupid) {
+ $this->DB->exec ("DELETE FROM wikipermission WHERE wikiid='$wikiid' AND userid_or_groupname='".SQLite3::escapeString($groupid)."'");
+ }
+
// returns true if $this->openid is a wikifarm admin
function isAdmin () {
$id = $this->q_openid;
View
60 WikifarmPageMachine.php
@@ -174,13 +174,9 @@ function page_mywikis() {
extract ($row);
$visible_to = implode(", ", $groups);
$output .= "\t\t<li><a href=\"#tab_$wikiname\">#$wikiid: $realname</a></li>\n";
- $content .= "
- <div id=\"tab_$wikiname\">
- <p>Wiki #$wikiid: $realname ($wikiname)<br>
- Login now as: ... <br>
- This wiki is visible to these groups: $visible_to<br>
- to do...</p>
- </div>";
+ $content .= "<div id=\"tab_$wikiname\">";
+ $content .= $this->frag_managewiki ($row);
+ $content .= "</div>\n";
}
$groups_options = "";
foreach ($this->getAllGroups() as $g) {
@@ -285,6 +281,29 @@ function uglydumpling ($x) {
return "<pre>".htmlspecialchars(print_r($x,true))."</pre>";
}
+ function frag_managewiki ($wiki) {
+ extract ($wiki);
+ $html = "<form id=\"mwf$wikiid\">";
+ $html .= "<input type=\"hidden\" name=\"wikiid\" value=\"$wikiid\" />\n";
+ $html .= "<table id=\"mwg${wikiid}\">";
+ $html .= "<thead><tr><th colspan=\"2\">Groups with access to this wiki</th></tr></thead><tbody>";
+ foreach ($this->getAllGroups() as $g) {
+ if ($g["groupid"] == "ADMIN") continue;
+ $html .= "<tr>";
+ $checked = false === array_search ($g["groupid"], $groups) ? "" : "checked";
+ $groupid = $g["groupid"];
+ $html .= "<td><input type=\"checkbox\" class=\"generic_ajax\" ga_form_id=\"mwf$wikiid\" ga_action=\"managewiki\" id=\"mw${wikiid}_group_".htmlspecialchars($g["groupid"])."\" name=\"mw${wikiid}_groups[]\" value=\"".htmlspecialchars($g["groupid"])."\" $checked></td>";
+ $html .= "<td>".htmlspecialchars($g["groupname"])."</td>";
+ $html .= "</tr>";
+ }
+ $html .= "</tbody></table>";
+ $html .= "</form>";
+ $html .= "<script language=\"JavaScript\">
+\$(\"#mwg$wikiid\").dataTable({\"bInfo\": false, \"bFilter\": false, \"bLengthChange\": false});
+</script>\n";
+ return $html;
+ }
+
// $obj->textHighlight("<strong>Hey!</strong> Sample ui-state-highlight style.");
function textHighlight($text) {
return "<div class=\"ui-widget\">
@@ -346,6 +365,29 @@ function ajax_test_activated ($post) {
"message" => "Sorry, your account is not yet activated.");
}
}
+ function ajax_managewiki ($post) {
+ $wikiid = $post["wikiid"];
+ $wiki = $this->getWiki($wikiid);
+ if (!$this->isAdmin() && $wiki["userid"] != $this->openid)
+ return $this->fail ("You are not allowed to do that.");
+ $want = $post["mw${wikiid}_groups"];
+ $checkus = array();
+ $uncheckus = array();
+ foreach ($this->getAllGroups() as $g) {
+ if ($g["groupid"] == "ADMIN") continue;
+ if (!$want || false === array_search ($g["groupid"], $want)) {
+ $this->disinviteGroup ($wikiid, $g["groupid"]);
+ $uncheckus[] = "mw${wikiid}_group_".$g["groupid"];
+ }
+ else {
+ $this->inviteGroup ($wikiid, $g["groupid"]);
+ $checkus[] = "mw${wikiid}_group_".$g["groupid"];
+ }
+ }
+ return array ("success" => true,
+ "check" => $checkus,
+ "uncheck" => $uncheckus);
+ }
function ajax_createwiki ($post) {
if (!$this->isActivated())
@@ -382,6 +424,10 @@ function fail($message) {
"message" => $message,
"alert" => $message);
}
+ function success($message) {
+ return array ("success" => true,
+ "message" => $message);
+ }
} // class ends
View
1 index.php
@@ -88,6 +88,7 @@
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.4.custom.min.js"></script>
<script type="text/javascript" src="js/wikifarm-ui.js" language="JavaScript"></script>
+<script type="text/javascript" src="js/jquery.dataTables.js" language="JavaScript"></script>
<script language="JavaScript">
$(function() {
$("#tabs").tabs({selected: <?=$tabActiveId?>});
View
2 install
@@ -30,6 +30,8 @@ install $SOURCEDIR/js/ajax-loader.gif $INSTALLDIR/wikis/js/
install $SOURCEDIR/js/jquery-1.4.2.min.js $INSTALLDIR/wikis/js/
install $SOURCEDIR/js/jquery-ui-1.8.4.custom.min.js $INSTALLDIR/wikis/js/
install $SOURCEDIR/js/wikifarm-ui.js $INSTALLDIR/wikis/js/
+[ -d DataTables-1.7.1 ] || unzip DataTables-1.7.1.zip
+rsync -av $SOURCEDIR/DataTables-1.7.1/media/js/ $INSTALLDIR/wikis/js/
mkdir -p $INSTALLDIR/wikis/css
cp -r $SOURCEDIR/css/* $INSTALLDIR/wikis/css/
View
6 js/wikifarm-ui.js
@@ -3,6 +3,12 @@
function generic_ajax_success(data, textStatus, req, button)
{
button.disabled = false;
+
+ if (data.check)
+ $.each(data.check, function (i,e) { if ($('#'+e)) $('#'+e).attr('checked', true); });
+ if (data.uncheck)
+ $.each(data.uncheck, function (i,e) { if ($('#'+e)) $('#'+e).attr('checked', false); });
+
if (data.request && data.request.ga_loader_id && $('#'+data.request.ga_loader_id))
$('#'+data.request.ga_loader_id).hide();
if (data.message && data.request && data.request.ga_message_id) {
View
13 style.css
@@ -1,6 +1,11 @@
img {border:none;}
-body { font: 11px verdana, arial, helvetica, sans-serif; background-color: #FFFFFF; margin-top: 0; margin-bottom: 0; }
+body, p, th, td, p, li { font: 11px verdana, arial, helvetica, sans-serif; }
+th { text-align: left; border-bottom: 1px solid black; }
+tr.even { background: #dddddd; }
+tr.odd { background: #eeeeee; }
+table { border-collapse: true; border-spacing: 0; }
.foo {position:absolute; bottom:30px; right:30px;}
-a {text-decoration:none; color:#0000ff;}
-a:visited {text-decoration:none; color:#0000ff;}
-
+/*
+ a {text-decoration:none; color:#0000ff;}
+ a:visited {text-decoration:none; color:#0000ff;}
+*/

0 comments on commit 7b2e18b

Please sign in to comment.