Gerrit Patch Uploader has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/343216 )
Change subject: Complete plaintext section markers
......................................................................
Complete plaintext section markers
The heading tags from getExtract is useful even in plaintext output
mode. These tags, scrambled to a special format by ExtractFormatter,
are used by doSection(), which looks for such tags and reformat them
into the format specified by sectionformat.
When truncated incorrectly, these markers will stay in the text and get
converted to U+FFFD characters, as noted in the bug below.
Bug: T92628
Change-Id: Ib91fab62601087c891fba0e7fadea7d249c7f18b
---
M includes/ApiQueryExtracts.php
1 file changed, 14 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TextExtracts
refs/changes/16/343216/1
diff --git a/includes/ApiQueryExtracts.php b/includes/ApiQueryExtracts.php
index f80b90b..ecedf27 100644
--- a/includes/ApiQueryExtracts.php
+++ b/includes/ApiQueryExtracts.php
@@ -318,13 +318,24 @@
}
/**
- * A simple wrapper around tidy
+ * Runs tidy for HTML, completes section markers otherwise
* @param string $text
* @return string
*/
private function tidy( $text ) {
- if ( $this->getConfig()->get( 'UseTidy' ) &&
!$this->params['plaintext'] ) {
- $text = trim( MWTidy::tidy( $text ) );
+ if ( $this->getConfig()->get( 'UseTidy' ) ) {
+ if ( $this->params['plaintext'] ) {
+ // Find and complete truncated sections markers
at the very end
+ $text = preg_replace(
+ // XXX: Assuming length of
SECTION_MARKER_END stays at 2
+ // (don't want to write nested group
generation [e.g. (a(b(c)?)?)?] for now)
+ "/\n\n" .
ExtractFormatter::SECTION_MARKER_START . '(\d)' .
ExtractFormatter::SECTION_MARKER_END[0] . "?$/D",
+ "\n\n" . self::SECTION_MARKER_START .
'$1' . self::SECTION_MARKER_END,
+ $text
+ );
+ } else {
+ $text = trim( MWTidy::tidy( $text ) );
+ }
}
return $text;
}
--
To view, visit https://gerrit.wikimedia.org/r/343216
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib91fab62601087c891fba0e7fadea7d249c7f18b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TextExtracts
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <[email protected]>
Gerrit-Reviewer: Artoria2e5 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits