Commit graph

67 commits

Author SHA1 Message Date
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
C. Scott Ananian
a17746274f Remove untidy wrapper from ImagePage::makeMetadataTable()
Replace a fragile <div> wrapper with the robust
OutputPage::wrapWikiTextAsInterface() wrapper.

Bug: T205624
Change-Id: I0a1ba0da6af97f0233afdd8ba7202abed0998419
2018-10-22 16:45:50 +00:00
jenkins-bot
98744107cd Merge "Use OutputPage::wrapWikiTextAsInterface() to add safe <div> wrappers" 2018-10-22 02:00:35 +00:00
jenkins-bot
72e5b5af65 Merge "Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()" 2018-10-22 01:49:58 +00:00
Bartosz Dziewoński
5f2cb872b5 ImagePage: Inherit parent's handling for action=render
ImagePage::render() was calling parent::view() instead of
parent::render(), thus skipping Article::render() entirely.
Therefore the logic to disable section edit links (and also,
to add an 'X-Robots-Tag: noindex' header) was not being used.
This fixes T65891 and T21415 for pages in 'File:' namespace.

Bug: T206546
Change-Id: I36ae716c9a363ae29b7a785cc41430301250baba
2018-10-18 05:08:11 +02:00
C. Scott Ananian
ade27ecba3 Use OutputPage::wrapWikiTextAsInterface() to add safe <div> wrappers
This ensures that broken messages can't break the <div> wrapper and
that the output is tidy.

Bug: T205624
Change-Id: I2511adf593a13528e205a82d9fcdc8a524d0a95f
2018-10-17 11:08:16 -04:00
C. Scott Ananian
c0ed262053 Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()
This change ensures that the output is tidy, and is necessary to support
future parsers which will not be able to produce untidy output.

Bug: T198214
Change-Id: I743f4185a03403f8d9b9db010ff1ee4e9342e062
2018-10-17 10:35:28 -04:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02:00
daniel
4835a75ec5 Use RevisionRenderer for rendering ParserOutput
Bug: T174035
Bug: T174036
Change-Id: I1085b05d635dd954c143c8a398fae909632ba0a9
2018-09-11 15:25:39 +00:00
Brian Wolff
89b21847e1 Start working on phan-taint-check warnings. Fix minor escaping issues.
This fixes 26 of the phan-taint-check warnings on MW core. Some
are outright fixed, others are false positives that were suppressed.

This really only covers some of the easy ones. There are still
314 warnings to go.

Change-Id: I30463bc3a09fd4324d190de8533f51784764dd3a
2018-07-12 03:26:59 +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
Bartosz Dziewoński
b191e5e860 Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.

It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.

* Replace a common pattern like `return $a < $b ? -1 : 1` with the
  new operator (and similar patterns with the variables, the numbers
  or the comparison inverted). Some of the uses were previously not
  correctly handling the variables being equal; this is now
  automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
  $a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
  when both variables are strings, but if any of the variables is not,
  'strcmp()' converts it to a string before comparison, which could
  give different results than '<=>', so changing this would require
  careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
  of the time (returns `1` if `$b` is lesser, and `0` if they are
  equal or `$a` is lesser) but is erroneous.

Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2018-05-30 18:05:20 -07:00
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
Jack Phoenix
741b09c1f4 Make ImagePage#getThumbPrevText and ImagePage#makeSizeLink protected instead of private
So that extensions wishing to modify ImagePage#openShowImage() that want
to preserve most of the existing functionality (at least in certain
contexts) do not have to copypaste these two methods over.
ImagePage#openShowImage() itself is ridiculously large and it's absurd
that to change a few things there you need to copy over the whole giant
block of code, but that's a separate matter.

Inspired by wikiHow's WikihowImagePage extension and their associated core
hacks to ImagePage.php, which hopefully won't be needed in the future.

Change-Id: Ic5e16acfc2cf4683154a60a3eaa9df69d30d03cb
2017-12-21 09:42:19 +02:00
Timo Tijhof
6400972eea ImagePage: Make metadata table's initial collapse CSS-only
Make the initial collapse of the metadata table not depend on
JavaScript. This eliminates the FOUC, and will also reduce JS
footprint once compat can be removed.

* Move the 'display: none;' styles from metadata.css to
  filepage.css so that they are part of the base styles for
  file pages (metadata.css is only for supporting metadata.js,
  which is loaded dynamically).

* Apply "collapsed" class from the PHP side immediately,
  instead of calling "addClass" in JavaScript.

* Restrict hide-styles to only apply under .client-js to make
  sure the rows remain visible in no-js mode.

* Declare dependency between metadata.js and filepage.css.
  This is just for documentation purposes, as they are both
  already separately loaded on all file pages.

Change-Id: If22bf7acb47b59151dc3b0843a62507c100e548b
2017-12-05 02:50:33 +00:00
Timo Tijhof
463e51203c ImagePage: Clean up metadata.js collapsing
In preparation for trying out a CSS-only approach for the initial
collapse that doesn't cause the expanded view to flash first.

Bug: T182047
Change-Id: I42941ccb05d5525599a0209f0f33db9fe836580b
2017-12-05 02:49:36 +00:00
Étienne Beaulé
653a18f683 Show protection log on every use of moveddeleted-notice
As a follow-up to T171338, the other uses of the message were ignored.
This change adds the protection log to these uses; that is, history and
image pages.

Bug: T174889
Change-Id: Ib9f22d6e06c372c4a32e77a08c846d768853bc21
2017-12-03 20:04:22 +00:00
Cormac Parle
2a05b74684 Handle case when there is no handler for a file
Bug: T181365
Change-Id: Ia76b9e891eeb50071ef91e1768a7ad50f6fd7563
2017-11-27 09:44:19 +00:00
jenkins-bot
716814a5d5 Merge "Treat langtags in SVG switch case-insensitively" 2017-11-15 10:17:32 +00:00
Cormac Parle
f6620e2a75 Treat langtags in SVG switch case-insensitively
See https://tools.ietf.org/html/bcp47#section-2.1.1

Also implement matching of systemLanguage attribs as
specified in the SVG spec

Note that librsvg that we use for rendering pngs of svg
files has a bug, and matches languages in the following
way instead of what is implemented in SVG::getMatchedLanguage()

public function getMatchedLanguage( $userPreferredLanguage, array $svgLanguages ) {
  foreach ( $svgLanguages as $svgLang ) {
    if ($svgLang == $userPreferredLanguage) {
      return $svgLang;
    }
    $dashPosition = strpos( $userPreferredLanguage, '-' );
    if ( $dashPosition !== false ) {
      if (
        strtolower( substr( $svgLang, 0, $dashPosition ) ) ==
        strtolower( substr( $userPreferredLanguage, 0, $dashPosition ) )
      ) {
        return $svgLang;
      }
    }
    return null;
}

Bug: T154132
Change-Id: Ibff66a0844f0cecfae0260c6a7d20aeedc2849a2
2017-11-10 09:14:42 +00:00
Brian Wolff
483d6f21f0 Fix escaping of i18n message shared-repo-from
[Discovered using an experimental phan plugin]

Change-Id: Ia580dbd0646e2087c676f9e6989b5330d2149845
2017-10-16 06:01:56 +00:00
Fomafix
ea0bd74a94 Refactor global function wfBCP47 to static function LanguageCode::bcp47
Deprecate global function wfBCP47.

Change-Id: Ie6bb061b5d6ca67289bb18bc468a87421f38fc94
2017-10-05 09:54:45 +02:00
Umherirrender
5544cef16b Add missing type to @param documentation
Change-Id: I6b2c9c7af9a281fe457099cc3a336a60a25e74aa
2017-08-11 20:37:35 +02:00
Max Semenik
fd6e9ef2d4 Human-readable section ID support
It adds the ability to replace the current section ID escaping
schema (.C0.DE) with a HTML5-compliant escaping schema that is
displayed as Unicode in many modern browsers.

See the linked bug for discussion of various options that were
considered before the implementation. A few remarks:
* Because Sanitizer::escapeId() is used in a bunch of places without
  escaping, I'm deprecating it without altering its behavior.
* The bug described in comments for Parser::guessLegacySectionNameFromWikiText()
  is still there in some Edge versions that display mojibake.

Bug: T152540
Change-Id: Id304010a0342efbb7ef2d56c5b8b244f2e4fb2c5
2017-08-01 20:32:20 -07:00
Matthias Mullie
6a8fcd3a7e Display categories on File redirects
This NS_FILE-specific redirect logic was introduced in 2008,
in 3c9536652a.

mTitle, as referenced to in the comments, no longer exists.
Article also no longer creates redirects in there, that’s now
in WikitextContent::fillParserOutput.
The original commit message describes that this was introduced
to be able to display redirects to foreign file repos. A lot
has changed in how that works since 2008, too :)

Back to the present: for redirects to foreign repos,
`$this->mPage->getFile()->getRedirected()` seems to always return
`null` (a placeholder object is created when the thing doesn’t
exist), so this this foreign repo-specific bit of code is bypassed
anyway. For local redirects, Article::view seems to be working just
fine.

By using Article::view, Categories used on file redirect pages
will now actually be displayed too.

And we can get rid of the otherwise no longer used Article::viewRedirect.

Bug: T29857
Change-Id: Icb02f3af32d10870f58d945cb06a84b3ba1305d3
2017-07-04 11:11:58 +02:00
Bartosz Dziewoński
ab05b12366 ImagePage: Do not parse message 'imgmultipageprev'
This message is used as alt text for an image thumbnail, and so it
can't contain HTML tags anyway. This matches the 'imgmultipagenext'
message now. (This inconsistency has been present ever since the
feature was introduced in 2006: 7f7e79022bfd421e49084b089e74c7a16b77bc03.)

Due to using OutputPage::parse() instead of Message::parse(), an
incorrect `<div class="mw-parser-output">` wrapper was also being added.

Bug: T166508
Change-Id: I092887cc91e2c800685d4e55177aed814bb3fce9
2017-05-29 15:22:03 +02:00
Bartosz Dziewoński
87a0d64d11 Add a space between "Go to page" dropdown and button for multipage images
Change-Id: I174da5597563be36cc6e67a485f8556b9bcd84f6
2017-04-25 16:41:51 +02:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
jenkins-bot
17eda64357 Merge "includes: Replace implicit Bugzilla bug numbers with Phab ones" 2017-02-28 00:51:57 +00:00
Umherirrender
4d16c2ad56 Use Database::addQuotes instead of hard coded apostrophs
Change-Id: I1404d68d7e2b7fde8f9a76c747bc2be0936f7bef
2017-02-22 18:55:56 +01:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
Brad Jorsch
fb3ae6fbe3 Replace use of &$this
Use of &$this doesn't work in PHP 7.1. For callbacks to methods like
array_map() it's completely unnecessary, while for hooks we still need
to pass a reference and so we need to copy $this into a local variable.

Bug: T153505
Change-Id: I8bbb26e248cd6f213fd0e7460d6d6935a3f9e468
2017-01-31 23:01:54 -05:00
divadsn
a18a0af425 Replace &$this with $this in MediaWiki/core hook system
Bug: T153505
Change-Id: Ie287adf8b1d384aa651c659a9d385877379a0f11
2016-12-26 14:26:21 +00:00
umherirrender
34fe90ac52 Remove empty lines at end of functions
It looks like there is something missing after the last statement
Also remove some other empty lines at begin of functions, ifs or loops
while at these files

Change-Id: Ib00b5cfd31ca4dcd0c32ce33754d3c80bae70641
2016-11-05 11:55:10 +01:00
Kunal Mehta
e65f93f827 Use late static binding in Article::newFromID()
Address the FIXME and remove subclass implementations by using late
static binding.

Change-Id: I4f1793c87dfe08f768a283128d14ee2226a9e275
2016-09-12 21:46:12 -07:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Prateek Saxena
8f9643d8f9 Pass addModuleStyles an array instead of calling it multiple times
Change-Id: Ia359c441714c039c505acd4bd37dd1b52c60b8ea
2016-07-07 10:54:43 +05:30
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Thomas Arrow
2c2d6248f9 Split ImagePage.php into separate classes
Change-Id: Id2ca94c50b75d24da4d02fe82747a7ce7edccd9f
2016-02-04 12:26:36 +01:00
addshore
3540bf8f6c Unroll Article::__call again
Adds all public functions from WikiPage to Article

Adds all public functions from WikiFilePage that
are not in Article to ImagePage

WikiCategoryPage has no methods that need moving

Removed __call from Article

If extensions extend WikiPage and rely on the __call
method in Article they may break with this change.
They cal easily call $article->getPage()->method..

Change-Id: I8cd8d69d0d59c67f4879212535206688387bead4
2016-02-02 17:55:17 +01:00
umherirrender
cf1d31b604 clone is not a function
Remove parenthesis around clone magic word

Change-Id: I2e0e53303f7c73745bd1ab4bcf32e74943efc4de
2015-10-16 19:34:31 +02:00
Brian Wolff
47de889181 Show different message if image thumb in different format than img
Users on commons feel that the other resolution links on the image
page can be confusing to users if they are in a different format
than the original image. Use a different message in that case
to clarify the situation.

See discussion at https://commons.wikimedia.org/?oldid=165672017

Change-Id: I76d7155e1c1e48a9824819135943d2385a0ee41a
2015-10-10 13:32:59 -06:00
Amir E. Aharoni
c5cb8fdc23 ImagePage.php: Make lines shorter to make phpcs happier
Change-Id: I7207bef25bdc82c92dd4adc669468513f367eda6
2015-09-26 13:55:51 +00:00
jenkins-bot
1b028a6c74 Merge "Avoid master queries on image history view" 2015-09-21 09:40:39 +00:00
Aaron Schulz
592a6e7d2e Avoid master queries on image history view
* The path that needs READ_LATEST already calls load() as needed first

Bug: T92357
Change-Id: Ia06bba6c2853823add2e527bb1b013b64d3f020a
2015-09-16 10:41:12 -07:00
Aaron Schulz
d9350ece7c Made uploadLinksBox() use quickUserCan() to avoid title blacklist queries
Change-Id: I48347acfa70020313d6860d95bc9f286ced9400b
2015-09-10 17:57:29 -07:00
umherirrender
8410a0de11 Add 'mediawiki.action.view.filepage' style module
Moved the style definition for a file page from shared.css to a new
module. Also for print styles.

Change-Id: I8a0f0fecc53967bf2b0241ce92bbbd10b8fc704a
2015-09-04 16:36:12 +02:00
Brian Wolff
120d71495b Do not suggest alternate svg sizes bigger than $wgMaxSVGSize on img pg
Suggesting a size bigger than the max svg size, will simply result
in a smaller rendering than the user has been lead to believe they
would recieve.

Additionally fix wrong argument order to $this->getThumbSizes
which was causing the nominal size for an SVG to not be suggested
as an alternate size on the image page.

See some of the comments T106263 (However, that bug is not about
this issue).

Change-Id: Ia63ddd6e89725f8e7979687310c3b6819da0cbbc
2015-07-19 15:38:57 -06:00
umherirrender
79c44dd0a6 Add LinkBatch to ImagePage for user pages in the file history
Each user in the file history trigger an own query to get the state of
the user page, talk page and gender information. Use a LinkBatch to
combine all of these queries to two (one for pages, one for gender).

Change-Id: Ic1973c1ccfa17002b343d8c0d110a7c1d20b0460
2015-06-19 21:53:02 +02:00