Commit graph

98 commits

Author SHA1 Message Date
Fomafix 9afddc19d0 Inject services into Hooks
Change-Id: I1b91c256b8b864efb29d6dbd41e89884804e001c
2024-12-08 13:09:15 +00:00
Fomafix 64bd35d95f Create new class Hooks and use this for HookHandlers
Change-Id: I7eaea1d3664dc5d9ac986b34732f45432b76e5be
2024-12-08 13:02:03 +00:00
Ammarpad 863391d7b8 Define remote extension path for dynamic RL modules
This path is needed for URL expansion in debug mode.

Bug: T378878
Change-Id: Ic7b067df2c03286575d0a390d90d6d2d4b3169e5
2024-11-03 19:24:46 +01:00
Umherirrender 63fbfa541e Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Iede38f051529229fce7660dce7d0dba64724ee8a
2024-10-20 11:56:25 +02:00
Siddharth VP d9f5c2a60e Parsoid DOM compatibility for links and copy buttons
Change-Id: Ib3d30ba38753a060772029379675a5552c9631af
2024-10-12 22:57:59 +05:30
Siddharth VP e45a7eac30 Avoid PHP_EOL while generating CSS
Change-Id: I242abd8fe68fd08ddb3c6358aa88b6f3d382823b
2024-09-30 22:43:05 +05:30
Siddharth VP b8dd28343c Support dark mode for code blocks
Update the CSS generation script to generate styles for both light and
dark modes. The Pygments style 'default' is used for light mode, as
before, and 'monokai' for dark mode.

Bug: T365926
Change-Id: I0cc1f9a10d4ff8e0c279a12cacbb1c300225328f
2024-09-28 23:06:30 +05:30
Siddharth VP 38cbb6fed6 copy button: use Codex colors for dark mode compatibility
Bug: T40932
Change-Id: I9a809954f64c6d3a14cc3e2b3c2fd38824f803f3
2024-09-28 23:06:30 +05:30
Siddharth VP 4c9ed25619 Link page references in Scribunto modules
In Scribunto modules, link page names used in require(), mw.loadData()
and mw.loadJsonData() invocations.

Inspired from the CodeLinks gadget[0] but rewritten for brevity,
avoiding Wiktionary specific code, making the code more generic,
and thereby adding support for mw.loadJsonData().

[0]: https://en.wiktionary.org/wiki/MediaWiki:Gadget-CodeLinks.js

Bug: T368166
Change-Id: Idc554269ee52a05660fa41f065a2b3c73e2e1b9b
2024-09-24 22:47:56 +05:30
Siddharth VP 55630cc5ea Implement copy buttons for code blocks
<syntaxhighlight> blocks with a boolean "copy" param will now have a
button next to them for copying the code to the clipboard. Not
applicable for inline code blocks.

Adapted from the mediawiki.org gadget written by Krinkle.

Bug: T40932
Change-Id: Ic8ef030514c3b6dd2cb9b137f032588869ab3762
2024-09-11 01:31:14 +05:30
jenkins-bot f2d0dde88c Merge "Enable clicking on wikilinks and external links in highlighted code" 2024-09-09 13:29:52 +00:00
Fomafix b58d0bded1 Use MainConfig instead of global variables
Also use MainConfigNames.

Change-Id: I5b61c2badd2aa2163cbc429003a890bf559dc4f6
2024-08-12 21:06:29 +00:00
Andrea Denisse Gómez-Martínez 0249ef7273 Migrate MediaWiki.syntaxhighlight_shell.*.rate to statslib
This patch migrates the `syntaxhighlight_shell` metric to the new Prometheus
format while copying the equivalent graphite counterpart to Graphite for
backwards compatibility with the existing Grafana dashboards.

Bug: T359270
Change-Id: I95bc2e749324092aae5db9135847c28aa16c64ea
2024-07-05 10:30:25 -06:00
Siddharth VP 7fa3abe91e Enable clicking on wikilinks and external links in highlighted code
It's common practise to use [[wikilink]] syntax to mention page names
in comments of JS/CSS/Scribunto code where the links ordinarily don't
work. Using JavaScript to actually make the syntax clickable makes
navigation easier.

{{Templates links}} and external links are also supported.

