evennia/docs/1.0-dev/Howtos/Web-Add-a-wiki.html

347 lines
23 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Add a wiki on your website &#8212; Evennia 1.0-dev documentation</title>
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Web Character Generation" href="Web-Character-Generation.html" />
2022-11-20 23:39:28 +00:00
<link rel="prev" title="Tutorial Tweeting Game Stats" href="Tutorial-Tweeting-Game-Stats.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Web-Character-Generation.html" title="Web Character Generation"
accesskey="N">next</a> |</li>
<li class="right" >
2022-11-20 23:39:28 +00:00
<a href="Tutorial-Tweeting-Game-Stats.html" title="Tutorial Tweeting Game Stats"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="Howtos-Overview.html" accesskey="U">Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Add a wiki on your website</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<h3><a href="../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Add a wiki on your website</a><ul>
<li><a class="reference internal" href="#basic-installation">Basic installation</a><ul>
<li><a class="reference internal" href="#installing-with-pip">Installing with pip</a></li>
<li><a class="reference internal" href="#adding-the-wiki-in-the-settings">Adding the wiki in the settings</a></li>
<li><a class="reference internal" href="#adding-the-new-urls">Adding the new URLs</a></li>
<li><a class="reference internal" href="#running-migrations">Running migrations</a></li>
<li><a class="reference internal" href="#initializing-the-wiki">Initializing the wiki</a></li>
</ul>
</li>
<li><a class="reference internal" href="#defining-wiki-permissions">Defining wiki permissions</a><ul>
<li><a class="reference internal" href="#group-permissions">Group permissions</a></li>
<li><a class="reference internal" href="#settings-permissions">Settings permissions</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
2022-11-20 23:39:28 +00:00
<p class="topless"><a href="Tutorial-Tweeting-Game-Stats.html"
title="previous chapter">Tutorial Tweeting Game Stats</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="Web-Character-Generation.html"
title="next chapter">Web Character Generation</a></p>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
2022-11-20 23:39:28 +00:00
<li><a href="../_sources/Howtos/Web-Add-a-wiki.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com">Home page</a> </li>
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li>
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
<a href="https://evennia.blogspot.com/">Blog</a>
</li>
</ul>
<h3>Versions</h3>
<ul>
2022-11-20 23:39:28 +00:00
<li><a href="Web-Add-a-wiki.html">1.0-dev (develop branch)</a></li>
2022-11-15 20:29:38 +00:00
<ul>
<li><a href="../0.9.5/index.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="bodywrapper">
<div class="body" role="main">
<section class="tex2jax_ignore mathjax_ignore" id="add-a-wiki-on-your-website">
<h1>Add a wiki on your website<a class="headerlink" href="#add-a-wiki-on-your-website" title="Permalink to this headline"></a></h1>
<p><strong>Before doing this tutorial you will probably want to read the intro in
<a class="reference internal" href="Beginner-Tutorial/Part5/Web-Tutorial.html"><span class="doc std std-doc">Basic Web tutorial</span></a>.</strong> Reading the three first parts of the
<a class="reference external" href="https://docs.djangoproject.com/en/1.9/intro/tutorial01/">Django tutorial</a> might help as well.</p>
<p>This tutorial will provide a step-by-step process to installing a wiki on your website.
Fortunately, you dont have to create the features manually, since it has been done by others, and
we can integrate their work quite easily with Django. I have decided to focus on
the <a class="reference external" href="https://django-wiki.readthedocs.io/">Django-wiki</a>.</p>
2022-11-20 23:39:28 +00:00
<p>The <a class="reference external" href="https://django-wiki.readthedocs.io/">Django-wiki</a> offers a lot of features associated with wikis, is actively maintained (at this time, anyway), and isnt too difficult to install in Evennia. You can
see a <a class="reference external" href="https://demo.django-wiki.org">demonstration of Django-wiki here</a>.</p>
<section id="basic-installation">
<h2>Basic installation<a class="headerlink" href="#basic-installation" title="Permalink to this headline"></a></h2>
<p>You should begin by shutting down the Evennia server if it is running. We will run migrations and
alter the virtual environment just a bit. Open a terminal and activate your Python environment, the
one you use to run the <code class="docutils literal notranslate"><span class="pre">evennia</span></code> command.</p>
<p>If you used the default location from the Evennia installation instructions, it should be one of the following:</p>
<ul>
<li><p>On Linux:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">source</span> <span class="n">evenv</span><span class="o">/</span><span class="nb">bin</span><span class="o">/</span><span class="n">activate</span>
</pre></div>
</div>
</li>
<li><p>Or Windows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">evenv</span>\<span class="nb">bin</span>\<span class="n">activate</span>
</pre></div>
</div>
</li>
</ul>
<section id="installing-with-pip">
<h3>Installing with pip<a class="headerlink" href="#installing-with-pip" title="Permalink to this headline"></a></h3>
<p>Install the wiki using pip:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>pip install wiki
</pre></div>
</div>
<p>It might take some time, the Django-wiki having some dependencies.</p>
</section>
<section id="adding-the-wiki-in-the-settings">
<h3>Adding the wiki in the settings<a class="headerlink" href="#adding-the-wiki-in-the-settings" title="Permalink to this headline"></a></h3>
<p>You will need to add a few settings to have the wiki app on your website. Open your
<code class="docutils literal notranslate"><span class="pre">server/conf/settings.py</span></code> file and add the following at the bottom (but before importing
<code class="docutils literal notranslate"><span class="pre">secret_settings</span></code>). Heres an example of a settings file with the Django-wiki added:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Use the defaults from Evennia unless explicitly overridden</span>
<span class="kn">from</span> <span class="nn">evennia.settings_default</span> <span class="kn">import</span> <span class="o">*</span>
<span class="c1">######################################################################</span>
<span class="c1"># Evennia base server config</span>
<span class="c1">######################################################################</span>
<span class="c1"># This is the name of your game. Make it catchy!</span>
<span class="n">SERVERNAME</span> <span class="o">=</span> <span class="s2">&quot;demowiki&quot;</span>
<span class="c1">######################################################################</span>
<span class="c1"># Django-wiki settings</span>
<span class="c1">######################################################################</span>
<span class="n">INSTALLED_APPS</span> <span class="o">+=</span> <span class="p">(</span>
<span class="s1">&#39;django.contrib.humanize.apps.HumanizeConfig&#39;</span><span class="p">,</span>
<span class="s1">&#39;django_nyt.apps.DjangoNytConfig&#39;</span><span class="p">,</span>
<span class="s1">&#39;mptt&#39;</span><span class="p">,</span>
<span class="s1">&#39;sorl.thumbnail&#39;</span><span class="p">,</span>
<span class="s1">&#39;wiki.apps.WikiConfig&#39;</span><span class="p">,</span>
<span class="s1">&#39;wiki.plugins.attachments.apps.AttachmentsConfig&#39;</span><span class="p">,</span>
<span class="s1">&#39;wiki.plugins.notifications.apps.NotificationsConfig&#39;</span><span class="p">,</span>
<span class="s1">&#39;wiki.plugins.images.apps.ImagesConfig&#39;</span><span class="p">,</span>
<span class="s1">&#39;wiki.plugins.macros.apps.MacrosConfig&#39;</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Disable wiki handling of login/signup</span>
<span class="n">WIKI_ACCOUNT_HANDLING</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">WIKI_ACCOUNT_SIGNUP_ALLOWED</span> <span class="o">=</span> <span class="kc">False</span>
<span class="c1">######################################################################</span>
<span class="c1"># Settings given in secret_settings.py override those in this file.</span>
<span class="c1">######################################################################</span>
<span class="k">try</span><span class="p">:</span>
<span class="kn">from</span> <span class="nn">server.conf.secret_settings</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;secret_settings.py file not found or failed to import.&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Everything in the section “Django-wiki settings” is what youll need to include.</p>
</section>
<section id="adding-the-new-urls">
<h3>Adding the new URLs<a class="headerlink" href="#adding-the-new-urls" title="Permalink to this headline"></a></h3>
<p>Next you will need to add two URLs to the file <code class="docutils literal notranslate"><span class="pre">web/urls.py</span></code>. Youll do that by modifying
<code class="docutils literal notranslate"><span class="pre">urlpatterns</span></code> to look something like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># add patterns</span>
<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
<span class="c1"># website</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s2">&quot;web.website.urls&quot;</span><span class="p">)),</span>
<span class="c1"># webclient</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;webclient/&quot;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s2">&quot;web.webclient.urls&quot;</span><span class="p">)),</span>
<span class="c1"># web admin</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;admin/&quot;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s2">&quot;web.admin.urls&quot;</span><span class="p">)),</span>
<span class="c1"># wiki</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;wiki/&quot;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s2">&quot;wiki.urls&quot;</span><span class="p">)),</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;notifications/&quot;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="s2">&quot;django_nyt.urls&quot;</span><span class="p">)),</span>
<span class="p">]</span>
</pre></div>
</div>
<p>The last two lines are what youll need to add.</p>
</section>
<section id="running-migrations">
<h3>Running migrations<a class="headerlink" href="#running-migrations" title="Permalink to this headline"></a></h3>
<p>Next youll need to run migrations, since the wiki app adds a few tables in our database:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>evennia migrate
</pre></div>
</div>
</section>
<section id="initializing-the-wiki">
<h3>Initializing the wiki<a class="headerlink" href="#initializing-the-wiki" title="Permalink to this headline"></a></h3>
<p>Last step! Go ahead and start up your server again.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>evennia start
</pre></div>
</div>
<p>Once thats finished booting, go to your evennia website (e.g. <a class="reference external" href="http://localhost:4001">http://localhost:4001</a> ) and log in
with your superuser account, if you arent already. Then, go to your new wiki (e.g.
<a class="reference external" href="http://localhost:4001/wiki">http://localhost:4001/wiki</a> ). Itll prompt you to create a starting page - put whatever you want,
you can change it later.</p>
<p>Congratulations! Youre all done!</p>
</section>
</section>
<section id="defining-wiki-permissions">
<h2>Defining wiki permissions<a class="headerlink" href="#defining-wiki-permissions" title="Permalink to this headline"></a></h2>
<p>A wiki is usually intended as a collaborative effort - but you probably still want to set
some rules about who is allowed to do what. Who can create new articles? Edit them? Delete
them? Etc.</p>
<p>The two simplest ways to do this are to use Django-wikis group-based permissions
system - or, since this is an Evennia site, to define your own custom permission rules
tied to Evennias permissions system in your settings file.</p>
<section id="group-permissions">
<h3>Group permissions<a class="headerlink" href="#group-permissions" title="Permalink to this headline"></a></h3>
<p>The wiki itself controls reading/editing permissions per article. The creator of an article will
always have read/write permissions on that article. Additionally, the article will have Group-based
permissions and general permissions.</p>
<p>By default, Evennias permission groups <em>wont</em> be recognized by the wiki, so youll have to create your own.
2022-11-20 23:39:28 +00:00
Go to the Groups page of your games Django admin panel and add whichever permission groups you want for your wiki here.</p>
<p><em><strong>Note:</strong></em> <em>If you want to connect those groups to your games permission levels, youll need to modify the game to apply both to accounts.</em></p>
<p>Once youve added those groups, theyll be usable in your wiki right away!</p>
</section>
<section id="settings-permissions">
<h3>Settings permissions<a class="headerlink" href="#settings-permissions" title="Permalink to this headline"></a></h3>
<p>Django-wiki also allows you to bypass its article-based permissions with custom site-wide permissions
rules in your settings file. If you dont want to use the Group system, or if you want a simple
solution for connecting the Evennia permission levels to wiki access, this is the way to go.</p>
<p>Heres an example of a basic set-up that would go in your <code class="docutils literal notranslate"><span class="pre">settings.py</span></code> file:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># In server/conf/settings.py</span>
<span class="c1"># ...</span>
<span class="c1"># Custom methods to link wiki permissions to game perms</span>
<span class="k">def</span> <span class="nf">is_superuser</span><span class="p">(</span><span class="n">article</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return True if user is a superuser, False otherwise.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="ow">not</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">()</span> <span class="ow">and</span> <span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span>
<span class="k">def</span> <span class="nf">is_builder</span><span class="p">(</span><span class="n">article</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return True if user is a builder, False otherwise.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="ow">not</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">()</span> <span class="ow">and</span> <span class="n">user</span><span class="o">.</span><span class="n">locks</span><span class="o">.</span><span class="n">check_lockstring</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s2">&quot;perm(Builders)&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">is_player</span><span class="p">(</span><span class="n">article</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return True if user is a builder, False otherwise.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="ow">not</span> <span class="n">user</span><span class="o">.</span><span class="n">is_anonymous</span><span class="p">()</span> <span class="ow">and</span> <span class="n">user</span><span class="o">.</span><span class="n">locks</span><span class="o">.</span><span class="n">check_lockstring</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="s2">&quot;perm(Players)&quot;</span><span class="p">)</span>
<span class="c1"># Create new users</span>
<span class="n">WIKI_CAN_ADMIN</span> <span class="o">=</span> <span class="n">is_superuser</span>
<span class="c1"># Change the owner and group for an article</span>
<span class="n">WIKI_CAN_ASSIGN</span> <span class="o">=</span> <span class="n">is_superuser</span>
<span class="c1"># Change the GROUP of an article, despite the name</span>
<span class="n">WIKI_CAN_ASSIGN_OWNER</span> <span class="o">=</span> <span class="n">is_superuser</span>
<span class="c1"># Change read/write permissions on an article</span>
<span class="n">WIKI_CAN_CHANGE_PERMISSIONS</span> <span class="o">=</span> <span class="n">is_superuser</span>
<span class="c1"># Mark an article as deleted</span>
<span class="n">WIKI_CAN_DELETE</span> <span class="o">=</span> <span class="n">is_builder</span>
<span class="c1"># Lock or permanently delete an article</span>
<span class="n">WIKI_CAN_MODERATE</span> <span class="o">=</span> <span class="n">is_superuser</span>
<span class="c1"># Create or edit any pages</span>
<span class="n">WIKI_CAN_WRITE</span> <span class="o">=</span> <span class="n">is_builder</span>
<span class="c1"># Read any pages</span>
<span class="n">WIKI_CAN_READ</span> <span class="o">=</span> <span class="n">is_player</span>
<span class="c1"># Completely disallow editing and article creation when not logged in</span>
<span class="n">WIKI_ANONYMOUS_WRITE</span> <span class="o">=</span> <span class="kc">False</span>
</pre></div>
</div>
2022-11-20 23:39:28 +00:00
<p>The permission functions can check anything you like on the accessing user, so long as the function returns either True (theyre allowed) or False (theyre not).</p>
<p>For a full list of possible settings, you can check out <a class="reference external" href="https://django-wiki.readthedocs.io/en/latest/settings.html">the django-wiki documentation</a>.</p>
</section>
</section>
</section>
</div>
</div>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="Web-Character-Generation.html" title="Web Character Generation"
>next</a> |</li>
<li class="right" >
2022-11-20 23:39:28 +00:00
<a href="Tutorial-Tweeting-Game-Stats.html" title="Tutorial Tweeting Game Stats"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 1.0-dev</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="Howtos-Overview.html" >Tutorials and Howtos</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Add a wiki on your website</a></li>
</ul>
<div class="develop">develop branch</div>
</div>
<div class="footer" role="contentinfo">
2022-11-15 19:52:44 +00:00
&#169; Copyright 2022, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>