Skip to content
38 changes: 25 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@
* Namespace IDs (rather than just namespace names) work for all namespaces.
* Support for a wide range of relative timestamps (e.g., "last week", "in 2 hours", "1 month ago").
Previously only a few relative timestamps where supported, now anything supported by PHPs `strtotime` is supported.
- **Gallery Mode Enhancements:**
- Properly supports retrieving **PageImages** when using `mode=gallery` on non-file namespace pages, if the **PageImages** extension is installed.
- Now pulls directly from the **PageImages** extension instead of relying on `page_props`, allowing access to both `page_image` and `page_image_free`.
- Added support for `mode=gallery` when using **Intersection compatibility mode** (i.e., `<DynamicPageList>` tags).
- Improves support for `%IMAGE%`:
* **Gallery Mode Enhancements:**
* Properly supports retrieving **PageImages** when using `mode=gallery` on non-file namespace pages, if the **PageImages** extension is installed.
* Now pulls directly from the **PageImages** extension instead of relying on `page_props`, allowing access to both `page_image` and `page_image_free`.
* Added support for `mode=gallery` when using **Intersection compatibility mode** (i.e., `<DynamicPageList>` tags).
* Improves support for `%IMAGE%`:
It no longer relies on stock `/images/` directories and instead dynamically resolves images based on whatever file backend is in use.
- Introduces a new parameter: `gallerymode`.
* Introduces two new parameters: `imagewidth` and `imageheight`, to control the size of images within galleries.
* Introduces another new parameter: `gallerymode`.
This sets the `mode=` attribute in the generated `<gallery>` tag. Defaults to **`traditional`**, but supports all standard modes:
- `traditional`
- `nolines`
- `packed`
- `packed-hover`
- `packed-overlay`
- `slideshow`
- Introduce two other new parameters: `imagewidth` and `imageheight`, to control the size of images within galleries.
* `traditional`
* `nolines`
* `packed`
* `packed-hover`
* `packed-overlay`
* `slideshow`

For more on supported gallery modes, see:
https://www.mediawiki.org/wiki/Help:Images#Gallery_syntax
Expand All @@ -85,6 +85,18 @@ Previously, using `&` in a category name would incorrectly be interpreted as a l

----

Previously, underscores (`_`) in LIKE-style patterns (like in `titlematch` and `nottitlematch`) were implicitly treated as single-character wildcards. This made it impossible to reliably match literal underscores (which also represent spaces), and caused patterns to match more broadly than intended.

This behavior has been fixed:

* A single-character wildcard must now be written explicitly as `[_]`.
* Each `[_]` represents exactly one character (for example, `[_][_][_]` matches three characters).
* A bare `_` is now treated as a literal underscore and will no longer act as a wildcard.

**NOTE:** We do it with brackets, because brackets are disallowed title characters, so they won't cause issues in the future with some edge-cases since no title can actually contain them. For similar reasons in the future, the same or similar method may be needed for `%` in order to allow better matching of literal `%` in titles, but that is a change that will break much more uses so will be done differently, perhaps keeping existing behavior but adding some other substitution to match literal `%`. For now, matching literal `%` remains unsupported or unreliable.

----

The template transclusion (`Extension DPL`) has been replaced with a proper tracking category, `Pages using DynamicPageList4`. All the references and usages of `Extension DPL` has been removed, including the `CreateTemplate` maintenance script. There is now a new maintenance script, `DeleteTemplate` to delete the old template. It will auto run when updated using `update.php`.

----
Expand Down
13 changes: 10 additions & 3 deletions includes/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,19 @@ private function buildRegexpExpression( string $field, string $value ): string {
* @return non-empty-array<string|LikeMatch>
*/
private function splitLikePattern( string $subject ): array {
$segments = preg_split( '/(%)/', $subject, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
// We use underscores in brackets so that it isn't a legal title character,
// which may cause confusing behavior in some edge cases where you enter
// underscore thinking it is for spaces, like it is elsewhere.
$segments = preg_split( '/(%|\[_\])/', $subject, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
$parts = array_map(
fn ( string $segment ): string|LikeMatch =>
$segment === '%' ? $this->dbr->anyString() : $segment,
fn ( string $segment ): string|LikeMatch => match ( $segment ) {
'%' => $this->dbr->anyString(),
'[_]' => $this->dbr->anyChar(),
default => $segment,
},
$segments
);

return $parts ?: [ '' ];
}

Expand Down
70 changes: 70 additions & 0 deletions tests/parser/selection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,48 @@ format=,%TITLE%,;,
</p>
!! end

!! test
titlematch: single-character wildcard ([_])
!! wikitext
<dpl>
namespace = 0
ordermethod=title
titlematch = P[_][_][_]
format=,%TITLE%,;,
</dpl>
!! html
<p>Pear;Plum;
</p>
!! end

!! test
titlematch: single-character wildcard with fixed prefix
!! wikitext
<dpl>
namespace = 0
ordermethod=title
titlematch = G[_][_][_][_]
format=,%TITLE%,;,
</dpl>
!! html
<p>Grape;
</p>
!! end

!! test
titlematch: mixed % and [_] wildcard
!! wikitext
<dpl>
namespace = 0
ordermethod=title
titlematch = [_]p%e
format=,%TITLE%,;,
</dpl>
!! html
<p>Apple;
</p>
!! end

!! test
nottitlematch: exclude specific pages
!! wikitext
Expand Down Expand Up @@ -106,6 +148,34 @@ format=,%TITLE%,;,
</p>
!! end

!! test
nottitlematch: single-character wildcard ([_])
!! wikitext
<dpl>
namespace = 0
ordermethod=title
nottitlematch = [_]range
format=,%TITLE%,;,
</dpl>
!! html
<p>Apple;Apricot;Banana;Grape;Mango;Pear;Plum;
</p>
!! end

!! test
nottitlematch: mixed % and [_] wildcard
!! wikitext
<dpl>
namespace = 0
ordermethod=title
nottitlematch = %a[_]g%
format=,%TITLE%,;,
</dpl>
!! html
<p>Apple;Apricot;Banana;Grape;Pear;Plum;
</p>
!! end

!! test
replaceintitle: simple string replacement
!! wikitext
Expand Down
Loading