Cenarium has uploaded a new change for review. https://gerrit.wikimedia.org/r/271467
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. Change-Id: I872d79335c8dd2bd19bbe254c28b0d9025d256be --- M Cite_body.php 1 file changed, 44 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cite refs/changes/67/271467/1 diff --git a/Cite_body.php b/Cite_body.php index c150821..f508038 100644 --- a/Cite_body.php +++ b/Cite_body.php @@ -849,7 +849,11 @@ */ function referenceText( $key, $text ) { if ( !isset( $text ) || $text === '' ) { - return $this->error( 'cite_error_references_no_text', $key, 'noparse' ); + if ( !$this->mParser->getOptions()->getIsSectionPreview() ) { + return $this->error( 'cite_error_references_no_text', $key, 'noparse' ); + } else { + return $this->warning( 'cite_warning_sectionpreview_no_text', $key, 'noparse' ); + } } return '<span class="reference-text">' . rtrim( $text, "\n" ) . "</span>\n"; } @@ -1256,16 +1260,6 @@ * @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. @@ -1273,20 +1267,53 @@ # 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 = '<strong class="error mw-ext-cite-error">' . $msg . '</strong>'; + $ret = '<strong class="error mw-ext-cite-error">' . $msg . '</strong>'; + + 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 + * @param string $param Parameter to pass to the message + * @param string $parse Whether to parse the message ('parse') or not ('noparse') + * @param bool $parentheses Whether to put the warning in parentheses + * @return string XHTML or wikitext ready for output + */ + function warning( $key, $param = null, $parse = 'parse', $parentheses = false ) { + # 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(); + + if ( $parentheses ) { + $msg = wfMessage( 'parentheses', $msg )->inLanguage( $lang )->plain(); + } + + $ret = '<span class="warning mw-ext-cite-warning mw-ext-cite-' . $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: newchange Gerrit-Change-Id: I872d79335c8dd2bd19bbe254c28b0d9025d256be Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Cite Gerrit-Branch: master Gerrit-Owner: Cenarium <cenarium.sy...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits