Ejemplo n.º 1
0
 /**
  * Rename page
  */
 function rename($a_new_name)
 {
     global $ilDB;
     // replace unallowed characters
     $a_new_name = str_replace(array("<", ">"), '', $a_new_name);
     // replace multiple whitespace characters by one single space
     $a_new_name = trim(preg_replace('!\\s+!', ' ', $a_new_name));
     $page_title = ilWikiUtil::makeDbTitle($a_new_name);
     $pg_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $page_title);
     $xml_new_name = str_replace("&", "&amp;", $a_new_name);
     if ($pg_id == 0 || $pg_id == $this->getId()) {
         include_once "./Services/COPage/classes/class.ilInternalLink.php";
         $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0);
         foreach ($sources as $s) {
             if ($s["type"] == "wpg:pg") {
                 $wpage = new ilWikiPage($s["id"]);
                 $col = ilWikiUtil::processInternalLinks($wpage->getXmlContent(), 0, IL_WIKI_MODE_EXT_COLLECT);
                 $new_content = $wpage->getXmlContent();
                 foreach ($col as $c) {
                     // this complicated procedure is needed due to the fact
                     // that depending on the collation e = é is true
                     // in the (mysql) database
                     // see bug http://www.ilias.de/mantis/view.php?id=11227
                     $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform);
                     $t2 = ilWikiUtil::makeDbTitle($this->getTitle());
                     // this one replaces C2A0 (&nbsp;) by a usual space
                     // otherwise the comparision will fail, since you
                     // get these characters from tiny if more than one
                     // space is repeated in a string. This may not be
                     // 100% but we do not store $t1 anywhere and only
                     // modify it for the comparison
                     $t1 = preg_replace('/\\xC2\\xA0/', ' ', $t1);
                     $t2 = preg_replace('/\\xC2\\xA0/', ' ', $t2);
                     $set = $ilDB->query($q = "SELECT " . $ilDB->quote($t1, "text") . " = " . $ilDB->quote($t2, "text") . " isequal");
                     $rec = $ilDB->fetchAssoc($set);
                     if ($rec["isequal"]) {
                         $new_content = str_replace("[[" . $c["nt"]->mTextform . "]]", "[[" . $xml_new_name . "]]", $new_content);
                         if ($c["text"] != "") {
                             $new_content = str_replace("[[" . $c["text"] . "]]", "[[" . $xml_new_name . "]]", $new_content);
                         }
                         $add = $c["text"] != "" ? "|" . $c["text"] : "";
                         $new_content = str_replace("[[" . $c["nt"]->mTextform . $add . "]]", "[[" . $xml_new_name . $add . "]]", $new_content);
                     }
                 }
                 $wpage->setXmlContent($new_content);
                 //echo htmlentities($new_content);
                 $wpage->update();
             }
         }
         include_once "./Modules/Wiki/classes/class.ilObjWiki.php";
         if (ilObjWiki::_lookupStartPage($this->getWikiId()) == $this->getTitle()) {
             ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name);
         }
         $this->setTitle($a_new_name);
         $this->update();
     }
     return $a_new_name;
 }