[MediaWiki-commits] [Gerrit] Improve handling of cite warnings - change (mediawiki...Cite)

2016-03-27 Thread jenkins-bot (Code Review)
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 '' . rtrim( $text, "\n" ) . 
"\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 = '' . 
$msg . '';
-   } else {
-   $this->mParser->addTrackingCategory( 
'cite-tracking-category-cite-error' );
+   $this->mParser->addTrackingCategory( 
'cite-tracking-category-cite-error' );
 
-   $ret = '' . $msg 
. '';
+   $ret = '' . $msg . 
'';
+
+   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 = '' . 

[MediaWiki-commits] [Gerrit] Improve handling of cite warnings - change (mediawiki...Cite)

2016-02-17 Thread Cenarium (Code Review)
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 '' . rtrim( $text, "\n" ) . 
"\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 = '' . 
$msg . '';
-   } else {
-   $this->mParser->addTrackingCategory( 
'cite-tracking-category-cite-error' );
+   $this->mParser->addTrackingCategory( 
'cite-tracking-category-cite-error' );
 
-   $ret = '' . 
$msg . '';
+   $ret = '' . $msg . 
'';
+
+   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 = '' . $msg . '';
+
if ( $parse === 'parse' ) {
$ret = $this->mParser->recursiveTagParse( $ret );
}

-- 
To view, visit