Extension talk:Sort2

Latest comment: 8 years ago by JimAlexP in topic Bugs

Discussion goes here

Option style=""

edit

I thought about implementing the style option to be restricted to the list style types valid for ordered lists. To be honest, I was too lazy and I chose to pass any style through.

If this is considered to be too threatening and if there's consensus I am willing to implement the restriction.

I just need your feedback on this.

Bugs

edit

Hey,

Before the Sort2 function you created I had a list like the following:

But when I changed it for the sort2 my link to my doc did not work anymore:

<Sort2> Software Configurations Permission -> Disconnects Unable to browse </sort2>

You might want to see if you could include this functionally

Thanks, Justin


Special characters like colons (:), asterisks (*), and hashes (#) are removed even if they are not serving as list item markers. This means that, for instance, sorting a list that includes any links with namespaces or external (http://) links will break the links.

CarLuva 21:41, 21 October 2009 (UTC)Reply

This extension strips the wiki syntax list tokens to allow the sorting of already existing lists. But unfortunately it does it wrong way. Only the leading characters should be removed, not all of them, otherwise the entire line will be corrupted. The problem can be solved with the following change:

function stripWikiListTokens( $text ) {
 $pattern ='/^\s*([\*\#\:])\s*/';
 return trim(preg_replace($pattern, ,$text ));
}
As such gives an error 500 on Mediawiki so added an empty char as a second argument for preg_replace. This works fine.
 function stripWikiListTokens( $text ) {
  $pattern ='/^\s*([\*\#\:])\s*/';
  return trim( preg_replace( $pattern, '', $text ) );
 }
--JimAlexP (talk) 21:14, 1 December 2016 (UTC)Reply

Suggestions

edit

Hi. Is it possible to sort links? SORT2 is removing ":"  ? Is this right? Anyway thank you for your extension. --Micc 20:55, 1 March 2007 (UTC)Reply

Used @

edit
edit

Useful extension. But breaks on lists with links. any fixes?

We use the extension at Stargate Wiki. We had no problems with links. Example: Template:Erd-Objekt.
We've tried to get it to work with in-page links; but since it removes the '#' sign (and other chars) these links cannot be sorted. It also can't deal with parameters sent into a template, e.g. <sort2>{{{myparams}}}</sort2>, --Callum Wilson 10:45, 23 August 2010 (UTC)Reply
Just tested it and it that standard link markup isn't being interpreted. --JimAlexP (talk) 02:30, 1 December 2016 (UTC)Reply
This is apparently caused by the following function removing the ":" in hyperlinks.
function stripWikiListTokens( $text ) {
	$find = array( '*', '#',':'); // ':' in hyperlinks needs to be ignored
	return trim(str_replace( $find, '', $text )); // All colons are being removed in the string here
}
--JimAlexP (talk) 20:45, 1 December 2016 (UTC)Reply

How to add first letter?

edit

How to create list for example?

A

  • AMD
  • argument

B

  • ball
  • BMW

Modifications

edit

I must admit that I'm still green when it comes to PHP. I've created the following modifications to extend the functionality of this extension. The mods are ugly and I can't be 100% they won't break something else.

In order to add URLs modify the function stripWikiListTokens to the following:

function stripWikiListTokens( $text ) {
	$text = trim(str_replace( 'http:', 'http{colon}', $text));
	$find = array( '*', '#', ':');
	$text = trim(str_replace( $find, '', $text ));
	return trim(str_replace( 'http{colon}', 'http:', $text ));
}

What we're doing is going through out Sort2 block and looking for http: and temporarily replacing it with http{colon}. Then we go through the Sort2 block again removing all the MediaWiki specific list tags. Finally we go through the Sort2 block one last time replacing http{colon} with http:.

If you are alphabetizing a list of links in standard [url display] format Sort2 will alphabetize based on the URL. So a URL of [http://www.google.com Google] will come AFTER [http://google.com Google]. Both links are evaluated on the first letter following the http://. Therefore Sort2 sorts using the W in the former and the G in the later.

This may sound odd but I didn't like how the 'br' type looked. Especially considering that paragraphs are separated using '<p>' tags instead. I added an additional type to support this. In order to implement add the following:

In function loadSettings look for this line:

if( $c == 'ol' || $c == 'ul' || $c == 'dl' || $c == 'inline' || $c == "br")

and replace it with the following line to make 'p' a valid 'type':

if( $c == 'ol' || $c == 'ul' || $c == 'dl' || $c == 'inline' || $c == "br" || $c == "p")

Finally we need to handle 'p' types. In the function makeList add the following case to the switch statement:

case ("p"):
	$starttoken = "";
	$endtoken = "";
	$listtoken = "<p>";
	$endlisttoken = "</p>";
	$this->separator = "";
	break;

Then just use Sort2 as you normally would using 'p' as a type, <sort2 type="p">

BlueSuede 21:21, 8 December 2011 (UTC)Reply

Extra Bullet Point

edit

If I use ul or ol it adds an extra bullet point at the bottom with no text beside it. I can get around this by using dl but I'd like the bullets. Any idea how I can fix this?

Return to "Sort2" page.