/** * Execute a page move/rename * * @param string $src original ID * @param string $dst new ID * @return bool */ public function movePage($src, $dst) { if (!$this->checkPage($src, $dst)) { return false; } // lock rewrites helper_plugin_move_rewrite::addLock(); /** @var helper_plugin_move_rewrite $Rewriter */ $Rewriter = plugin_load('helper', 'move_rewrite'); // remember what this page was called before the move in meta data $Rewriter->setSelfMoveMeta($src); // ft_backlinks() is not used here, as it does a hidden page and acl check but we really need all pages $affected_pages = idx_get_indexer()->lookupKey('relation_references', $src); $affected_pages[] = $dst; // the current page is always affected, because all relative links may have changed $affected_pages = array_unique($affected_pages); $src_ns = getNS($src); $src_name = noNS($src); $dst_ns = getNS($dst); $dst_name = noNS($dst); // pass this info on to other plugins $eventdata = array('opts' => array('ns' => $src_ns, 'name' => $src_name, 'newns' => $dst_ns, 'newname' => $dst_name), 'affected_pages' => &$affected_pages, 'src_id' => $src, 'dst_id' => $dst); // give plugins the option to add their own meta files to the list of files that need to be moved // to the oldfiles/newfiles array or to adjust their own metadata, database, ... // and to add other pages to the affected pages $event = new Doku_Event('PLUGIN_MOVE_PAGE_RENAME', $eventdata); if ($event->advise_before()) { lock($src); /** @var helper_plugin_move_file $FileMover */ $FileMover = plugin_load('helper', 'move_file'); // Move the Subscriptions & Indexes (new feature since Spring 2013 release) $Indexer = idx_get_indexer(); if (($idx_msg = $Indexer->renamePage($src, $dst)) !== true || ($idx_msg = $Indexer->renameMetaValue('relation_references', $src, $dst)) !== true) { msg(sprintf($this->getLang('indexerror'), $idx_msg), -1); return false; } if (!$FileMover->movePageMeta($src_ns, $src_name, $dst_ns, $dst_name)) { msg(sprintf($this->getLang('metamoveerror'), $src), -1); return false; } // prepare the summary for the changelog entry if ($src_ns == $dst_ns) { $lang_key = 'renamed'; } elseif ($src_name == $dst_name) { $lang_key = 'moved'; } else { $lang_key = 'move_rename'; } $summary = $this->symbol . ' ' . sprintf($this->getLang($lang_key), $src, $dst); // Wait a second when the page has just been rewritten $oldRev = filemtime(wikiFN($src)); if ($oldRev == time()) { sleep(1); } // Save the updated document in its new location $text = rawWiki($src); saveWikiText($dst, $text, $summary); // Delete the orginal file if (@file_exists(wikiFN($dst))) { saveWikiText($src, '', $summary); } // Move the old revisions if (!$FileMover->movePageAttic($src_ns, $src_name, $dst_ns, $dst_name)) { // it's too late to stop the move, so just display a message. msg(sprintf($this->getLang('atticmoveerror'), $src), -1); } // Add meta data to all affected pages, so links get updated later foreach ($affected_pages as $id) { $Rewriter->setMoveMeta($id, $src, $dst, 'pages'); } unlock($src); } $event->advise_after(); // store this for later use $this->affectedPages = $affected_pages; // unlock rewrites helper_plugin_move_rewrite::removeLock(); return true; }