Debian Codegraph @

includes/editpage/ParametersHelper.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\EditPage;
4
5 use MediaWiki\Context\RequestContext;
6 use MediaWiki\Page\PageIdentity;
7 use MediaWiki\Permissions\Authority;
8 use MediaWiki\SpecialPage\SpecialPageFactory;
9 use MediaWiki\Specials\SpecialMyLanguage;
10 use MediaWiki\Title\Title;
11
12 /**
13 * Helper methods for resolving EditPage parameters that deal with page titles.
14 *
15 * @internal
16 * @property SpecialPageFactory $specialPageFactory
17 */
18 trait ParametersHelper {
19
20 /**
21 * If the given Title is Special:MyLanguage/Foo, resolve the language chain for the
22 * actual target title desired.
23 *
24 * @param ?Title $title
25 * @return ?Title
26 */
27 private function getTargetTitleIfSpecialMyLanguage( ?Title $title ): ?Title {
28 if ( $title && $title->isSpecialPage() ) {
29 [ $spName, $spParam ] = $this->specialPageFactory->resolveAlias( $title->getText() );
30 if ( $spName ) {
31 $specialPage = $this->specialPageFactory->getPage( $spName );
32 if ( $specialPage instanceof SpecialMyLanguage ) {
33 // TODO This should pass a language as a parameter, instead of the whole context
34 $specialPage->setContext( RequestContext::getMain() );
35 $title = $specialPage->findTitleForTransclusion( $spParam );
36 }
37 }
38 }
39
40 return $title;
41 }
42
43 /**
44 * Verify if a given title exists and the given user is allowed to view it
45 *
46 * @param PageIdentity|null $page
47 * @param Authority $performer
48 * @return bool
49 * @phan-assert-true-condition $page
50 */
51 private function isPageExistingAndViewable( ?PageIdentity $page, Authority $performer ): bool {
52 return $page && $page->exists() && $performer->authorizeRead( 'read', $page );
53 }
54 }