Skip to content

Commit

Permalink
Fix #59: Refactor roles from inline blocks to files
Browse files Browse the repository at this point in the history
A lot of the configuration was inline blocks that were dumped directly
into LocalSettings.php.  This change separates those configurations out
into their own files for easier maintenance and documentation.

Issue #59: Change MediaWiki configurations to have multiple files
  • Loading branch information
Frank Duncan committed Oct 29, 2020
1 parent ebaa71a commit f60d50a
Show file tree
Hide file tree
Showing 16 changed files with 445 additions and 358 deletions.
30 changes: 30 additions & 0 deletions roles/activitylog/files/activity-log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
wfLoadExtension('ActivityLog');
$wgMessagesDirs['ActivityLogConfiguration'] = 'ActivityLogConfiguration/i18n';
$wgActivityLogHooksToWatch["ArticleViewHeader"] = function ($article) {
$referrer = $_SERVER['HTTP_REFERER'];
$ourServer = "http://torque.leverforchange.org";

if($referrer && $ourServer == substr($referrer, 0, strlen($ourServer))) {
return array($article->getContext()->getUser(),
$article->getTitle(),
"activitylog-articleviewheader-with-referrer",
$_SERVER['HTTP_REFERER']
);
} else {
return array($article->getContext()->getUser(),
$article->getTitle(),
"activitylog-articleviewheader"
);
}
};

$wgActivityLogHooksToWatch["UserLoginComplete"] = function(&$user, &$inject_html, $direct) {
global $wgTitle;
return array($user, $wgTitle, "activitylog-userlogin");
};

$wgActivityLogHooksToWatch["PageContentSave"] = function($wikiPage, $user, $content, &$summary, $isMinor, $isWatch, $section, $flags, $status) {
return array($user, $wikiPage->getTitle(), "activitylog-articlesavepage");
};
?>
34 changes: 6 additions & 28 deletions roles/activitylog/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,14 @@
src: ActivityLogConfiguration
dest: "{{ mediawiki_install_directory }}/mediawiki-1.33.0/"

- name: Transfer Config
copy:
src: activity-log.php
dest: "{{ mediawiki_install_directory }}/mediawiki-1.33.0/torque-sites-config/"

- name: Enable ActivityLog
blockinfile:
path: "{{ mediawiki_install_directory }}/mediawiki-1.33.0/LocalSettings.php"
marker: "## {mark} ANSIBLE ACTIVITYLOG CONFIG"
block: |
wfLoadExtension('ActivityLog');
$wgMessagesDirs['ActivityLogConfiguration'] = 'ActivityLogConfiguration/i18n';
$wgActivityLogHooksToWatch["ArticleViewHeader"] = function ($article) {
$referrer = $_SERVER['HTTP_REFERER'];
$ourServer = "http://torque.leverforchange.org";
if($referrer && $ourServer == substr($referrer, 0, strlen($ourServer))) {
return array($article->getContext()->getUser(),
$article->getTitle(),
"activitylog-articleviewheader-with-referrer",
$_SERVER['HTTP_REFERER']
);
} else {
return array($article->getContext()->getUser(),
$article->getTitle(),
"activitylog-articleviewheader"
);
}
};
$wgActivityLogHooksToWatch["UserLoginComplete"] = function(&$user, &$inject_html, $direct) {
global $wgTitle;
return array($user, $wgTitle, "activitylog-userlogin");
};
$wgActivityLogHooksToWatch["PageContentSave"] = function($wikiPage, $user, $content, &$summary, $isMinor, $isWatch, $section, $flags, $status) {
return array($user, $wikiPage->getTitle(), "activitylog-articlesavepage");
};
include "{{ mediawiki_install_directory }}/mediawiki-1.33.0/torque-sites-config/activity-log.php";
27 changes: 6 additions & 21 deletions roles/collection/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,17 @@
src: "{{ playbook_dir }}/../../thirdparty/extensions/Collection-REL1_33-8566dd1.tar.gz"
dest: "{{ mediawiki_install_directory }}/mediawiki-1.33.0/extensions/"

- name: Transfer Config
template:
src: collection.php.j2
dest: "{{ mediawiki_install_directory }}/mediawiki-1.33.0/torque-sites-config/collection.php"

