X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=includes%2FTitle.php;h=b27baa8db10ea397ae3032811196914298eba56f;hb=b08b334d599de59ffe1eabb1762a73b94d9deb71;hp=c4fe858ac8ba5b715d17d654baf93bbb0f9e65fb;hpb=2c3694463a02bae9102bfe76b8baeafb924d33a8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index c4fe858ac8..b27baa8db1 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -23,6 +23,7 @@ */ use MediaWiki\Permissions\PermissionManager; +use Wikimedia\Assert\Assert; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; use MediaWiki\Linker\LinkTarget; @@ -851,7 +852,10 @@ class Title implements LinkTarget, IDBAccessObject { /** * Returns true if the title is valid, false if it is invalid. * - * Valid titles can be round-tripped via makeTitleSafe() and newFromText(). + * Valid titles can be round-tripped via makeTitle() and newFromText(). + * Their DB key can be used in the database, though it may not have the correct + * capitalization. + * * Invalid titles may get returned from makeTitle(), and it may be useful to * allow them to exist, e.g. in order to process log entries about pages in * namespaces that belong to extensions that are no longer installed. @@ -870,10 +874,23 @@ class Title implements LinkTarget, IDBAccessObject { try { $services->getTitleParser()->parseTitle( $this->mDbkeyform, $this->mNamespace ); - return true; } catch ( MalformedTitleException $ex ) { return false; } + + try { + // Title value applies basic syntax checks. Should perhaps be moved elsewhere. + new TitleValue( + $this->mNamespace, + $this->mDbkeyform, + $this->mFragment, + $this->mInterwiki + ); + } catch ( InvalidArgumentException $ex ) { + return false; + } + + return true; } /** @@ -1728,6 +1745,9 @@ class Title implements LinkTarget, IDBAccessObject { /** * Get the root page name text without a namespace, i.e. the leftmost part before any slashes * + * @note the return value may contain trailing whitespace and is thus + * not safe for use with makeTitle or TitleValue. + * * @par Example: * @code * Title::newFromText('User:Foo/Bar/Baz')->getRootText(); @@ -1761,12 +1781,20 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.20 */ public function getRootTitle() { - return self::makeTitle( $this->mNamespace, $this->getRootText() ); + $title = self::makeTitleSafe( $this->mNamespace, $this->getRootText() ); + Assert::postcondition( + $title !== null, + 'makeTitleSafe() should always return a Title for the text returned by getRootText().' + ); + return $title; } /** * Get the base page name without a namespace, i.e. the part before the subpage name * + * @note the return value may contain trailing whitespace and is thus + * not safe for use with makeTitle or TitleValue. + * * @par Example: * @code * Title::newFromText('User:Foo/Bar/Baz')->getBaseText(); @@ -1794,7 +1822,7 @@ class Title implements LinkTarget, IDBAccessObject { } /** - * Get the base page name title, i.e. the part before the subpage name + * Get the base page name title, i.e. the part before the subpage name. * * @par Example: * @code @@ -1806,7 +1834,12 @@ class Title implements LinkTarget, IDBAccessObject { * @since 1.20 */ public function getBaseTitle() { - return self::makeTitle( $this->mNamespace, $this->getBaseText() ); + $title = self::makeTitleSafe( $this->mNamespace, $this->getBaseText() ); + Assert::postcondition( + $title !== null, + 'makeTitleSafe() should always return a Title for the text returned by getBaseText().' + ); + return $title; } /** @@ -1979,7 +2012,7 @@ class Title implements LinkTarget, IDBAccessObject { * * @param string|string[] $query An optional query string, * not used for interwiki links. Can be specified as an associative array as well, - * e.g., array( 'action' => 'edit' ) (keys and values will be URL-escaped). + * e.g., [ 'action' => 'edit' ] (keys and values will be URL-escaped). * Some query patterns will trigger various shorturl path replacements. * @param string|string[]|bool $query2 An optional secondary query array. This one MUST * be an array. If a string is passed it will be interpreted as a deprecated @@ -2235,7 +2268,7 @@ class Title implements LinkTarget, IDBAccessObject { * @throws Exception * * @deprecated since 1.33, - * use MediaWikiServices::getInstance()->getPermissionManager()->getUserPermissionsErrors() + * use MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors() * */ public function getUserPermissionsErrors( @@ -2256,7 +2289,7 @@ class Title implements LinkTarget, IDBAccessObject { * Add the resulting error code to the errors array * * @param array $errors List of current errors - * @param array $result Result of errors + * @param array|string|MessageSpecifier|false $result Result of errors * * @return array List of errors */ @@ -3429,6 +3462,8 @@ class Title implements LinkTarget, IDBAccessObject { * @return array|bool True on success, getUserPermissionsErrors()-like array on failure */ public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) { + wfDeprecated( __METHOD__, '1.25' ); + global $wgUser; if ( !( $nt instanceof Title ) ) { @@ -3465,6 +3500,8 @@ class Title implements LinkTarget, IDBAccessObject { public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true, array $changeTags = [] ) { + wfDeprecated( __METHOD__, '1.25' ); + global $wgUser; $mp = new MovePage( $this, $nt ); @@ -3495,26 +3532,10 @@ class Title implements LinkTarget, IDBAccessObject { public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true, array $changeTags = [] ) { - // Check permissions - if ( !$this->userCan( 'move-subpages' ) ) { - return [ - [ 'cant-move-subpages' ], - ]; - } - // Do the source and target namespaces support subpages? - $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); - if ( !$nsInfo->hasSubpages( $this->mNamespace ) ) { - return [ - [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $this->mNamespace ) ], - ]; - } - if ( !$nsInfo->hasSubpages( $nt->getNamespace() ) ) { - return [ - [ 'namespace-nosubpages', $nsInfo->getCanonicalName( $nt->getNamespace() ) ], - ]; - } + wfDeprecated( __METHOD__, '1.34' ); global $wgUser; + $mp = new MovePage( $this, $nt ); $method = $auth ? 'moveSubpagesIfAllowed' : 'moveSubpages'; $result = $mp->$method( $wgUser, $reason, $createRedirect, $changeTags ); @@ -3592,9 +3613,12 @@ class Title implements LinkTarget, IDBAccessObject { * @return bool */ public function isValidMoveTarget( $nt ) { + wfDeprecated( __METHOD__, '1.25' ); + # Is it an existing file? if ( $nt->getNamespace() == NS_FILE ) { - $file = wfLocalFile( $nt ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo() + ->newFile( $nt ); $file->load( File::READ_LATEST ); if ( $file->exists() ) { wfDebug( __METHOD__ . ": file exists\n" ); @@ -4066,15 +4090,15 @@ class Title implements LinkTarget, IDBAccessObject { return true; // any interwiki link might be viewable, for all we know } + $services = MediaWikiServices::getInstance(); switch ( $this->mNamespace ) { case NS_MEDIA: case NS_FILE: // file exists, possibly in a foreign repo - return (bool)wfFindFile( $this ); + return (bool)$services->getRepoGroup()->findFile( $this ); case NS_SPECIAL: // valid special page - return MediaWikiServices::getInstance()->getSpecialPageFactory()-> - exists( $this->mDbkeyform ); + return $services->getSpecialPageFactory()->exists( $this->mDbkeyform ); case NS_MAIN: // selflink, possibly with fragment return $this->mDbkeyform == '';