Extension talk:LinkAttributes

Jump to navigation Jump to search

About this board

Johnywhy (talkcontribs)

hi

we found support for "target" in your code (we think). https://github.com/rotsee/LinkAttributes/blob/master/LinkAttributes.body.php#L4

but not working for me.

when i try to save this:

[http://www.twitter.com Twitter|target=_self]

i get this:

[WuyUHc4dk4cRU9a4Ioa2DQAAAI8] /index.php?title=Draft:ParamTester&action=submit Error from line 26 of /home/gunsywtx/public_html/extensions/LinkAttributes/LinkAttributes.body.php: Undefined class constant 'attrsAllowed'

Backtrace:

#0 /home/gunsywtx/public_html/extensions/LinkAttributes/LinkAttributes.body.php(44): LinkAttributes::doExtractAttributes(string, array)
#1 /home/gunsywtx/public_html/includes/Hooks.php(177): LinkAttributes::ExternalLink(string, string, string, array, string)
#2 /home/gunsywtx/public_html/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#3 /home/gunsywtx/public_html/includes/Linker.php(875): Hooks::run(string, array)
#4 /home/gunsywtx/public_html/includes/parser/Parser.php(1885): Linker::makeExternalLink(string, string, boolean, string, array, Title)
#5 /home/gunsywtx/public_html/includes/parser/Parser.php(1304): Parser->replaceExternalLinks(string)
#6 /home/gunsywtx/public_html/includes/parser/Parser.php(451): Parser->internalParse(string)
#7 /home/gunsywtx/public_html/includes/content/WikitextContent.php(329): Parser->parse(string, Title, ParserOptions, boolean, boolean, NULL)
#8 /home/gunsywtx/public_html/includes/content/AbstractContent.php(516): WikitextContent->fillParserOutput(Title, NULL, ParserOptions, boolean, ParserOutput)
#9 /home/gunsywtx/public_html/includes/page/WikiPage.php(2080): AbstractContent->getParserOutput(Title, NULL, ParserOptions)
#10 /home/gunsywtx/public_html/includes/page/WikiPage.php(1606): WikiPage->prepareContentForEdit(WikitextContent, NULL, User, string, boolean)
#11 /home/gunsywtx/public_html/includes/EditPage.php(2203): WikiPage->doEditContent(WikitextContent, string, integer, boolean, User, string, array, integer)
#12 /home/gunsywtx/public_html/includes/EditPage.php(1514): EditPage->internalAttemptSave(array, boolean)
#13 /home/gunsywtx/public_html/includes/EditPage.php(667): EditPage->attemptSave(array)
#14 /home/gunsywtx/public_html/includes/actions/EditAction.php(60): EditPage->edit()
#15 /home/gunsywtx/public_html/includes/actions/SubmitAction.php(38): EditAction->show()
#16 /home/gunsywtx/public_html/includes/MediaWiki.php(499): SubmitAction->show()
#17 /home/gunsywtx/public_html/includes/MediaWiki.php(293): MediaWiki->performAction(Article, Title)
#18 /home/gunsywtx/public_html/includes/MediaWiki.php(851): MediaWiki->performRequest()
#19 /home/gunsywtx/public_html/includes/MediaWiki.php(523): MediaWiki->main()
#20 /home/gunsywtx/public_html/index.php(43): MediaWiki->run()
#21 {main}
Reply to "error with target=_self"
Verdy p (talkcontribs)

Instead of the syntax you propose that alters the meaning of the displayed text (pipes no longer working the same way, and even broken pipes now):

[[User:Verdy_p|my userpage|rel=me|attribute2=value2]]

which normally means the standard wikilink rendered as:

my userpage|rel=me|attribute2=value2

It would seem more natural to put attributes at the begining where it is easy to discriminate them from a pagename:

[[|rel=me|attribute2=value2||User:Verdy_p|my userpage]]

The leading pipe isolates an "empty" page name that annot be a valid target link; at this time, the next pipe separators are used to separate one or more attributes (all of them must have an equal sign to create the attribute's key=value pair), an empty part terminates the sequence and indicates that what follows is the wikilink (which can include an equal sign but no pipe!), and everything after the next pîpe is part of the displayed text (including all other pipes up to the double closing brackets).

With the unextended wiki parser you get this plain text, kept verbatim by MediaWiki (confirming that the leading pipe between brackets cannot be a classic wikilink target:

[[|rel=me|attribute2=value2||User:Verdy_p|my userpage]]

Note also how this renders if you forget the leading pipe (MediaWiki still attempts to parse a wikilink to a page named "rel=me")

attribute2=value2||User:Verdy_p|my userpage

And this last example explains why we need a way to terminate attributes with double pipes before the wikilink target (where equal signs are valid part of target page names. However we may forget the double pipe if what follows the last attribute is a page name that has no equal sign (the double pipe is an escaping mechanism not needed below as the target page has no equal sign in its name):

[[|rel=me|attribute2=value2|User:Verdy_p|my userpage]]

Another way to specify attributes could be to put them between square brackets, anywhere within the wikilink target part (because standard wikilink targets cannot contain square brackets) :

[attribute2=value2]User:Verdy_p|my userpage
[[[rel=me]User:Verdy_p[attribute2=value2]|my userpage]]
[[User:Verdy_p[rel=me][attribute2=value2]|my userpage]]
[[User:Verdy_p[rel=me|attribute2=value2]|my userpage]]

which MediaWiki will also leaves as verbatim text:

[attribute2=value2]User:Verdy_p|my userpage
[[[rel=me]User:Verdy_p[attribute2=value2]|my userpage]]
[[User:Verdy_p[rel=me][attribute2=value2]|my userpage]]
[[User:Verdy_p[rel=me|attribute2=value2]|my userpage]]

This is not the case however if you put bracketed attributes in the second part:

[[User:Verdy_p|my userpage[rel=me]]]

which gives a standard wikilink (not what we want)

my userpage[rel=me]

In summary: any extensions for wikilinks must be within their 1st part, not their 2nd part containing the displayed text, and use the restrictions that apply to valid link targets (it is even possible that MediaWiki will accept to insert embedded links within them, for example a whole line going somewhere, except one small icon or small notecall going somewhere else):

my userpage is here (but my talk page is elsewhere)

For now this syntax is not accepted in standard MediaWiki, but it should remain valid to put embedded links within a larger surrounding link (it is perfectly valid in pure HTML).

One of the most desired feature for attributes of wikilinks would be to allow them to be styled in a much simpler way (without having to use complex HTML spans in the second part):

[[User:Verdy_p[rel=me][style=background:black;color:white]|my userpage]]

But we could also give them other common attributes (all predefined in the standard HTML anchor "a" element) such as "id=*", "title=*", "lang=*"

Another usage would be to give attributes to numbered or bulleted lists, including in the middle of the list, without interrupting it, by defining special targets (they'll reach an HTML "li", or "dd" or "dt" attribute), for such usage the second part is just standard wiki text but optional (it may still be useful to delimit it if it has to spen several lines:

[[[#][start=10]|this is the item number ten in a numbered list]]
[[[*][style=square]|this item and the next ones will use a square bullet]] (note that Wiki page names with an asterisk * are valid)
[[[:][id=example]|this is an indented example]]

Thanks... this is just a suggestion...

Reply to "alternate safer syntax"
Tosfos (talkcontribs)

It seems that the extension calls its functions statically (self::), but it does not declare its functions to be static. Thanks!

Reply to "Minor "static" bug"
There are no older topics