Bug: T368166
Change-Id: I999937c1f6303ecc64adb6285e73a9ce10f67bd8
2024-06-22 12:35:22 +05:30
Umherirrender 888aa0e373 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Ifa5d93fd8c4b96fa22e6c4bbadc0e9c5315d7be1
2024-06-10 20:40:28 +02:00
Bryan Davis ee1a6c20d7 Pygmentize: report stderr when exit code != 0 and stdout is empty
Most python error messages are reported to stderr rather than stdout. In
the event of a catastrophic failure executing the Pygments binary we are
likely to need to report stderr so that folks can debug the problem with
the executable.

Bug: T364249
Change-Id: Id5e5dbc515fdcdeb6eec61aacbbb9cbeddc79fab
2024-05-17 11:01:28 -06:00
Umherirrender c0703d33ec build: Upgrade mediawiki/mediawiki-codesniffer to v43.0.0
Change-Id: If2acd67c6275e74e487a2e0ce8d34277a70782ca
2024-03-12 20:48:18 +01:00
Ed Sanders f5dd12e83b Allow linelinks prefix to be any character(s)
Old HTML IDs had to start with Latin letters, but
in HTML5 IDs can use any characters.

Bug: T359214
Change-Id: I6b6733eb07267faca1990bb7445a967405f9327e
2024-03-06 21:32:48 +00:00
thiemowmde 040f45302b Fix GeSHi support, update PHP/JSDocs, use modern PHP
The PHPDoc/JSDoc updates are mostly about generic "array" types that
can be made more specific.

In PHP we can remove documentation when it is 100% identical to the
type declarations in the code.

A few mistakes are fixed as well, e.g. a missing "null".

This patch also made a major mistake visible. It looks like the
$geshi2pygments compatibility map was broken since 2018. The array was
changed from values to keys via I7a852dd and some usages updated, but
one was forgotten.

Change-Id: I480999d21f2f69cba84166bb877aa75882778966
2024-01-22 20:10:04 +01:00
jenkins-bot 73e1073108 Merge "Add a few missing type declarations to properties and methods" 2024-01-22 14:21:55 +00:00
thiemowmde 006455ec37 Add a few missing type declarations to properties and methods
Most of the code in this codebase already uses language-level types.

Change-Id: I1df9439c69eec5ad0b2a9a608729975027a04172
2024-01-22 09:39:30 +01:00
thiemowmde 7a4d59accc Replace preg_replace() with more simple trim()
This does the same as before. Only newlines are trimmed from the
left, but all whitespace from the right.

Change-Id: I6b7c860d8a2fc2a1f28428447ee8f18ab4bbe46c
2024-01-22 09:37:01 +01:00
Umherirrender 890a260032 Use namespaced classes
This requires 1.42 for some new names

Change-Id: I3821d2bca4aa8e7c0fce2a730c070b597c526247
2024-01-05 19:29:59 +01:00
Isabelle Hurbain-Palatin e4e8f8e076 Set hasWikitextInput flag to false
The content of the SyntaxHighlight extension is not wikitext and
annotations should be stripped from it before rendering.

Bug: T341009
Depends-On: I4e9a7a8bec3cb9532ef8a729fd2c6c4acca5d8a0
Change-Id: Ibada54d517830b1112b59513b090dc4bbdc7c917
2023-10-03 20:52:29 +00:00
gerritbot fc431bcd8d Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: I7a26d8653e2ed41ab65e8b199c748d1a9e6a80d6
2023-08-19 12:26:03 +00:00
Umherirrender 7087e991d5 Use HookHandlers for core hooks
The use of "HookHandlers" attribute in extension.json makes it possible
to inject services into hook handler classes in a future patch.

Bug: T271029
Change-Id: I6df44cf4a160e618a6546fb9eec36070bf4b868e
2023-08-14 20:23:40 +02:00
Daimona Eaytoy 52ac696e25 Replace deprecated MWException
Bug: T328220
Change-Id: Iaf4a9bb4aafc741395d5ccc5a42c6a72b5d42b99
2023-06-08 11:14:08 +00:00
jenkins-bot 81f673bc6d Merge "Pygmentize: Treat Shellbox network loss like non-zero exit code" 2023-06-06 23:55:12 +00:00
Ed Sanders 274cc4ab77 Always use the strict equality flag when using in_array
Change-Id: Iedd51f31db2bc4e5257d211719f8bdcf1abb09dd
2023-06-06 13:35:40 +01:00
Timo Tijhof 682fe922f9 Pygmentize: Treat Shellbox network loss like non-zero exit code
Prior to the shellbox migration, if during the parsing of a page,
pygmentize failed (i.e. non-zero exit from its local shell command,
pretty much the only way a php shell exec could fail), then
SyntaxHighlight would fallback to outputting a preformatted plain
`<pre>`.

