User:Lucas Werkmeister/createPagePile

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

The following function can be used to create a PagePile in JavaScript:

function createPagePile( titles ) {
  return $.post( 'https://tools.wmflabs.org/pagepile/api.php', {
    action: 'create_pile_with_data',
    wiki: 'commonswiki',
    data: titles.map( function ( title ) {
      return title + '\t-999';
    } ).join( '\n' ),
  } ).then( function ( response ) {
    return response.pile.id;
  } );
}

It should be called with an array of title strings (including the namespace, if not in the main namespace), and returns a promise that resolves with the PagePile ID. Example:

var titles = [ 'Main Page', 'Commons:Welcome' ];
createPagePile( titles ).then( function ( id ) {
  console.log( 'https://tools.wmflabs.org/pagepile/api.php?action=get_data&id=' + id );
} );