summaryrefslogtreecommitdiff
path: root/bin/reevotech/ListarPaginas.php
blob: 96a4d6ef933f4f0cca72f4e5408325b7b5bd6c44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
# ----
# Copyright (C) 2013-2020 - Reevo Project (http://reevo.org)
# License: Affero GPL version 3 - http://www.gnu.org/licenses/agpl.html
# ES: Este script recibe el nombre de una Plantilla o Categoría y lista todas las paginas que lo usan.
# Se usa con: php ListarPaginas.php "Categoría:Experiencia"
# ----


// error_reporting(0);
// Load all the stuff
require_once( __DIR__ . '/vendor/autoload.php' );
require_once( __DIR__ .'/../../etc/global_config.php' );

// Log in to a wiki
$api = new \Mediawiki\Api\MediawikiApi( $wgServer .'/api.php' );
$api->login( new \Mediawiki\Api\ApiUser( $REEVO_WIKI_API_USER, $REEVO_WIKI_API_PASS ) );
$services = new \Mediawiki\Api\MediawikiFactory( $api );

// Obtengo el nombre del template como parámetro
if ($argv[1]) {

  $pageListGetter = $services->newPageListGetter();
  $tipo = explode(':',$argv[1]);
  switch ($tipo[0]) {
    case 'Categoria':
      $examplePages =  $pageListGetter->getPageListFromCategoryName( $argv[1] );
      break;
    case 'Plantilla':
      $examplePages =  $pageListGetter->getPageListFromPageTransclusions( $argv[1] );
      break;
    default:
      echo "No reconozco el tipo de objeto que estas intentando listar (debe ser Categoría o Plantilla)\n\n";
      exit();
  }
  $array = accessProtected($examplePages,'pages');
  foreach ( $array as $exPage ) {
      $pagename = $exPage->getTitle()->getText();
      echo "$pagename \n";
  }
} else {
  echo "Hay que indicar una plantilla como parametro \n";
}

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());






?>