The logic still exists in the code, and is still triggered for cases
where the command reached shellbox and its result was "successfully"
communicated to MediaWiki (HTTP 200), with the boxed result reporting
the non-zero exit code on the shellbox server.

However, the more likely scenario in the new setup is that the command
times out or never reaches the server in the first place, in which
case we don't get any shell exit code. Instead, we get a Shellbox
exception since the result is unknowable.

Instead of fatalling the entire pageview with a PHP exception and
HTTP 500 from MW, use the same graceful fallback.

Bug: T292663
Change-Id: Icaa8c34ff97ad8a99d044beab529ef943071269c
2023-06-03 14:25:50 +01:00
Tim Starling 54b02b02e1 Migrate ResourceLoaderSyntaxHighlightVisualEditorModule to a virtual file callback
Depends-On: I97d61b5793159cea365740e0563f7b733e0f16de
Bug: T47514
Change-Id: I10fceeee808e4d08f7ed63afb13b4d87129365c7
2023-05-08 17:15:48 +10:00
Ed Sanders e39f530bfb Document the linelinks attribute and load JS when used
Change-Id: Iaf6e2ef58e85ac92e5fcf9dd3449baae927feb9c
2023-03-09 12:48:55 +00:00
jenkins-bot 14cb8415da Merge "fetchLexers: Pass '--json' to Pygmentize" 2022-12-21 01:00:30 +00:00
Ori Livneh 508e926b5d fetchLexers: Pass '--json' to Pygmentize
Use the '--json' flag to get Pygments to output its list of supported
lexers in a machine-readable format. Support for this flag was added (at
our request) to Pygments and included in the 2.11 release[1].

Tested by running updateLexerList.php and confirming empty diff.

  [1]: https://github.com/pygments/pygments/issues/1437

Change-Id: I0f1d7fceca9034e6034bafa6a8dd312b99d379d1
2022-12-20 23:18:55 +00:00
jenkins-bot 4fead6c331 Merge "Fix lexer list parsing on Windows" 2022-12-20 22:40:50 +00:00
jenkins-bot 362ca84426 Merge "Make the code size limit for highlighting configurable" 2022-11-26 12:54:41 +00:00
Ryan Schmidt 2ae82c7fb7 Fix lexer list parsing on Windows
When using a non-bundled Pygments (which is required on Windows, as the
bundled version is an ELF binary), we call into the Pygments executable
to generate the list of supported languages (lexers). This list seems to
occasionally include carraige returns, causing some languages to not be
processed correctly. Trim those CRs out so the language list is
accurate.

Change-Id: If8b1f145dd10e2c4707d6d32927e85d1d2459f15
2022-11-20 22:46:55 -07:00
libraryupgrader 27ca45e8cb build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 39.0.0 → 40.0.1

npm:
* stylelint-config-wikimedia: 0.13.0 → 0.13.1

Change-Id: Ifd15d37271ad474c948e9187b7b6bccc1f336489
2022-11-16 23:22:01 +00:00
jenkins-bot 1351b2e427 Merge "Count only real highlighting as expensive parser tag hooks" 2022-11-11 09:18:52 +00:00
alex4401 90ee9a9774
Make the code size limit for highlighting configurable
Replacing the HIGHLIGHT_MAX_LINES and HIGHLIGHT_MAX_BYTES constants with $wgSyntaxHighlightMaxLines and $wgSyntaxHighlightMaxBytes respectively, so sysadmins can adjust the limits to their needs if performance is not of their concern.

Bug: T322293
Bug: T104109
Change-Id: I80768d3cb45ac01c004fc812832878c83ca4ecdb
2022-11-03 12:04:35 +01:00
Ryan Schmidt d7a6038211 Fix pygments on Windows
Python on Windows requires the SystemRoot environment variable in order
to initialize its internal RNG, so make sure that is passed along to the
subprocess.

Bug: T300223
Change-Id: I170ce627a3f00c023f4b1f11613f4fe2cb17bd31
2022-11-02 19:02:59 -07:00
Reedy d94fec0141 Remove global class alias
Change-Id: I334a6ce9040385b11f30bb5d25e45bb124e0acce
2022-10-31 23:07:39 +00:00
Umherirrender fe6415836d Count only real highlighting as expensive parser tag hooks
Skip the expensive check,
for example when no highlighting is wanted because there is no lexer

Also all validation of the tag is now processed and
invalid tags also not counted.

Bug: T316858
Change-Id: Ifad9a9a14fae92463c345fb12defb41f14c2e1f3
2022-10-09 18:22:02 +02:00
Umherirrender 0cb5db91b8 Track syntaxhighlighting as expensive parser tag hook
The shell out to get styled text is expensive.
Call Parser::incrementExpensiveFunctionCount to limit the highlighted
text snippet on a page and not reaching a timeout.

This would count each tag and not deduplicate the text snippet to count
only once or if pygmentize needs to call or is in the cache.
This also not affect Parsoid, not sure if the concept of expensive
parser function exists there

Bug: T316858
Change-Id: I8afe61e9be4a34e5f0725a9b65ef43c345e1be5f
2022-09-07 21:41:17 +02:00
Sébastien Beyou b08c0a7cb9 Fix the case of empty <syntaxhighlight /> tags
Bug: T315740
Change-Id: I685806d4e8992a54f17d29a9187807bb30e31ef8
2022-08-21 13:46:17 +02:00
Subramanya Sastry 0eef7add67 Add Parsoid support for syntaxhighlight
* Added Parsoid config, and refactored code slightly to
  add native Parsoid handlers for parser tags exposed
  by this extension.
* Enabled parsoid mode testing on the test file.
* Added html/parsoid sections on a few tests.
* Marked rest of tests as wt2html and wt2wt only since
  html2wt and html2html will fail without a html/parsoid section
  and there is no real benefit to adding them to all tests.
* Added a couple tests to the known failures list:
  - One is because of T299103.
  - The other is because Parsoid always emits attributes in the
    form <tag .. foo="bar"..> instead of just <tag ... foo ..>
    Since Parsoid needs to accept this format that is present on
    wikis, I added a html/parsoid section for this test and
    added the failures to the known failures list.

Bug: T272939
Change-Id: Ie30aa6b082d4fc43c73296ff2ed6cb8c3873f48f
2022-08-08 20:07:46 -04:00
Bryan Davis 3bee59df01 fix: Mark Pygmentize::fetchVersion as public, but @internal
Follow up to ae07430. The method needs to be public so that
WANObjectCache can call it from a callback, but we don't expect any
external callers.

Follows-Up: I424926d071e1cfd454a0c2d45a83693f41bdea55
Change-Id: Ia96d3132782435c693d2eaa77fd551fe9590b113
2022-07-15 19:13:52 -06:00
Timo Tijhof ae074306e8 Pygmentize: Cache pygments-version in memc (in addition to APCU)
* Add rationale for each cache key's strategy being in Memc vs APCU.

* Extend pygmentize-lexers from 1 day to 1 week. It rarely changes
  and already varies by version. Few things survive the day, but
  there's not a reason to explicitly expire it sooner I think.

* Add a layer of Memc to the pygments-version APCU cache given that
  it has a short expiry and thus relatively high miss rate.

  The main rationale for this is noise in mwdebug logs since this
  is currently the only thing we log by default in Logstash with prod
  severity (exec INFO) during every pageview (after a php-fpm restart
  which clears APCU). By adding Memc here we lose less of the cache
  churn by reviving it via Memcached, and we keep the sense of there
  being nothing in the logs "by default" at prod severity after restart,
  e.g. don't get used to any fatigue.

  Unlike the other cache keys and hooks, getVersion is the only
  thing that gets called widely regardless of whether syntaxhighlight
  is in use on the given page.

Change-Id: I424926d071e1cfd454a0c2d45a83693f41bdea55
2022-07-12 05:56:16 +00:00
Tim Starling 956aa8ecd7 Use new ResourceLoader namespace
Extensions using Phan need to be updated simultaneously with core due
to T308443.

Bug: T308718
Depends-On: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
Change-Id: Ie1356c582baf9a66b868f7349cc71c26f8f1ead3
2022-05-27 03:42:55 +00:00
Reedy 39b4f0c7c1 Namespace rest of the extension
Global alias of SyntaxHighlight left behind for migration

Change-Id: I35b2caa42ac91454abe359949e360d1601748121
2022-03-18 01:42:11 +00:00