Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente |
scrutaridata:impl:mediawiki [2009/06/02 19:36] – vincent | scrutaridata:impl:mediawiki [2016/07/06 18:38] (Version actuelle) – [class-MediawikiScrutariDataWriter.php] vincent |
---|
*Les premières méthodes de //MediawikiScrutariDataWriter// qui commencent par **set** sont des méthodes de définition des différents paramètres utilisés dans la méthode principale //writeScrutariData()// | *Les premières méthodes de //MediawikiScrutariDataWriter// qui commencent par **set** sont des méthodes de définition des différents paramètres utilisés dans la méthode principale //writeScrutariData()// |
*L'argument //$file// de la méthode //writeScrutariData()// correspond à un pointeur vers un fichier, s'il est omis, le XML sera écrit en sortie (fonction **echo**) | *L'argument //$file// de la méthode //writeScrutariData()// correspond à un pointeur vers un fichier, s'il est omis, le XML sera écrit en sortie (fonction **echo**) |
*Seules les pages de l'espace de nom principal sont extraites. Pour affiner la requête, il faut modifier la ligne //$requete = "SELECT page_id,page_title FROM page WHERE page_namespace=0 ORDER BY page_id";//. | *Seules les pages de l'espace de nom principal sont extraites et les pages de redirection sont ignorées. Pour affiner la requête, il faut modifier la ligne //$requete = "SELECT page_id,page_title FROM page WHERE page_namespace=0 AND page_is_redirect != 1 ORDER BY page_id";//. |
| |
Le résultat est accessible ici : http://scrutari.coredem.info/infos/php/coredem.scrutari-data.php?lang=fr. | Le résultat est accessible ici : http://scrutari.coredem.info/infos/php/coredem.scrutari-data.php?lang=fr. |
| |
class MediawikiScrutariDataWriter { | class MediawikiScrutariDataWriter { |
private $uuid; | private $authority; |
private $baseName; | private $baseName; |
private $baseIcon; | private $baseIcon; |
private $hrefParent; | private $hrefParent; |
| |
public function setUuid($uuid) { | public function setAuthority($authority) { |
$this->uuid = $uuid; | $this->authority = $authority; |
} | } |
| |
| |
public function writeScrutariData($file) { | public function writeScrutariData($file) { |
$xmlWriter = new UtilXmlWriter($file); | $xmlWriter = new UtilXmlWriter($file); |
$xmlWriter->appendDeclaration(); | $xmlWriter->appendDeclaration(); |
$xmlWriter->openTag("base"); | $xmlWriter->openTag("base"); |
$xmlWriter->openTag("base-metadata"); | $xmlWriter->openTag("base-metadata"); |
$xmlWriter->addElement("authority-uuid",$this->uuid); | $xmlWriter->addElement("authority",$this->authority); |
$xmlWriter->addElement("base-name",$this->baseName); | $xmlWriter->addElement("base-name",$this->baseName); |
$xmlWriter->addElement("base-icon",$this->baseIcon); | $xmlWriter->addElement("base-icon",$this->baseIcon); |
$xmlWriter->openTag("intitule-short"); | $xmlWriter->openTag("intitule-short"); |
$xmlWriter->addLibElement($this->lang,$this->baseIntituleShort); | $xmlWriter->addLibElement($this->lang,$this->baseIntituleShort); |
$xmlWriter->closeTag("intitule-short"); | $xmlWriter->closeTag("intitule-short"); |
$xmlWriter->openTag("intitule-long"); | $xmlWriter->openTag("intitule-long"); |
$xmlWriter->addLibElement($this->lang,$this->baseIntituleLong); | $xmlWriter->addLibElement($this->lang,$this->baseIntituleLong); |
$xmlWriter->closeTag("intitule-long"); | $xmlWriter->closeTag("intitule-long"); |
$xmlWriter->openTag("langs-ui"); | $xmlWriter->openTag("langs-ui"); |
$xmlWriter->addElement("lang",$this->lang); | $xmlWriter->addElement("lang",$this->lang); |
$xmlWriter->closeTag("langs-ui"); | $xmlWriter->closeTag("langs-ui"); |
$xmlWriter->closeTag("base-metadata"); | $xmlWriter->closeTag("base-metadata"); |
| |
$xmlWriter->write("<corpus corpus-name=\""); | $xmlWriter->write("<corpus corpus-name=\""); |
$xmlWriter->write($this->corpusName); | $xmlWriter->write($this->corpusName); |
$xmlWriter->write("\">"); | $xmlWriter->write("\">"); |
$xmlWriter->openTag("corpus-metadata"); | $xmlWriter->openTag("corpus-metadata"); |
$xmlWriter->openTag("intitule-corpus"); | $xmlWriter->openTag("intitule-corpus"); |
$xmlWriter->addLibElement($this->lang,$this->corpusIntituleCorpus); | $xmlWriter->addLibElement($this->lang,$this->corpusIntituleCorpus); |
$xmlWriter->closeTag("intitule-corpus"); | $xmlWriter->closeTag("intitule-corpus"); |
$xmlWriter->openTag("intitule-fiche"); | $xmlWriter->openTag("intitule-fiche"); |
$xmlWriter->addLibElement($this->lang,$this->corpusIntituleFiche); | $xmlWriter->addLibElement($this->lang,$this->corpusIntituleFiche); |
$xmlWriter->closeTag("intitule-fiche"); | $xmlWriter->closeTag("intitule-fiche"); |
$xmlWriter->addElement("type","CNC"); | $xmlWriter->addElement("type","CNC"); |
$xmlWriter->addElement("href-parent",$this->hrefParent); | $xmlWriter->addElement("href-parent",$this->hrefParent); |
$xmlWriter->closeTag("corpus-metadata"); | $xmlWriter->closeTag("corpus-metadata"); |
| |
$requete = "SELECT page_id,page_title FROM page WHERE page_namespace=0 ORDER BY page_id"; | $requete = "SELECT page_id,page_title FROM page WHERE page_namespace=0 AND page_is_redirect != 1 ORDER BY page_id"; |
| |
$resultat = mysql_query($requete); | $resultat = mysql_query($requete); |
| |
while($row = mysql_fetch_row($resultat)) { | while($row = mysql_fetch_row($resultat)) { |
$page_id = $row[0]; | $page_id = $row[0]; |
$page_title = $row[1]; | $page_title = $row[1]; |
$xmlWriter->write("<fiche fiche-id=\""); | $xmlWriter->write("<fiche fiche-id=\""); |
$xmlWriter->write($page_id); | $xmlWriter->write($page_id); |
$xmlWriter->write("\">"); | $xmlWriter->write("\">"); |
$titre = str_replace("_"," ",$page_title); | $titre = str_replace("_"," ",$page_title); |
$xmlWriter->addElement("titre",$titre); | $xmlWriter->addElement("titre",$titre); |
$xmlWriter->addElement("lang",$this->lang); | $xmlWriter->addElement("lang",$this->lang); |
$href = rawurlencode($page_title); | $href = rawurlencode($page_title); |
$xmlWriter->addElement(href,$href); | $xmlWriter->addElement(href,$href); |
$xmlWriter->closeTag("fiche"); | $xmlWriter->closeTag("fiche"); |
} | } |
| |
$xmlWriter->closeTag("corpus"); | $xmlWriter->closeTag("corpus"); |
$xmlWriter->closeTag("base"); | $xmlWriter->closeTag("base"); |
} | } |
| |