- name: Enable Collection
blockinfile:
path: "{{ mediawiki_install_directory }}/mediawiki-1.33.0/LocalSettings.php"
marker: "## {mark} ANSIBLE COLLECTION CONFIG"
block: |
require_once "$IP/extensions/Collection/Collection.php";
$wgCollectionMWServeURL = "http://127.0.0.1:8899";
$wgCollectionMaxArticles = 250;
$wgEnableApi = true;
$wgCollectionFormats = array( 'rl' => 'PDF',);
$wgCollectionPortletFormats = [];
$wgCollectionDisableDownloadSection = false;
$wgHooks['ApiBeforeMain'][] = function($main) {
global $wgTorqueDataConnectGroup, $wgTorqueDataConnectRenderToHTML, $wgTorqueDataConnectView;
if($main->getUser() && strtolower($main->getUser()->getName()) == "{{ mediawiki_mwlib_username }}") {
$wgTorqueDataConnectRenderToHTML = false;
$tdcinfo = $main->getRequest()->getText("tdcinfo", false);
list($wgTorqueDataConnectGroup, $wgTorqueDataConnectView) = explode("|", $tdcinfo);
}
};
$wgHooks['BeforeInitialize'][] = function(&$title, &$article = null, &$output, &$user, $request, $mediaWiki) {
global $wgCollectionMWServeCredentials;
$group = TorqueDataConnectConfig::getValidGroup($user);
$view = TorqueDataConnectConfig::getCurrentView();
$wgCollectionMWServeCredentials = "{{ mediawiki_mwlib_username }}:${group}|${view}:{{ mediawiki_mwlib_password }}";
};
include "{{ mediawiki_install_directory }}/mediawiki-1.33.0/torque-sites-config/collection.php";
- name: Disable Collection Warning 1
replace:
Expand Down
23 changes: 23 additions & 0 deletions roles/collection/templates/collection.php.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require_once "$IP/extensions/Collection/Collection.php";
$wgCollectionMWServeURL = "http://127.0.0.1:8899";
$wgCollectionMaxArticles = 250;
$wgEnableApi = true;
$wgCollectionFormats = array( 'rl' => 'PDF',);
$wgCollectionPortletFormats = [];
$wgCollectionDisableDownloadSection = false;
$wgHooks['ApiBeforeMain'][] = function($main) {
global $wgTorqueDataConnectGroup, $wgTorqueDataConnectRenderToHTML, $wgTorqueDataConnectView;
if($main->getUser() && strtolower($main->getUser()->getName()) == "{{ mediawiki_mwlib_username }}") {
$wgTorqueDataConnectRenderToHTML = false;
$tdcinfo = $main->getRequest()->getText("tdcinfo", false);
list($wgTorqueDataConnectGroup, $wgTorqueDataConnectView) = explode("|", $tdcinfo);
}
};
$wgHooks['BeforeInitialize'][] = function(&$title, &$article = null, &$output, &$user, $request, $mediaWiki) {
global $wgCollectionMWServeCredentials;
$group = TorqueDataConnectConfig::getValidGroup($user);
$view = TorqueDataConnectConfig::getCurrentView();
$wgCollectionMWServeCredentials = "{{ mediawiki_mwlib_username }}:${group}|${view}:{{ mediawiki_mwlib_password }}";
};
?>
41 changes: 41 additions & 0 deletions roles/mediawiki/files/lfc-analysis-rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
$wgHooks['SkinTemplateNavigation'][] = function ( $template, &$links ) {
$currentTitle = $template->getTitle()->getFullText();
$lfc_prepend = "LFC Analysis of ";
$eval_prepend = "Evaluations of ";

$isAnalysisPage = (strlen($currentTitle) > strlen($lfc_prepend) && substr($currentTitle, 0, strlen($lfc_prepend)) === $lfc_prepend);
$isEvalPage = (strlen($currentTitle) > strlen($eval_prepend) && substr($currentTitle, 0, strlen($eval_prepend)) === $eval_prepend);

$originalPageTitle = $currentTitle;
if($isAnalysisPage) {
$originalPageTitle = substr($currentTitle, strlen($lfc_prepend));
$links['namespaces']['main']['class'] = '';
$links['namespaces']['main']['href'] = Title::newFromText($originalPageTitle)->getLocalUrl();
} else if($isEvalPage) {
$originalPageTitle = substr($currentTitle, strlen($eval_prepend));
$links['namespaces']['main']['class'] = '';
$links['namespaces']['main']['href'] = Title::newFromText($originalPageTitle)->getLocalUrl();
}
$lfcAnalysisTitle = Title::newFromText($lfc_prepend . $originalPageTitle);
$evalTitle = Title::newFromText($eval_prepend . $originalPageTitle);
if($isAnalysisPage || $lfcAnalysisTitle->exists()) {
$links['namespaces']['main']['text'] = 'Proposal';
$links['namespaces']['lfcanalysis'] = [
'class' => ($isAnalysisPage ? 'selected' : ''),
'href' => ($isAnalysisPage ? $template->getTitle()->getLocalUrl() : $lfcAnalysisTitle->getLocalUrl()),
'text' => 'LFC Analysis',
];
}
if($isEvalPage || $evalTitle->exists()) {
$links['namespaces']['main']['text'] = 'Proposal';
$links['namespaces']['evaluations'] = [
'class' => ($isEvalPage ? 'selected' : ''),
'href' => ($isEvalPage ? $template->getTitle()->getLocalUrl() : $evalTitle->getLocalUrl()),
'text' => 'Evaluations',
];
}

unset($links['namespaces']['talk']);
};
?>
46 changes: 46 additions & 0 deletions roles/mediawiki/files/special-log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

