version=pmwiki-2.2.4 ordered=1 urlencoded=1 agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5 author=Simon charset=ISO-8859-1 csum=category ctime=1208705045 host=202.37.32.2 name=PmWiki.UpdatePage rev=15 targets=PmWiki.Functions,PmWiki.CustomMarkup,Cookbook.MarkupExpressionSamples,PmWiki.CustomActions,Category.PmWikiInternals,Category.PmWikiDeveloper text=(:Summary:Techical notes on the UpdatePage function:)%0a(:Audience:Developers:)%0aThis page is a collection of technical notes regarding [@UpdatePage()@]. You can get all the same information by code-reading in pmwiki.php, but this page summarizes things in a slightly more readable form...%0a%0aIt is updated as of 2.2.0 Beta65.%0a%0a[@UpdatePage()@] allows cookbook recipes to mimic the behavior of editing wiki pages via the browser. Internally, PmWiki does several house keeping tasks which are accessible via this function (preserving history/diff information, updating page revision numbers, updating RecentChanges pages, sending email notifications, etc._%0a* "Page object" refers to an array pulled from [@ReadPage($pagename); @] Note that $new['text'] should contain all page data for the new version of the page. %0a* If a page doesn't exist, UpdatePage() will attempt to create it.%0a* Ignoring $old (e.g. [@UpdatePage($pagename, '', $new);@]) will erase all historical page data---a ''tabula rasa''.%0a%0a[@UpdatePage()@] does very little itself other than traverse [@$EditFunctions@] and call each function contained there. ([@$EditFunctions@] can be overridden by the 4th argument [@$fnlist@], but this is fairly rare).%0a%0aThe global [@$IsPagePosted@] is set to true at the start of UpdatePage() and then returned at the end of this function. Any of the intervening functions have the potential of setting it to false if an error condition occurs.%0a%0aHere is the definition of $EditFunctions from pmwiki.php:%0a%0a[@$EditFunctions = array('EditTemplate', 'RestorePage', 'ReplaceOnSave',%0a 'SaveAttributes', 'PostPage', 'PostRecentChanges', 'AutoCreateTargets',%0a 'PreviewPage');@]%0a%0a!EditTemplate%0aThis function allows pre-populating new pages with the contents of a template page. If the $new['text'] contains anything then this function does nothing.%0a%0aThe pagename of the template can be passed in the [@$_REQUEST['template']@].%0a%0aOtherwise the [@$EditTemplatesFmt@] array is traversed and each page read until obtaining some text which then becomes the text of the $new['text'].%0a%0a!RestorePage%0a%0aOn a normal save of a page this function does nothing.%0a%0aThe value for [@$Restore@] can be passed by argument to the function, but it will not in the context of UpdatePage(). The value will be obtained instead from [@$_REQUEST['restore']@]. If this value is not set then this function will do nothing. If this value is set to a timestamp then the page history will be traversed and the various diff's in page history will be reverse applied until the requested timestamp.%0a%0a!ReplaceOnSave%0a%0aThere are 2 arrays: [@$ROEPatterns@] and [@$ROSPatterns@]. In each array the key to the hash is the search-pattern and the value to the hash is the replace-pattern. [@$ROEPatterns@] is replaced on each edit, [@$ROSPatterns@] only if [@$EnablePost@] is set. %0a%0a!SaveAttributes%0a%0aSeveral different attributes are calculated to become one of the keys of the $new[] page array. (Each of these will then become their own line in the pagefile.) Targets are calculated as a space-separated list of pages which are linked to from this page. Properties held in the global [@$SaveProperties@] are copied from the $page[] (old page) array.%0a%0a!PostPage%0a%0a[@$IsPagePosted@] is set to false.%0a%0aIf [@$EnablePost@] is true then these steps occur:%0a*Attributes such as 'charset' ([@$Charset@]), 'author' ([@$Author@]), 'author:%3ctimestamp>' ([@$Author@]), and 'host:%3ctimestamp>' ([@$_SERVER['REMOTE_ADDR']@]) are set.%0a*A diff is done between the previous text and the current text and the result stored as a '%3ctimestamp>' key.%0a*If the text matches the global [@$DeleteKeyPattern@] then the page is deleted.%0a*WritePage() is called %0a*[@$IsPagePosted@] is set to true.%0a%0a!PostRecentChanges%0a%0aIf [@$IsPagePosted@] is NOT true then do nothing.%0a%0aThe global array [@$RecentChangesFmt[]@] is traversed with the KEY to the hashed array being the pagename where the changes should be written to and the VALUE of the hashed array being the text to be written to the end of that page.%0a%0aIf the number of lines in the recentchanges page exceeds the global [@$RCLinesMax@] then the page is chopped appropriately.%0a%0aThe recentchanges page is written via WritePage().%0a%0a!AutoCreateTargets%0a%0aIf link targets within the page match some global and they do not exist then they will be automatically created. See also [[(Cookbook:)AutoCreatePages]].%0a%0a!PreviewPage%0a%0aThis function does nothing if you're not doing a preview.%0a%0a----%0a%0a!!Notes%0a%0a!!!!!Can I call @@UpdatePage()@@ directly from @@config.php@@?%0aNo. As stated on the [[PmWiki/Functions | PmWiki/Functions]]: @@UpdatePage()@@ cannot be called directly from @@config.php@@ because there are necessary initializations which occur later in @@pmwiki.php@@. It is not enough to just load @@stdconfig.php@@. If you want to use @@UpdatePage()@@ you will need to do it within a [[PmWiki/CustomMarkup | custom markup]], a [[Cookbook/MarkupExpressionSamples | custom markup expression]], or a [[PmWiki/CustomActions | custom action]].%0a%0a----%0a%0aCategory: [[!PmWiki Internals]] [[!PmWiki Developer]] time=1250635981