Commit graph

858 commits

Author SHA1 Message Date
Fomafix
ebd1016e5a Linker: Simplify return paths
* Avoid else after return.
* Use early-return pattern.

Change-Id: I059e233d019dbc2233756776dfa09f8f2fdb2df7
2019-01-17 12:25:39 +01:00
jdlrobson
c6a96b4bd5 Separate content parts of mw-usertoollinks from presentation
Use the existing class mw-changeslist-links to visually separate
the user tools in CSS rather than in the HTML.

Bug: T205581
Change-Id: I024c8298ca5da753d96ec392be05d4530bb3ffa9
2019-01-09 00:56:40 +00:00
Fomafix
dffbbdbe39 Linker: Deprecate non-Language types for $lang of tocList() and generateTOC()
$lang still defaults to $wgLang on unset parameter.

Change-Id: I15b65fec987641885374dfef9e1229ea405f7c30
2018-12-21 17:41:30 +01:00
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
Kunal Mehta
1706d353ae Don't link wikilinks in section heading autocomments
Previously, a manually constructed autocomment in the form of
/* [[Some link]] */

would create a link to the the section, and then the "Some link" page.

After T165189 was implemented, the entire autocomment is now a link to
the section, so we're creating links inside of a link...which is
problematic. In most contexts (history and watchlist particularly), the
section link is more important than the title in the section heading, so
that's what we'll favor here.

It's worth noting that this situation is a manually created edge case.
Even if the section heading is a wikilink, the edit summary will
autofill a section autocomment without the double brackets.

We'll now render the double brackets ([[...]]) and not link them. This
is what the user literally typed, and matches the existing practice of
rendering templates in section headings with their literal syntax. And
as a bonus, it's still possible for user scripts such as wikEdDiff to
turn the rendered double brackets into a real link if users want.

Bug: T165189
Change-Id: Ib10679edd76c72a60d7e1c89fc8454166e34c463
2018-12-03 12:43:03 -08:00
Kunal Mehta
0c9cf24b05 Restore old HTML structure for history section links
A follow-up to 0a8e16d7cf thanks to Anomie's code review.

The section title is now inside <span dir="auto"> and <span
class="autocomment">, as before. $wgLang->getDirMark() between the arrow
and the text was restored.

Given the comment
 /* External links */ removed bogus entries
the HTML before 0a8e16d7cf looked like:
 <a href="#External_links">→</a>‎<span dir="auto"><span
 class="autocomment">External links: </span> removed bogus entries</span>
after this change, it will look like:
 <span dir="auto"><span class="autocomment"><a
 href="#External_links">→‎External links</a>: </span> removed bogus
 entries</span>

The issue of having links be inside other links will be addressed in a
separate patch.

Bug: T165189
Change-Id: I31d87a87ccaf50de58fdd0621c46133b2881b490
2018-12-03 12:42:56 -08:00
Bjornskjald
0a8e16d7cf Make "→" link to page section on History page larger by adding section name to it
Bug: T165189
Change-Id: I1f845592bd3de342fda84b60fc412055973950fd
2018-11-24 03:22:16 +00:00
jdlrobson
8f694424bd Differentiate comments with and without brackets
Per T205581#4768548 cached HTML might render a comment with
double brackets in the text. The CSS selector should not apply
there so a new class is used.

Using a BEM convention for the time being. This class can be
removed in future if needed.

Bug: T205581
Change-Id: If1552d6ddd4729b8beca45a1ca19ec6ce36e6118
2018-11-22 11:46:37 -08:00
jdlrobson
a7b8043cc3 Remove hardcoded parentheticals from ChangesList "comments"
From now on, the edit summary in ContribsPager results
will be wrapped in brackets via CSS pseudo elements.

Changes:
* Linker::revComment and Linker::commentBlock now accept a parameter which
can be used to disable wrapping in the text
* ContribsPager makes use of it

Bug: T205581
Change-Id: I60403a4a23d89107b7a28f0c12326d828a76614e
2018-11-21 20:15:06 +00:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
Max Semenik
c16704c33a Display SVGs in target language
Previously, they were always displayed in defult language unless
forced explicitly in wikitext, e.g. [[File:Foo.svg|lang=ru]].
This change adds a feature flag that would enable always trying to
display in page language.

* If enabled, Parser will pass a new parameter - 'pagelang' - to
  the media handler.
* SvgHandler uses page language when determining what language to
  render the image in.
* 'pagelang' can always be overridden by 'lang'.
* If no translation in page language is available, the default
  language (English) will be used for thumbnail URLs, to prevent
  cluttering media storage and HTTP caches with useless copies.

