From f7a76316ff5c6149403ade8325a6935d08f93bc3 Mon Sep 17 00:00:00 2001 From: Ichi Date: Sat, 5 Dec 2020 22:48:58 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BD=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=D1=81=D0=B5=D0=BC=D0=B8=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B0=D0=BC=D0=B8=20=D0=91=D0=94?= =?UTF-8?q?.=20=D0=92=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D1=81=D0=B2?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B1=D1=83=D0=B4=D1=83=D1=82=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D1=8F=D1=82=D1=8C=D1=81=D1=8F=20=D1=82?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5?= =?UTF-8?q?=D0=B4=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B5=D0=B2=D0=B8=D0=B7=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cContent.php | 25 ++++++++++++++++++------- cPageList.php | 21 +++++++++++++++++++++ cParse.php | 7 +++++-- params_init.json | 10 ++++++++++ params_init_page.json | 10 ++++++++++ params_page_list.json | 5 ++--- params_page_parse.json | 1 - 7 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 params_init.json create mode 100644 params_init_page.json diff --git a/cContent.php b/cContent.php index 369b650..bad247a 100644 --- a/cContent.php +++ b/cContent.php @@ -3,7 +3,7 @@ class cContent { - protected $urlAPI; + protected string $urlAPI; protected string $fileParams; protected $params; @@ -23,6 +23,15 @@ public function __construct($urlAPI) return $this->params = json_decode($json, true); } + public function initParamFile($file) + { + if (!file_exists($file)) { + return false; + } + $json = file_get_contents($file); + return json_decode($json, true); + } + /** * получаем данные от АПИ * @param array $params параметры обращения @@ -41,16 +50,18 @@ protected function getContent(array $params): array /** * при запросах, где ответы от АПИ превышают одну страницу - считываем все страницы * @param array $params параметры обращения к АПИ - * @return array ответ от АПИ + * @return array|null ответ от АПИ */ - protected function getContentAll(array $params): array + protected function getContentAll(array $params) { $out = $this->getContent($params); - $result = $out['query']['recentchanges']; - while ($out['query-continue']['recentchanges']['rccontinue'] != "") { - $params['rccontinue'] = $out['query-continue']['recentchanges']['rccontinue']; + $result = $out['query'][$params['list']]; + while ($out['query-continue'][$params['list']]['rccontinue'] != "" || + $out['query-continue'][$params['list']]['apcontinue'] != "") { + $params['rccontinue'] = $out['query-continue'][$params['list']]['rccontinue']; + $params['apcontinue'] = $out['query-continue'][$params['list']]['apcontinue']; $out = $this->getContent($params); - $result = array_merge($result, $out['query']['recentchanges']); + $result = array_merge($result, $out['query'][$params['list']]); } return $result; } diff --git a/cPageList.php b/cPageList.php index f728222..72a6b6f 100644 --- a/cPageList.php +++ b/cPageList.php @@ -15,6 +15,21 @@ public function __construct($config) $this->getPages(); } + public function init() + { + $params = $this->initParamFile("params_init.json"); + $pagesIndex = $this->getContentAll($params); + $pages = []; + foreach ($pagesIndex as $pageIndex) { + $page = new cPage( + $pageIndex['pageid'], + $pageIndex['title'], + date(DATE_RFC822, 0)); + $pages[] = $page; + } + return $pages; + } + function getPages() { $list = $this->getContentAll($this->params); @@ -64,6 +79,12 @@ public function getPageId($id) return $this->convertArrayToPage($pageDB); } + public function countPageDB() + { + $db = new cDB(); + return $db->getCountPage(); + } + public function countPage() { return count($this->listPage); diff --git a/cParse.php b/cParse.php index 7552322..71f76e4 100644 --- a/cParse.php +++ b/cParse.php @@ -52,9 +52,9 @@ function fillingURL() /** * получаем данные страницы (текст в формате html и список категорий) * @param int $id ИД страницы - * @return array массив с данными + * @return array|null массив с данными */ - private function parsePageByPageId(int $id): array + private function parsePageByPageId(int $id) { $params = $this->params; $params['pageid'] = $id; @@ -69,6 +69,9 @@ private function parsePageByPageId(int $id): array private function updatePageByPage(cPage &$page) { $parse = $this->parsePageByPageId($page->id); + if (!is_array($parse)) { + return false; + } $page->text = $parse['text']['*']; $page->revid = $parse['revid']; if (is_array($parse['categories'])) { diff --git a/params_init.json b/params_init.json new file mode 100644 index 0000000..171ad5f --- /dev/null +++ b/params_init.json @@ -0,0 +1,10 @@ +{ + "action": "query", + "format": "json", + "list": "allpages", + "iwurl": 1, + "rawcontinue": 1, + "aplimit": "2", + "utf8": 1, + "formatversion": "2" +} \ No newline at end of file diff --git a/params_init_page.json b/params_init_page.json new file mode 100644 index 0000000..171ad5f --- /dev/null +++ b/params_init_page.json @@ -0,0 +1,10 @@ +{ + "action": "query", + "format": "json", + "list": "allpages", + "iwurl": 1, + "rawcontinue": 1, + "aplimit": "2", + "utf8": 1, + "formatversion": "2" +} \ No newline at end of file diff --git a/params_page_list.json b/params_page_list.json index dd20200..52d87c0 100644 --- a/params_page_list.json +++ b/params_page_list.json @@ -9,7 +9,6 @@ "utf8": 1, "formatversion": "2", "rcdir": "older", - "rcprop": "title|timestamp|ids|revid|user", - "rclimit": "500", - "rctoponly": 1 + "rcprop": "title|timestamp|ids|user", + "rclimit": "500" } \ No newline at end of file diff --git a/params_page_parse.json b/params_page_parse.json index bd54c94..89d6dd0 100644 --- a/params_page_parse.json +++ b/params_page_parse.json @@ -5,5 +5,4 @@ "prop": "text|categories|categorieshtml|revid|langlinks|headhtml|url", "disableeditsection": 1, "utf8": 1 - } \ No newline at end of file