EditTitle

Summary: Provide a separate edit field for the page title.
Version: 1.1 (09 Nov 2005)
Prerequisites: PmWiki version 2.1.5
Status: Works for me
Maintainer: Waylan
Discussion: EditTitle-Talk

Question

How can I display an input field in the edit form for editing a page's Title and have the option to require a title be given for every page?

Answer

  • Download edittitle.phpΔ and copy to your cookbook directory.
  • Add the following line to your config.php file:
          include_once("$FarmD/cookbook/edittitle.php");
As of version 1.0 the $EditTitle = 1; is not nesseccary. The functions are enabled by default. (See Optional Configuration below)
          (:input e_title:)
Upgrade Notice: Previous to version 0.9 you had to provide a label. This is now automaticly added and can be translated from the phrase "Title" in your translation table. Anyone upgrading from a previous version should remove the label from Site.EditForm to avoid the label displaying twice (remove '$[Title]' from the markup). See Fmt Variables below for additional customization.
  • Save your changes and edit titles to your hearts content.

Optional Configuration

  • To display those titles on your pages add the following where you want the Title to appear in the template file (path/to/skin/SkinName.tmpl) for the skin you are using (adjust to fit in with your skin as necessary):
          <h1>$Titlespaced</h1>
  • If you prefer using wiki markup add the following somewhere in your markup:
          !{$Titlespaced}
  • If you want to require your users to always enter a page title add the following anywhere in config.php:
          $ForceTitle = 1;
  • To temporarily turn off either $EditTitle or $ForceTitle set to zero:
          $EditTitle = 0;
          $ForceTitle = 0;
  • You may also set $EditTitle or $ForceTitle for individual groups or pages in their respective config files. See LocalCustomizations for more details.
  • In the event that you would like to force your users to include a title on each page, but prefer the (:title:) markup rather than the input field, the following settings should work:
          $EditTitle = 0;
          $ForceTitle = 1;

Fmt Variables

The following variables are provided, allowing a site admin to alter the HTML generated by the script.

  • $EditTitleInputFormat
This defines the HTML of the input field and its label that will appear in the edit form. The default is set as follows:
          $EditTitleInputFmt = "<label>\$[Title]: <input type='text' \$InputFormArgs /></label>";
  • $ForceTitleMessageFmt
This defines the error message as well as the HTML it's wrapped in when a title is not provided. The default is set as follows:
          $ForceTitleMessageFmt = '<h3 class="wikimessage">A Title must be defined for this page</h3>';
  • $EditTitlePattern
This it the regular expression pattern used to find, remove, and check for the (:title:) markup. It is set to be identical to the pattern used to define the (:title:) markup by PmWiki and there should be no reason to alter this variable.

Notes

Reasoning Behind Approach of Code (or Why did you do it that way?)

In order to maintain backward compatibility (things should still work if this recipe is disabled or removed) we don't want to change the way PmWiki stores and manages Page Titles. Therefore, before displaying the page content in the edit form, this script strips the "(:title ..." markup, displays the Title input field with the current title and the page content in the textarea without the "(:title ..." markup. Then, on save (or 'save and edit' or 'preview') the "(:title ..." markup is added back in (with new edited title) before PmWiki saves (or displays the preview of) the changed content. Upon disabling EditTitle, the "(:title ..." markup will again display in the edit form and work as previously.

An additional benefit of doing things this way, is that any changes to the Title are included in the version history of the page. Reverting to a previous Title is as simple as viewing the page history and restoring the previous state. If we were to save the Title separate from the page content, this would not be possible without also building a versioning system (or at least branching the existing one) for the Title alone.

Possible Improvements:

  • Add code to force users to enter a Title (as an option to turn on/off). <== Done (v 0.3)
  • Add ability to set ForceTitle for individual groups/pages independent of rest of recipe. <== Done (v 0.4)
  • Clean up the RemoveTitle function so it uses only one regex call. <== Done (v 0.5)
  • Add changes to the $PageEditFmt in case there is no Site.EditForm.<== Depreciated
  • Define a $Title global variable to use in the php code (see previous item).<== Depreciated
  • Add (:keyword:) markup to specify location of the title rather than editing template (thanks Sergey)Not necessary. Use !{$Titlespaced} instead. (See comments below)
  • Get ForceTitle to work independent of EditTitle. <== Done (v 1.0)

Prerequisite

  • This recipe was last tested and works on PmWiki version: 2.2.61
  • This recipe requires at least PmWiki version: 2.0.x and no other recipes
  • This recipe, version 1.1 was installed here 9 November, 2005

Releases

  • v 1.1Δ Waylan November 09, 2005, at 02:06 PM
    • ForceTitle is now aware of the $DeleteKeyPattern variable.
    • Set the (:title:) matching pattern ($EditTitlePattern) to be case-insensitive by default which is inline with PmWiki's default behavior.
  • v 1.0Δ Waylan November 04, 2005, at 11:05 AM
    • Now uses PmWiki's isEnabled() function, making toggles easier ($EditTitle is on and $ForceTitle off by default).
    • ForceTitle now works completely independant of EditTitle.
    • Added Fmt variables allowing additional customization by site admins.
  • v 0.9Δ Waylan October 28, 2005, at 01:30 PM
    • Fixed incompatibility with EditTemplates (See comments below).
    • Added input field label as built in feature (as a real html <label>).
  • v 0.8Δ Waylan October 27, 2005, at 10:56 AM
    • Added $EditTitle toggle - turn on or off for individual groups or pages.
    • Fix bug with page deletion - you can now delete pages when using ForceTitle.
  • v 0.7Δ (14 Oct, 2005) Waylan
    • Simplified RemoveTitle() function to use $new[title] to fill input field
  • v 0.6 (never released - listed for consistency) Waylan
  • v 0.5Δ (13 Oct, 2005) Waylan
    • Removed need to redefine the HandleEdit() function.
    • Rewrote RemoveTitle() function to only use one regex call rather than two.
    • 95 lines of code down to 53!! :P
  • v 0.4Δ (12 Oct, 2005) Waylan
    • Increased ForceTitle functionality (set for any page or group).
    • Defined default input width (set to 60).
    • Added AddTitle function bringing saving the Title inline with PmWiki ways (no ugly hacks to $_POST vars).
  • v 0.3 (11 Oct, 2005) Waylan
    • Added ability to ForceTitle with on/off toggle
  • v 0.2 (11 Oct, 2005) Waylan
    • Stopped the "(:title :)" markup from being added on save when the input field is left blank.
  • v 0.1 (11 Oct, 2005) Waylan
    • Usable but ugly in parts.

See Also

  • EditAttributes Edit a page's title, description and other attributes using separate EditForm fields

Contributors

Waylan

Comments

See discussion at EditTitle-Talk

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.