Wiki source for PreventLongTags


Show raw source

[''Note: This is now included in Wikka by default starting with Wikka 1.1.3.1''. Thanks to DreckFehler.]

VeryLongTagWhichConfusesWakkaWikiBecauseOnlyPartsOfItWillBeStoredInThePagesTable - if this link looks strange to you, try out how strange it looks to wakkawiki ;)

this mod takes care that wakkawiki will not be fed with tags that are too long for saving. this only occurs to "new" pages, because any existing page has a tag that fits in the database. since such new pages call the edit-method, we'll put our stuff there.

we need a mechanism to chose a new (shorter) tag which will be postet as an input-field called "newtag". if the editor receives such a field, it should redirect to newtag/edit.

let's do this redirect first. insert at the top of the method edit.php after the first if-clause

**if ($this->""HasAccess""("write") && $this->""HasAccess""("read")) {**

the following line:

%%if ($newtag = $_POST["newtag"]) $this->Redirect($this->href("edit", $newtag));%%

now we need a form, which posts that newtag. insert the **uncommented lines** near the end of the edit-method after the preview-section:

%%$this->maxtaglen = 50; // check length of the field "tag" in the wakka_pages table for the correct value. it's only for testing purpose. we will advance it later, see below.

// if ($_POST["submit"] == "Preview") {
// leave the preview-stuff as is
} else if (!$this->page && strlen($this->tag) > $this->maxtaglen) {
$output = "<div class='error'>Tag too long!</div>\n";
$output .= $this->FormOpen("edit");
$output .= "<input name='newtag' size='50' value='".htmlspecialchars($this->tag)."' />"; // use htmlspecialchars($this->tag, ENT_QUOTES) if you need single quotation marks (i.e. apostrophies) in tags
$output .= "<input name='submit' type='submit' value='Rename' /> ";
$output .= $this->FormClose();

$this->tag = substr($this->tag, 0, $this->maxtaglen); // truncate tag to feed a backlinks-handler with the correct value. may be omited. it only works if the link to a backlinks-handler is built in the footer.
// } else {
// edit-form follows here
// }
// print($output);%%

that's it, folks!

if everything works fine, we can set the maxtaglen-value automatically to the propper value, even if the tag-field is altered in the database.

replace the line **$this->maxtaglen = 50;** from above with the following code:

%%if ($result = mysql_query("describe ".$this->config["table_prefix"]."pages tag")) {
$field = mysql_fetch_assoc($result);
if (preg_match("/varchar\((\d+)\)/", $field["Type"], $matches)) $this->maxtaglen = $matches[1];
}%%

i've placed this code at the end of the constructor of the wakka-class (in wakka.php), but it works fine within the edit-method.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki