Commit graph

136 commits

Author SHA1 Message Date
addshore c1de73eb32 Move php files in includes directory
Change-Id: Ic6afacbf2a944954826c9d68dd292c28f1c731da
2016-09-20 15:33:10 +01:00
addshore be288a7596 Cite::referencesFormatEntry: Avoid Undefined index: key
Bug: T132583
Change-Id: I00e5bb461324aa017a4f60f04cd73370cfd73b52
2016-08-03 01:07:18 +00:00
Kunal Mehta 4bbd227702 build: Updating mediawiki/mediawiki-codesniffer to 0.7.1
Also added "composer fix" command.

Change-Id: I3cdaa7aac81fc3f9b3e284b049a2dd07b1abf0f3
2016-05-09 16:36:49 -07:00
Chad Horohoe 893db13b5c Move check for non-existing reference count higher up
It doesn't make sense to check for negative numbers or 0 if the
value doesn't even exist. It ends up spamming the warning logs
prior to actually hitting the case we want.

Change-Id: I8f6cf17d4cd628fdcff13f2d29c7ae9661444de2
2016-05-05 12:10:32 -07:00
Amir E. Aharoni 52293b1749 Add lang and dir attributes to cite errors
This is needed when the error appears in an element with
a direction that is different from the UI language.

Change-Id: I583c9cc30f5bec24ab92e97ab938463ea0e45c15
2016-04-30 16:16:58 +03:00
jenkins-bot 90999021b5 Merge "Improve handling of cite warnings" 2016-03-27 10:33:58 +00:00
cenarium 640e0919e9 Improve handling of cite warnings
This improves handling of cite warnings by creating a function
specifically for them instead of using the error function with an
optional downgrade.
This also adds span classes specific to each message so it can be
easily hidden / modified with css.

Change-Id: I872d79335c8dd2bd19bbe254c28b0d9025d256be
2016-03-25 22:27:08 +01:00
cenarium 3a71ac095c Preview of list-defined references
This allows to preview list-defined references in the section where they
are defined.

Bug: T128036
Change-Id: Ifeeef1129a64e73add8dfe0ee8519e8477712693
2016-03-22 18:57:26 +01:00
jdlrobson 92ef12a433 Remove num parameter from referencesKey function
Change-Id: Ib215a09dc2d77988cb63a1b3c5fce4cd0cb886cb
2016-03-11 18:13:06 +00:00
jdlrobson 342a3a0ec3 referencesKey is now a static function and renamed
There seems to be no reason for this to be a member function

Per suggestion of Ori, It should also be clearer
it is a getter so it is now prefixed with get
There are no consumers according to Github so a rename is safe

Change-Id: I414959d4cc107135ccbd0739f2fc7d62ca8d04c5
2016-02-26 19:01:41 +00:00
jenkins-bot 22668e53e2 Merge "Change a condition with == to something more precise" 2016-02-24 21:29:23 +00:00
Thiemo Mättig 4eeb884e98 Add array type hints and more specific documentation
The two public functions ref() and references() are called from
Parser::extensionSubstitution(). Everything else is derived from that.

Change-Id: Ib9bb37ac0303f0e90149f5b1c4f4aa3bcf08b957
2016-02-24 20:57:10 +00:00
Amir E. Aharoni adf113af86 Change a condition with == to something more precise
It can be both NULL and an empty string here.
Tests for both cases are added in the following patches:
Ia6c10419a7a92dac642db6ea21908927a5830b69
Ibb3bb1ab3450a34889dcd66b34542f2dd25fdc2b

Change-Id: Ia2b2b6545bb889de59a363a2c1d7569cbc971361
2016-02-24 20:56:12 +00:00
cenarium 469217073a Use span with css instead of strong for cite errors
Change-Id: I9b8954b56646ca9c4632788824346e6116de3146
2016-02-24 18:57:37 +00:00
jenkins-bot bf3df3fce6 Merge "Use div for references in section preview" 2016-02-18 11:06:09 +00:00
cenarium a6f023902b Use div for references in section preview
This uses a div instead of a span to wrap the section displaying
references in section preview. It also adds an id for the section
header specifically, and does not display the header if its message
is disabled.

Bug: T127188
Change-Id: If3df97319358706f7646f451ff2f4948537130e8
2016-02-18 09:56:52 +00:00
cenarium b991617bc6 Avoid calculating md5 when not caching references
In the old caching system for references, the cache key needs the md5 of
the references, but it shouldn't be calculated when one is not using
this caching system.

Change-Id: I83c17d1df5c5e620ea21d1bf955b86ce94bc119a
2016-02-18 08:17:48 +01:00
jenkins-bot 194532751b Merge "#cite_note and #cite_ref links generated from empty references are broken" 2016-02-12 21:42:56 +00:00
Petr Matas 216b60cb9a #cite_note and #cite_ref links generated from empty references are broken
Bug: T126241
Change-Id: I1e84d3361424e57e9f115a665f77d686a80a9135
2016-02-12 20:49:43 +00:00
cenarium 70e14ebaeb Store references in page_props and cache
This stores references in page_props during links update in
compressed JSON form. If the size is too big, it's broken up
in several parts to fit, which is very unlikely to occur more
than once.

When the data is retrieved from the db, it's always cached. If
set in config, it's also saved in the cache on parse. If not,
the cache is invalidated when references are modified.

Uses cases include : section preview to also show refs defined
elsewhere on the page (T124840) and MobileFrontend (T123328).
For the later, this still needs API support (T123290).

There's a soft dependency on the core change
I0c73b3d181f32502da75687857ae9aeff731f559.

Bug: T125329
Change-Id: I7b106254b8f264f93b0f0c9cfa89f65adeeea4f0
2016-02-10 14:47:02 +01:00
cenarium 71889ff017 In section preview, add preview of references to its own section
This is to make it apparent that this isn't part of the preview
of the section itself. A span class is also added.

Bug: T125981
Change-Id: I62c8dca8ee42e79c6b7cd7f837f4e7ee65f77770
2016-02-07 16:34:09 +00:00
Bartosz Dziewoński e116699480 Rollback all, then redo all, when fixing out-of-order tags; not one-by-one
Imagine the following wikitext:

  <ref name=r/>
  <references>
  <ref name=r>A</ref>
  <ref name=r>B</ref>
  </references>

This is simple. Cite would see these as the following operations, in
order:

1. Use only:       <ref name=r/>
2. References block
3. Define only:    <ref name=r>A</ref>
4. Define only:    <ref name=r>B</ref>

<ref name=r> is defined twice with different content and we get an
error message.

Now, imagine the following wikitext:

  <ref name=r/>
  {{#tag:references|
  <ref name=r>A</ref>
  <ref name=r>B</ref>
  }}

Cite would see these as the following operations, in order:
1. Use only:       <ref name=r/>
2. Use and define: <ref name=r>A</ref>
3. Use and define: <ref name=r>B</ref>
4. References block

When the 'references' block appears, Cite notices that the tag has
parsed content, and deduces that it was called with #tag. We need to
undo the last operations to update internal bookkeeping, as the last
two 'ref' tags do not actually represent ref usages, as we assumed,
but only definitions.

5. Undo:          <ref name=r> reused
6. Define only:   <ref name=r>B</ref>
7. Undo:          <ref name=r> defined
(Right now, it appears to Cite that <ref name=r> was never defined!)
8. Define only: <ref name=r>A</ref>

Thus we get no errors, although we should.

This patch changes the order of the rollback operations:

5. Undo:          <ref name=r> reused
6. Undo:          <ref name=r> defined
7. Define only:   <ref name=r>A</ref>
8. Define only:   <ref name=r>B</ref>

Aha! <ref name=r> is defined twice with different content! We get an
error correctly.

Bug: T124227
Change-Id: I61766c4104856323987cca9a5e4ff85a76b3618b
2016-02-02 21:21:30 +01:00
PiRSquared17 739962b6d1 Add reference list to section preview if missing
For a section preview with missing <references/> tag,
add reference lists for each group.

Bug: T7984
Change-Id: I2ca1b62fc068b20b7df4b0af2e3e79535e656259
2016-01-20 04:25:46 +00:00
Kunal Mehta 55080cb5ed Display Cite errors in the user language
To make debugging easier when something goes wrong, display Cite errors
in the user language. This will fragment the parser cache, but since
these errors should be rate to not make this a problem.

Bug: T33216
Change-Id: I0f116f6da4b8f07b34f7d122458b6e23f542d468
2016-01-06 12:48:33 -08:00
Paladox 669d19c916 Add php code sniffer
Change-Id: Icd5e488f6d7009e1ed7a901298cd35c70c683f13
2015-12-16 13:11:00 +00:00
Bartosz Dziewoński 9aa7961c60 Detect duplicate <ref> definitions inside <references> too
For some reason there's an entirely separate function generating the
ref in this case.

This changes the behavior (in addition to adding the error message):
now the contents of the first <ref> with the same name inside
<references> are displayed, not the last. (This was already the case
for <ref>s outside <references>.)

Bug: T116377
Change-Id: I81b64ccd8a2e58f3b25938a63b8ad5967fe2a2c0
2015-11-21 11:25:29 +00:00
Timo Tijhof c12ca466f3 Add isset() check before accessing $this->mRefs[$group]
Follows-up c00cf4a which wrongly assumed the reason for empty()
to be about array count but the real reason was existence.

All other code in Cite extension already uses isset() so this
makes it match the rest.

Bug: T117084
Change-Id: Ic9b0d74ae6ceda5acba187c2fab18c8f5dc9526b
2015-10-29 21:57:40 +00:00
Thiemo Mättig c00cf4a204 Avoid counting arrays if not needed
count() tends to be one of the slowest PHP functions and should be
avoided, especially if the actual number of elements is not needed.

Change-Id: Ia979c481f898d2fccedb0ed127417ef05ba7ff38
2015-10-26 17:30:19 +01:00
Bartosz Dziewoński 2e588a7424 Do not double-parse 'cite_error_references_duplicate_key' error message
This value is supposed to be wikitext, which will be parsed later,
not HTML ready for outputting.

Follow-up to 6c59f47805.

Bug: T116149
Change-Id: I6d6f474db7c7a075499f94301978572179975749
2015-10-21 11:59:34 +00:00
Bartosz Dziewoński 6c59f47805 Display 'cite_error_references_duplicate_key' next to the affected ref
Follow-up to 5d0fb0309b.

Bug: T114898
Change-Id: Id6d0b7f2c0b76b67a50fc981b9255dff99137bed
2015-10-18 19:44:04 +00:00
jenkins-bot f75e136ec7 Merge "Add pages with Cite errors to a tracking category" 2015-10-08 19:40:45 +00:00
eranroz 5d0fb0309b Show an error if a named ref is defined multiple times
Bug: T85386
Change-Id: I6e7a7594628b3e0c09724c11e5d9f650dde25906
2015-09-30 21:27:35 +03:00
Amir E. Aharoni 68304fcacd Add pages with Cite errors to a tracking category
Bug: T104792
Change-Id: I6f8b12788a20480bd8880332238d545ee70a8ef9
2015-09-24 12:16:13 +03:00
jenkins-bot 1a9f0f2010 Merge "Fix doc block for checkRefsNoReferences" 2015-08-29 15:48:55 +00:00
Fomafix fd5fc271a8 Fix white spaces
Change-Id: I372455a77f3265933767dc8fc6774bcb184499ad
2015-08-25 15:56:42 +00:00
Florian ad929ad538 Fix doc block for checkRefsNoReferences
Doesn't show an error for the default references group anymore. Only,
if a custom group was defined, but no corresponding references tag added.

Follow up: I9c7c13269d5ec355ccb280402aa8c0cedd208883

Change-Id: I67f4277b83b6b83ba5fc54cdcc021044b65f61c5
2015-08-06 19:36:52 +02:00
physikerwelt a7a072edc0 Ignore parsers without extCite
If a parser does not include the extCite property, ignore
the call and do not check references.

Depends on Ic77aa79aa6e2bf2a9ec00be4cc775d0123bed91a

Bug: T105598
Change-Id: Ic2257eef94fd73932f1e95a84b3b8b0eb245bafc
2015-07-22 15:03:10 +00:00
Timo Tijhof de550c717c Hygiene: Main return as root structure (handle errors early)
Restructure code to return early for errors instead of nesting
conditionals. This leaves the outer tree of the function as
the natural flow of the primary purpose.

Makes code more resilient by ensuring that new code added to the
function will not execute under error conditions by removing the
need to keep everything encapsulated in the various levels of
error conditionals.

Change-Id: I1b4a67d344fd9843ca088d008487914f87b1c640
2015-07-18 15:55:32 -05:00
Amir E. Aharoni 147f6ced19 Change == to === according to PHP coding conventions
Change-Id: I2a93194e3c2160000d30f2f2fd7717f4ba501c23
2015-07-07 15:20:53 +03:00
Bartosz Dziewoński 3f30e08d77 Revert "Do all of Cite's real work during unstrip" and followup
This reverts commits 944b245428
and fa7be37d15.

