X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=a8a17cf90be9914af62ca5e0536abed86b36a8a6;hb=1abec6cce38830b41da0c594d6d55a900419c29c;hp=6497c40619e852c486a0df60963318587be32fab;hpb=d726bc7c3456d9742d4cb32640aa5847ad6b1782;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 6497c40619..a8a17cf90b 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -504,7 +504,7 @@ class EditPage { } } - $permErrors = $this->getEditPermissionErrors(); + $permErrors = $this->getEditPermissionErrors( $this->save ? 'secure' : 'full' ); if ( $permErrors ) { wfDebug( __METHOD__ . ": User can't edit\n" ); // Auto-block user's IP if the account was "hard" blocked @@ -515,8 +515,6 @@ class EditPage { return; } - wfProfileIn( __METHOD__ . "-business-end" ); - $this->isConflict = false; // css / js subpages of user pages get a special treatment $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); @@ -536,8 +534,9 @@ class EditPage { # in the back door with a hand-edited submission URL. if ( 'save' == $this->formtype ) { - if ( !$this->attemptSave() ) { - wfProfileOut( __METHOD__ . "-business-end" ); + $resultDetails = null; + $status = $this->attemptSave( $resultDetails ); + if ( !$this->handleStatus( $status, $resultDetails ) ) { return; } } @@ -547,7 +546,6 @@ class EditPage { if ( 'initial' == $this->formtype || $this->firsttime ) { if ( $this->initialiseForm() === false ) { $this->noSuchSectionPage(); - wfProfileOut( __METHOD__ . "-business-end" ); return; } @@ -560,19 +558,25 @@ class EditPage { } $this->showEditForm(); - wfProfileOut( __METHOD__ . "-business-end" ); } /** + * @param string $rigor Same format as Title::getUserPermissionErrors() * @return array */ - protected function getEditPermissionErrors() { + protected function getEditPermissionErrors( $rigor = 'secure' ) { global $wgUser; - $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ); + + $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser, $rigor ); # Can this title be created? if ( !$this->mTitle->exists() ) { - $permErrors = array_merge( $permErrors, - wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) ); + $permErrors = array_merge( + $permErrors, + wfArrayDiff2( + $this->mTitle->getUserPermissionsErrors( 'create', $wgUser, $rigor ), + $permErrors + ) + ); } # Ignore some permissions errors when a user is just previewing/viewing diffs $remove = array(); @@ -584,6 +588,7 @@ class EditPage { } } $permErrors = wfArrayDiff2( $permErrors, $remove ); + return $permErrors; } @@ -725,7 +730,6 @@ class EditPage { function importFormData( &$request ) { global $wgContLang, $wgUser; - # Section edit can come from either the form or a link $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) ); @@ -744,13 +748,10 @@ class EditPage { // Skip this if wpTextbox2 has input, it indicates that we came // from a conflict page with raw page text, not a custom form // modified by subclasses - wfProfileIn( get_class( $this ) . "::importContentFormData" ); $textbox1 = $this->importContentFormData( $request ); if ( $textbox1 !== null ) { $this->textbox1 = $textbox1; } - - wfProfileOut( get_class( $this ) . "::importContentFormData" ); } # Truncate for whole multibyte characters @@ -982,7 +983,6 @@ class EditPage { protected function getContentObject( $def_content = null ) { global $wgOut, $wgRequest, $wgUser, $wgContLang; - $content = false; // For message page not locally set, use the i18n message. @@ -1286,18 +1286,20 @@ class EditPage { /** * Attempt submission + * @param array $resultDetails See docs for $result in internalAttemptSave * @throws UserBlockedError|ReadOnlyError|ThrottledError|PermissionsError - * @return bool False if output is done, true if the rest of the form should be displayed + * @return Status The resulting status object. */ - public function attemptSave() { + public function attemptSave( &$resultDetails = false ) { global $wgUser; - $resultDetails = false; # Allow bots to exempt some edits from bot flagging $bot = $wgUser->isAllowed( 'bot' ) && $this->bot; $status = $this->internalAttemptSave( $resultDetails, $bot ); - return $this->handleStatus( $status, $resultDetails ); + Hooks::run( 'EditPage::attemptSave:after', array( $this, $status, $resultDetails ) ); + + return $status; } /** @@ -1526,13 +1528,10 @@ class EditPage { $status = Status::newGood(); - wfProfileIn( __METHOD__ . '-checks' ); - if ( !Hooks::run( 'EditPage::attemptSave', array( $this ) ) ) { wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" ); $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } @@ -1549,7 +1548,6 @@ class EditPage { ); $status->fatal( 'spamprotectionmatch', false ); $status->value = self::AS_SPAM_ERROR; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } @@ -1564,7 +1562,6 @@ class EditPage { $ex->getMessage() ); $status->value = self::AS_PARSE_ERROR; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } @@ -1576,8 +1573,6 @@ class EditPage { $code = $wgUser->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED; $status->setResult( false, $code ); - wfProfileOut( __METHOD__ . '-checks' ); - return $status; } @@ -1606,7 +1601,6 @@ class EditPage { wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" ); $status->fatal( 'spamprotectionmatch', $match ); $status->value = self::AS_SPAM_ERROR; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } if ( !Hooks::run( @@ -1616,13 +1610,11 @@ class EditPage { # Error messages etc. could be handled within the hook... $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } elseif ( $this->hookError != '' ) { # ...or the hook could be expecting us to produce an error $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR_EXPECTED; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } @@ -1631,7 +1623,6 @@ class EditPage { $wgUser->spreadAnyEditBlock(); # Check block state against master, thus 'false'. $status->setResult( false, self::AS_BLOCKED_PAGE_FOR_USER ); - wfProfileOut( __METHOD__ . '-checks' ); return $status; } @@ -1640,19 +1631,16 @@ class EditPage { // Error will be displayed by showEditForm() $this->tooBig = true; $status->setResult( false, self::AS_CONTENT_TOO_BIG ); - wfProfileOut( __METHOD__ . '-checks' ); return $status; } if ( !$wgUser->isAllowed( 'edit' ) ) { if ( $wgUser->isAnon() ) { $status->setResult( false, self::AS_READ_ONLY_PAGE_ANON ); - wfProfileOut( __METHOD__ . '-checks' ); return $status; } else { $status->fatal( 'readonlytext' ); $status->value = self::AS_READ_ONLY_PAGE_LOGGED; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } } @@ -1661,20 +1649,17 @@ class EditPage { && !$wgUser->isAllowed( 'editcontentmodel' ) ) { $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL ); - wfProfileOut( __METHOD__ . '-checks' ); return $status; } if ( wfReadOnly() ) { $status->fatal( 'readonlytext' ); $status->value = self::AS_READ_ONLY_PAGE; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } if ( $wgUser->pingLimiter() || $wgUser->pingLimiter( 'linkpurge', 0 ) ) { $status->fatal( 'actionthrottledtext' ); $status->value = self::AS_RATE_LIMITED; - wfProfileOut( __METHOD__ . '-checks' ); return $status; } @@ -1682,12 +1667,9 @@ class EditPage { # confirmation if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) { $status->setResult( false, self::AS_ARTICLE_WAS_DELETED ); - wfProfileOut( __METHOD__ . '-checks' ); return $status; } - wfProfileOut( __METHOD__ . '-checks' ); - # Load the page data from the master. If anything changes in the meantime, # we detect it by using page_latest like a token in a 1 try compare-and-swap. $this->mArticle->loadPageData( 'fromdbmaster' ); @@ -1859,7 +1841,6 @@ class EditPage { } # All's well - wfProfileIn( __METHOD__ . '-sectionanchor' ); $sectionanchor = ''; if ( $this->section == 'new' ) { $this->summary = $this->newSectionSummary( $sectionanchor ); @@ -1876,7 +1857,6 @@ class EditPage { } } $result['sectionanchor'] = $sectionanchor; - wfProfileOut( __METHOD__ . '-sectionanchor' ); // Save errors may fall down to the edit form, but we've now // merged the section into full text. Clear the section field @@ -2328,7 +2308,6 @@ class EditPage { function showEditForm( $formCallback = null ) { global $wgOut, $wgUser; - # need to parse the preview early so that we know which templates are used, # otherwise users with "show preview after edit box" will get a blank list # we parse this near the beginning so that setHeaders can do the title @@ -3017,6 +2996,12 @@ HTML if ( $this->formtype == 'preview' ) { $this->showPreview( $previewOutput ); + } else { + // Empty content container for LivePreview + $pageViewLang = $this->mTitle->getPageViewLanguage(); + $attribs = array( 'lang' => $pageViewLang->getHtmlCode(), 'dir' => $pageViewLang->getDir(), + 'class' => 'mw-content-' . $pageViewLang->getDir() ); + $wgOut->addHTML( Html::rawElement( 'div', $attribs ) ); } $wgOut->addHTML( '' ); @@ -3202,7 +3187,6 @@ HTML return ''; } - $limitReport = Html::rawElement( 'div', array( 'class' => 'mw-limitReportExplanation' ), wfMessage( 'limitreport-title' )->parseAsBlock() ); @@ -3237,7 +3221,6 @@ HTML Html::closeElement( 'table' ) . Html::closeElement( 'div' ); - return $limitReport; } @@ -3423,7 +3406,6 @@ HTML global $wgOut, $wgUser, $wgRawHtml, $wgLang; global $wgAllowUserCss, $wgAllowUserJs; - if ( $wgRawHtml && !$this->mTokenOk ) { // Could be an offsite preview attempt. This is very unsafe if // HTML is enabled, as it could be an attack.