jenkins-bot has submitted this change and it was merged.
Change subject: Improve handling of cite warnings
......................................................................
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
---
M Cite_body.php
1 file changed, 40 insertions(+), 17 deletions(-)
Approvals:
WMDE-Fisch: Looks good to me, but someone else must approve
TheDJ: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Cite_body.php b/Cite_body.php
index 4bcab61..a89aecf 100644
--- a/Cite_body.php
+++ b/Cite_body.php
@@ -851,6 +851,9 @@
*/
function referenceText( $key, $text ) {
if ( !isset( $text ) || $text === '' ) {
+ if (
$this->mParser->getOptions()->getIsSectionPreview() ) {
+ return $this->warning(
'cite_warning_sectionpreview_no_text', $key, 'noparse' );
+ }
return $this->error( 'cite_error_references_no_text',
$key, 'noparse' );
}
return '<span class="reference-text">' . rtrim( $text, "\n" ) .
"</span>\n";
@@ -1257,21 +1260,11 @@
* Return an error message based on an error ID
*
* @param string $key Message name for the error
- * @param string $param Parameter to pass to the message
+ * @param string|null $param Parameter to pass to the message
* @param string $parse Whether to parse the message ('parse') or not
('noparse')
* @return string XHTML or wikitext ready for output
*/
function error( $key, $param = null, $parse = 'parse' ) {
- $decreaseToWarning = false;
- if (
- $this->mParser->getOptions()->getIsSectionPreview() &&
- $key === 'cite_error_references_no_text'
- ) {
- // ref may be defined somewhere else on the page so use
distinct message
- // and be less intrusive than in a real error
- $key = 'cite_warning_sectionpreview_no_text';
- $decreaseToWarning = true;
- }
# We rely on the fact that PHP is okay with passing unused argu-
# ments to functions. If $1 is not used in the message,
wfMessage will
# just ignore the extra parameter.
@@ -1279,20 +1272,50 @@
# use the user language and split the parser cache.
$lang = $this->mParser->getOptions()->getUserLangObj();
$msg = wfMessage(
- $decreaseToWarning ? 'cite_warning' : 'cite_error',
+ 'cite_error',
wfMessage( $key, $param )->inLanguage( $lang )->plain()
)
->inLanguage( $lang )
->plain();
- if ( $decreaseToWarning ) {
- $ret = '<span class="warning mw-ext-cite-warning">' .
$msg . '</span>';
- } else {
- $this->mParser->addTrackingCategory(
'cite-tracking-category-cite-error' );
+ $this->mParser->addTrackingCategory(
'cite-tracking-category-cite-error' );
- $ret = '<span class="error mw-ext-cite-error">' . $msg
. '</span>';
+ $ret = '<span class="error mw-ext-cite-error">' . $msg .
'</span>';
+
+ if ( $parse === 'parse' ) {
+ $ret = $this->mParser->recursiveTagParse( $ret );
}
+ return $ret;
+ }
+
+ /**
+ * Return a warning message based on a warning ID
+ *
+ * @param string $key Message name for the warning. Name should start
with cite_warning_
+ * @param string|null $param Parameter to pass to the message
+ * @param string $parse Whether to parse the message ('parse') or not
('noparse')
+ * @return string XHTML or wikitext ready for output
+ */
+ function warning( $key, $param = null, $parse = 'parse' ) {
+ # We rely on the fact that PHP is okay with passing unused argu-
+ # ments to functions. If $1 is not used in the message,
wfMessage will
+ # just ignore the extra parameter.
+ # For ease of debugging and because errors are rare, we
+ # use the user language and split the parser cache.
+ $lang = $this->mParser->getOptions()->getUserLangObj();
+ $msg = wfMessage(
+ 'cite_warning',
+ wfMessage( $key, $param )->inLanguage( $lang )->plain()
+ )
+ ->inLanguage( $lang )
+ ->plain();
+
+ $key = preg_replace( '/^cite_warning_/', '', $key ) . '';
+ $ret = '<span class="warning mw-ext-cite-warning
mw-ext-cite-warning-' .
+ Sanitizer::escapeClass( $key ) .
+ '">' . $msg . '</span>';
+
if ( $parse === 'parse' ) {
$ret = $this->mParser->recursiveTagParse( $ret );
}
--
To view, visit https://gerrit.wikimedia.org/r/271467
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I872d79335c8dd2bd19bbe254c28b0d9025d256be
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Cite
Gerrit-Branch: master
Gerrit-Owner: Cenarium <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Cenarium <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits