PHPackages                             lucasdavies/wikitextbuilder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lucasdavies/wikitextbuilder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lucasdavies/wikitextbuilder
===========================

A fluent PHP library for programmatically building MediaWiki wikitext markup, including tables, lists, and templates

v0.1.6(2mo ago)08MITPHPPHP ^8.4

Since Dec 30Pushed 2mo agoCompare

[ Source](https://github.com/lucasdavies/wikitext-builder)[ Packagist](https://packagist.org/packages/lucasdavies/wikitextbuilder)[ RSS](/packages/lucasdavies-wikitextbuilder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (8)Used By (0)

PHP Wikitext Builder
====================

[](#php-wikitext-builder)

A PHP library for building MediaWiki wikitext markup programmatically.

Requirements
------------

[](#requirements)

- PHP 8.4 or higher

Installation
------------

[](#installation)

Install via Composer:

```
composer require lucasdavies/wikitextbuilder
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
use LucasDavies\WikitextBuilder\Builder;

$builder = new Builder();
```

### Headings

[](#headings)

Generate headings with the appropriate number of equals signs:

```
$builder->heading('Section Title', 2); // ==Section Title==
$builder->heading('Subsection', 3);    // ===Subsection===
```

### Templates

[](#templates)

Create templates with various formatting options:

```
// Basic template
$builder->template('Citation needed');
// {{Citation needed}}

// Template with unnamed parameters
$builder->template('Convert')->params(['100', 'km', 'mi']);
// {{Convert|100|km|mi}}

// Template with named parameters
$builder->template('Infobox')
    ->params([
        'name' => 'Example',
        'type' => 'Sample'
    ]);
// {{Infobox|name=Example|type=Sample}}

// Multiline template
$builder->template('Infobox')
    ->multiline()
    ->params([
        'name' => 'Example',
        'type' => 'Sample'
    ]);
// {{Infobox
// |name=Example
// |type=Sample
// }}

// Multiline with spacing
$builder->template('Infobox')
    ->multiline()
    ->spaced()
    ->params([
        'name' => 'Example',
        'type' => 'Sample'
    ]);
// {{Infobox
// |name = Example
// |type = Sample
// }}

// Multiline with alignment
$builder->template('Infobox')
    ->multiline()
    ->aligned()
    ->params([
        'name' => 'Example',
        'description' => 'A longer parameter'
    ]);
// {{Infobox
// |name        = Example
// |description = A longer parameter
// }}
```

Alternatively you can build templates by using the component classes directly and calling the `render()` method:

```
use LucasDavies\WikitextBuilder\Components\Template;

$template = new Template('Citation needed');
echo $template->render();
// {{Citation needed}}
```

### Tables

[](#tables)

Build tables with headers, body rows, captions, and styling:

```
$builder->table(function (Table $table) {
    return $table
        ->caption('Example Table')
        ->headerRow(['Column 1', 'Column 2', 'Column 3'])
        ->bodyRow(['Value 1', 'Value 2', 'Value 3'])
        ->bodyRow(['Value 4', 'Value 5', 'Value 6']);
});
```

Outputs:

```
{| class="wikitable"
|+ Example Table
|-
!Column 1!!Column 2!!Column 3
|-
|Value 1||Value 2||Value 3
|-
|Value 4||Value 5||Value 6
|}

```

#### Table Styling

[](#table-styling)

```
$builder->table(function (Table $table) {
    return $table
        ->styles(['width' => '100%', 'margin' => 'auto'])
        ->classes(['sortable', 'collapsible'])
        ->headerRow(['Name', 'Age', 'City'])
        ->bodyRow(['Alice', '30', 'New York']);
});
```

Outputs:

```
{| class="wikitable sortable collapsible" style="width:100%;margin:auto"
|-
!Name!!Age!!City
|-
|Alice||30||New York
|}

```

Alternatively, like templates, you can build tables by using the component classes directly and calling the `render()` method:

```
use LucasDavies\WikitextBuilder\Components\Table;

echo new Table()
    ->styles(['width' => '100%', 'margin' => 'auto'])
    ->classes(['sortable', 'collapsible'])
    ->headerRow(new TableHeaderRow(['Name', 'Age', 'City']))
    ->bodyRow(new TableBodyRow(['Alice', '30', 'New York']))
    ->render();
```

Outputs:

```
{| class="wikitable sortable collapsible" style="width:100%;margin:auto"
|-
!Name!!Age!!City
|-
|Alice||30||New York
|}

```

### Styles

[](#styles)

When applying styles to components, predefined styles can be used:

```
use LucasDavies\WikitextBuilder\Components\Table\TableCell;

$cell = new TableCell('value')->textCenter();
echo $cell->render();
// |style="text-align:center"|value
```

Currently only text alignment styles are predefined: `textLeft()`, `textCenter()`, and `textRight()`.

These can be used in conjunction with custom styles:

```
use LucasDavies\WikitextBuilder\Components\Table\TableCell;

$cell = new TableCell('value')->textCenter()->styles(['color' => 'red']);
echo $cell->render();
// |style="text-align:center;color:red"|value
```

Note that styles will overwrite each other depending on the order in which they are applied.

```
use LucasDavies\WikitextBuilder\Components\Table\TableCell;

// Custom style applied after predefined style
$cell = new TableCell('value')->textCenter()->styles(['color' => 'red', 'text-align' => 'left']);
echo $cell->render();
// |style="color:red;text-align:left"|value

// Predefined style applied after custom style
$cell = new TableCell('value')->styles(['text-align' => 'left', 'color' => 'green'])->textRight();
echo $cell->render();
// |style="color:red;text-align:right"|value
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Or with PHPUnit directly:

```
./vendor/bin/phpunit
```

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance87

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Recently: every ~17 days

Total

7

Last Release

62d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17126568f2e6dd80afef852c3a0f7eaa2ab7d51dd808f7663fd4028ea99fdfdb?d=identicon)[lucasdavies](/maintainers/lucasdavies)

---

Top Contributors

[![lucasdavies](https://avatars.githubusercontent.com/u/583014?v=4)](https://github.com/lucasdavies "lucasdavies (7 commits)")

---

Tags

mediawikibuilderwikimarkupwikitextwikipedia

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lucasdavies-wikitextbuilder/health.svg)

```
[![Health](https://phpackages.com/badges/lucasdavies-wikitextbuilder/health.svg)](https://phpackages.com/packages/lucasdavies-wikitextbuilder)
```

###  Alternatives

[mediawiki/chameleon-skin

A highly flexible MediaWiki skin using Bootstrap 4

12481.8k2](/packages/mediawiki-chameleon-skin)[mediawiki/semantic-extra-special-properties

Provides extra special properties for Semantic MediaWiki

3074.6k1](/packages/mediawiki-semantic-extra-special-properties)[mediawiki/semantic-scribunto

A Semantic Mediawiki extension to natively support the Scribunto extension

2967.5k](/packages/mediawiki-semantic-scribunto)[mediawiki/semantic-glossary

A terminology markup extension with a Semantic MediaWiki back-end

1352.4k](/packages/mediawiki-semantic-glossary)[professional-wiki/modern-timeline

Adds a modern timeline visualization as Semantic MediaWiki result format

1820.8k1](/packages/professional-wiki-modern-timeline)[mediawiki/semantic-cite

A Semantic MediaWiki extension to manage citation resources.

2310.2k1](/packages/mediawiki-semantic-cite)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
