[pmwiki-users] FASTData change request
Crisses
crisses at kinhost.org
Wed Sep 27 09:50:22 CDT 2006
I updated my version of data.php:
//XES -added flag to break before resetting page
function Data($flag=0) {
...
// xes - added flag to stop running....
$MessagesFmt[] = "<h5 class='wikimessage'>$[$m]</h5>";
if ($flag) return;
if ($_POST[nextpage] == $pagename) HandleBrowse($pagename);
else Redirect(FmtPageName($_POST[nextpage], $pagename));
}
That part is fine.
I changed my config.php part of the hack:
function Simile () {
global $pagename, $DataKey, $ScriptUrl, $data, $MessagesFmt;
// save data that will be changed
$hold_pagename = $pagename;
// split up data from simile on form
$similes = explode("\n", $_POST['Simile']);
foreach ($similes as $value) {
if ((trim($value)) == "") continue;
$simile = explode(" ", $value);
$firstfour="$simile[0] $simile[1] $simile[2] $simile[3]";
// create new page title(s)
// Simile/BookTitle:AuthorName:FirstFourWordsOf
$newpage = $_POST['Work'] . ":" . $_POST['Author'] . ":" . $firstfour;
$pagename = MakePageName("Simile.HomePage", $newpage);
$_POST['makepage'] = $pagename;
// add new pages to wiki
Data(1);
}
// reset data that changed
$pagename = $hold_pagename;
HandleBrowse($pagename);
}
And it adds the pages I want, and returns the user to the original
page. Not perfect, but it's working so far.
But the AllRecentChanges and RecentChanges don't have the new pages.
Is that coming soon? :)
The relevant FASTData code I'm calling is:
if (substr($field, 0, 8) == "makepage") {
$contents = "";
$s = explode("|", $_POST[$field]);
if (isset($s[1])) $contents = GetTemplate("page",$s[1]);
if (! PageExists($s[0])) {
$page['text'] = $contents;
$page['title'] = $_POST[title];
Lock(2);
WritePage($s[0], $page);
Lock(0);
PageIndexUpdate($s[0]);
$m .= "Page $s[0] created.";
}
else "Page $s[0] already exists. Could not be created";
}
I think I remember PM saying that he was changing a function to
replace WritePage so that everything got updated properly across the
wiki, but if that's not implemented yet, this might do.
Crisses
On Sep 27, 2006, at 10:00 AM, Crisses wrote:
> I added a wrapper to config.php that parasites off of your Data
> function so that I (theoretically) wouldn't have to hack your script.
>
>
> function Simile () {
> global $pagename, $DataKey, $ScriptUrl, $data, $MessagesFmt;
>
> // save data that will be changed
> $hold_pagename = $pagename;
> // split up data from simile on form
>
> $similes = explode("\n", $_POST['Simile']);
> foreach ($similes as $value) {
> if ((trim($value)) == "") continue;
> $simile = explode(" ", $value);
> $firstfour="$simile[0] $simile[1] $simile[2] $simile[3]";
>
> // create new page title(s)
> // Simile/BookTitle:AuthorName:FirstFourWordsOf
> $newpage = $_POST['Work'] . ":" . $_POST['Author'] . ":" .
> $firstfour;
> $pagename = MakePageName("Simile.HomePage", $newpage);
> // add new pages to wiki
> Data();
> }
> // reset data that changed
>
>
> $pagename = $hold_pagename;
>
> }
> $HandleActions['simile'] = 'Simile';
>
>
> As it stands it only adds the first page sent to it. Everything up
> to the call to Data works just fine -- it iterates through, creates
> new page names, etc.
>
> I think I need a flag for Data() that will stop it from ending the
> script execution and return control to the wrapper script. That
> allows Data to be a usable hook for similar recipes to mine. i.e.
>
> your definition:
> function Data() {
> ...
> }
> becomes your definition:
> function Data($flag=0) {
> ...
> // check flag & if set, stop function execution; return control to
> the calling program
> if ($flag) { break; }
>
> //this is the end of the processing, so now you can refresh the
> page, and return the user to the browser
> // this will only execute if $flag=0 or $flag is unset by the
> calling program
> // i.e. this is what you're doing now, after the page is created,
> but before you refresh the page since that makes your script stop
> anything else from running
>
> }
>
> this change won't break anything already running using the Data
> function, but will allow more wrappers to use it. :)
>
> Crisses
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users/attachments/20060927/2d23a6c7/attachment.html
More information about the pmwiki-users
mailing list