Commit 9624d430 authored by Nigel Cunningham's avatar Nigel Cunningham

(Bug548021) Add support for anonymising pages.

This patch adds support for anonymising pages.

It creates a site option in the General Settings section named 'Allow
anonymous pages' that must be checked for any page to be anonymised.

If the site option is enabled, a new 'Anonymise' setting in the
'Edit title and description' tab of pages is enabled, allowing the owner
to request that this page be anonymised.

When both settings are enabled and a user views a page, two things may
happen to the author's information.

First, if the user is not logged in or does not have admin, staff or
owner privileges for the page, the author's name is replaced by the
anonymous text (defaulting to "(Author's name hidden)") in both the
body of the page and the metadata author field.

If the user does have admin, staff or owner privileges for the page,
the author's name is anonymised as above except that the text displayed
is made into a link. When this link is clicked, the anonymous author
text is replaced by the normal author information for the page.

Anonymous pages displayed in the 'Latest pages' block and shared with
a group are also anonymised by this patch.

Change-Id: I2e2c92f641329a1a305cf58a5c5d47bf95436a8b
Signed-off-by: default avatarNigel Cunningham <nigelc@catalyst-au.net>
parent 6e97dfd9
......@@ -570,6 +570,14 @@ $siteoptionform = array(
'help' => true,
'disabled' => in_array('allowpublicprofiles', $OVERRIDDEN) || get_config('allowpublicviews'),
),
'allowanonymouspages' => array(
'type' => 'checkbox',
'title' => get_string('allowanonymouspages', 'admin'),
'description' => get_string('allowanonymouspagesdescription', 'admin'),
'defaultvalue' => get_config('allowanonymouspages'),
'help' => true,
'disabled' => in_array('allowanonymouspages', $OVERRIDDEN),
),
'generatesitemap' => array(
'type' => 'checkbox',
'title' => get_string('generatesitemap', 'admin'),
......@@ -732,7 +740,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array(
'sitename','lang','theme', 'dropdownmenu',
'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'generatesitemap',
'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap',
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm',
'showselfsearchsideblock', 'searchusernames', 'searchplugin', 'showtagssideblock',
'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
......
{*
I wanted to put author_link_index in templates/author.tpl, but its
state is non-persistent. So until Dwoo gets smarter...
*}
{assign var='author_link_index' value=1}
{foreach from=$items item=view}
<div class="{cycle values='r0,r1'} listrow">
{if $view.template}
......@@ -9,7 +14,19 @@
{if $view.group}
<a href="{group_homepage_url($view.groupdata)}">{$view.sharedby}</a>
{elseif $view.owner}
<a href="{profile_url($view.user)}">{$view.sharedby}</a>
{if $view.anonymous}
{if $view.staff_or_admin}
{assign var='realauthor' value=$view.sharedby}
{assign var='realauthorlink' value=profile_url($view.user)}
{/if}
{assign var='author' value=get_string('anonymoususer')}
{include file=author.tpl}
{if $view.staff_or_admin}
{assign var='author_link_index' value=`$author_link_index+1`}
{/if}
{else}
<a href="{profile_url($view.user)}">{$view.sharedby}</a>
{/if}
{else}
{$view.sharedby}
{/if}
......
{if $views}
<div class="viewlist fullwidth listing">
{*
I wanted to put author_link_index in templates/author.tpl, but its
state is non-persistent. So until Dwoo gets smarter...
*}
{assign var='author_link_index' value=1}
{foreach from=$views item=view}
<div class="{cycle values='r0,r1'} listrow">
<h3 class="title"><a href="{$view.fullurl}">{$view.title}</a></h3>
......@@ -9,7 +14,19 @@
{if $view.group && $loggedin}
<a href="{group_homepage_url($view.groupdata)}">{$view.sharedby}</a>
{elseif $view.owner && $loggedin}
<a href="{profile_url($view.user)}">{$view.sharedby}</a>
{if $view.anonymous}
{if $view.staff_or_admin}
{assign var='realauthor' value=$view.sharedby}
{assign var='realauthorlink' value=profile_url($view.user)}
{/if}
{assign var='author' value=get_string('anonymoususer')}
{include file=author.tpl}
{if $view.staff_or_admin}
{assign var='author_link_index' value=`$author_link_index+1`}
{/if}
{else}
<a href="{profile_url($view.user)}">{$view.sharedby}</a>
{/if}
{else}
{$view.sharedby}
{/if}
......
......@@ -73,7 +73,7 @@ if ($group->public) {
$headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '">';
}
$javascript = array('paginator');
$javascript = array('paginator', 'author');
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
......
......@@ -31,7 +31,7 @@ if ($USER->is_logged_in()) {
require_once(get_config('libroot') . 'view.php');
$view = $USER->get_view_by_type('dashboard');
$javascript = array('paginator');
$javascript = array('paginator', 'author');
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
......
/**
* Javascript for the hidden author template
* @source: http://gitorious.org/mahara/mahara
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
addLoadEvent(function () {
function callbackHandler(i) {
return function(e) {
e.stop();
addElementClass('hidden_author_' + i, 'js-safe-hidden');
addElementClass('hidden_author_' + i, 'hidden');
removeElementClass('real_author_' + i, 'js-safe-hidden');
removeElementClass('real_author_' + i, 'hidden');
}
};
index = 1;
while ($('show_real_author_' + index)) {
connect('show_real_author_' + index, 'onclick', callbackHandler(index));
index += 1;
}
});
......@@ -300,6 +300,8 @@ $string['allowinstitutionpublicviews'] = 'Allow institution public pages';
$string['allowinstitutionpublicviewsdescription'] = 'If set to yes, users belonging to this institution will be able to create portfolio pages that are accessible to the public rather than only to logged-in users.';
$string['allowpublicprofiles'] = 'Allow public profiles';
$string['allowpublicprofilesdescription'] = 'If checked, users will be able to set their profile pages to be accessible to the public rather than only to logged-in users.';
$string['allowanonymouspages'] = 'Allow anonymous pages';
$string['allowanonymouspagesdescription'] = 'If checked, users will be able to choose to hide their name as the author of a page from other users. Administrators will still be able to see the author\'s name if they so desire.';
$string['anonymouscomments'] = 'Anonymous comments';
$string['anonymouscommentsdescription'] = 'If checked, anyone can leave comments on public pages or pages they can access by secret URL.';
$string['loggedinprofileviewaccess'] = 'Logged-in profile access';
......
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Allow anonymous pages</h3>
<p>If you wish to allow users to hide their name on pages, enable this option.</p>
<p>Administrators will still be able to view authorship information via a link, and an additional 'Flag objectionable content' button will be added for logged in users where the name normally appears.</p>
......@@ -1055,6 +1055,7 @@ $string['hidden'] = 'hidden';
$string['lastupdate'] = 'Last update';
$string['lastupdateorcomment'] = 'Last update or comment';
$string['Title'] = 'Title';
$string['anonymoususer'] = '(Author\'s name hidden)';
// import related strings (maybe separated later)
$string['importedfrom'] = 'Imported from %s';
......
......@@ -35,6 +35,8 @@ $string['unrecogniseddateformat'] = 'Unrecognised date format';
$string['allowcommentsonview'] = 'If checked, users will be allowed to leave comments.';
$string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'How do you want people who look at your page to see your name?';
$string['anonymise'] = 'Anonymise';
$string['anonymisedescription'] = 'Hide your name as the author of the page from other users. Administrators will still be able to see your name if they so desire.';
$string['Locked'] = 'Locked';
$string['lockedgroupviewdesc'] = 'If you lock this page, only group administrators will be able to edit it.';
$string['profileviewtitle'] = 'Profile page';
......
......@@ -783,6 +783,7 @@
<FIELD NAME="accessconf" TYPE="char" LENGTH="40" NOTNULL="false"/>
<FIELD NAME="locked" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
<FIELD NAME="urlid" TYPE="char" LENGTH="100" NOTNULL="false" />
<FIELD NAME="anonymise" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -3467,6 +3467,13 @@ function xmldb_core_upgrade($oldversion=0) {
if ($data = check_upgrades('blocktype.text')) {
upgrade_plugin($data);
}
if ($oldversion < 2014091600) {
$table = new XMLDBTable('view');
$field = new XMLDBField('anonymise');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
set_config('allowanonymouspages', 0);
}
return $status;
......
......@@ -820,6 +820,7 @@ function core_install_firstcoredata_defaults() {
set_config('createpublicgroups', 'all');
set_config('allowpublicviews', 1);
set_config('allowpublicprofiles', 1);
set_config('allowanonymouspages', 0);
set_config('generatesitemap', 1);
set_config('showselfsearchsideblock', 0);
set_config('showtagssideblock', 1);
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014081900;
$config->version = 2014091600;
$config->release = '1.10.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
......@@ -61,6 +61,7 @@ class View {
private $locked;
private $urlid;
private $skin;
private $anonymise = 0;
/**
* Which view layout is considered the "default" for views with the given
......@@ -557,6 +558,7 @@ class View {
'template' => 0,
'type' => 'portfolio',
'title' => (array_key_exists('title', $viewdata)) ? $viewdata['title'] : self::new_title(get_string('Untitled', 'view'), (object)$viewdata),
'anonymise' => 0,
);
$data = (object)array_merge($defaultdata, $viewdata);
......@@ -2786,6 +2788,25 @@ class View {
return null;
}
/**
* This function returns a boolean indicating whether the current page should be anonymised.
*/
public function is_anonymous()
{
return get_config('allowanonymouspages') && $this->anonymise;
}
/**
* This function returns a boolean indicating whether author information should be made
* available in an ajax link if the page is anonymised.
*/
public function is_staff_or_admin_for_page()
{
global $USER;
return (($USER->get('id') === $this->get('owner')) || $USER->is_staff_for_user($this->get_owner_object()));
}
/**
* Returns a record from the view_layout table matching the layout for this View.
*
......@@ -4437,9 +4458,15 @@ class View {
$needsubdomain = get_config('cleanurlusersubdomains');
foreach ($viewdata as &$v) {
$v->anonymous = FALSE;
if (!empty($v->owner)) {
$v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]);
$v->user = $owners[$v->owner];
// Get a real view object so we can do the checks.
$view_obj = new View($v->id);
$v->anonymous = $view_obj->is_anonymous();
$v->staff_or_admin = $view_obj->is_staff_or_admin_for_page();
}
else if (!empty($v->group)) {
$v->sharedby = $groups[$v->group]->name;
......
{if $realauthor}
<span id="hidden_author_{$author_link_index}">
<a id="show_real_author_{$author_link_index}" class="show_real_author" href="">{$author|safe}</a>
</span>
<span id="real_author_{$author_link_index}" class="js-safe-hidden hidden">
{if $realauthorlink}
<a href="{$realauthorlink}">{$realauthor|safe}</a>
{else}
{$realauthor|safe}
{/if}
</span>
{else}
{$author|safe}
{/if}
......@@ -21,7 +21,10 @@
{include file=collectionnav.tpl}
{/if}
<p>{$author|safe}</p>
<p>
{assign var='author_link_index' value=1}
{include file=author.tpl}
<p>
<div id="view-description">{$viewdescription|clean_html|safe}</div>
......
......@@ -167,6 +167,15 @@ if (!($group || $institution)) {
);
}
if (get_config('allowanonymouspages')) {
$editview['elements']['anonymise'] = array(
'type' => 'checkbox',
'title' => get_string('anonymise','view'),
'description' => get_string('anonymisedescription','view'),
'defaultvalue' => $view->get('anonymise'),
);
}
$editview['elements']['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
......@@ -203,6 +212,9 @@ function editview_submit(Pieform $form, $values) {
if (isset($values['ownerformat']) && $view->get('owner')) {
$view->set('ownerformat', $values['ownerformat']);
}
if (isset($values['anonymise'])) {
$view->set('anonymise', (int)$values['anonymise']);
}
if (isset($values['urlid'])) {
$view->set('urlid', strlen($values['urlid']) == 0 ? null : $values['urlid']);
}
......@@ -236,4 +248,4 @@ if (get_config('viewmicroheaders')) {
}
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
$smarty->display('view/edit.tpl');
\ No newline at end of file
$smarty->display('view/edit.tpl');
......@@ -167,7 +167,7 @@ function releaseview_submit() {
redirect($view->get_url());
}
$javascript = array('paginator', 'viewmenu', 'expandable');
$javascript = array('paginator', 'viewmenu', 'expandable', 'author');
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
......@@ -276,9 +276,20 @@ $smarty->assign('viewtype', $viewtype);
$smarty->assign('feedback', $feedback);
$smarty->assign('owner', $owner);
$smarty->assign('tags', $view->get('tags'));
$smarty->assign('author', $view->display_author());
$smarty->assign('PAGEAUTHOR', $view->formatted_owner());
if ($view->is_anonymous()) {
$smarty->assign('PAGEAUTHOR', get_string('anonymoususer'));
$smarty->assign('author', get_string('anonymoususer'));
if ($view->is_staff_or_admin_for_page()) {
$smarty->assign('realauthor', $view->display_author());
}
$smarty->assign('anonymous', TRUE);
} else {
$smarty->assign('PAGEAUTHOR', $view->formatted_owner());
$smarty->assign('author', $view->display_author());
$smarty->assign('anonymous', FALSE);
}
$titletext = ($collection && $shownav) ? hsc($collection->get('name')) : $view->display_title(true, false, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment