Esempio n. 1
0
 /**
  * gets tmost recent page revision from the wiki
  */
 public static function get_page_data($page_id = false)
 {
     if ($page_id === false) {
         return array();
     }
     /* check for cache */
     $cache_key = "bios/" . $page_id;
     $page_data = json_decode(wkwCache::get_cache($cache_key));
     if (!$page_data) {
         /* get page from MediaWIki */
         $results = self::query(array('query' => 'page', 'term' => $page_id));
         $page_data = array();
         if ($results && $results->query && $results->query->pages) {
             /* use $all_names to supplement data */
             $all_names = self::get_all_names();
             foreach ($results->query->pages as $id => $name) {
                 foreach ($all_names as $n) {
                     if ($n->pageid == $id) {
                         $page_data['pageid'] = $n->pageid;
                         $page_data['title'] = $n->title;
                         $page_data['surname'] = $n->surname;
                         if (count($name->revisions)) {
                             foreach ($name->revisions[0] as $rev => $content) {
                                 $page_data['full_text'] = $content;
                                 $c = explode("<h2", $content);
                                 $page_data['biog'] = $c[0];
                                 break;
                             }
                         } else {
                             $page_data['full_text'] = '';
                             $page_data['biog'] = '';
                         }
                     }
                 }
             }
         }
         wkwCache::save_cache($cache_key, json_encode($page_data));
     }
     return $page_data;
 }