AnsweredAssumed Answered

Mediawiki-Integration: Redirect to Wikipages

Question asked by nicof on Jul 22, 2008
Latest reply on Jan 2, 2009 by siquser
Hi everyone,

the current Mediawiki-Integration saves the content of Wikipages in the Alfresco-Repository.

If your search results in a Wikipage, you can open it and just see the plain text of the content. The following hack will make it redirect you to the referred Wikipage itself.

Open ExternalStoreAlfresco.php in the extensions-folder of your Mediawiki.
Change the function fetchFromURL($url) so it looks like this:
   public function fetchFromURL($url) 
   {
      $version = $this->urlToVersion($url);      
      return preg_replace("#\n<html>\n<head>\n<title></title><meta http-equiv=\"refresh\" content=\"0; URL=http://XXXYOURSERVERADDRESSXXX/index.php/.*\">\n</head>\n<body>\n#", "", preg_replace("#\n</body>\n</html>#", "", $version->cm_content->content, 1), 1);
   }

Replace the function &store($store, $data) with:
   public function &store($store, $data) 
   {
           $url = $_SESSION["lastVersionUrl"];
      $node = null;
      
      $isNormalText = (strpos($url, 'alfresco://') === false);
      
      if ($url != null && $isNormalText == false)
      {
         $node = $this->urlToNode($url);   
      }
      else
      {
         $node = $this->wikiSpace->createChild("cm_content", "cm_contains", "cm_".$_SESSION["title"]);
         $node->cm_name = $_SESSION["title"];
      
         $node->addAspect("cm_versionable");
         $node->cm_initialVersion = false;
         $node->cm_autoVersion = false;
      }
      
      // Set the content and save
      $node->setContent("cm_content", "text/html", "UTF-8", "\n<html>\n<head>\n<title></title><meta http-equiv=\"refresh\" content=\"0; URL=http://XXXYOURSERVERADDRESSXXX/index.php/" . preg_replace("#Image - #", "Image:", $_SESSION["title"]) . "\">\n</head>\n<body>\n" . $data . "\n</body>\n</html>");      
      $this->session->save();
      
      $description = $_SESSION["description"];
      if ($description == null)
      {
         $description = "";
      }
      
      // Create the version
      $version = $node->createVersion($description);
      
      $result = "alfresco://".$node->store->scheme."/".$node->store->address."/".$node->id."/".$version->store->scheme."/".$version->store->address."/".$version->id;      
      return $result;      
   }

That's all, I hope someone will like it. :)


Regards

Nico

Outcomes