# Make it so names of log types are more amenable to LFC users
$logTitlesOverrideMessages = [
"picksomelogpage" => "Selection",
"activitylogpage" => "Misc. Activity (page views, login, logout, etc)",
"simplefavoriteslog" => "Favorites",
"log-name-create" => "Page Creation",
"movelogpage" => "Page Rename",
"uploadlogpage" => "File Upload",
"dellogpage" => "Page Deletion",
"newuserlogpage" => "User Creation",
"log-name-teamcomments" => "Comments",
"torquedataconnect-apiaccesslog" => "API Accesses",
"torquedataconnect-datachangeslog" => "Data Changes",
"rightslog" => "Changes to Access Control / Permissions"
];

$wgHooks['MessagesPreLoad'][] = function($title, &$message, $code) {
global $logTitlesOverrideMessages;
if(array_key_exists(strtolower($title), $logTitlesOverrideMessages)) {
$message = $logTitlesOverrideMessages[strtolower($title)];
}
};


# Remove log types that we don't want
$logTypesBlacklist = ["block", "contentmodel", "import", "managetags", "merge", "patrol", "protect", "rights", "tag"];

$wgHooks['SetupAfterCache'][] = function () {
global $wgLogTypes, $logTypesBlacklist;
foreach($logTypesBlacklist as $logType) {
unset($wgLogTypes[array_search($logType, $wgLogTypes)]);
}

return true;
};

# Change the log format a little
#
# This is a little brittle, based on how the lines are rendered by the skin currently used
# but should work for the foreseeable future.
$wgHooks['LogEventsListLineEnding'][] = function ($page, &$line, &$entry, &$classes, &$attribs){
$line = preg_replace('/(\d\d\d\d)/', '\1 &mdash;', $line, 1);
};
?>
15 changes: 15 additions & 0 deletions roles/mediawiki/files/upload-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
$wgEnableUploads = true;
$wgFileExtensions = array_merge($wgFileExtensions, array('doc', 'docx', 'html', 'pdf', 'xlsx'));
$wgFileBlacklist = array();
$wgMimeTypeBlacklist = array();
$wgStrictFileExtensions = false;
$wgTrustedMediaFormats = array('application/zip', 'text/html');
$wgVerifyMimeType = false;
$wgAllowJavaUploads = true;
$wgCheckFileExtensions = false;
$wgGroupPermissions['bot']['edit'] = true;
$wgGroupPermissions['bot']['upload'] = true;
$wgGroupPermissions['bot']['torquedataconnect-admin'] = true;
$wgGroupPermissions['autoconfirmed']['reupload'] = true;
?>
Loading

0 comments on commit f60d50a

Please sign in to comment.