DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:wrap:migration

Migration of other plugin’s syntax

The Wrap Plugin offers functionality similar to many other plugins, some of which have been discontinued. Sometimes explicitly in favor of the wrap plugin.

This Page collects instructions to ease the migration of other plugin's syntax to (more or less) equivalent syntax of the wrap plugin. It is recommended to either use the batchedit-plugin or to use a php script, especially if there are multiple steps necessary.

Box Plugin

box – discontinued in favor of the Wrap Plugin.

The box plugin centers its boxes by default, but the wrap plugin does not. Further the Wrap Plugin does not know of titles and captions. Therefore we need multiple search/replace steps to transform the syntax.

box2wrap.php
<?php
 
$replacements = [
    [ // move box titles into box body
        'search' => '/<box ([^>]*?)\|([^>]+?)>(.*?)<\/box(\|(?:[^>]*)?)?>/s',
        'replace' => "<box $1>\n$2\n\n$3</box$4>",
    ],
    [ // move box caption into box body
        'search' => '/<box ([^>]*?)>(.*?)<\/box\|([^>]+?)>/s',
        'replace' => "<box $1>$2\n\n//$3//</box>",
    ],
    [ // replace left/right aligned boxes with wrap syntax
        'search' => '/<box([^>]*?)(left|right) ([^>]*?)>(.*?)<\/box\|?>/s',
        'replace' => '<WRAP box $1 $2 $3>$4</WRAP>',
    ],
    [ // replace remaining boxes with centered wrap syntax
        'search' => '/<box ([^>]*?)>(.*?)<\/box\|?>/s',
        'replace' => '<WRAP box $1 center>$2</WRAP>',
    ]
];
 
function replaceSyntax($replacement, $dir){
    $files = scandir($dir, SCANDIR_SORT_ASCENDING);
    foreach ($files as $file) {
        if ($file === '.' || $file === '..') {
            continue;
        }
        $filename = $dir . '/' . $file;
        if (is_dir($filename)) {
            replaceSyntax($replacement, $filename);
        }
 
        if (substr($filename, -4) !== '.txt') {
            continue;
        }
 
        $fileContents = file_get_contents($filename);
        $newContent = preg_replace($replacement['search'], $replacement['replace'], $fileContents);
        if ($fileContents === $newContent) {
            continue;
        }
        if (null === $newContent) {
            die('replacement failed!');
        }
 
        $writeOK = file_put_contents($filename, $newContent);
        if ($writeOK === false) {
            die('write failed!');
        }
    }
}
 
$pagesDir = __DIR__;
foreach ($replacements as $replacement) {
    replaceSyntax($replacement, $pagesDir);
}

Run this in your data/pages/ directory with php box2wrap.php. But make an backup before you do!

plugin/wrap/migration.txt · Last modified: 2018-01-26 17:45 by grosse