X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=ec9840a228f2c84ff36afc61e0e9adc824dcb6ec;hb=29ef5f88ab95a7df05d5b48cced165bcc2f88b60;hp=66aadebc1938e4e2c51155406dded784376b0a57;hpb=d47071884ca1bfb5f24befb3231d948a05f29d3a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 66aadebc19..ec9840a228 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -625,20 +625,6 @@ class Title implements LinkTarget { return $wgLegalTitleChars; } - /** - * Returns a simple regex that will match on characters and sequences invalid in titles. - * Note that this doesn't pick up many things that could be wrong with titles, but that - * replacing this regex with something valid will make many titles valid. - * - * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead - * - * @return string Regex string - */ - static function getTitleInvalidRegex() { - wfDeprecated( __METHOD__, '1.25' ); - return MediaWikiTitleCodec::getTitleInvalidRegex(); - } - /** * Utility method for converting a character sequence from bytes to Unicode. * @@ -1041,12 +1027,11 @@ class Title implements LinkTarget { */ public function getNsText() { if ( $this->isExternal() ) { - // This probably shouldn't even happen, - // but for interwiki transclusion it sometimes does. - // Use the canonical namespaces if possible to try to - // resolve a foreign namespace. - if ( MWNamespace::exists( $this->mNamespace ) ) { - return MWNamespace::getCanonicalName( $this->mNamespace ); + // This probably shouldn't even happen, except for interwiki transclusion. + // If possible, use the canonical name for the foreign namespace. + $nsText = MWNamespace::getCanonicalName( $this->mNamespace ); + if ( $nsText !== false ) { + return $nsText; } } @@ -1292,15 +1277,15 @@ class Title implements LinkTarget { } /** - * Could this page contain custom CSS or JavaScript for the global UI. - * This is generally true for pages in the MediaWiki namespace having CONTENT_MODEL_CSS - * or CONTENT_MODEL_JAVASCRIPT. + * Could this MediaWiki namespace page contain custom CSS, JSON, or JavaScript for the + * global UI. This is generally true for pages in the MediaWiki namespace having + * CONTENT_MODEL_CSS, CONTENT_MODEL_JSON, or CONTENT_MODEL_JAVASCRIPT. * - * This method does *not* return true for per-user JS/CSS. Use isCssJsSubpage() + * This method does *not* return true for per-user JS/JSON/CSS. Use isUserConfigPage() * for that! * - * Note that this method should not return true for pages that contain and - * show "inactive" CSS or JS. + * Note that this method should not return true for pages that contain and show + * "inactive" CSS, JSON, or JS. * * @return bool * @since 1.31 @@ -1310,6 +1295,7 @@ class Title implements LinkTarget { NS_MEDIAWIKI == $this->mNamespace && ( $this->hasContentModel( CONTENT_MODEL_CSS ) + || $this->hasContentModel( CONTENT_MODEL_JSON ) || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) ); @@ -1317,7 +1303,7 @@ class Title implements LinkTarget { /** * @return bool - * @deprecated Since 1.31; use ::isSiteConfigPage() instead + * @deprecated Since 1.31; use ::isSiteConfigPage() instead (which also checks for JSON pages) */ public function isCssOrJsPage() { wfDeprecated( __METHOD__, '1.31' ); @@ -1327,7 +1313,7 @@ class Title implements LinkTarget { } /** - * Is this a "config" (.css or .js) sub-page of a user page? + * Is this a "config" (.css, .json, or .js) sub-page of a user page? * * @return bool * @since 1.31 @@ -1338,6 +1324,7 @@ class Title implements LinkTarget { && $this->isSubpage() && ( $this->hasContentModel( CONTENT_MODEL_CSS ) + || $this->hasContentModel( CONTENT_MODEL_JSON ) || $this->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) ); @@ -1345,7 +1332,7 @@ class Title implements LinkTarget { /** * @return bool - * @deprecated Since 1.31; use ::isUserConfigPage() instead + * @deprecated Since 1.31; use ::isUserConfigPage() instead (which also checks for JSON pages) */ public function isCssJsSubpage() { wfDeprecated( __METHOD__, '1.31' ); @@ -1355,9 +1342,9 @@ class Title implements LinkTarget { } /** - * Trim down a .css or .js subpage title to get the corresponding skin name + * Trim down a .css, .json, or .js subpage title to get the corresponding skin name * - * @return string Containing skin name from .css or .js subpage title + * @return string Containing skin name from .css, .json, or .js subpage title * @since 1.31 */ public function getSkinFromConfigSubpage() { @@ -1365,14 +1352,14 @@ class Title implements LinkTarget { $subpage = $subpage[count( $subpage ) - 1]; $lastdot = strrpos( $subpage, '.' ); if ( $lastdot === false ) { - return $subpage; # Never happens: only called for names ending in '.css' or '.js' + return $subpage; # Never happens: only called for names ending in '.css'/'.json'/'.js' } return substr( $subpage, 0, $lastdot ); } /** * @deprecated Since 1.31; use ::getSkinFromConfigSubpage() instead - * @return string Containing skin name from .css or .js subpage title + * @return string Containing skin name from .css, .json, or .js subpage title */ public function getSkinFromCssJsSubpage() { wfDeprecated( __METHOD__, '1.31' ); @@ -1403,7 +1390,21 @@ class Title implements LinkTarget { } /** - * Is this a .js subpage of a user page? + * Is this a JSON "config" sub-page of a user page? + * + * @return bool + * @since 1.31 + */ + public function isUserJsonConfigPage() { + return ( + NS_USER == $this->mNamespace + && $this->isSubpage() + && $this->hasContentModel( CONTENT_MODEL_JSON ) + ); + } + + /** + * Is this a JS "config" sub-page of a user page? * * @return bool * @since 1.31 @@ -2316,7 +2317,7 @@ class Title implements LinkTarget { } /** - * Check CSS/JS sub-page permissions + * Check CSS/JSON/JS sub-page permissions * * @param string $action The action to check * @param User $user User to check @@ -2327,7 +2328,7 @@ class Title implements LinkTarget { * @return array List of errors */ private function checkUserConfigPermissions( $action, $user, $errors, $rigor, $short ) { - # Protect css/js subpages of user pages + # Protect css/json/js subpages of user pages # XXX: this might be better using restrictions if ( $action != 'patrol' ) { @@ -2337,6 +2338,11 @@ class Title implements LinkTarget { && !$user->isAllowedAny( 'editmyusercss', 'editusercss' ) ) { $errors[] = [ 'mycustomcssprotected', $action ]; + } elseif ( + $this->isUserJsonConfigPage() + && !$user->isAllowedAny( 'editmyuserjson', 'edituserjson' ) + ) { + $errors[] = [ 'mycustomjsonprotected', $action ]; } elseif ( $this->isUserJsConfigPage() && !$user->isAllowedAny( 'editmyuserjs', 'edituserjs' ) @@ -2349,6 +2355,11 @@ class Title implements LinkTarget { && !$user->isAllowed( 'editusercss' ) ) { $errors[] = [ 'customcssprotected', $action ]; + } elseif ( + $this->isUserJsonConfigPage() + && !$user->isAllowed( 'edituserjson' ) + ) { + $errors[] = [ 'customjsonprotected', $action ]; } elseif ( $this->isUserJsConfigPage() && !$user->isAllowed( 'edituserjs' ) @@ -2545,7 +2556,10 @@ class Title implements LinkTarget { return $errors; } - if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) { + if ( $wgEmailConfirmToEdit + && !$user->isEmailConfirmed() + && $action === 'edit' + ) { $errors[] = [ 'confirmedittext' ]; } @@ -3824,6 +3838,8 @@ class Title implements LinkTarget { // If we are looking at a css/js user subpage, purge the action=raw. if ( $this->isUserJsConfigPage() ) { $urls[] = $this->getInternalURL( 'action=raw&ctype=text/javascript' ); + } elseif ( $this->isUserJsonConfigPage() ) { + $urls[] = $this->getInternalURL( 'action=raw&ctype=application/json' ); } elseif ( $this->isUserCssConfigPage() ) { $urls[] = $this->getInternalURL( 'action=raw&ctype=text/css' ); } @@ -4781,14 +4797,12 @@ class Title implements LinkTarget { */ public function getNamespaceKey( $prepend = 'nstab-' ) { global $wgContLang; - // Gets the subject namespace if this title - $namespace = MWNamespace::getSubject( $this->getNamespace() ); - // Checks if canonical namespace name exists for namespace - if ( MWNamespace::exists( $this->getNamespace() ) ) { - // Uses canonical namespace name - $namespaceKey = MWNamespace::getCanonicalName( $namespace ); - } else { - // Uses text of namespace + // Gets the subject namespace of this title + $subjectNS = MWNamespace::getSubject( $this->getNamespace() ); + // Prefer canonical namespace name for HTML IDs + $namespaceKey = MWNamespace::getCanonicalName( $subjectNS ); + if ( $namespaceKey === false ) { + // Fallback to localised text $namespaceKey = $this->getSubjectNsText(); } // Makes namespace key lowercase