[MediaWiki-commits] [Gerrit] Output error message instead of failing for more than just html - change (mediawiki...Flow)

2015-06-19 Thread Matthias Mullie (Code Review)
Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/219476

Change subject: Output error message instead of failing for more than just html
..

Output error message instead of failing for more than just html

Just like for html output, other formats (like plaintext for title)
should show a failed to load content content instead of failing
completely.

Meanwhile also moved the other (valid) exception up top: for
practical reasons so I can have an overarching try/catch for content
failures, but also because bad data request should fail before even
checking those permissions.

Bug: T98547
Change-Id: I2609626e18c80d379cb839ccaed2a4b10924bfd6
---
M includes/Templating.php
1 file changed, 18 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/76/219476/1

diff --git a/includes/Templating.php b/includes/Templating.php
index 8f56593..3d9cd77 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -122,6 +122,10 @@
 * @throws InvalidInputException
 */
public function getContent( AbstractRevision $revision, $format = 
'fixed-html' ) {
+   if ( !in_array( $format, array( 'fixed-html', 'html', 
'plaintext', 'wikitext' ) ) ) {
+   throw new InvalidInputException( 'Invalid format: ' . 
$format );
+   }
+
$allowed = $this-permissions-isAllowed( $revision, 'view' );
// Posts require view access to the topic title as well
if ( $allowed  $revision instanceof PostRevision  
!$revision-isTopicTitle() ) {
@@ -136,26 +140,23 @@
return '';
}
 
-   // fixed html format
-   if ( $format === 'fixed-html' ) {
-   // Parsoid doesn't render redlinks  doesn't strip bad 
images
-   try {
+   try {
+   if ( $format === 'fixed-html' ) {
+   // Parsoid doesn't render redlinks  doesn't 
strip bad images
$content = $this-contentFixer-getContent( 
$revision );
-   } catch ( \Exception $e ) {
-   wfDebugLog( 'Flow', __METHOD__ . ': Failed fix 
content for rev_id = ' . $revision-getRevisionId()-getAlphadecimal() );
-   \MWExceptionHandler::logException( $e );
-
-   $content = wfMessage( 'flow-stub-post-content' 
)-parse();
+   } else {
+   // plaintext = wikitext
+   $format = $format === 'plaintext' ? 'wikitext' 
: $format;
+   $content = $revision-getContent( $format );
}
-   // all other formats
-   } elseif ( in_array( $format, array( 'html', 'plaintext', 
'wikitext' ) ) ) {
-   if ( $format === 'plaintext' ) {
-   $format = 'wikitext';
-   }
+   } catch ( \Exception $e ) {
+   wfDebugLog( 'Flow', __METHOD__ . ': Failed to get 
content for rev_id = ' . $revision-getRevisionId()-getAlphadecimal() );
+   \MWExceptionHandler::logException( $e );
 
-   $content = $revision-getContent( $format );
-   } else {
-   throw new InvalidInputException( 'Invalid format: ' . 
$format );
+   $content = wfMessage( 'flow-stub-post-content' 
)-parse();
+   if ( !in_array( $format, array( 'html', 'fixed-html' ) 
) ) {
+   $content = strip_tags( $content );
+   }
}
 
return $content;

-- 
To view, visit https://gerrit.wikimedia.org/r/219476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2609626e18c80d379cb839ccaed2a4b10924bfd6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie mmul...@wikimedia.org

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Output error message instead of failing for more than just html - change (mediawiki...Flow)

2015-06-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Output error message instead of failing for more than just html
..


Output error message instead of failing for more than just html

Just like for html output, other formats (like plaintext for title)
should show a failed to load content content instead of failing
completely.

Meanwhile also moved the other (valid) exception up top: for
practical reasons so I can have an overarching try/catch for content
failures, but also because bad data request should fail before even
checking those permissions.

Bug: T98547
Change-Id: I2609626e18c80d379cb839ccaed2a4b10924bfd6
---
M includes/Templating.php
1 file changed, 18 insertions(+), 17 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Templating.php b/includes/Templating.php
index 8f56593..3d9cd77 100644
--- a/includes/Templating.php
+++ b/includes/Templating.php
@@ -122,6 +122,10 @@
 * @throws InvalidInputException
 */
public function getContent( AbstractRevision $revision, $format = 
'fixed-html' ) {
+   if ( !in_array( $format, array( 'fixed-html', 'html', 
'plaintext', 'wikitext' ) ) ) {
+   throw new InvalidInputException( 'Invalid format: ' . 
$format );
+   }
+
$allowed = $this-permissions-isAllowed( $revision, 'view' );
// Posts require view access to the topic title as well
if ( $allowed  $revision instanceof PostRevision  
!$revision-isTopicTitle() ) {
@@ -136,26 +140,23 @@
return '';
}
 
-   // fixed html format
-   if ( $format === 'fixed-html' ) {
-   // Parsoid doesn't render redlinks  doesn't strip bad 
images
-   try {
+   try {
+   if ( $format === 'fixed-html' ) {
+   // Parsoid doesn't render redlinks  doesn't 
strip bad images
$content = $this-contentFixer-getContent( 
$revision );
-   } catch ( \Exception $e ) {
-   wfDebugLog( 'Flow', __METHOD__ . ': Failed fix 
content for rev_id = ' . $revision-getRevisionId()-getAlphadecimal() );
-   \MWExceptionHandler::logException( $e );
-
-   $content = wfMessage( 'flow-stub-post-content' 
)-parse();
+   } else {
+   // plaintext = wikitext
+   $format = $format === 'plaintext' ? 'wikitext' 
: $format;
+   $content = $revision-getContent( $format );
}
-   // all other formats
-   } elseif ( in_array( $format, array( 'html', 'plaintext', 
'wikitext' ) ) ) {
-   if ( $format === 'plaintext' ) {
-   $format = 'wikitext';
-   }
+   } catch ( \Exception $e ) {
+   wfDebugLog( 'Flow', __METHOD__ . ': Failed to get 
content for rev_id = ' . $revision-getRevisionId()-getAlphadecimal() );
+   \MWExceptionHandler::logException( $e );
 
-   $content = $revision-getContent( $format );
-   } else {
-   throw new InvalidInputException( 'Invalid format: ' . 
$format );
+   $content = wfMessage( 'flow-stub-post-content' 
)-parse();
+   if ( !in_array( $format, array( 'html', 'fixed-html' ) 
) ) {
+   $content = strip_tags( $content );
+   }
}
 
return $content;

-- 
To view, visit https://gerrit.wikimedia.org/r/219476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2609626e18c80d379cb839ccaed2a4b10924bfd6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie mmul...@wikimedia.org
Gerrit-Reviewer: Catrope roan.katt...@gmail.com
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits