Commit graph

99 commits

Author SHA1 Message Date
Kosta Harlan 47660475b9 Tests: Stub getRequest/getConfig for OutputPage mock
Needed due to I4bf53dabb6e6c5446cea99a64db68b300cef2fd4

Bug: T236723
Change-Id: I8505d2dad69aefed5f8ed1f599b3ca1b7e79acf5
2019-10-29 12:23:57 +01:00
James D. Forrester a9518ea914 build: Upgrade mediawiki-codesniffer to v28.0.0
Change-Id: Ic742e7cde506b7d0c1865453cc8895faefe10e90
2019-10-11 11:05:53 -07:00
Max Semenik 0665baacc3 Fix PHPUnit 4 rudiments
Change-Id: Idcba8dce56f7a5deea7f8dd5a126c7bdfa499064
2019-10-04 19:16:34 -07:00
Thiemo Kreuz 71b5c4db22 Relax score calculation in LinksUpdateHookHandler to use floats
This allows to use floats in the $wgPageImagesScores configuration.
Before, decimal places have just been cut off with no warning. I find
this pretty unexpected. When I see the terminology "score" being used,
I always think of float values. I checked all the code that consumes
these scores (it is all internal to LinksUpdateHookHandler), and it's
all fine with floats. I don't see a reason to forcefully cut decimal
places off.

Bug: T212013
Change-Id: I0f1f0ea0865f07b3e58a2fc142dcd838eb687c97
2019-01-10 09:31:20 +01:00
Thiemo Kreuz 0fd9a2b5f4 Fix score calculation in LinksUpdateHookHandler failing on unordered input
This patch is motivated by Iad694e0.

* I rearranged the code a little bit to avoid a duplicate line of code.
* I added a ksort() and a comment explaining it.
* Additional tests demonstrate why the ksort() is needed.
* I had to refactor the tests a little bit to allow for more test cases
  that have been missing before.

Bug: T212013
Change-Id: Ia96dc8c6cf57ddcea410a7300756d0013052ac79
2019-01-10 09:26:54 +01:00
Thiemo Kreuz baabc300ba Remove bogus @doc… elements from default $wgPageImagesScores setting
Such @doc… keys are not allowed at this level. They make it to the code
and cause confusion there. I added a test case for an edge case where this
really causes wrong results.

Bug: T212013
Change-Id: Ib391e5639ef5a34f9ee44f8c19b99e1dd19207bc
2019-01-09 12:41:21 +01:00
Kunal Mehta a9ad31c7f8 Fix MediaWiki.Commenting.LicenseComment.InvalidLicenseTag issues
Change-Id: I3b0c14dcd5961254d49a98df4061f8ff83589f3a
2018-05-24 21:42:59 -07:00
Kunal Mehta 34b0dd5ff6 Unbreak test that only worked by accident, and fails on PHP 7.2
`$leadImages || $images` will return a boolean, it doesn't work like
JavaScript or Python. Use `?:` to implement what was wanted.

This only worked because `count( true ) === 1`. Using assertCount()
would have caught it also.

Change-Id: I11357b23ad1124ed96d863872014cdca7c59e284
2018-04-13 22:25:26 -07:00
Kunal Mehta b138993e96 Properly specify method that will be mocked
Change-Id: I2bb3b586727a4a7c52f4fd8813f87d0a4e7c5952
2018-04-13 22:20:17 -07:00
jdlrobson fcc96696d5 Fix remaining php sniffs
* Separate the ApiQueryPageImages mock into its own file

Bug: T170583
Change-Id: I3db5de11618f952eb7974c456445eaa1d5e4e6a4
2018-03-05 18:49:11 +01:00
Kunal Mehta 3ad50a314a Fix "Only variables should be passed by reference" test failure
Bug: T188272
Change-Id: Ib8d0974b1a98fecca39abc0df2bf42ef64420965
2018-02-26 08:49:10 -08:00
libraryupgrader 89089faaa9 build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: Id9338a658104d1da7942c6c7bdb6e53eebf31db0
2018-02-15 13:32:16 +00:00
Umherirrender f75bf11ff8 Use namespaced version of FakeResultWrapper
Change-Id: If76eb8d5cdeac94e938c9b31946a4d7f688ae24e
2018-01-04 23:41:54 +01:00
Umherirrender a2f97b9b27 Use absolute class name in @covers
Namespaced classes need to be absolutely named.

Change-Id: Ic98e4e3b9fbc1b7cb3187cdbffcb973795a02a6b
2017-12-27 20:25:59 +01:00
Pppery 60735a010d Remove old string-based API description functions
These have been deprecated since MediaWiki core 1.25 and no longer have any effect.

Change-Id: Icbaaa395af8303c1018e92ab2bfddb02ed587115
2017-12-17 23:58:15 +00:00
Pppery d81dfe6e9e Re-enable "MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" sniff
Bug: T170583
Change-Id: I76ed85cf960269c5692e9ec8c92877bcb13e4100
2017-12-07 14:02:09 +00:00
Pppery 3f2ce4da97 Partially fix class-file name mismatch sniffs
Fix one instance of bad code that triggers both MediaWiki.Files.ClassMatchesFilename.NotMatch
and MediaWiki.Files.OneClassPerFile.MultipleFound. One more set of errors remains.

Bug: T170583
Change-Id: I45c237b4366477954726a0116fb2d56256276693
2017-12-06 23:35:36 -05:00
jenkins-bot bec09c03b3 Merge "More compatible PHPDoc comment syntax in LinksUpdateHookHandlerTest" 2017-11-24 10:10:37 +00:00
Thiemo Mättig 1ad897baf4 More compatible PHPDoc comment syntax in LinksUpdateHookHandlerTest
Change-Id: I5217eb5e1b91a5ce4a2c3ce0cbff83f579461118
2017-11-24 10:43:21 +01:00
Thiemo Mättig 4674c77e45 Family name of Thiemo changed
Change-Id: I74bf3041439e839b575ff5c163427b5c032c4398
2017-11-24 08:33:49 +01:00
Kunal Mehta fa58780171 build: Updating mediawiki/mediawiki-codesniffer to 0.11.0
Change-Id: I121ac2e4b2bc165ca6aaa8a7b6f8f973faaf0f9d
2017-08-11 00:15:33 -04:00
Kunal Mehta 924efcc96e build: Updating mediawiki/mediawiki-codesniffer to 0.9.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.MissingParamComment
* MediaWiki.Commenting.FunctionComment.MissingParamTag
* MediaWiki.Commenting.FunctionComment.MissingReturn
* MediaWiki.Commenting.FunctionComment.ParamNameNoMatch
* MediaWiki.FunctionComment.Missing.Public
* MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
* MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment

Change-Id: I3554682b5c8686299dc8cf23a3ec8c59514ff008
2017-06-25 17:26:03 +00:00
jenkins-bot d4bf297f6e Merge "Remove incomplete PHPDoc @param tags" 2017-06-07 16:59:57 +00:00
Thiemo Mättig 37cae03ebb Remove incomplete PHPDoc @param tags
Plus:
* Add a missing "array" type hint.
* Use more specific assert… functions instead of isset().

Change-Id: Iaa423620d493b4bee11bf89f627d0420a645a8de
2017-06-07 10:35:50 +01:00
Umherirrender 88758f5884 Add phpcs and make pass
Change-Id: I129fd23a375b4f7de893d3b98f67fdd8de89b4bd
2017-05-30 21:49:44 +02:00
jenkins-bot 9b63fdc577 Merge "Make PageImages default API license parameter configurable" 2017-05-20 16:02:19 +00:00
aude 97572615e0 Make PageImages default API license parameter configurable
Bug: T156190
Change-Id: Id4b43f2597d5a063dca0d46f308b6283620e9974
2017-05-20 17:36:56 +02:00
Baha a7fc68ced6 Increase default API limit from 1 to 50
Bug: T153709
Change-Id: Ie7c48117ac94e4902948f7336b5e1da7229dbe2d
2017-05-19 09:06:04 -04:00
jenkins-bot c75e19ffd1 Merge "Switch TestingAccessWrapper to librarized version" 2017-04-20 19:36:58 +00:00
Gergő Tisza 928a8f6687 Switch TestingAccessWrapper to librarized version
Bug: T163434
Change-Id: Ie3d29b3522d5e176430708b15359803d76a39a2f
Depends-On: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 11:35:03 +00:00
Zach 4c0e441833 Make PageImagesLeadSectionOnly default to true
Supporting changes:
* Update the LinksUpdateHookHandlerTest test case to set the config
  variable to its expected value of false.

Bug: T162203
Change-Id: Ic7b4d5ab42f71f6b4cf24cb5bbbbe808341a09e8
2017-04-18 10:16:22 +01:00
Thiemo Mättig a7a74f51ce Add basic test for PageImages::onBeforePageDisplay
This is still only testing negative cases with no page image.

In addition this patch does sort all the hook handlers
alphabetically, and adds a missing PHPDoc block.

Bug: T51859
Change-Id: Iea65f2181dd3cac3ec2ceac191f002f74af3ec24
2017-01-31 19:43:12 +00:00
Baha 83e712791f API: return free images by default
The maintenance script to populate free images has finished executing.

Follow-up on I1d35e965dc37c8c4ecdcc43313b3198e951e1978.

Bug: T152216
Change-Id: I32669e937efa6f5566eee582b911d170a32762e3
2017-01-19 15:20:00 -05:00
Michael Holloway a8c7cbc870 API: Surface dimensions when requesting original image info
It's useful for API consumers to have the dimensions of the original
image so that they know the bounds within which they can safely rewrite
the thumb URL (bearing in mind the prerendered widths[1], in the case of
WMF wiki consumers).

This change adds an 'original' property to the page object, containing
the original image source URL along with its width and height, when
original image info is requested.

A warning is added when original image info is requested, noting the
format change and warning the consumer that the original image URL will
no longer be provided within the 'thumbnail' property in a future release.

[1] https://github.com/wikimedia/operations-mediawiki-config/blob/master/wmf-config/InitialiseSettings.php#L17535

Bug: T152163
Change-Id: I9d937f73a974dfb099b93552405531464b8ad3ae
2017-01-17 15:07:28 -05:00
jdlrobson 5e1d488d65 Provide test case for getPageImageCandidates
Additional changes:
* Add test @covers statements for existing tests for code
coverage purposes

Change-Id: I1a0d2d331c79df3e5505ae54d27f23e1cb5b910c
2016-12-08 20:12:03 +00:00
Max Semenik 5145dd3d74 Convert to new array syntax
Change-Id: Iaec0c9ad47d28559adb8c46a82a00a61fba3602d
2016-12-01 16:49:13 -08:00
Erik Bernhardson f6f6bf00e1 Page images return non-free images by default
Page images was updated to have a split between the 'best' page
image, and the best free page image. Unfortunately the deployment
plan didn't take into account that the default 'free' would be
pointing to an unpopulated page prop, which will not be populated
until LinksUpdate has run for every page on every wiki which could
take weeks or months.

To restore some semblance of order, make the default point at the
currently populated field. A followup will need to be done to
populate the appropriate field.

Bug: T152155
Change-Id: I1d35e965dc37c8c4ecdcc43313b3198e951e1978
2016-12-01 23:54:14 +00:00
Baha 382c70f981 Allow querying non-free images too
The API accepts a new query parameter `license`, whose
value can either be `free` or `any`. `free` is the default value.

When the value of `licence` is:
  * `free`, then only the best image whose copyright allows
    reusing it will be returned;
  * `any`, then the best image, regardless of its copyright
    status, will be returned.

Bug: T131105
Change-Id: I83ac5266e382d2d121aff3f7d28711787251c03b
2016-11-21 17:29:25 -05:00
Baha 7617affabd Add phpunit tests
The tests cover ApiQueryPageImages::execute.

Change-Id: I22619c860aa3d1ed859a00f0e6f29dbb6f61b85b
2016-11-18 06:02:52 -05:00
Baha 76108cba37 Add phpunit tests
Bug: T131105
Change-Id: Ib774f18e62f050f48783e5ccccaedc23000533d2
2016-11-16 16:34:19 -05:00
Thiemo Mättig 6c53cac48e Refactor duplicate code in LinksUpdateHookHandlerTest
Change-Id: I9acaadf18e859758cd7bdcb7d260007402695060
2016-03-10 16:27:40 +01:00
Gergő Tisza 151a5d7248 Add sanity check test for LinksUpdateHookHandler::getMetadata
Change-Id: I840902c8397c8442def8239504ce1cfa8eafbb8e
2016-03-07 22:53:00 +00:00
Thiemo Mättig 4fee70fc1f Remove not needed "return true" from hook handlers
* Do not "return true" in hook handlers. I was told it's good practice
  to either return false on failure, or nothing/null.
* Remove "static" from method that does not need to be static.
* Make some type hints more specific.
* Add missing imports. I wonder how this can work without the imports.
  My PHPStorm complains.

Change-Id: Ia0e980ff99f0e004d700b22dd07ff17f04bed4ec
2016-03-07 12:07:06 +01:00
Thiemo Mättig d9df7178a0 Extract LinksUpdateHookHandler to separate file
This patch only moves existing code around, but does not change any
implementation detail.

I found it very suprising that all code called by this hook handler
is 100% exclusive to this hook handler. There is zero interaction
between this hook handlers code and all other code. Why is it in the
same file then? And why is it all static? It doesn't have to be. I
had to change literally nothing, except cutting and pasting, removing
all "static" and replacing all "self::..." with "$this->...". That's
all.

Change-Id: I5ffe6fdf4e57135e6f3b32636c80f22be758607c
2015-12-30 13:40:48 +01:00
Thiemo Mättig 369eda24b8 Add missing and fix wrong @license tags
Change-Id: I07f77735bb0050e2e59491d3c045b11705f3a08f
2015-11-16 15:59:34 +01:00
Thiemo Mättig 1f1c72bb2c Use mExtensionData instead of undeclared class property
Change-Id: I155e37fda412cd467da7b34c52b34661c7c20224
2015-10-26 12:09:52 +01:00
Thiemo Mättig 23cf541f1b Add inline documentation and newlines for readability
Change-Id: I3a5a4ef67836cbfe0277f511f8b23030d248141c
2015-10-26 11:41:13 +01:00
Thiemo Mättig ccbee562f3 Add basic PHPUnit tests
This adds a few very basic tests to this component. I started doing this
while working on T112865 but later realized I do not need to touch this
extension. However, I started setting up tests and wanted to submit them.

Bug: T112865
Change-Id: I9d00b2baed8da97ffb6af94a6e3b8b63621b876a
2015-10-08 10:39:59 +02:00
Sam Smith 56243a6c65 Include foreign files in ApiQueryPageImages
Titles that correspond to foreign files aren't included in the set of
titles returned by ApiPageSet#getGoodTitles. However, since
ApiQueryPageImages#execute finds files with wfFindFile, these "missing"
titles can be included.

Add the ApiQueryPageImages#getTitles helper function, which returns the
set of "good" titles union the set of missing titles in the File
namespace.

Also, register the PHPUnit tests directory in the UnitTestsList hook
handler.

The original version of this patch was reverted due to a (stupid) bug
wherein a fatal error was triggered because there was no check for there
being no missing titles in the File namespace [0] and, consequently, an
invalid operand was being passed to the array union operator. This bug
is fixed as well as proven to work with a simple set of test cases.

[0] https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FPageImages.git/47137e7ee671c89667d620bc04ac7649b1d9af96/ApiQueryPageImages.php#L31

Bug: T98791
Bug: T114417
Change-Id: I923e88dde3a8ced4921b4192d90b4f3dc4b19e7b
2015-10-05 13:24:00 +01:00