DokuWiki

It's better when it's simple

User Tools

Site Tools


faq:howto-rename-pages

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
faq:howto-rename-pages [2014-04-01 22:33] – [Using a Plugin] Klap-infaq:howto-rename-pages [2022-07-02 19:18] (current) – old revision restored (2016-10-08 23:58) andi
Line 1: Line 1:
 ====== HOWTO: Rename Pages ====== ====== HOWTO: Rename Pages ======
  
-:?: Is there a way to rename a page DokuWiki? +:?: Is there a way to rename a page in DokuWiki?
- +
- +
-===== The easy way ===== +
- +
-Renaming would possibly break a lot of links linking to the old page. Since DokuWiki doesn't know which pages link where this cannot be handled by DokuWiki. An easy way to "rename" a page is to simply create the new one and then change the content of the old page to something like this: +
- +
-  Moved to [[newpage]]. +
- +
-Then visit the [[:backlinks|pages linking to the old page]], and update them to refer to the new page.  This can be done gradually.  Alternatively, use one of the page-redirect plugins listed at: [[:faq:redirect|How to make a redirect page?]]. +
- +
-Note that the old revisions will not be moved with that page. If you like to move them too, you should either write a script or use a plugin (see below). +
- +
- +
-===== On the file system ===== +
- +
-You can also rename/move the txt files in the file system, and the gz files in the attic. This will break links and metadata.+
  
 ===== Using a Plugin ===== ===== Using a Plugin =====
  
  
-The [[plugin:move]] plugin allows a simpler way for an administrator to move/rename pages. It moves history and fixes backlinks. +The [[plugin:move]] plugin adds functionality to DokuWiki that allows a simpler way for an administrator to move/rename pages and media. It moves history and fixes backlinks. 
  
 ===Old plugins=== ===Old plugins===
-   * The [[plugin:pagemove]] plugin. But some report that it does not work currently and produces a lot of unwanted changes! Predecessor of the Move plugin. +For historical references: 
 +   * The [[plugin:pagemove]] plugin. Moves pages. But some report that it does not work currently and produces a lot of unwanted changes! Predecessor of the Move plugin. 
   * The [[plugin:editx]] plugin moves/renames pages with their history metadata, but does not update any other pages for you. You still have to check/fix backlinks manually.   * The [[plugin:editx]] plugin moves/renames pages with their history metadata, but does not update any other pages for you. You still have to check/fix backlinks manually.
  
  
-===== Using UNIX commands  ===== 
  
-**Note**: This tip assumes one is using a Unix-like OS with text file utilities installed, or is using Cygwin under Windows.+===== Just copy & delete page =====
  
-Note that following this tip prevents DokuWiki from keeping coherent page history (old revisions). Remember to back up all raw text files and data.+Renaming would possibly break a lot of links linking to the old page. Since DokuWiki doesn't know which pages link where this cannot be handled by DokuWiki. An easy way to "rename" a page is to simply create the new one and then change the content of the old page to something like this:
  
-How-To Rename a set of pages? +  Moved to [[newpage]].
-Use sed regular expressions to match a filename pattern and replace it with a new filename pattern.+
  
