Skip to content

Commit

Permalink
Add categories module
Browse files Browse the repository at this point in the history
Change-Id: I0d2f768605e66a91a51593d7a4748a49cf161cad
  • Loading branch information
Sophivorus committed Jun 7, 2023
1 parent 58eba41 commit 7b64f46
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions StandardWikitext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static function fixWikitext( $wikitext ) {
$wikitext = self::fixReferences( $wikitext );
$wikitext = self::fixLists( $wikitext );
$wikitext = self::fixSections( $wikitext );
$wikitext = self::fixCategories( $wikitext );
$wikitext = self::fixSpacing( $wikitext );
return $wikitext;
}
Expand Down Expand Up @@ -357,6 +358,26 @@ public static function fixSections( $wikitext ) {
return $wikitext;
}

/**
* Move categories to the bottom
* @todo Only works in English
*/
public static function fixCategories( $wikitext ) {
$count = preg_match_all( "/\n*\[\[ ?[Cc]ategory ?: ?([^]]+) ?\]\]/", $wikitext, $matches );
if ( $count ) {
foreach ( $matches[0] as $match ) {
$wikitext = str_replace( $match, '', $wikitext );
}
$categories = $matches[1];
$categories = array_unique( $categories );
$wikitext .= "\n";
foreach ( $categories as $category ) {
$wikitext .= "\n[[Category:$category]]";
}
}
return $wikitext;
}

public static function fixSpacing( $wikitext ) {
// Give block templates some room
$templates = self::getElements( "\n{{", "}}\n", $wikitext );
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "StandardWikitext",
"version": "2.0",
"version": "2.1",
"author": "[https://www.mediawiki.org/wiki/User:Sophivorus Sophivorus]",
"url": "https://www.mediawiki.org/wiki/Extension:StandardWikitext",
"descriptionmsg": "standardwikitext-desc",
Expand Down

0 comments on commit 7b64f46

Please sign in to comment.