| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Rest\Handler\Helper; |
| 4 |
|
| 5 |
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface; |
| 6 |
use MediaWiki\ChangeTags\ChangeTagsStore; |
| 7 |
use MediaWiki\Config\ServiceOptions; |
| 8 |
use MediaWiki\Content\IContentHandlerFactory; |
| 9 |
use MediaWiki\Edit\ParsoidOutputStash; |
| 10 |
use MediaWiki\Languages\LanguageConverterFactory; |
| 11 |
use MediaWiki\Languages\LanguageFactory; |
| 12 |
use MediaWiki\Page\PageIdentity; |
| 13 |
use MediaWiki\Page\PageLookup; |
| 14 |
use MediaWiki\Page\ParserOutputAccess; |
| 15 |
use MediaWiki\Page\RedirectStore; |
| 16 |
use MediaWiki\Parser\Parsoid\Config\SiteConfig as ParsoidSiteConfig; |
| 17 |
use MediaWiki\Parser\Parsoid\HtmlTransformFactory; |
| 18 |
use MediaWiki\Permissions\Authority; |
| 19 |
use MediaWiki\Rest\RequestInterface; |
| 20 |
use MediaWiki\Rest\ResponseFactory; |
| 21 |
use MediaWiki\Rest\Router; |
| 22 |
use MediaWiki\Revision\RevisionLookup; |
| 23 |
use MediaWiki\Revision\RevisionRecord; |
| 24 |
use MediaWiki\Revision\RevisionRenderer; |
| 25 |
use MediaWiki\Title\TitleFactory; |
| 26 |
use MediaWiki\Title\TitleFormatter; |
| 27 |
use Wikimedia\Bcp47Code\Bcp47Code; |
| 28 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 29 |
use Wikimedia\Stats\StatsFactory; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class PageRestHelperFactory { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public const CONSTRUCTOR_OPTIONS = PageContentHelper::CONSTRUCTOR_OPTIONS; |
| 41 |
|
| 42 |
private ServiceOptions $options; |
| 43 |
private RevisionLookup $revisionLookup; |
| 44 |
private RevisionRenderer $revisionRenderer; |
| 45 |
private TitleFormatter $titleFormatter; |
| 46 |
private PageLookup $pageLookup; |
| 47 |
private ParsoidOutputStash $parsoidOutputStash; |
| 48 |
private StatsdDataFactoryInterface $stats; |
| 49 |
private ParserOutputAccess $parserOutputAccess; |
| 50 |
private ParsoidSiteConfig $parsoidSiteConfig; |
| 51 |
private HtmlTransformFactory $htmlTransformFactory; |
| 52 |
private IContentHandlerFactory $contentHandlerFactory; |
| 53 |
private LanguageFactory $languageFactory; |
| 54 |
private RedirectStore $redirectStore; |
| 55 |
private LanguageConverterFactory $languageConverterFactory; |
| 56 |
private TitleFactory $titleFactory; |
| 57 |
private IConnectionProvider $connectionProvider; |
| 58 |
private ChangeTagsStore $changeTagStore; |
| 59 |
private StatsFactory $statsFactory; |
| 60 |
|
| 61 |
public function __construct( |
| 62 |
ServiceOptions $options, |
| 63 |
RevisionLookup $revisionLookup, |
| 64 |
RevisionRenderer $revisionRenderer, |
| 65 |
TitleFormatter $titleFormatter, |
| 66 |
PageLookup $pageLookup, |
| 67 |
ParsoidOutputStash $parsoidOutputStash, |
| 68 |
StatsdDataFactoryInterface $statsDataFactory, |
| 69 |
ParserOutputAccess $parserOutputAccess, |
| 70 |
ParsoidSiteConfig $parsoidSiteConfig, |
| 71 |
HtmlTransformFactory $htmlTransformFactory, |
| 72 |
IContentHandlerFactory $contentHandlerFactory, |
| 73 |
LanguageFactory $languageFactory, |
| 74 |
RedirectStore $redirectStore, |
| 75 |
LanguageConverterFactory $languageConverterFactory, |
| 76 |
TitleFactory $titleFactory, |
| 77 |
IConnectionProvider $connectionProvider, |
| 78 |
ChangeTagsStore $changeTagStore, |
| 79 |
StatsFactory $statsFactory |
| 80 |
) { |
| 81 |
$this->options = $options; |
| 82 |
$this->revisionLookup = $revisionLookup; |
| 83 |
$this->revisionRenderer = $revisionRenderer; |
| 84 |
$this->titleFormatter = $titleFormatter; |
| 85 |
$this->pageLookup = $pageLookup; |
| 86 |
$this->parsoidOutputStash = $parsoidOutputStash; |
| 87 |
$this->stats = $statsDataFactory; |
| 88 |
$this->parserOutputAccess = $parserOutputAccess; |
| 89 |
$this->parsoidSiteConfig = $parsoidSiteConfig; |
| 90 |
$this->htmlTransformFactory = $htmlTransformFactory; |
| 91 |
$this->contentHandlerFactory = $contentHandlerFactory; |
| 92 |
$this->languageFactory = $languageFactory; |
| 93 |
$this->redirectStore = $redirectStore; |
| 94 |
$this->languageConverterFactory = $languageConverterFactory; |
| 95 |
$this->statsFactory = $statsFactory; |
| 96 |
$this->titleFactory = $titleFactory; |
| 97 |
$this->connectionProvider = $connectionProvider; |
| 98 |
$this->changeTagStore = $changeTagStore; |
| 99 |
} |
| 100 |
|
| 101 |
public function newRevisionContentHelper(): RevisionContentHelper { |
| 102 |
return new RevisionContentHelper( |
| 103 |
$this->options, |
| 104 |
$this->revisionLookup, |
| 105 |
$this->titleFormatter, |
| 106 |
$this->pageLookup, |
| 107 |
$this->titleFactory, |
| 108 |
$this->connectionProvider, |
| 109 |
$this->changeTagStore |
| 110 |
); |
| 111 |
} |
| 112 |
|
| 113 |
public function newPageContentHelper(): PageContentHelper { |
| 114 |
return new PageContentHelper( |
| 115 |
$this->options, |
| 116 |
$this->revisionLookup, |
| 117 |
$this->titleFormatter, |
| 118 |
$this->pageLookup, |
| 119 |
$this->titleFactory, |
| 120 |
$this->connectionProvider, |
| 121 |
$this->changeTagStore |
| 122 |
); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public function newHtmlOutputRendererHelper( |
| 142 |
$page = null, |
| 143 |
array $parameters = [], |
| 144 |
?Authority $authority = null, |
| 145 |
$revision = null, |
| 146 |
bool $lenientRevHandling = false |
| 147 |
): HtmlOutputRendererHelper { |
| 148 |
if ( is_bool( $page ) ) { |
| 149 |
|
| 150 |
$lenientRevHandling = $page; |
| 151 |
$page = null; |
| 152 |
wfDeprecated( __METHOD__ . ' with boolean first parameter', '1.43' ); |
| 153 |
} |
| 154 |
if ( $page === null ) { |
| 155 |
wfDeprecated( __METHOD__ . ' with null $page', '1.43' ); |
| 156 |
} |
| 157 |
if ( $authority === null ) { |
| 158 |
wfDeprecated( __METHOD__ . ' with null $authority', '1.43' ); |
| 159 |
} |
| 160 |
return new HtmlOutputRendererHelper( |
| 161 |
$this->parsoidOutputStash, |
| 162 |
$this->statsFactory, |
| 163 |
$this->parserOutputAccess, |
| 164 |
$this->pageLookup, |
| 165 |
$this->revisionLookup, |
| 166 |
$this->revisionRenderer, |
| 167 |
$this->parsoidSiteConfig, |
| 168 |
$this->htmlTransformFactory, |
| 169 |
$this->contentHandlerFactory, |
| 170 |
$this->languageFactory, |
| 171 |
$page, |
| 172 |
$parameters, |
| 173 |
$authority, |
| 174 |
$revision, |
| 175 |
$lenientRevHandling |
| 176 |
); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public function newHtmlMessageOutputHelper( ?PageIdentity $page = null ): HtmlMessageOutputHelper { |
| 183 |
if ( $page === null ) { |
| 184 |
wfDeprecated( __METHOD__ . ' with null $page', '1.43' ); |
| 185 |
} |
| 186 |
return new HtmlMessageOutputHelper( $page ); |
| 187 |
} |
| 188 |
|
| 189 |
public function newHtmlInputTransformHelper( |
| 190 |
$envOptions = [], |
| 191 |
?PageIdentity $page = null, |
| 192 |
$body = null, |
| 193 |
array $parameters = [], |
| 194 |
?RevisionRecord $originalRevision = null, |
| 195 |
?Bcp47Code $pageLanguage = null |
| 196 |
): HtmlInputTransformHelper { |
| 197 |
if ( $page === null || $body === null ) { |
| 198 |
wfDeprecated( __METHOD__ . ' without $page or $body' ); |
| 199 |
} |
| 200 |
return new HtmlInputTransformHelper( |
| 201 |
$this->statsFactory, |
| 202 |
$this->htmlTransformFactory, |
| 203 |
$this->parsoidOutputStash, |
| 204 |
$this->parserOutputAccess, |
| 205 |
$this->pageLookup, |
| 206 |
$this->revisionLookup, |
| 207 |
$envOptions, |
| 208 |
$page, |
| 209 |
$body ?? '', |
| 210 |
$parameters, |
| 211 |
$originalRevision, |
| 212 |
$pageLanguage |
| 213 |
); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public function newPageRedirectHelper( |
| 220 |
ResponseFactory $responseFactory, |
| 221 |
Router $router, |
| 222 |
string $route, |
| 223 |
RequestInterface $request |
| 224 |
): PageRedirectHelper { |
| 225 |
return new PageRedirectHelper( |
| 226 |
$this->redirectStore, |
| 227 |
$this->titleFormatter, |
| 228 |
$responseFactory, |
| 229 |
$router, |
| 230 |
$route, |
| 231 |
$request, |
| 232 |
$this->languageConverterFactory |
| 233 |
); |
| 234 |
} |
| 235 |
|
| 236 |
} |