-This is example is bad. See [[http://mywiki.wooledge.org/ParsingLs|why you should never parse LS]] for details.+Then visit the [[:backlinks|pages linking to the old page]], and update them to refer to the new page This can be done gradually Alternatively, use one of the page-redirect plugins listed at: [[:faq:redirect|How to make a redirect page?]].
  
-Example: Rename all pages starting with <project_name> to another prefix: +Note that the old revisions will not be moved with that page. If you like to move them too, use a plugin.
-  for f in `ls *.txt`; do sed -e 's:\[\[project_name\(.*\)\]\]:[[prj_code.\1]]:g' $f > $f.new; done +
-  for f in `ls *.new | sed -e 's:\(.*\)\.new:\1:g'`; do mv $f.new $f; done +
-  for f in `ls *.txt | sed -e 's:project_name\(.*\)\.txt:\1.txt:g'`; do mv project_name-$f prj_code-$f; done+
  
-Better: 
-  find . -name '*.txt' -exec sed -e 's:\[\[project_name\(.*\)\]\]:[[prj_code.\1]]:g' '{}' > '{}'.new \; 
-  find . -name '*.new' -exec sed -e 's:\(.*\)\.new:\1:g'`; do mv '{}'.new '{}' \; 
-  find . -name '*.txt' -exec sed -e 's:project_name\(.*\)\.txt:\1.txt:g'`; do mv project_name-'{}' prj_code-'{}' \; 
  
-Explanation: +===== On the file system =====
-  * The first command uses sed to find all occurrences of a DokuWiki FreeLink that starts with %%project_name%% and replaces them with a new FreeLink that is like the old one except that instead of prefix %%project_name%% it has prefix %%prj_code%%. +
-  * The second command is used to replace the old raw text files (with old FreeLink) with the new raw text files (with new FreeLink). +
-  * Finally, the third command renames the files that match those FreeLinks, by replacing the prefix %%project_name%% with prefix %%prj_code%% in their filename.+
  
------------------------------------ +You can also rename/move the txt files in the file systemand the gz files in the attic. This will break links and metadata. 
-Noob questions - I believe using the above script code is a replacement for the "in the filesystem" methodplus it handles all the backlinks, right? The meta data would still be broken? Is that important? (I personally don't care about history, but for completeness would be good to address that). This example seems to be for renaming a namespace, would it also work for renaming the .txt files themselves? If these questions are inappropriate here, my apologies - feel free to delete them, but if you're feeling magnanimous please address the issues in a reply here: [[http://forum.dokuwiki.org/thread/7677]] Thanks. +>:?: Break links? I assume this mean the old link have to update manually to able to point to new page name.
- +
------------------------------------- +
-Here's a simple script to rename any page/namespace and updated links in all files.  Simply change the path to your data (aka base) directory In this script you'd change ''/www/dokuwiki'' to your base directory. +
- +
-==== Using a Script ==== +
-FIXME This script is **very dangerous!** +
-There no checks on valid input and the perl subsitute commands can change page content throughout the whole wiki! +
-What if we change a file named //dangerous// to //safe// then also all the words //dangerous// on all wiki pages will be subsituted! +
- +
- +
-  # vi rename_page +
- +
- +
-<code> +
-#! /bin/ksh +
- +
-cd /www/dokuwiki || exit $? +
- +
-O=$1 +
-N=$2 +
- +
- +
-#-- Moving a name space +
-if echo "$O" | grep -q : +
-then +
-        OPATH="$( echo "$O" | sed 's/:/\//g' )" +
-        NPATH="$( echo "$N" | sed 's/:/\//g' )" +
- +
-        find * -type d | grep -w "${OPATH}" | while read ODIR +
-        do +
-                NDIR="$( echo "$ODIR" | sed "s:${OPATH}:${NPATH}:" )" +
-                mkdir -p ${NDIR} +
-                [[ -d ${NDIR} ]] && mv ${ODIR}/* ${NDIR}/ +
-        done +
- +
-#-- Moving a file +
-else +
-        find * -type f -name "*${O}*" | while read F +
-        do +
-                NFILE="$( echo "$F" | sed "s/${O}/${N}/" )" +
-                mv "$F" "${NFILE}" +
-        done +
-fi +
- +
-find * -type f -exec grep -wl "$O" {} \; | while read F +
-do +
-        perl -i -pe "s/$O/$N/g" "$F"; +
-done +
-</code> +
- +
-=== Renaming a page === +
-Now let's rename ALL pages and links with the pattern dog_lover in their name to k9_lover. +
-  # chmod 700 rename_page +
-  # rename_page dog_lover k9_lover +
-   +
-If the file name has a space or other special charater +
-  # rename_page "dog lover" "k9 lover" +
-   +
-Only got-cha is the ALL references in ANY file to dog_lover will now read k9_lover.  So links in all namespaces will be renamed. +
-   +
-=== Renaming a namespace === +
-To move a name space, assuming /www/dokuwiki as the base directory.  The following command moves namespace n1:n2 to n3:n4.  This also tries to update all pages with the new namespace.+
  
-  # rename_page ns1:ns2 n3:n4+>About **losing metadata**, [[..:metadata|see here]] (bottom page).
faq/howto-rename-pages.1396384395.txt.gz · Last modified: 2014-04-01 22:33 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki