77 * @author thomas-topway-it for KM-A
88 */
99
10+ // use MediaWiki\Extension\KnowledgeGraph\Aliases\Category as CategoryClass;
11+ use MediaWiki \Extension \KnowledgeGraph \Aliases \Title as TitleClass ;
1012use MediaWiki \MediaWikiServices ;
1113use MediaWiki \Revision \SlotRecord ;
1214use SMW \MediaWiki \Specials \SearchByProperty \PageRequestOptions ;
@@ -142,7 +144,7 @@ public static function onParserFirstCallInit( Parser $parser ) {
142144 public static function onLoadExtensionSchemaUpdates ( DatabaseUpdater $ updater = null ) {
143145 $ text = file_get_contents ( __DIR__ . '/../data/KnowledgeGraphOptions.js ' );
144146 $ user = RequestContext::getMain ()->getUser ();
145- $ title = Title ::makeTitleSafe ( NS_MEDIAWIKI , 'KnowledgeGraphOptions ' );
147+ $ title = TitleClass ::makeTitleSafe ( NS_MEDIAWIKI , 'KnowledgeGraphOptions ' );
146148
147149 $ wikiPage = self ::getWikiPage ( $ title );
148150 $ pageUpdater = $ wikiPage ->newPageUpdater ( $ user );
@@ -226,15 +228,15 @@ public static function parserFunctionKnowledgeGraph( Parser $parser, ...$argv )
226228 // property-related options
227229 foreach ( $ values as $ val ) {
228230 if ( preg_match ( '/^property-options(\?(.+))?=(.+)/ ' , $ val , $ match ) ) {
229- $ title_ = Title ::makeTitleSafe ( \SMW_NS_PROPERTY , $ match [2 ] );
231+ $ title_ = TitleClass ::makeTitleSafe ( \SMW_NS_PROPERTY , $ match [2 ] );
230232 if ( $ title_ ) {
231233 $ propertyOptions [$ title_ ->getText ()] = $ match [3 ];
232234 }
233235 }
234236 }
235237
236238 foreach ( $ params ['nodes ' ] as $ titleText ) {
237- $ title_ = Title ::newFromText ( $ titleText );
239+ $ title_ = TitleClass ::newFromText ( $ titleText );
238240 if ( $ title_ && $ title_ ->isKnown () ) {
239241 if ( !isset ( self ::$ data [$ title_ ->getFullText ()] ) ) {
240242 self ::setSemanticData ( $ title_ , $ params ['properties ' ], 0 , $ params ['depth ' ] );
@@ -245,7 +247,7 @@ public static function parserFunctionKnowledgeGraph( Parser $parser, ...$argv )
245247 $ graphOptions = [];
246248 if ( !empty ( $ params ['graph-options ' ] ) ) {
247249 // , NS_KNOWLEDGEGRAPH
248- $ title_ = Title ::newFromText ( $ params ['graph-options ' ], NS_MEDIAWIKI );
250+ $ title_ = TitleClass ::newFromText ( $ params ['graph-options ' ], NS_MEDIAWIKI );
249251
250252 if ( $ title_ && $ title_ ->isKnown () ) {
251253 // $graphOptions = json_decode( self::getWikipageContent( $title_ ), true );
@@ -254,7 +256,7 @@ public static function parserFunctionKnowledgeGraph( Parser $parser, ...$argv )
254256 }
255257
256258 foreach ( $ propertyOptions as $ property => $ titleText ) {
257- $ title_ = Title ::newFromText ( $ titleText , NS_MEDIAWIKI );
259+ $ title_ = TitleClass ::newFromText ( $ titleText , NS_MEDIAWIKI );
258260 if ( $ title_ && $ title_ ->isKnown () ) {
259261 // $propertyOptions[$property] = json_decode( self::getWikipageContent( $title_ ), true );
260262 $ propertyOptions [$ property ] = self ::getWikipageContent ( $ title_ );
@@ -320,7 +322,7 @@ public static function getSubjectsByProperty( $propertyText, $limit = 100, $offs
320322 }
321323
322324 /**
323- * @param Title $title
325+ * @param Title|MediaWiki\Title\Title $title $title
324326 * @return string|null
325327 */
326328 public static function getWikipageContent ( $ title ) {
@@ -337,7 +339,7 @@ public static function getWikipageContent( $title ) {
337339 }
338340
339341 /**
340- * @param Title $title
342+ * @param Title|MediaWiki\Title\Title $title
341343 * @return WikiPage|null
342344 */
343345 public static function getWikiPage ( $ title ) {
@@ -443,30 +445,46 @@ public static function parseParameters( $parameters, $defaultParameters ) {
443445 }
444446
445447 /**
446- *
447448 * @param string $category
449+ * @param int $limit
450+ * @param int $offset
448451 * @return array
449452 */
450- public static function articlesInCategories ( $ category ) {
451- $ dbr = wfGetDB ( DB_REPLICA );
452- $ res = $ dbr ->select ( 'categorylinks ' ,
453+ public static function articlesInCategories ( $ category , $ limit , $ offset ) {
454+ $ options = [
455+ 'LIMIT ' => $ limit ,
456+ 'OFFSET ' => $ offset
457+ ];
458+ $ dbr = wfGetDB ( DB_REPLICA );
459+ $ res = $ dbr ->select ( 'categorylinks ' ,
453460 [ 'pageid ' => 'cl_from ' ],
454461 [ 'cl_to ' => str_replace ( ' ' , '_ ' , $ category ) ],
455- __METHOD__
456- );
457- $ ret = [];
462+ __METHOD__ ,
463+ $ options
464+ );
465+ $ ret = [];
458466 foreach ( $ res as $ row ) {
459- $ title_ = Title ::newFromID ( $ row ->pageid );
467+ $ title_ = TitleClass ::newFromID ( $ row ->pageid );
460468 if ( $ title_ ) {
461469 $ ret [] = $ title_ ;
462470 }
463471 }
464472 return $ ret ;
473+
474+ // *** this does not work with numerical offset
475+ // $cat = CategoryClass::newFromName( str_replace( ' ', '_', $category ) );
476+ // $iterator_ = $cat->getMembers( $limit, $offset );
477+ // $ret = [];
478+ // while ( $iterator_->valid() ) {
479+ // $ret[] = $iterator_->current();
480+ // $iterator_->next();
481+ // }
482+ // return $ret;
465483 }
466484
467485 /**
468486 * @see https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/PageProperties/+/refs/heads/1.0.3/includes/PageProperties.php
469- * @param Title $title
487+ * @param Title|MediaWiki\Title\Title $title
470488 * @param array $onlyProperties
471489 * @param int $depth
472490 * @param int $maxDepth
@@ -532,7 +550,8 @@ public static function setSemanticData( Title $title, $onlyProperties, $depth, $
532550
533551 if ( count ( $ onlyProperties )
534552 && !in_array ( $ canonicalLabel , $ onlyProperties )
535- && !in_array ( $ preferredLabel , $ onlyProperties ) ) {
553+ && !in_array ( $ preferredLabel , $ onlyProperties )
554+ ) {
536555 continue ;
537556 }
538557
0 commit comments