diff options
author | Ebrahim Byagowi <ebrahim@gnu.org> | 2024-08-06 17:10:20 +0330 |
---|---|---|
committer | Ebrahim Byagowi <ebrahim@gnu.org> | 2024-08-06 17:42:51 +0330 |
commit | 4c270a72ac83dae230897a16dfee74496546093e (patch) | |
tree | 61dcc83fd07e195fb10f51c721ce9041f2dc5273 /includes/content | |
parent | e1c682d1e9ceedb972728bd44ffeaa8e8fb3cc32 (diff) | |
download | mediawikicore-4c270a72ac83dae230897a16dfee74496546093e.tar.gz mediawikicore-4c270a72ac83dae230897a16dfee74496546093e.zip |
Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.
Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
Diffstat (limited to 'includes/content')
-rw-r--r-- | includes/content/FileContentHandler.php | 1 | ||||
-rw-r--r-- | includes/content/TextContent.php | 1 | ||||
-rw-r--r-- | includes/content/WikiTextStructure.php | 19 | ||||
-rw-r--r-- | includes/content/WikitextContent.php | 14 | ||||
-rw-r--r-- | includes/content/WikitextContentHandler.php | 19 |
5 files changed, 51 insertions, 3 deletions
diff --git a/includes/content/FileContentHandler.php b/includes/content/FileContentHandler.php index c7affed71447..ee12bf4ee404 100644 --- a/includes/content/FileContentHandler.php +++ b/includes/content/FileContentHandler.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Content\WikitextContentHandler; use MediaWiki\MediaWikiServices; use MediaWiki\Parser\ParserOutput; use MediaWiki\Revision\RevisionRecord; diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php index fa5979f9f2c6..a88c304c5b61 100644 --- a/includes/content/TextContent.php +++ b/includes/content/TextContent.php @@ -35,7 +35,6 @@ use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; use MWUnknownContentModelException; use Wikimedia\Diff\Diff; -use WikitextContent; /** * Content object implementation for representing flat text. diff --git a/includes/content/WikiTextStructure.php b/includes/content/WikiTextStructure.php index 0bb1ca6a62c7..09c813667329 100644 --- a/includes/content/WikiTextStructure.php +++ b/includes/content/WikiTextStructure.php @@ -1,5 +1,7 @@ <?php +namespace MediaWiki\Content; + use HtmlFormatter\HtmlFormatter; use MediaWiki\Parser\ParserOutput; use MediaWiki\Parser\Sanitizer; @@ -64,6 +66,7 @@ class WikiTextStructure { /** * Gets headings from the page. + * * @return string[] * First strip out things that look like references. We can't use HTML filtering because * the references come back as <sup> tags without a class. To keep from breaking stuff like @@ -104,6 +107,7 @@ class WikiTextStructure { $headings[] = $heading; } } + return $headings; } @@ -112,6 +116,7 @@ class WikiTextStructure { * parse settings stored as i18n messages (see search-ignored-headings). * * @param string $message + * * @return string[] */ public static function parseSettingsInMessage( $message ) { @@ -120,12 +125,14 @@ class WikiTextStructure { $lines = preg_replace( '/#.*$/', '', $lines ); // Remove extra spaces $lines = array_map( 'trim', $lines ); + // Remove empty lines return array_filter( $lines ); } /** * Gets a list of heading to ignore. + * * @return string[] */ private function getIgnoredHeadings() { @@ -139,6 +146,7 @@ class WikiTextStructure { $ignoredHeadings = $lines; } } + return $ignoredHeadings; } @@ -152,6 +160,7 @@ class WikiTextStructure { $text = $this->parserOutput->getRawText(); if ( $text === '' ) { $this->allText = ""; + // empty text - nothing to seek here return; } @@ -178,7 +187,9 @@ class WikiTextStructure { /** * Get text before first heading. + * * @param string $text + * * @return string|null */ private function extractTextBeforeFirstHeading( $text ) { @@ -215,6 +226,7 @@ class WikiTextStructure { */ public function getOpeningText() { $this->extractWikitextParts(); + return $this->openingText; } @@ -223,6 +235,7 @@ class WikiTextStructure { */ public function getMainText() { $this->extractWikitextParts(); + return $this->allText; } @@ -231,11 +244,13 @@ class WikiTextStructure { */ public function getAuxiliaryText() { $this->extractWikitextParts(); + return $this->auxText; } /** * Get the "defaultsort" property + * * @return string|null */ public function getDefaultSort() { @@ -243,6 +258,10 @@ class WikiTextStructure { if ( $sort === false ) { return null; } + return $sort; } } + +/** @deprecated class alias since 1.43 */ +class_alias( WikiTextStructure::class, 'WikiTextStructure' ); diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index fb94cd4f97ae..28ed326ca6d5 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -25,7 +25,10 @@ * @author Daniel Kinzler */ -use MediaWiki\Content\TextContent; +namespace MediaWiki\Content; + +use Content; +use InvalidArgumentException; use MediaWiki\Context\RequestContext; use MediaWiki\HookContainer\HookRunner; use MediaWiki\MainConfigNames; @@ -78,6 +81,7 @@ class WikitextContent extends TextContent { * @param string|int|null|false $sectionId * @param Content $with New section content, must have the same content model as $this. * @param string $sectionTitle + * * @return Content * * @see Content::replaceSection() @@ -241,6 +245,7 @@ class WikitextContent extends TextContent { /** * @param int $maxlength + * * @return string */ public function getTextForSummary( $maxlength = 250 ) { @@ -269,7 +274,9 @@ class WikitextContent extends TextContent { /** * Records flags set by preSaveTransform + * * @internal for use by WikitextContentHandler + * * @param string[] $flags */ public function setPreSaveTransformFlags( array $flags ) { @@ -278,6 +285,7 @@ class WikitextContent extends TextContent { /** * Records flags set by preSaveTransform + * * @internal for use by WikitextContentHandler * @return string[] */ @@ -288,6 +296,10 @@ class WikitextContent extends TextContent { public function getContentHandler(): WikitextContentHandler { $handler = parent::getContentHandler(); '@phan-var WikitextContentHandler $handler'; + return $handler; } } + +/** @deprecated class alias since 1.43 */ +class_alias( WikitextContent::class, 'WikitextContent' ); diff --git a/includes/content/WikitextContentHandler.php b/includes/content/WikitextContentHandler.php index f517c0ebb198..f332489c90c7 100644 --- a/includes/content/WikitextContentHandler.php +++ b/includes/content/WikitextContentHandler.php @@ -23,8 +23,11 @@ * @ingroup Content */ +namespace MediaWiki\Content; + +use Content; +use FileContentHandler; use MediaWiki\Content\Renderer\ContentParseParams; -use MediaWiki\Content\TextContentHandler; use MediaWiki\Content\Transform\PreloadTransformParams; use MediaWiki\Content\Transform\PreSaveTransformParams; use MediaWiki\Languages\LanguageNameUtils; @@ -37,7 +40,12 @@ use MediaWiki\Parser\Parsoid\ParsoidParserFactory; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Title\Title; use MediaWiki\Title\TitleFactory; +use MessageContent; +use ParserFactory; +use SearchEngine; +use SearchIndexField; use Wikimedia\UUID\GlobalIdGenerator; +use WikiPage; /** * Content handler for wiki text pages. @@ -116,6 +124,7 @@ class WikitextContentHandler extends TextContentHandler { } $class = $this->getContentClass(); + return new $class( $redirectText ); } @@ -191,6 +200,7 @@ class WikitextContentHandler extends TextContentHandler { $fields['opening_text']->setFlag( SearchIndexField::FLAG_SCORING | SearchIndexField::FLAG_NO_HIGHLIGHT ); + // Until we have the full first-class content handler for files, we invoke it explicitly here return array_merge( $fields, $this->getFileHandler()->getFieldsForSearchIndex( $engine ) ); } @@ -219,6 +229,7 @@ class WikitextContentHandler extends TextContentHandler { $this->getFileHandler()->getDataForSearchIndex( $page, $parserOutput, $engine, $revision ) ); } + return $fields; } @@ -264,6 +275,7 @@ class WikitextContentHandler extends TextContentHandler { $contentClass = $this->getContentClass(); $ret = new $contentClass( $pst ); $ret->setPreSaveTransformFlags( $parser->getOutput()->getAllFlags() ); + return $ret; } @@ -291,6 +303,7 @@ class WikitextContentHandler extends TextContentHandler { ); $contentClass = $this->getContentClass(); + return new $contentClass( $plt ); } @@ -341,6 +354,7 @@ class WikitextContentHandler extends TextContentHandler { * using the global Parser service. * * @since 1.38 + * * @param Content $content * @param ContentParseParams $cpoParams * @param ParserOutput &$parserOutput The output object to fill (reference). @@ -418,3 +432,6 @@ class WikitextContentHandler extends TextContentHandler { } } } + +/** @deprecated class alias since 1.43 */ +class_alias( WikitextContentHandler::class, 'WikitextContentHandler' ); |