Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ An article
- A template can include other templates, ten levels deep at most; a template that includes itself, directly or through another template, shows an error where the loop is (it cannot stop its own recursion with `{{#if:}}`, as on Wikipedia). A call to a template that does not exist is a red link to `Template:Name`.
- The text of a template is parsed like article text, so it can use BBCode, `[[links]]`, headings and tables, and nothing an article could not.
- The page of a template shows its documentation (what is inside `<noinclude>`, with its calls worked out, so it can show examples), then **Template text**: the text an article gets, as it is written and not worked out, with how many articles use it. `<includeonly>` text is left off the page. **What links here** lists the articles that use the template.
- **Templates** at `/wiki/templates`, linked from the overview, lists every template A to Z with its short description (the article's description field), how many articles use it, and when it was last edited.
- Like headings and tables, this works in wiki articles only; in a forum post `{{Name}}` stays plain text. The first letter of a template name is not case-sensitive (`{{out of date}}` finds `Template:Out of date`).
- **Parser functions** decide what a template shows. Only the part that is chosen is worked out, so the branch that is not taken can hold anything.

Expand Down
4 changes: 4 additions & 0 deletions config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ phpbbmodders_wiki_recent_changes:
path: /wiki/recent-changes
defaults: { _controller: phpbbmodders.wiki.recent_changes:page }

phpbbmodders_wiki_templates:
path: /wiki/templates
defaults: { _controller: phpbbmodders.wiki.template_list:page }

phpbbmodders_wiki_contributions:
path: /wiki/contributions/{username}
defaults: { _controller: phpbbmodders.wiki.contributions:view }
Expand Down
14 changes: 14 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ services:
- '%core.root_path%'
- '%core.php_ext%'

phpbbmodders.wiki.template_list:
class: phpbbmodders\wiki\controller\template_list
arguments:
- '@auth'
- '@config'
- '@dbal.conn'
- '@controller.helper'
- '@pagination'
- '@request'
- '@template'
- '@user'
- '@phpbbmodders.wiki.links'
- '%tables.wiki.article%'

phpbbmodders.wiki.contributions:
class: phpbbmodders\wiki\controller\contributions
arguments:
Expand Down
146 changes: 146 additions & 0 deletions controller/template_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
*
* Wiki extension for the phpBB Forum Software package
*
* @copyright (c) 2026, phpBB Modders, https://www.phpbbmodders.com/
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbbmodders\wiki\controller;

/**
* The list of templates: the live version of every article called "Template:Name",
* A to Z, with its short description and how many articles use it.
*/
class template_list
{
/** @var \phpbb\auth\auth */
protected $auth;

/** @var \phpbb\config\config */
protected $config;

/** @var \phpbb\db\driver\driver_interface */
protected $db;

/** @var \phpbb\controller\helper */
protected $helper;

/** @var \phpbb\pagination */
protected $pagination;

/** @var \phpbb\request\request */
protected $request;

/** @var \phpbb\template\template */
protected $template;

/** @var \phpbb\user */
protected $user;

/** @var \phpbbmodders\wiki\wiki\links */
protected $links;

/** @var string */
protected $article_table;

/**
* @param \phpbb\auth\auth $auth
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\controller\helper $helper
* @param \phpbb\pagination $pagination
* @param \phpbb\request\request $request
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbbmodders\wiki\wiki\links $links
* @param string $article_table
*/
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\pagination $pagination, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \phpbbmodders\wiki\wiki\links $links, $article_table)
{
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->helper = $helper;
$this->pagination = $pagination;
$this->request = $request;
$this->template = $template;
$this->user = $user;
$this->links = $links;
$this->article_table = $article_table;
}

/**
* SQL condition for the live version of a template: approved, and not
* replaced by a newer approved version.
*
* @return string
*/
protected function live_template_where()
{
return 'a.article_approved = 1
AND a.article_url ' . $this->db->sql_like_expression(\phpbbmodders\wiki\wiki\templates::PREFIX . $this->db->get_any_char()) . '
AND NOT EXISTS (
SELECT 1 FROM ' . $this->article_table . ' b
WHERE b.article_url = a.article_url
AND b.article_approved = 1
AND (b.article_last_edit > a.article_last_edit
OR (b.article_last_edit = a.article_last_edit AND b.article_id > a.article_id)))';
}

/**
* The templates page.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function page()
{
$this->user->add_lang_ext('phpbbmodders/wiki', 'common');

if (!$this->auth->acl_get('u_wiki_view'))
{
trigger_error('NOT_AUTHORISED');
}

$sql = 'SELECT COUNT(a.article_id) AS total
FROM ' . $this->article_table . ' a
WHERE ' . $this->live_template_where();
$result = $this->db->sql_query($sql);
$total = (int) $this->db->sql_fetchfield('total');
$this->db->sql_freeresult($result);

$per_page = max(1, (int) $this->config['topics_per_page']);
$start = $this->pagination->validate_start($this->request->variable('start', 0), $per_page, $total);

$sql = 'SELECT a.article_id, a.article_title, a.article_url, a.article_description, a.article_last_edit
FROM ' . $this->article_table . ' a
WHERE ' . $this->live_template_where() . '
ORDER BY a.article_title ASC, a.article_id ASC';
$result = $this->db->sql_query_limit($sql, $per_page, $start);
while ($row = $this->db->sql_fetchrow($result))
{
$this->template->assign_block_vars('templates', array(
'NAME' => substr($row['article_url'], strlen(\phpbbmodders\wiki\wiki\templates::PREFIX)),
'DESCRIPTION' => $row['article_description'],
'USED_ON' => count($this->links->what_links_here($row['article_url'])),
'EDIT_TIME' => $this->user->format_date($row['article_last_edit']),
'U_TEMPLATE' => $this->helper->route('phpbbmodders_wiki_article', array('article' => $row['article_url'])),
));
}
$this->db->sql_freeresult($result);

$this->template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $this->user->lang('WIKI'),
'U_VIEW_FORUM' => $this->helper->route('phpbbmodders_wiki_index', array()),
));

$this->pagination->generate_template_pagination($this->helper->route('phpbbmodders_wiki_templates', array()), 'pagination', 'start', $total, $per_page, $start);

$this->template->assign_vars(array(
'TOTAL_ITEMS' => $this->user->lang('TOTAL_ITEMS', $total),
));

return $this->helper->render('template_list.html', $this->user->lang('WIKI_TEMPLATES'));
}
}
2 changes: 1 addition & 1 deletion docs/TODO/todo-wiki-markup.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ out. Still to do:
functions per article. Add the cache only if articles with hundreds of calls become common.
- A template call holds other calls in its parameters three levels deep, and a default value holds
one level of `{{template}}`; deeper nesting stays text.
- A list of templates and a "Template" start-point in the article picker.
- A "Start from" choice for templates in the article picker.

A set of ready-made templates, adapted from Wikipedia's, is planned as a separate
repository: [Starter templates repository](todo-wiki-templates-repo.md).
Expand Down
1 change: 1 addition & 0 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public function page_header($event)
$this->template->assign_vars(array(
'U_WIKI' => $this->helper->route('phpbbmodders_wiki_index', array()),
'U_WIKI_RECENT_CHANGES' => $this->helper->route('phpbbmodders_wiki_recent_changes', array()),
'U_WIKI_TEMPLATES' => $this->helper->route('phpbbmodders_wiki_templates', array()),
'U_WIKI_FEED_RSS' => \phpbbmodders\wiki\wiki\feed::offers($feed_setting, \phpbbmodders\wiki\wiki\feed::RSS) ? $this->helper->route('phpbbmodders_wiki_recent_changes_feed', array('_format' => 'rss')) : '',
'U_WIKI_FEED_ATOM' => \phpbbmodders\wiki\wiki\feed::offers($feed_setting, \phpbbmodders\wiki\wiki\feed::ATOM) ? $this->helper->route('phpbbmodders_wiki_recent_changes_feed', array('_format' => 'atom')) : '',
'WIKI_ICON_CLASSES' => \phpbbmodders\wiki\wiki\icon::classes(isset($this->config['wiki_icon']) ? $this->config['wiki_icon'] : \phpbbmodders\wiki\wiki\icon::DEFAULT_ICON),
Expand Down
6 changes: 6 additions & 0 deletions language/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
'WIKI_NOW_WATCHING' => 'You are now watching this article. You will be notified when a new version goes live.',
'WIKI_NO_LONGER_WATCHING' => 'You are no longer watching this article.',
'WIKI_RECENT_CHANGES' => 'Recent changes',
'WIKI_TEMPLATES' => 'Templates',
'WIKI_TEMPLATES_EXPLAIN' => 'Every template of the wiki, A to Z. A template is an article called “Template:Name”; write {{Name}} in an article to use it.',
'WIKI_TEMPLATES_NONE' => 'There are no templates yet.',
'WIKI_TEMPLATE' => 'Template',
'WIKI_TEMPLATE_DESCRIPTION' => 'Description',
'WIKI_TEMPLATE_USED_IN' => 'Used in',
'WIKI_RECENT_CHANGES_EXPLAIN' => 'Every version saved to the wiki that is or was live, newest first.',
'WIKI_FEED_RSS_LINK' => 'RSS feed',
'WIKI_FEED_ATOM_LINK' => 'Atom feed',
Expand Down
1 change: 1 addition & 0 deletions styles/prosilver/template/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h2>{L_OVERVIEW}</h2>
<p>
<a href="{U_WIKI_RECENT_CHANGES}">{L_WIKI_RECENT_CHANGES}</a>
&bull; <a href="{U_WIKI_TEMPLATES}">{L_WIKI_TEMPLATES}</a>
<!-- IF U_WIKI_FEED_RSS --> &bull; <a href="{U_WIKI_FEED_RSS}">{L_WIKI_FEED_RSS_LINK}</a><!-- ENDIF -->
<!-- IF U_WIKI_FEED_ATOM --> &bull; <a href="{U_WIKI_FEED_ATOM}">{L_WIKI_FEED_ATOM_LINK}</a><!-- ENDIF -->
</p>
Expand Down
44 changes: 44 additions & 0 deletions styles/prosilver/template/template_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!-- INCLUDE overall_header.html -->
<h2>{L_WIKI_TEMPLATES}</h2>
<p>{L_WIKI_TEMPLATES_EXPLAIN}</p>
<!-- IF .templates -->
<div class="forumbg forumbg-table">
<div class="inner">
<table class="table1">
<thead>
<tr>
<th>{L_WIKI_TEMPLATE}</th>
<th>{L_WIKI_TEMPLATE_DESCRIPTION}</th>
<th class="middle">{L_WIKI_TEMPLATE_USED_IN}</th>
<th class="big">{L_LAST_EDIT}</th>
</tr>
</thead>
<tbody>
<!-- BEGIN templates -->
<tr class="<!-- IF templates.S_ROW_COUNT is even -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">
<td><a href="{templates.U_TEMPLATE}"><strong>{templates.NAME}</strong></a></td>
<td>{templates.DESCRIPTION}</td>
<td>{templates.USED_ON}</td>
<td>{templates.EDIT_TIME}</td>
</tr>
<!-- END templates -->
</tbody>
</table>
</div>
</div>
<!-- ELSE -->
<p>{L_WIKI_TEMPLATES_NONE}</p>
<!-- ENDIF -->

<div class="action-bar bottom">
<div class="pagination">
{TOTAL_ITEMS}
<!-- IF .pagination -->
<!-- INCLUDE pagination.html -->
<!-- ELSE -->
&bull; {PAGE_NUMBER}
<!-- ENDIF -->
</div>
</div>

<!-- INCLUDE overall_footer.html -->
Loading