+ /**
+ * Helper for Html::namespaceSelector().
+ * @param array $params See Html::namespaceSelector()
+ * @return array
+ */
+ public static function namespaceSelectorOptions( array $params = array() ) {
+ global $wgContLang;
+
+ $options = array();
+
+ if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
+ $params['exclude'] = array();
+ }
+
+ if ( isset( $params['all'] ) ) {
+ // add an option that would let the user select all namespaces.
+ // Value is provided by user, the name shown is localized for the user.
+ $options[$params['all']] = wfMessage( 'namespacesall' )->text();
+ }
+ // Add all namespaces as options (in the content language)
+ $options += $wgContLang->getFormattedNamespaces();
+
+ $optionsOut = array();
+ // Filter out namespaces below 0 and massage labels
+ foreach ( $options as $nsId => $nsName ) {
+ if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
+ continue;
+ }
+ if ( $nsId === NS_MAIN ) {
+ // For other namespaces use the namespace prefix as label, but for
+ // main we don't use "" but the user message describing it (e.g. "(Main)" or "(Article)")
+ $nsName = wfMessage( 'blanknamespace' )->text();
+ } elseif ( is_int( $nsId ) ) {
+ $nsName = $wgContLang->convertNamespace( $nsId );
+ }
+ $optionsOut[$nsId] = $nsName;
+ }
+
+ return $optionsOut;
+ }
+