Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting dates range for Page History #149

Merged
merged 1 commit into from
Jan 12, 2018
Merged

Add setting dates range for Page History #149

merged 1 commit into from
Jan 12, 2018

Conversation

Albert221
Copy link
Contributor

Bug: T181694

Copy link
Member

@MusikAnimal MusikAnimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! I left a few comments. This is not a complete review. I unfortunately might be away much of the day, but I'll definitely get to this as soon as possible.

@@ -121,13 +121,22 @@ public function gadgetAction(Request $request)

/**
* Display the results.
* @Route("/articleinfo/{project}/{article}", name="ArticleInfoResult", requirements={"article"=".+"})
* @Route(
* "/articleinfo/{project}/{start}/{end}/{article}", name="ArticleInfoResult",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This routing change will be a problem :( ArticleInfo is very popular and there are a lot of links to it. As optional parameters it'd be better if the start/end dates are at the end, but I suppose there's the caveat that "My article/2017-01-23/2018-01-23" is a valid page title.

Maybe we should use query string parameters instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we could use some trickery to handle the "My article/2017-01-23/2018-01-23" edge case, or perhaps we don't care... Interested to hear your thoughts.

/** @var false|int From what date to obtain records. */
protected $startDate;

/** @var false|string To what date to obtain records. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string or int?

}

list($start, $end) = $this->translateDatesToYYYYMMDD($this->startDate, $this->endDate);
list($start, $end) = $this->applyDatesDefaults($start, $end, $latest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why we're using $latest in this case. The pageviews should be for the same date as what was requested. So if they only gave an end date, it'd use the date of the first revision to the specified end date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was what I meant when I told you on IRC that I have minor logical-thinking problems :D

* @param string $field
* @return string
*/
public static function createDatesConditions($start, $end, $tableAlias = '', $field = 'rev_timestamp')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we moved this to Repository? Then it's accessible in PageRepository, ArticleInfoRepository, etc., and it doesn't have to be static.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second that

@MusikAnimal
Copy link
Member

Now that I'm finally home, I'm able to do a more thorough review. A few more issues, I'm afraid:

  • "Page size" is not that of the last edit. In the view, instead of calling page.length I would do ai.length, and that method in ArticleInfo will conditionally call $this->page->getLength() or $this->lastEdit->getLength() based on whether a date range was provided. Probably should have some sort of hasDateRange() method in ArticleInfo, too.
  • "Total edits" does not respect the date range. For this I suppose we need to keep a running total of the number of edits in the while loop of ArticleInfo::parseHistory(), setting it on $this->numRevisionsProcessed, and then hopefully getNumRevisions() will just work (because it is called after ArticleInfo::prepareData() is called).
  • The "Month counts" section always goes through December, even if you put say, July, as the end date.
  • Super duper minor priority -- the Pageviews links at the top ("Pageviews (All languages · Redirects)") should pass in the date range to the Pageviews tool. This would mean allowing for start/end parameters in the wiki.pageviewsLinks macro. Definitely don't worry about this! I can do it :)

Some things simply need to be hidden when there is a date range:

  • "Assessment" and "Bugs" -- both in General stats and the dedicated <section>'s.
  • "Page watchers"
  • The "(60 days)" part of the "Pageviews (60 days)" label.
  • Possibly the "Edits in the past..." fields? The numbers are right, but are relative to the end date, so the language "in the past" might be confusing. I'm definitely OK just hiding them altogether, as I don't think that information is as relevant when working within a date range.

If you need/want help with ANY of this please feel free to ask. I was worried this task was a bit too big, so don't feel like you have to do everything!

@Albert221
Copy link
Contributor Author

I localized issue of having all months to be here:

];
for ($i = 1; $i <= 12; $i++) {
$timeObj = mktime(0, 0, 0, $i, 1, $editYear);
// Don't show zeros for months before the first edit or after the current month.
if ($timeObj < $firstEditTime || $timeObj > strtotime('last day of this month')) {
continue;
}
$this->yearMonthCounts[$editYear]['months'][sprintf('%02d', $i)] = [
'all' => 0,
'minor' => 0,
'anon' => 0,
'automated' => 0,
];
}

Copy link
Member

@MusikAnimal MusikAnimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good!! Just a few more minor complaints :) Thanks so much, I know this is a lot of work!

@include center('vertical');
right: 0;
font-size: 70%;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor complaint: We could use some mobile-friendliness here, something like:

@media (max-width: $bootstrap-sm) {
    .date-range {
        display: block;
        position: relative;
        top: 0;
        transform: none;
    }
}

@@ -42,7 +57,7 @@
{% if ai.assessments and not (page.isMainPage) %}
{% set sections = sections|merge(['assessments']) %}
{% endif %}
{% if ai.numBugs > 0 %}
{% if ai.numBugs > 0 and not (ai.hasDateRange) %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do not (ai.hasDateRange) first, because ai.numBugs will run the queries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need the not (ai.hasDateRange) check on line 57

@@ -92,7 +107,7 @@
</td>
<td>{{ ai.numEditors|num_format }}</td>
</tr>
{% if ai.assessments and not (page.isMainPage) %}
{% if ai.assessments and not (page.isMainPage) and not (page.hasDateRange) %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ai.hasDateRange (not page), and again I'd put this check before ai.assessments

@@ -260,22 +277,22 @@
<td>{{ msg('links-external') }}</td>
<td>{{ ai.linksExtCount|num_format }}</td>
</tr>
{% if page.watchers is not empty %}
{% if page.watchers is not empty and not (ai.hasDateRange) %}
Copy link
Member

@MusikAnimal MusikAnimal Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not (ai.hasDateRange) first. Here I think Page::getPageInfo() has already been ran, but good to be consistent with the placement of the hasDateRange check.

<td>
{{ wiki.pageviewsLink(page, ai.pageviews(pageviewsOffset)|num_format, 'range=latest-' ~ pageviewsOffset) }}
</td>
</tr>
{% endif %}

{% if ai.numBugs > 0 %}
{% if ai.numBugs > 0 and not (ai.hasDateRange) %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not (ai.hasDateRange) first

@@ -753,7 +770,7 @@
{% endif %}

{# ======================== ASSESSMENTS ======================== #}
{% if ai.assessments and not (page.isMainPage) %}
{% if ai.assessments and not (page.isMainPage) and not (ai.hasDateRange) %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not (ai.hasDateRange) first

@@ -792,7 +809,7 @@
{% endif %}

{# ======================== BUGS ======================== #}
{% if ai.numBugs > 0 %}
{% if ai.numBugs > 0 and not (ai.hasDateRange) %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not (ai.hasDateRange) first

)}} &middot; {{ extLink(
'https://tools.wmflabs.org/redirectviews?project=' ~ page.project.domain ~ '&page=' ~ page.title,
msg('redirects')
msg('redirects') ~ start is not null ? ('&start=' ~ start) : '' ~ end is not null ? ('&end=' ~ end) : ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the ~ start ... is next to the link text and not in the URL.

@@ -217,17 +217,17 @@
{{ extLink(url, msg('pageviews'), label) }}
{% endspaceless %}{% endmacro %}

{% macro pageviewsLinks(page) %}{% spaceless %}
{% macro pageviewsLinks(page, start, end) %}{% spaceless %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider setting the defaults start = null, end = null, then we don't need the null checks at https://github.com/x-tools/xtools/pull/149/files#diff-fefe304fbb1893557366c352e22673cfR42

$article = $matches[1];
$start = $matches[2];
$end = $matches[3];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@MusikAnimal MusikAnimal merged commit 120b584 into x-tools:master Jan 12, 2018
@Albert221 Albert221 deleted the date-filter branch January 12, 2018 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants