X-Git-Url: http://git.cyclocoop.org/%24image?a=blobdiff_plain;f=includes%2FEditPage.php;h=d27ef9c7a936e2f22f94abaccd47fe44e26c6513;hb=7388b7b62b842ef1e80faa677656a26a90803ece;hp=7908fcc585088a9566b901588abe64e322af353f;hpb=bec3717780aa3f605a31f7cc2b18023f3d34ab26;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 7908fcc585..d27ef9c7a9 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\Block\DatabaseBlock; use MediaWiki\EditPage\TextboxBuilder; use MediaWiki\EditPage\TextConflictHelper; use MediaWiki\Logger\LoggerFactory; @@ -565,14 +566,6 @@ class EditPage { $this->enableApiEditOverride = $enableOverride; } - /** - * @deprecated since 1.29, call edit directly - */ - public function submit() { - wfDeprecated( __METHOD__, '1.29' ); - $this->edit(); - } - /** * This is the function that gets called for "action=edit". It * sets up various member variables, then passes execution to @@ -629,7 +622,8 @@ class EditPage { if ( $this->context->getUser()->getBlock() ) { // track block with a cookie if it doesn't exists already - $this->context->getUser()->trackBlockWithCookie(); + MediaWikiServices::getInstance()->getBlockManager() + ->trackBlockWithCookie( $this->context->getUser() ); // Auto-block user's IP if the account was "hard" blocked if ( !wfReadOnly() ) { @@ -1483,8 +1477,9 @@ class EditPage { $user = $this->context->getUser(); $title = Title::newFromText( $preload ); + # Check for existence to avoid getting MediaWiki:Noarticletext - if ( $title === null || !$title->exists() || !$title->userCan( 'read', $user ) ) { + if ( !$this->isPageExistingAndViewable( $title, $user ) ) { // TODO: somehow show a warning to the user! return $handler->makeEmptyContent(); } @@ -1493,7 +1488,7 @@ class EditPage { if ( $page->isRedirect() ) { $title = $page->getRedirectTarget(); # Same as before - if ( $title === null || !$title->exists() || !$title->userCan( 'read', $user ) ) { + if ( !$this->isPageExistingAndViewable( $title, $user ) ) { // TODO: somehow show a warning to the user! return $handler->makeEmptyContent(); } @@ -1526,6 +1521,21 @@ class EditPage { return $content->preloadTransform( $title, $parserOptions, $params ); } + /** + * Verify if a given title exists and the given user is allowed to view it + * + * @see EditPage::getPreloadedContent() + * @param Title|null $title + * @param User $user + * @return bool + * @throws Exception + */ + private function isPageExistingAndViewable( $title, User $user ) { + $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); + + return $title && $title->exists() && $permissionManager->userCan( 'read', $user, $title ); + } + /** * Make sure the form isn't faking a user's credentials. * @@ -1988,6 +1998,8 @@ ERROR; } } + $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); + $changingContentModel = false; if ( $this->contentModel !== $this->mTitle->getContentModel() ) { if ( !$config->get( 'ContentHandlerUseDB' ) ) { @@ -2001,10 +2013,19 @@ ERROR; // Make sure the user can edit the page under the new content model too $titleWithNewContentModel = clone $this->mTitle; $titleWithNewContentModel->setContentModel( $this->contentModel ); - if ( !$titleWithNewContentModel->userCan( 'editcontentmodel', $user ) - || !$titleWithNewContentModel->userCan( 'edit', $user ) + + $canEditModel = $permissionManager->userCan( + 'editcontentmodel', + $user, + $titleWithNewContentModel + ); + + if ( + !$canEditModel + || !$permissionManager->userCan( 'edit', $user, $titleWithNewContentModel ) ) { $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); + return $status; } @@ -2048,7 +2069,7 @@ ERROR; if ( $new ) { // Late check for create permission, just in case *PARANOIA* - if ( !$this->mTitle->userCan( 'create', $user ) ) { + if ( !$permissionManager->userCan( 'create', $user, $this->mTitle ) ) { $status->fatal( 'nocreatetext' ); $status->value = self::AS_NO_CREATE_PERMISSION; wfDebug( __METHOD__ . ": no create permission\n" ); @@ -2571,7 +2592,7 @@ ERROR; } } elseif ( $namespace == NS_FILE ) { # Show a hint to shared repo - $file = wfFindFile( $this->mTitle ); + $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $this->mTitle ); if ( $file && !$file->isLocal() ) { $descUrl = $file->getDescriptionUrl(); # there must be a description url to show a hint to shared repo @@ -2595,13 +2616,13 @@ ERROR; $username = explode( '/', $this->mTitle->getText(), 2 )[0]; $user = User::newFromName( $username, false /* allow IP users */ ); $ip = User::isIP( $username ); - $block = Block::newFromTarget( $user, $user ); + $block = DatabaseBlock::newFromTarget( $user, $user ); if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist $out->wrapWikiMsg( "
\n$1\n
", [ 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ] ); } elseif ( !is_null( $block ) && - $block->getType() != Block::TYPE_AUTO && + $block->getType() != DatabaseBlock::TYPE_AUTO && ( $block->isSitewide() || $user->isBlockedFrom( $this->mTitle ) ) ) { // Show log extract if the user is sitewide blocked or is partially @@ -2672,7 +2693,7 @@ ERROR; protected function showCustomIntro() { if ( $this->editintro ) { $title = Title::newFromText( $this->editintro ); - if ( $title instanceof Title && $title->exists() && $title->userCan( 'read' ) ) { + if ( $this->isPageExistingAndViewable( $title, $this->context->getUser() ) ) { // Added using template syntax, to take 's into account. $this->context->getOutput()->addWikiTextAsContent( '
{{:' . $title->getFullText() . '}}
', @@ -4109,7 +4130,7 @@ ERROR; if ( !Hooks::run( 'EditPageBeforeEditToolbar', [ &$toolbar ] ) ) { return null; - }; + } // Don't add a pointless `
` to the page unless a hook caller populated it return ( $toolbar === $startingToolbar ) ? null : $toolbar; }