Phuedx has uploaded a new change for review. https://gerrit.wikimedia.org/r/118063
Change subject: Import config generation script from Gist ...................................................................... Import config generation script from Gist Import gettingStartedConfigGenerator.php from https://gist.github.com/phuedx/8941767 with the following modifications: * Convert it to a maintenance script * The list of DB names (see $wmgUseGettingStarted in gettingStartedConfigGenerator.php) is passed via the dbnames option - by default the config isn't filtered Change-Id: I708753d298c8eb04a687d07afcd5833ad8da68ba --- A maintenance/generate_config.php 1 file changed, 106 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GettingStarted refs/changes/63/118063/1 diff --git a/maintenance/generate_config.php b/maintenance/generate_config.php new file mode 100644 index 0000000..6f78a72 --- /dev/null +++ b/maintenance/generate_config.php @@ -0,0 +1,106 @@ +<?php + +/** + * Generates a file that contains the value for the + * wgGettingStartedCategoriesForTaskTypes configuration variable from specific + * Wikidata entities. + * + * @author Sam Smith <samsm...@wikimedia.org> + */ + +namespace GettingStarted; + +use Title; + +$IP = getenv( 'MW_INSTALL_PATH' ); +if( $IP === false ) { + $IP = __DIR__ . '/../../..'; +} + +require_once "$IP/maintenance/Maintenance.php"; + +class GenerateConfig extends \Maintenance { + /** + * @var array An associative array of which the key is the task type + * (see $wgGettingStartedTasks) and the value is the QID of a + * Wikidata entity. + */ + private $qidsForTaskTypes = array( + 'copyedit' => 'Q9125773', // Category:Wikipedia articles needing copy edit + 'clarify' => 'Q8235653', // Category:All Wikipedia articles needing clarification + 'addlinks' => 'Q8235714', // Category:All articles with too few wikilinks + ); + + public function __construct() { + $this->mDescription = 'Generates a file that contains the value for the wgGettingStartedCategoriesForTaskTypes configuration variable from specific Wikidata entities.'; + $this->addOption( 'dbnames', 'Location of the list of DB names to filter by', false, true ); + + // TODO (phuedx, 2014-03-10) Extend addOption to include a + // default value, which could be included in the output of + // $ php /path/to/maintenance/script.php --help. + $this->addOption( 'output', 'Location of the output file', false, true ); + + } + + public function execute() { + $dbnames = $this->getOption( 'dbnames' ); + if ( $dbnames ) { + if ( ! is_file( $dbnames ) || ! is_readable( $dbnames ) ) { + $this->error( "{$dbnames} isn't a file or cant't be read.", 1 ); + } + + $contents = file_get_contents( $dbnames ); + $dbnames = explode( PHP_EOL, $contents ); + } + + $config = array(); + foreach ( $this->qidsForTaskTypes as $task => $qid ) { + $sitelinks = $this->getSitelinksByQID( $qid ); + foreach ( $sitelinks as $dbname => $categoryName ) { + if ( $dbnames && ! in_array( $dbname, $dbnames ) ) { + continue; + } + + if ( ! isset( $config[ $dbname ] ) ) { + $config[ $dbname ] = array(); + } + + // TODO (phuedx, 2014-03-10) Create a utility + // class for canonicalising category names for + // this extension. + + // Canonicalise the category name. + $title = Title::newFromText( $categoryName ); + + if ( !$title ) { + continue; + } + + $config[ $dbname ][ $task ] = $title->getDBkey(); + } + } + + $output = $this->getOption( 'output', 'config.out' ); + $contents = var_export( $config, true ); + if ( ! file_put_contents( $output, $contents ) ) { + $this->error( "Couldn't write to {$output}.", 2 ); + } + } + + private function getSitelinksByQID( $qid ) { + $url = "https://www.wikidata.org/w/api.php?format=json&action=wbgetentities&props=sitelinks&ids={$qid}"; + $responseBodyRaw = file_get_contents( $url ); + $responseBody = json_decode( $responseBodyRaw, true ); + $entity = $responseBody[ 'entities' ][ $qid ]; + $result = array(); + + foreach ( $entity[ 'sitelinks' ] as $dbname => $sitelink ) { + $result[ $dbname ] = $sitelink[ 'title' ]; + } + + return $result; + } +} + +$maintClass = 'GettingStarted\GenerateConfig'; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- To view, visit https://gerrit.wikimedia.org/r/118063 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I708753d298c8eb04a687d07afcd5833ad8da68ba Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GettingStarted Gerrit-Branch: master Gerrit-Owner: Phuedx <g...@samsmith.io> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits