$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
$this->context->getUser()->spreadAnyEditBlock();
} );
}
-
- $config = $this->context->getConfig();
- if ( $config->get( 'EnableBlockNoticeStats' ) ) {
- $wiki = $config->get( 'DBname' );
- $statsd = MediaWikiServices::getInstance()->getStatsdDataFactory();
- $statsd->increment( 'BlockNotices.' . $wiki . '.WikitextEditor.shown' );
- }
}
$this->displayPermissionsError( $permErrors );
$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();
}
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();
}
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.
*
* @return string
*/
private function newSectionSummary( &$sectionanchor = null ) {
- global $wgParser;
-
if ( $this->sectiontitle !== '' ) {
$sectionanchor = $this->guessSectionName( $this->sectiontitle );
// If no edit summary was specified, create one automatically from the section
// title and have it link to the new section. Otherwise, respect the summary as
// passed.
if ( $this->summary === '' ) {
- $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
+ $cleanSectionTitle = MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $this->sectiontitle );
return $this->context->msg( 'newsectionsummary' )
->plaintextParams( $cleanSectionTitle )->inContentLanguage()->text();
}
$sectionanchor = $this->guessSectionName( $this->summary );
# This is a new section, so create a link to the new section
# in the revision summary.
- $cleanSummary = $wgParser->stripSectionName( $this->summary );
+ $cleanSummary = MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $this->summary );
return $this->context->msg( 'newsectionsummary' )
->plaintextParams( $cleanSummary )->inContentLanguage()->text();
}
}
}
+ $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
$changingContentModel = false;
if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
if ( !$config->get( 'ContentHandlerUseDB' ) ) {
// 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;
}
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" );
LogEventsList::showLogExtract(
$out,
'block',
- MWNamespace::getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
+ MediaWikiServices::getInstance()->getNamespaceInfo()->
+ getCanonicalName( NS_USER ) . ':' . $block->getTarget(),
'',
[
'lim' => 1,
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 <noinclude>'s into account.
$this->context->getOutput()->addWikiTextAsContent(
'<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',
}
if ( !$this->mTitle->isUserConfigPage() ) {
- $out->addHTML( self::getEditToolbar( $this->mTitle ) );
+ $out->addHTML( self::getEditToolbar() );
}
if ( $this->blankArticle ) {
public static function extractSectionTitle( $text ) {
preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
if ( !empty( $matches[2] ) ) {
- global $wgParser;
- return $wgParser->stripSectionName( trim( $matches[2] ) );
+ return MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( trim( $matches[2] ) );
} else {
return false;
}
return "";
}
- global $wgParser;
-
if ( $isSubjectPreview ) {
$summary = $this->context->msg( 'newsectionsummary' )
- ->rawParams( $wgParser->stripSectionName( $summary ) )
+ ->rawParams( MediaWikiServices::getInstance()->getParser()
+ ->stripSectionName( $summary ) )
->inContentLanguage()->text();
}
/**
* Allow extensions to provide a toolbar.
*
- * @param Title|null $title Title object for the page being edited (optional)
* @return string|null
*/
- public static function getEditToolbar( $title = null ) {
+ public static function getEditToolbar() {
$startingToolbar = '<div id="toolbar"></div>';
$toolbar = $startingToolbar;
$out->addReturnTo( $this->getContextTitle(), [ 'action' => 'edit' ] );
}
- /**
- * Filter an input field through a Unicode de-armoring process if it
- * came from an old browser with known broken Unicode editing issues.
- *
- * @deprecated since 1.30, does nothing
- *
- * @param WebRequest $request
- * @param string $field
- * @return string
- */
- protected function safeUnicodeInput( $request, $field ) {
- return rtrim( $request->getText( $field ) );
- }
-
- /**
- * Filter an output field through a Unicode armoring process if it is
- * going to an old browser with known broken Unicode editing issues.
- *
- * @deprecated since 1.30, does nothing
- *
- * @param string $text
- * @return string
- */
- protected function safeUnicodeOutput( $text ) {
- return $text;
- }
-
/**
* @since 1.29
*/
protected function addPageProtectionWarningHeaders() {
$out = $this->context->getOutput();
if ( $this->mTitle->isProtected( 'edit' ) &&
- MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) !== [ '' ]
+ MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+ $this->mTitle->getNamespace()
+ ) !== [ '' ]
) {
# Is the title semi-protected?
if ( $this->mTitle->isSemiProtected() ) {
* @return string
*/
private function guessSectionName( $text ) {
- global $wgParser;
-
// Detect Microsoft browsers
$userAgent = $this->context->getRequest()->getHeader( 'User-Agent' );
+ $parser = MediaWikiServices::getInstance()->getParser();
if ( $userAgent && preg_match( '/MSIE|Edge/', $userAgent ) ) {
// ...and redirect them to legacy encoding, if available
- return $wgParser->guessLegacySectionNameFromWikiText( $text );
+ return $parser->guessLegacySectionNameFromWikiText( $text );
}
// Meanwhile, real browsers get real anchors
- $name = $wgParser->guessSectionNameFromWikiText( $text );
+ $name = $parser->guessSectionNameFromWikiText( $text );
// With one little caveat: per T216029, fragments in HTTP redirects need to be urlencoded,
// otherwise Chrome double-escapes the rest of the URL.
return '#' . urlencode( mb_substr( $name, 1 ) );