Performance: this requires accessing image's metadata during parsing.
My testing indicates there were no code path where this wasn't the
case already, so no performance hit is expected, however we should
still keep an eye on page save performance.

Bug: T205040
Change-Id: I348840ef405e1370cc0c17d69051bce30153c9c0
2018-10-30 16:12:11 -07:00
Roan Kattouw
39e2e85a44 Linker: Document parseComment() as returning HTML
It's not entirely clear from the documentation whether this method
returns wikitext or HTML, so make it explicit.

Change-Id: I094e370e921c43dd8c5dc4376b3dddd803665d90
2018-10-12 15:18:03 -07:00
jenkins-bot
2311183aa0 Merge "Linker: Remove outdated comment" 2018-09-08 01:35:49 +00:00
Thiemo Kreuz (WMDE)
2c58fbaa29 Linker: more consistent whitespace parsing in formatLinksInComment
Try to paste and preview this in the wikitext as well as the summary
line: [[:a]] [[ :a]]

The wikitext will show "a a", but the summary line will show "a :a".
This is only a display issue, all 4 links correctly link to the
article [[A]].

Change-Id: I08253a6d0b55b9aa3eace519bbdc1a456400bf84
2018-09-06 17:19:32 +00:00
Bartosz Dziewoński
f08f6fcbc2 Linker: Remove outdated comment
This talks about references and values the way they worked in PHP 4.
Comment was added in r4927 (b025ad54) in 2004.

Change-Id: I58a74219665bed9e804d7c01f271fd96fd889072
2018-09-05 16:41:40 +02:00
Brian Wolff
5f577437e8 Change @return-taint to use onlysafefor_html instad of escapes_html
This prevents some double escaped warnings. Requires
I2f4e33656b9f94 to be effective. Follow up faf2e14517.

Change-Id: I255c96592f3baff2df34e07c81510c8874908e28
Bug: T202797
2018-08-31 09:48:30 +00:00
Kunal Mehta
faf2e14517 Linker: Add @return-taint for formatLinksInComment()
Works around a false positive in the phan-taint-check-plugin.

Bug: T202797
Change-Id: If7c9e729ca7624b3f791fe01d0b768791657277b
2018-08-29 22:22:24 -07:00
jenkins-bot
4e021bb8d4 Merge "Paranoia, escape image alignment parameters before outputting." 2018-08-27 19:10:41 +00:00
Aryeh Gregor
e68fdb4065 Mass conversion to SpecialPageFactory service
Change-Id: Ia6e1e819ec6cbe8bf75b820109f51d47863e31fc
2018-08-17 12:03:12 -07:00
Brian Wolff
d370c51df1 Paranoia, escape image alignment parameters before outputting.
The alignment parameter is totally safe (See the very convoluted
code in the parser) but its best practise to escape things right
before the output. Additionally this protects in case any extension
uses a hook to do anything silly.

Change-Id: Ie19b106409d55c704b69280e2d0e2bb29068bd2e
2018-08-13 23:30:50 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Bartosz Dziewoński
6e09d07b20 Set role=button on TOC show/hide checkbox
This should give more intuitive hints in assistive technology,
identical (or similar) to the hints for the JavaScript-generated
button we had before 68527cf479.
See results of testing with Windows Narrator/VoiceOver: T195053#4428563.

Bug: T195053
Change-Id: I9358b29f56ac1e43e9c5ed00d30ce6ffdf903299
2018-07-16 18:15:48 +00:00
Arlo Breault
ce9f5c2546 Put <dt>/<dd>/<li> in the always-suppressing category of doBlockLevels
This is a clarification of what already happens in practice for lists
generated from wikitext syntax, since that parsing happens
simultaneously.

Parsoid, for its part, does list handling prior to paragraph wrapping,
so must make use of these definitions.

Further, this helps reduce paragraph wrapping in interstitial spacing of
lists from HTML syntax, as spec'd in the tests, though the possibility
isn't eliminated entirely.

The TOC generation code is altered to reduce the number of newlines
emitted in between list items, since those are now left intact.

Change-Id: I6888b6e8e6768b0737565b87924fefa5a06ebd18
2018-07-13 12:40:49 -04:00
jenkins-bot
56d45558b1 Merge "Hide TOC with CSS instead of JavaScript" 2018-07-11 20:36:22 +00:00
Fomafix
68527cf479 Hide TOC with CSS instead of JavaScript
Changes in the behavior:
* The toggle button generate no FOUC on loading.
* On keyboard navigation the toggle key is the space key and not the
  return key.
