Skip to content

Commit

Permalink
Bug 70196: Add categories added directly from extensions
Browse files Browse the repository at this point in the history
Some extensions such as parser functions add categories directly
to the page rathen than as wikitext links. This patch gets them
from action=expandtemplates or action=parse and adds them to the
expanded content.

Change-Id: I1acdb14044badd767a46e81ef246a1c8de2419ce
  • Loading branch information
marcoil committed Oct 1, 2014
1 parent c4ae060 commit 6266eef
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions lib/mediawiki.ApiRequest.js
Expand Up @@ -365,7 +365,7 @@ function PreprocessorRequest( env, title, text ) {
var apiargs = {
format: 'json',
action: 'expandtemplates',
prop: 'wikitext',
prop: 'wikitext|categories',
text: text
};

Expand Down Expand Up @@ -426,6 +426,18 @@ PreprocessorRequest.prototype._handleJSON = function ( error, data ) {

// Add the source to the cache
this.env.pageCache[this.text] = src;

// Add the categories which were added by extensions
if (data.expandtemplates.categories) {
for (var i in data.expandtemplates.categories) {
var category = data.expandtemplates.categories[i];
src += '\n[[Category:' + category['*'];
if (category.sortkey) {
src += "|" + category.sortkey;
}
src += ']]';
}
}
} catch ( e2 ) {
error = new DoesNotExistError( 'Did not find page revisions in the returned body for ' +
this.title + e2 );
Expand Down Expand Up @@ -461,7 +473,7 @@ function PHPParseRequest ( env, name, text ) {
text: text,
disablepp: 'true',
contentmodel: 'wikitext',
prop: 'text|modules'
prop: 'text|modules|categories'
};
var uri = env.conf.wiki.apiURI;

Expand Down Expand Up @@ -549,6 +561,23 @@ PHPParseRequest.prototype._handleJSON = function ( error, data ) {
}
for (i in data.parse.modulemessages) { this.env.page.extensionModuleMessages.add(data.parse.modulemessages[i]); }
}

// Add the categories which were added by extensions
if (data.parse.categories) {
for (i in data.parse.categories) {
var category = data.parse.categories[i];
// Only add those categories given as hidden by the parser, the
// rest will be already included in the parser output.
if (category.hidden !== undefined) {
parsedHtml += '\n<link rel="mw:PageProp/Category" href="./Category:"' +
category['*'];
if (category.sortkey) {
parsedHtml += "#" + category.sortkey;
}
parsedHtml += '"/>';
}
}
}
} catch ( e2 ) {
error = new DoesNotExistError( 'Could not expand extension content for ' +
this.title + e2 );
Expand Down

0 comments on commit 6266eef

Please sign in to comment.