These resulted in too many new exciting behaviors for the improvement
of nested refs behavior to be worth it. We should try again later.

Also, use Parser::MARKER_PREFIX instead of $parser->uniqPrefix()
which has been deprecated in the meantime by 12571bde.

Fixes T101390, fixes T100477. Reopens T22707, reopens T18330.

Bug: T100477
Bug: T101390
Change-Id: I1a71854cf24e85697ab171be43eeec9054bc504c
2015-06-08 16:24:27 +02:00
Derk-Jan Hartman 05cb5cc1a0 Cleanup style RL modules for Cite
Move the JS which is purely for accessibility purposes into a separate
JS RL module named ext.cite.a11y. Move all pure CSS, which is not dependant
on accompanying JS into a separate ext.cite.styles module

Bug: T101559
Change-Id: I58adcfbcf9af2bb3b6d5dabb6c38c42af78e0416
2015-06-06 15:43:27 +02:00
Jackmcbarn fa7be37d15 Don't run references if the output type isn't HTML
It's possible that the output type is set to HTML when extensionSubstitution
is called, but that when we eventually get unstripped, it isn't anymore. If
this happens, detect it and bail out.

Bug: T99787
Change-Id: I32abaefeebc5357a2ab3fd23bcd47aa9b2a1663a
2015-05-25 13:34:02 +00:00
Jackmcbarn 944b245428 Do all of Cite's real work during unstrip
Cite has side effects that currently happen at the same time that the
preprocessor is running. This can cause oddities like references being out
of order, or references showing up in the reference list but never used in
the text. By moving the work to unstrip, only references actually used in
the final text will be present, and the numbering order will always match
the order they were used in the text. This depends on If83b0623 in core.

Change-Id: I0e136f952302b65f1abeeac5273bd842867e1dac
2015-05-13 02:54:37 +00:00
Kunal Mehta db9ff2bd18 Get rid of "wfCite" global function
As of Icdf82cb9771e6, MediaWiki core now looks for the "Cite" class
instead of the "wfCite" global function. The WYSIWYG extension is also
checking for wfCite and a patch was submitted for that in I3de3e069e4be.

Change-Id: Ie0f190b7bd9c9226856f150c95a0b139812dcf98
2015-04-30 11:41:06 -07:00
Kunal Mehta 49c2a5d595 Move CITE_DEFAULT_GROUP constant to Cite::DEFAULT_GROUP
Change-Id: I13c77f78563beb6e4ebf2a6d19327273ee2dbc07
2015-04-30 11:34:47 -07:00
Chad Horohoe b818a87315 Remove obvious function-level profiling
Change-Id: I435365313846d7529601a2440ea2e3c40a5418f3
2015-02-10 13:53:33 -08:00
Ori Livneh ee4d83a1a7 MWException -> Exception
Change-Id: Ibc0d80f6cb66d96eb1bcb71bb1ee1b097c7878e6
2015-01-09 17:47:47 -08:00
Bryan Davis db56e255d4 Guard against unset array access
From prod error logs:
  Undefined index: 0 in Cite_body.php on line 396
  Undefined index: 1 in Cite_body.php on line 396
  Undefined index: 2 in Cite_body.php on line 396
  Undefined index: 3 in Cite_body.php on line 396
  Undefined index: follow in Cite_body.php on line 396

Change-Id: Id727f2fd7e72d8c4ceb74fdac42885d5c030b4af
2015-01-09 09:09:42 -07:00
Amir E. Aharoni c9a5b7b1cb Replace == with test for isset and empty string
The coding conventions suggest avoiding ==,
and for this condition definedness is actually more relevant
than whether the string has any text, but since
the string can also be '0', checking for !$text doesn't work.

Similar to I15b422d3345bf4522e68a17dce9682ff28484559 .

Change-Id: Ib823678b639bf4f1a92dffcd9e41c780b56ab128
2014-10-28 19:07:24 +00:00
Amir E. Aharoni 60a0821634 Replace == with isset
The coding conventions suggest avoiding ==,
and for this condition definedness is actually more relevant
than whether the string has any text.

Change-Id: I15b422d3345bf4522e68a17dce9682ff28484559
2014-10-28 19:06:33 +00:00