ItSpiderman has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/373294 )
Change subject: Add getSubpagesSorted function
......................................................................
Add getSubpagesSorted function
When calling getSubpages on Title object it will return a list that is not
sorted, pages with capital letter will be before lowercased even if letter
itself should go later. Eg. "Beta" would go before "alpha".
This helper method fixed that sorting issue and returns properly sorted
array
Change-Id: I73fe4a9a44babaf4c9afd257612436578233551e
ERM: #7287
---
M includes/utility/ArticleHelper.class.php
1 file changed, 22 insertions(+), 0 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation
refs/changes/94/373294/1
diff --git a/includes/utility/ArticleHelper.class.php
b/includes/utility/ArticleHelper.class.php
index 4c6a611..d09ad1c 100644
--- a/includes/utility/ArticleHelper.class.php
+++ b/includes/utility/ArticleHelper.class.php
@@ -177,4 +177,26 @@
BsCacheHelper::invalidateCache( $sKey );
}
+ /**
+ * Retuns subpages of a title sorted by name
+ *
+ * @param Title $oTitle
+ * @param int $iLimit
+ * @return array
+ */
+ public static function getSubpagesSorted( $oTitle, $iLimit ) {
+ $aSubpages = $oTitle->getSubpages( $iLimit );
+ $aTitleArray = [];
+ foreach( $aSubpages as $oSubpage ) {
+ $aTitleArray[] = $oSubpage;
+ }
+ usort( $aTitleArray, array( 'BsArticleHelper',
'sortSubpagesInternal' ) );
+
+ return $aTitleArray;
+ }
+
+ protected static function sortSubpagesInternal( $a, $b ) {
+ return strcmp( strtolower( $a->getFullText() ), strtolower(
$b->getFullText() ) );
+ }
+
}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/373294
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I73fe4a9a44babaf4c9afd257612436578233551e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: ItSpiderman <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits