<?php

class ModuleWiki extends Module
{
  function __construct(System $System)
  {
    parent::__construct($System);
    $this->Name = 'Wiki';
    $this->Version = '1.0';
    $this->Creator = 'Chronos';
    $this->License = 'GNU/GPLv3';
    $this->Description = 'Mediawiki style page management';
    $this->Dependencies = array();
  }

  function DoStart(): void
  {
    $this->LoadPages();
  }

  function LoadPages()
  {
    $DbResult = $this->Database->select('WikiPage', '*', '`VisibleInMenu`=1');
    while ($DbRow = $DbResult->fetch_assoc())
    {
      $this->System->RegisterPage($DbRow['NormalizedName'], 'PageWiki');
      Core::Cast($this->System)->RegisterMenuItem(array(
        'Title' => $DbRow['Name'],
        'Hint' => '',
        'Link' => $this->System->Link('/'.$DbRow['NormalizedName'].'/'),
        'Permission' => LICENCE_ANONYMOUS,
        'Icon' => '',
      ), 6);
    }
  }
}
