login( new \Mediawiki\Api\ApiUser( $REEVO_WIKI_API_USER, $REEVO_WIKI_API_PASS ) ); $services = new \Mediawiki\Api\MediawikiFactory( $api ); // Obtengo el nombre de la página como parámetro function GeneraSnapshot($pagetitle, $services) { $page = $services->newPageGetter()->getFromTitle( $pagetitle ); $pagecontent = $page->getRevisions()->getLatest(); if (!$pagecontent) { echo "No existe una página con el nombre '$pagetitle'\n"; return; } $page_archivo = $services->newPageGetter()->getFromTitle( $pagetitle . '/Archivo'); $pagecontent_archivo = $page_archivo->getRevisions()->getLatest(); if ($pagecontent_archivo) { echo "La página '$pagetitle' ya tiene una subpágina /Archivo\n"; return; } $pagecontent = $page->getRevisions()->getLatest()->getContent()->getData(); // armo un array con las propiedades de SMW $rows = explode("|", $pagecontent); foreach($rows as $row => $data) { $row_data = explode('=', $data); $page_properties[$row_data[0]] = $row_data[1]; } if (array_key_exists('prensa:url', $page_properties)) { $urltmp = $page_properties['prensa:url']; $url = preg_replace( "/\r|\n/", "", $urltmp ); // echo $url; } else { echo "La página '$pagetitle' no tiene definida la propiedad 'prensa:url'\n"; return; } // Obtiene copia de texto del articulo $command = 'curl -Ls ' . $url . ' | unfluff | jq -r .text > /tmp/linkcontent'; // echo "$command\n"; exec($command); // Almacena la imagen exec('wget "https://manet.herokuapp.com/?width=1920&hesight=1080&quality=0.3&url=`echo ' . $url . ' | perl -p -e \'s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg\'`" -O /tmp/temp.jpg && convert -strip -interlace Plane -quality 25% /tmp/temp.jpg /tmp/final.jpg'); // Definimos el nombre del archivo de la imagen $pagename = str_replace( ":", "-", $pagetitle); $snapshot_name = $pagename . '-snapshot.jpg'; $snaphot_pagecontent = 'Snapshot generada para [['. $pagetitle .']]'; $snaphot_desc = 'Snapshot generada para [['. $pagetitle .']]'; $fileUploader = $services->newFileUploader(); $fileUploader->setChunkSize( 1024 * 1024 * 10 ); $fileUploader->upload( $snapshot_name, '/tmp/final.jpg', $snaphot_pagecontent, $snaphot_desc ); // Crea nueva o actualiza existente $fileContent = file_get_contents('/tmp/linkcontent'); $fileContent = iconv("UTF-8","ISO-8859-1//IGNORE",$fileContent); $fileContent = iconv("ISO-8859-1","UTF-8",$fileContent); $linkContent = ' {{Prensa-Archivo |prensa:archivo:imagen='. $snapshot_name.' |prensa:archivo:texto='; $linkContent .= $fileContent; $linkContent .= ' }}'; $newContent = new \Mediawiki\DataModel\Content( $linkContent ); $title = new \Mediawiki\DataModel\Title( $pagetitle . '/Archivo' ); $identifier = new \Mediawiki\DataModel\PageIdentifier( $title ); $revision = new \Mediawiki\DataModel\Revision( $newContent, $identifier ); $services->newRevisionSaver()->save( $revision ); } if ($argv[1]) { GeneraSnapshot($argv[1],$services); } else { echo "Al no indicar una página, voy a generar los snapshots de todas las pagínas que usen Plantilla:Prensa y que no tengan snapshot \n"; // Obtengo todas las paginas con Plantilla:Prensa $pageListGetter = $services->newPageListGetter(); $examplePages = $pageListGetter->getPageListFromPageTransclusions( 'Template:Prensa' ); $array = accessProtected($examplePages,'pages'); foreach ( $array as $exPage ) { $pagename = $exPage->getTitle()->getText(); echo "$pagename \n"; GeneraSnapshot($pagename, $services); } } function accessProtected($obj, $prop) { $reflection = new ReflectionClass($obj); $property = $reflection->getProperty($prop); $property->setAccessible(true); return $property->getValue($obj); } // print_r($examplePages); // $myArray = json_decode(json_encode($examplePages), true); // print_r($examplePages->getPageList()); ?>