* Animation on hide and show is missing. Maybe a new animation with CSS
  can added.
* The state of the button is not saved in a cookie.
* Self-build TOCs can not get hidden.

Browser support:
* The new implementation does not need JavaScript and therefor it works
  on browser with disabled JavaScript and on Grade C browser.
* The new implementation requires the CSS pseudo-class selector
  :checked. Therefor IE8 and lower are not supported.

Risks:
* The new implementation needs additional HTML elements. These elements
  also get cached and crawled. The elements have no content so they get
  hopefully ignored by crawler.
* The new CSS code imitates some styles (link, focus). This must kept
  up to date.
* Multiple TOCs on one page would generate the same id attribute.
  This can avoided by appending a counter or better and easier a random
  string to the id attribute.

Bug: T195053
Change-Id: I82db33d656b3795d7134a91d20ed9d93a3471086
2018-07-09 08:07:52 +02:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
jenkins-bot
c451267578 Merge "Pass $parser, &$query and &$widthOption to the 'ImageBeforeProduceHTML' hook" 2018-06-13 15:31:01 +00:00
Kunal Mehta
03e7ae45bc Remove deprecated Linker::getLinkColour()
Change-Id: I1818d9eb369c620cc436c13446a5362816e8362d
2018-06-13 01:30:04 -07:00
Jack Phoenix
088c6db48b Pass $parser, &$query and &$widthOption to the 'ImageBeforeProduceHTML' hook
This allows extensions to essentially reimplement Linker#makeImageLink
completely. Before this wasn't 100% possible as these three are needed for
that.

Inspired by wikiHow's core hacks to /includes/Linker.php, which can now be
moved to an ImageBeforeProduceHTML hook subscriber. wikiHow uses those
changes together with the WikihowArticle extension to heavily modify the
article DOM for various extensions and the default skin.

Change-Id: I8b5ab42d9cf021d66b90d15be68a0239643c10e3
2018-06-10 18:31:56 +03:00
jenkins-bot
0c4debc0b0 Merge "Escape text in Linker::specialLink()" 2018-06-10 07:49:49 +00:00
Matěj Suchánek
2b2a93e202 Escape text in Linker::specialLink()
Linker::linkKnown -> Linker::link -> $text is wrapped by HtmlArmor

Bug: T85864
Change-Id: I8755948131ffca4a0b5949b2f8cabf19f59c1c9e
2018-06-09 08:42:41 +00:00
Erik Bernhardson
3a565d6b17 Resolve required parameter after optional parameter in Linker
Change-Id: I2569e30922e93404a59fa282df8ae8d3d19912fd
2018-06-08 21:49:04 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Kunal Mehta
230958d97c Autofix MediaWiki.Commenting.FunctionComment.SpacingDoc* errors
Change-Id: I63761ebce04c03b9b13237919c27cc10180f198f
2018-05-19 14:07:03 -07:00
Brad Jorsch
27c61fb1e9 Add actor table and code to start using it
Storing the user name or IP in every row in large tables like revision
and logging takes up space and makes operations on these tables slower.
This patch begins the process of moving those into one "actor" table
which other tables can reference with a single integer field.

A subsequent patch will remove the old columns.

Bug: T167246
Depends-On: I9293fd6e0f958d87e52965de925046f1bb8f8a50
Change-Id: I8d825eb02c69cc66d90bd41325133fd3f99f0226
2018-02-23 10:06:20 -08:00
jenkins-bot
ea43303951 Merge "Move methods for handling external usernames to a dedicated class" 2018-01-19 14:43:42 +00:00
Amir Sarabadani
dc4089b268 Move methods for handling external usernames to a dedicated class
This makes things centralized to reduce maintenance cost and also
enables me to use this methods in Wikibase to handle RC injection

Bug: T185034
Change-Id: Ic8c602e316144ccb5b05c69a0cc607cd53e38912
2018-01-18 21:02:49 +01:00
jenkins-bot
a18476eab3 Merge "Remove @param comments that literally repeat what the code says" 2018-01-11 23:48:03 +00:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01:00
Albert221
a9cbe0c847 Add text to tab links telling if they do exist
And changed a little bit signature of Linker::titleAttrib
and Linker::tooltipAndAcceskeyAttribs. Added $options
parameter to the second one and made $options parameter
satisfied by passing an array with options, because there
is one more now: 'nonexisting' which tells to add text
about the thing that the page does not exist to its tooltip.

