Ori.livneh has uploaded a new change for review. https://gerrit.wikimedia.org/r/53733
Change subject: Ensure task targets are editable and bite-sized ...................................................................... Ensure task targets are editable and bite-sized Instead of fetching three articles, we'll fetch six and grab the first three (or fewer, if fewer than three are available) that are editable by the current user and not too big. Change-Id: I963553dcce90b93d363c9e740561fd89c902badf --- M SpecialGettingStarted.php 1 file changed, 21 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GettingStarted refs/changes/33/53733/1 diff --git a/SpecialGettingStarted.php b/SpecialGettingStarted.php index 4681128..80e9212 100644 --- a/SpecialGettingStarted.php +++ b/SpecialGettingStarted.php @@ -1,6 +1,8 @@ <?php class SpecialGettingStarted extends SpecialPage { + const ARTICLE_COUNT = 3; + const MAX_ARTICLE_LENGTH = 10000; public function __construct() { parent::__construct( 'GettingStarted' ); @@ -32,6 +34,8 @@ public function getHtmlResult() { global $wgExtensionAssetsPath, $wgGettingStartedTasks; + + $user = $this->getUser(); $result = ''; $headerText = $this->msg( 'gettingstarted-task-header' )->escaped(); @@ -57,7 +61,23 @@ ); foreach ( $tasks as $task ) { $roulette = new CategoryRoulette( Category::newFromName( $task['category'] ) ); - $taskArticles = $roulette->getRandomArticles( self::ARTICLE_COUNT ); + + // Get ARTICLE_COUNT * 2 articles and pick the first ARTICLE_COUNT + // articles that meet the requirements (not too big and is editable + // by the current user). If fewer than ARTICLE_COUNT articles in + // result set meet requirements, get as many as possible. + // FIXME(ori-l, 14-March-2013): should be a separate method. + $taskArticles = array(); + foreach( $roulette->getRandomArticles( self::ARTICLE_COUNT * 2 ) as $article ) { + $length = $article->getLength(); + $editRestrictions = $article->getUserPermissionsErrors( 'edit', $user ); + if ( $length > 0 && $length <= self::MAX_ARTICLE_LENGTH && empty( $editRestrictions ) ) { + $taskArticles[] = $article; + } + if ( count( $taskArticles ) === self::ARTICLE_COUNT ) { + break; + } + } $imageSrc = wfFindFile( $task['image'] )->getURL(); $descriptionMessage = $this->msg( $task['descriptionMessage'] ); -- To view, visit https://gerrit.wikimedia.org/r/53733 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I963553dcce90b93d363c9e740561fd89c902badf Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GettingStarted Gerrit-Branch: master Gerrit-Owner: Ori.livneh <o...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits