Skip to content

Commit

Permalink
Fix checking of user opt-in page for advanced stats
Browse files Browse the repository at this point in the history
https://phabricator.wikimedia.org/T179304

Comment out querying wb_entity_per_page as that table has been removed

Bug: https://phabricator.wikimedia.org/T179293
  • Loading branch information
MusikAnimal committed Oct 30, 2017
1 parent b132468 commit 0cce72f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 89 deletions.
74 changes: 39 additions & 35 deletions src/Xtools/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,41 +421,45 @@ public function getCheckWikiErrors()
*/
public function getWikidataErrors()
{
$errors = [];

if (empty($this->getWikidataId())) {
return [];
}

$wikidataInfo = $this->getRepository()->getWikidataInfo($this);

$terms = array_map(function ($entry) {
return $entry['term'];
}, $wikidataInfo);

$lang = $this->getLang();

if (!in_array('label', $terms)) {
$errors[] = [
'prio' => 2,
'name' => 'Wikidata',
'notice' => "Label for language <em>$lang</em> is missing", // FIXME: i18n
'explanation' => "See: <a target='_blank' " .
"href='//www.wikidata.org/wiki/Help:Label'>Help:Label</a>",
];
}

if (!in_array('description', $terms)) {
$errors[] = [
'prio' => 3,
'name' => 'Wikidata',
'notice' => "Description for language <em>$lang</em> is missing", // FIXME: i18n
'explanation' => "See: <a target='_blank' " .
"href='//www.wikidata.org/wiki/Help:Description'>Help:Description</a>",
];
}

return $errors;
// FIXME: wikidatawiki_p.wb_entity_per_page is no more.
// Figure out how to check for missing description, etc.
return [];

// $errors = [];

// if (empty($this->getWikidataId())) {
// return [];
// }

// $wikidataInfo = $this->getRepository()->getWikidataInfo($this);

// $terms = array_map(function ($entry) {
// return $entry['term'];
// }, $wikidataInfo);

// $lang = $this->getLang();

// if (!in_array('label', $terms)) {
// $errors[] = [
// 'prio' => 2,
// 'name' => 'Wikidata',
// 'notice' => "Label for language <em>$lang</em> is missing", // FIXME: i18n
// 'explanation' => "See: <a target='_blank' " .
// "href='//www.wikidata.org/wiki/Help:Label'>Help:Label</a>",
// ];
// }

// if (!in_array('description', $terms)) {
// $errors[] = [
// 'prio' => 3,
// 'name' => 'Wikidata',
// 'notice' => "Description for language <em>$lang</em> is missing", // FIXME: i18n
// 'explanation' => "See: <a target='_blank' " .
// "href='//www.wikidata.org/wiki/Help:Description'>Help:Description</a>",
// ];
// }

// return $errors;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Xtools/ProjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function pageHasContent(Project $project, $namespaceId, $pageTitle)
. " LIMIT 1";
$params = [
'ns' => $namespaceId,
'title' => $pageTitle,
'title' => str_replace(' ', '_', $pageTitle),
];
$pages = $conn->executeQuery($query, $params)->fetchAll();
return count($pages) > 0;
Expand Down
107 changes: 54 additions & 53 deletions tests/Xtools/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,50 +229,50 @@ public function testUsersEdits()
//$this->assertCount(3, $page->getRevisions($user)->getCount());
}

/**
* Wikidata errors. With this test getWikidataInfo doesn't return a Description,
* so getWikidataErrors should complain accordingly
*/
public function testWikidataErrors()
{
$pageRepo = $this->getMock(PagesRepository::class, ['getWikidataInfo', 'getPageInfo']);

$pageRepo
->method('getWikidataInfo')
->with()
->willReturn([
[
'term' => 'label',
'term_text' => 'My article',
],
]);
$pageRepo
->method('getPageInfo')
->with()
->willReturn([
'pagelanguage' => 'en',
'pageprops' => [
'wikibase_item' => 'Q123',
],
]);

$page = new Page(new Project('exampleWiki'), 'Page');
$page->setRepository($pageRepo);

$wikidataErrors = $page->getWikidataErrors();

$this->assertArraySubset(
[
'prio' => 3,
'name' => 'Wikidata',
],
$wikidataErrors[0]
);
$this->assertContains(
'Description',
$wikidataErrors[0]['notice']
);
}
// /**
// * Wikidata errors. With this test getWikidataInfo doesn't return a Description,
// * so getWikidataErrors should complain accordingly
// */
// public function testWikidataErrors()
// {
// $pageRepo = $this->getMock(PagesRepository::class, ['getWikidataInfo', 'getPageInfo']);

// $pageRepo
// ->method('getWikidataInfo')
// ->with()
// ->willReturn([
// [
// 'term' => 'label',
// 'term_text' => 'My article',
// ],
// ]);
// $pageRepo
// ->method('getPageInfo')
// ->with()
// ->willReturn([
// 'pagelanguage' => 'en',
// 'pageprops' => [
// 'wikibase_item' => 'Q123',
// ],
// ]);

// $page = new Page(new Project('exampleWiki'), 'Page');
// $page->setRepository($pageRepo);

// $wikidataErrors = $page->getWikidataErrors();

// $this->assertArraySubset(
// [
// 'prio' => 3,
// 'name' => 'Wikidata',
// ],
// $wikidataErrors[0]
// );
// $this->assertContains(
// 'Description',
// $wikidataErrors[0]['notice']
// );
// }

/**
* Test getErros and getCheckWikiErrors.
Expand All @@ -292,15 +292,16 @@ public function testErrors()
'explanation' => 'This is how to fix the error'
],
];
$wikidataErrors = [
[
'prio' => 3,
'name' => 'Wikidata',
'notice' => 'Description for language <em>en</em> is missing',
'explanation' => "See: <a target='_blank' " .
"href='//www.wikidata.org/wiki/Help:Description'>Help:Description</a>",
],
];
// $wikidataErrors = [
// [
// 'prio' => 3,
// 'name' => 'Wikidata',
// 'notice' => 'Description for language <em>en</em> is missing',
// 'explanation' => "See: <a target='_blank' " .
// "href='//www.wikidata.org/wiki/Help:Description'>Help:Description</a>",
// ],
// ];
$wikidataErrors = [];

$pageRepo->method('getCheckWikiErrors')
->willReturn($checkWikiErrors);
Expand Down

0 comments on commit 0cce72f

Please sign in to comment.