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

Significant Events Endpoint for Article as a Living Document experiment #2

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0ab0818
Merge pull request #1 from wikimedia/master
tonisevener Jul 10, 2020
b05e514
initial commit from gerrit patch
tonisevener Jul 10, 2020
682bc40
rename history-batch to significant-changes
tonisevener Jul 10, 2020
c29af0f
progress converting to promises
tonisevener Jul 10, 2020
51f3e70
progress processing data
tonisevener Jul 13, 2020
8c0b268
more progress processing data
tonisevener Jul 14, 2020
c9b2991
more progress processing data (trimming snippets, fixing bugs, starti…
tonisevener Jul 15, 2020
d6b09b3
fix some section bugs, fix linter warnings
tonisevener Jul 16, 2020
931b5b2
fix threshold caching issue and some snippet stripping issue
tonisevener Jul 16, 2020
9720591
added vandalism reverts and new talk page topics
tonisevener Jul 18, 2020
7220953
remove old prototype code
tonisevener Jul 18, 2020
53e76d4
progress structuring templates
tonisevener Jul 21, 2020
ac62416
finish adding new reference type
tonisevener Jul 21, 2020
45b2c00
quick added-templates endpoint for evaluating all templates
tonisevener Jul 21, 2020
f612aa2
quick new-talk-topics endpoint for evaluating new talk page data
tonisevener Jul 21, 2020
3f24a7b
rename to significant-events, remove debug endpoints
tonisevener Aug 10, 2020
1ea5049
progress showing new reference, added text, and deleted text all toge…
tonisevener Aug 11, 2020
dd4c5ff
fixed a bug, found another bug
tonisevener Aug 11, 2020
71f8ad6
fixing talk page bugs, attempt at truncating snippets
tonisevener Aug 13, 2020
18e46b7
add article description template detection, editor counts, editor gro…
tonisevener Aug 17, 2020
a270924
attempt at reworking cache, still needs testing
tonisevener Aug 18, 2020
8f2fe8d
stripping additional tags from snippets, inspired by talk pages
tonisevener Aug 19, 2020
6b6f794
bug fixes
tonisevener Aug 19, 2020
812ee82
attempt to add some safety
tonisevener Aug 24, 2020
00da926
some bug fixes
tonisevener Aug 25, 2020
60ad6f5
more bug fixes
tonisevener Aug 25, 2020
fabfc5f
still more bug fixes
tonisevener Aug 25, 2020
88f6664
some rework to catch addtional missed templates
tonisevener Aug 25, 2020
f719ae1
fixed split citation bug
tonisevener Aug 25, 2020
c574535
rename new reference type
tonisevener Aug 25, 2020
cf93d11
allowing cache to handle changing thresholds
tonisevener Aug 28, 2020
f510075
Revert "fixed split citation bug"
tonisevener Aug 28, 2020
d776684
fix nested array issue with templates
tonisevener Aug 28, 2020
567021c
delete unused code
tonisevener Sep 8, 2020
99a70d4
delete more unused code
tonisevener Sep 8, 2020
da84625
Merge remote-tracking branch 'upstream/master'
tonisevener Sep 8, 2020
5236d3a
Merge branch 'master' into significant-changes
tonisevener Sep 8, 2020
7a35df8
Update talkPageTitle function to getTalkPageTitle, utilize it in clea…
joewalsh Sep 9, 2020
f7c292a
Ensure significantChangesCache is updated
joewalsh Sep 9, 2020
1c59ff7
outputting expanded small objects instead of collapsed
tonisevener Sep 9, 2020
859e4f5
small section determination bugfix
tonisevener Sep 25, 2020
f49da1b
do not allow citation needed templates through
tonisevener Oct 2, 2020
097f8af
fix some talk page bugs causing null snippets
tonisevener Oct 5, 2020
9744e3b
Better talk page fix to allow templates into talk page snippets if ab…
tonisevener Oct 6, 2020
8ec4a48
return parentID for pushing directly to diff screen
tonisevener Oct 21, 2020
f5c0326
various bug fixes discovered from working on counts report
tonisevener Oct 26, 2020
e6f6f50
text now meets a minimum length for truncating to avoid single space …
tonisevener Nov 11, 2020
6a40006
strip out comments from section titles
tonisevener Nov 20, 2020
2ba0f82
fix null break
tonisevener Nov 20, 2020
8e40440
add significant-events-warmup endpoint
tonisevener Dec 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ services:
user-agent: '{{user-agent}}'
accept-language: '{{accept-language}}'
body: '{{ default(request.query, {}) }}'
# the template used for contacting MW Rest API
mwrestapi_req:
method: '{{request.method}}'
uri: https://{{domain}}/w/rest.php/v1/{+path}
query: '{{ default(request.query, {}) }}'
headers: '{{request.headers}}'
body: '{{request.body}}'
timeout: 60000 # 60 * 1000
# the template used for requesting ResourceLoader module content from load.php
mw_resource_loader_req:
method: post
Expand Down
8 changes: 8 additions & 0 deletions config.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ services:
user-agent: '{{user-agent}}'
accept-language: '{{accept-language}}'
body: '{{ default(request.query, {}) }}'
# the template used for contacting MW Rest API
mwrestapi_req:
method: '{{request.method}}'
uri: https://{{domain}}/w/rest.php/v1/{+path}
query: '{{ default(request.query, {}) }}'
headers: '{{request.headers}}'
body: '{{request.body}}'
timeout: 60000 # 60 * 1000
# the template used for requesting ResourceLoader module content from load.php
mw_resource_loader_req:
method: post
Expand Down
8 changes: 8 additions & 0 deletions config.labs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ services:
user-agent: '{{user-agent}}'
accept-language: '{{accept-language}}'
body: '{{ default(request.query, {}) }}'
# the template used for contacting MW Rest API
mwrestapi_req:
method: '{{request.method}}'
uri: https://{{domain}}/w/rest.php/v1/{+path}
query: '{{ default(request.query, {}) }}'
headers: '{{request.headers}}'
body: '{{request.body}}'
timeout: 60000 # 60 * 1000
# the template used for requesting ResourceLoader module content from load.php
mw_resource_loader_req:
method: post
Expand Down
8 changes: 8 additions & 0 deletions config.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ services:
user-agent: '{{user-agent}}'
accept-language: '{{accept-language}}'
body: '{{ default(request.query, {}) }}'
# the template used for contacting MW Rest API
mwrestapi_req:
method: '{{request.method}}'
uri: https://{{domain}}/w/rest.php/v1/{+path}
query: '{{ default(request.query, {}) }}'
headers: '{{request.headers}}'
body: '{{request.body}}'
timeout: 60000 # 60 * 1000
# the template used for requesting ResourceLoader module content from load.php
mw_resource_loader_req:
method: post
Expand Down
7 changes: 7 additions & 0 deletions dist/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ services:
headers:
user-agent: '{{user-agent}}'
body: '{{ default(request.query, {}) }}'
# the template used for contacting MW Rest API
mwrestapi_req:
method: '{{request.method}}'
uri: https://{{domain}}/w/rest.php/v1/{+path}
query: '{{ default(request.query, {}) }}'
headers: '{{request.headers}}'
body: '{{request.body}}'
# the template used for contacting RESTBase
restbase_req:
method: '{{request.method}}'
Expand Down
43 changes: 42 additions & 1 deletion lib/api-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,46 @@ function prettyMwApiReq(request) {
return `${request.uri}?${querystring.stringify(request.body)}`;
}

/**
* Calls the MW REST API with the supplied domain, path and request parameters
* @param {!Object} req the incoming request object
* @param {?string} path the REST API path to contact without the leading slash
* @param {?Object} [restReq={}] the object containing the REST request details
* @param {?string} [restReq.method=get] the request method
* @param {?Object} [restReq.query={}] the query string to send, if any
* @param {?Object} [restReq.headers={}] the request headers to send
* @param {?Object} [restReq.body=null] the body of the request, if any
* @return {!Promise} a promise resolving as the response object from the REST API
*
*/
function mwRestApiGet(req, path, restReq) {

const app = req.app;
if (path.constructor === Object) {
restReq = path;
path = undefined;
}
restReq = restReq || {};
restReq.method = restReq.method || 'get';
restReq.query = restReq.query || {};
restReq.headers = restReq.headers || {};
restReq.params = restReq.params || {};
restReq.params.path = path || restReq.params.path;
restReq.params.domain = restReq.params.domain || req.params.domain;
if (!restReq.params.path || !restReq.params.domain) {
return BBPromise.reject(new HTTPError({
status: 500,
type: 'internal_error',
title: 'Invalid internal call',
detail: 'domain and path need to be defined for the REST API call'
}));
}
restReq.params.path = restReq.params.path[0] === '/' ?
restReq.params.path.slice(1) : restReq.params.path;

return req.issueRequest(app.mwrestapi_tbl.expand({ request: restReq }));
}

/**
* Make a request for ResourceLoader modules to MediaWiki's load.php entry point.
*
Expand Down Expand Up @@ -229,6 +269,7 @@ function setupApiTemplates(app) {
};
}
app.restbase_tpl = new Template(app.conf.restbase_req);
app.mwrestapi_tbl = new Template(app.conf.mwrestapi_req);

// set up the MediaWiki page request template
if (!app.conf.mw_resource_loader_req) {
Expand All @@ -240,7 +281,6 @@ function setupApiTemplates(app) {
};
}
app.mw_resource_loader_tpl = new Template(app.conf.mw_resource_loader_req);

}

/**
Expand Down Expand Up @@ -277,6 +317,7 @@ function getCommonsDomain(domain) {
module.exports = {
// Shared with service-template-node
mwApiGet,
mwRestApiGet,
restApiGet,
setupApiTemplates,

Expand Down
1 change: 1 addition & 0 deletions lib/mobile-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mUtil.CONTENT_TYPES = {
type: 'application/json'
},
talk: { name: 'Talk', version: '0.1.1', type: 'application/json' },
significantChanges: { name: 'SignificantChanges', version: '0.0.1', type: 'application/json' },
mediaList: { name: 'MediaList', version: '1.1.0', type: 'application/json' },
i18n: { name: 'i18n', version: '0.0.1', type: 'application/json' }
};
Expand Down
47 changes: 47 additions & 0 deletions lib/mwapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,53 @@ mwapi.getSiteInfo = function(req) {
return siteInfoCache[rp.domain];
};

mwapi.queryForRevisions = function(req, title, pageSize, rvStart, rvEnd) {
const query = apiParams({
action: 'query',
prop: 'revisions',
titles: title || req.params.title,
rvslots: 'main',
rvprop: 'ids|timestamp|user|userid|size|parsedcomment|comment|tags|flags|size',
rvdir: 'older',
format: 'json',
rvlimit: pageSize || '20'
});

// to get around "parameters rvstartid & rvstart cannot be used together" error
if (rvStart && rvEnd) {
query.rvstart = rvStart;
query.rvend = rvEnd;
} else if (rvEnd) {
query.rvend = rvEnd;
} else {
query.rvstartid = req.query.rvstartid;
}

return api.mwApiGet(req, query);
};

mwapi.queryForUsers = function(req, userids) {

var useridstring = '';
for (let i = 0; i < userids.length; i++) {
const userid = userids[i];
if (i === 0) {
useridstring += userid;
} else {
useridstring += `|${userid}`;
}
}

const query = apiParams({
action: 'query',
list: 'users',
ususerids: useridstring,
usprop: 'groups|editcount',
});

return api.mwApiGet(req, query);
};

/**
* Given protection status for an article simplify it to allow easy reference
*
Expand Down
10 changes: 10 additions & 0 deletions lib/mwrestapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const api = require('./api-util');
const mwrestapi = {};

mwrestapi.queryForDiff = function(req, fromRevID, toRevID) {
const path = `revision/${fromRevID}/compare/${toRevID}`;

return api.mwRestApiGet(req, path);
};

module.exports = mwrestapi;
Loading