Bug: T19099
Change-Id: Ia76dd6db363f6add5efb8955be9e23a1f8e8476f
2018-01-08 16:42:01 +00:00
Thiemo Mättig
544122a6c2 Remove self-explaining "section heading" comments from classes
I can see that "parent::__construct" literally calls the parent
constructor. I can see that stuff preceeded by the keyword "protected"
is protected. I really (really) don't need comments explaining such.

Change-Id: I7458e714976a6acd3ba6a7c93fdc27d03903df83
2017-12-28 16:12:08 +01:00
Fomafix
65b888a520 Add HTML attributes lang and dir to toctitle
The toctitle is in user interface language. This change add the
HTML attributes lang and dir to the toctitle.

This allows to copy (a part of) the rendered HTML to a word processing
and the language for spell checking has the right language.

Change-Id: I17730869f81744560672d7d0acb67ced71e69c4e
2017-12-27 20:26:06 +01:00
jenkins-bot
86b4925b2e Merge "Linker: Use Parser::guessSectionNameFromStrippedText()" 2017-12-12 13:13:07 +00:00
Roan Kattouw
62f284a6ac Linker: Use Parser::guessSectionNameFromStrippedText()
Instead of weird partial stuff.

Change-Id: Ibe7435a4723d2741e32d37d2ba67396d78d14044
2017-12-07 10:23:10 -08:00
Brad Jorsch
96bd79b4a3 Avoid DB rows with usable names but ID = 0 by introducing "interwiki" usernames
Importing revisions in MediaWiki has long been weird: if the username on
the imported revision exists locally it's automatically attributed to
the local user, while if the name does not exist locally we wind up with
revision table rows with rev_user = 0 and rev_user_text being a valid
name that someone might later create. "Global" blocks too create rows
with ipb_by = 0 an ipb_by_text being a valid name.

The upcoming actor table change, as things currently stand, would
regularize that a bit by automatically attributing those imported
revisions to the newly-created user. But that's not necessarily what we
actually want to happen. And it would certainly confuse CentralAuth's
attempt to detect its own global blocks.

Thus, this patch introduces "interwiki" usernames that aren't valid for
local use, of the format "iw>Example".[1] Linker will interpret these
names and generate an appropriate interwiki link in history pages and
the like, as if from wikitext like `[[iw:User:Example]]`.

Imports for non-existant local users (and optionally for existing local
users too) will credit the edit to such an interwiki name. There is also
a new hook, 'ImportHandleUnknownUser', to allow extension such as
CentralAuth to create local users as their edits are imported.

Block will no longer accept usable-but-nonexistent names for 'byText' or
->setBlocker(). CentralAuth's global blocks will be submitted with an
interwiki username (see Ieae5d24f9).

Wikis that have imported edits or CentralAuth global blocks should run
the new maintenance/cleanupUsersWithNoId.php maintenance script. This
isn't done by update.php because (1) it needs an interwiki prefix to use
and (2) the updater can't know whether to pass the `--assign` flag.

[1]: '>' was used instead of the more usual ':' because WMF wikis have
many existing usernames containing colons.

Bug: T9240
Bug: T20209
Bug: T111605
Change-Id: I5401941c06102e8faa813910519d55482dff36cb
Depends-On: Ieae5d24f9098c1977447c50a8d4e2cab58a24d9f
2017-11-30 13:12:44 +11:00
jenkins-bot
afbf5e7899 Merge "Do not double decode HTML entities for IDs" 2017-09-13 17:50:37 +00:00
jenkins-bot
f1c7c0f03d Merge "Linker: Accept LinkTargets in makeCommentLink()" 2017-09-13 10:15:54 +00:00
jenkins-bot
62a9ee2f45 Merge "Linker: Accept LinkTarget objects in link()" 2017-09-13 10:10:39 +00:00
jenkins-bot
083c0dce4e Merge "Linker: Don't use Title::setFragment()" 2017-09-13 10:07:16 +00:00
Fomafix
b6c895ddc5 Do not double decode HTML entities for IDs
* in links (T103714)
* in indicators (T104196)

This change removes the automatic Sanitizer::decodeCharReferences from
Sanitizer::escapeId and Sanitizer::escapeIdInternal. Where decoding of
HTML entities are wanted an explicit call to
Sanitizer::decodeCharReferences is added.

Explicit decode HTML entities in non local autocomments. (T104311)

Bug: T103714
Bug: T104196
Bug: T104311
Change-Id: I88e8e2077e6f5eec2b232391f7818370894a62dc
2017-09-12 15:42:17 +02:00