X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=585e156d642d372dceead29e82bc3c1227c99acd;hb=3205049d446abb53b217e7cf1af82a640f9e0480;hp=ac51a42fb93c60a920cef67420032ba963a4363f;hpb=d19599aeccb95fcaddd01ed1dbf3c590ccdd8812;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index ac51a42fb9..585e156d64 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1,6 +1,7 @@ editFormTextAfterTools = $this->editFormTextBottom = ""; } - + /** * Fetch initial editing page content. * @private */ function getContent( $def_text = '' ) { - global $wgOut, $wgRequest, $wgParser; + global $wgOut, $wgRequest, $wgParser, $wgMessageCache; # Get variables from query string :P $section = $wgRequest->getVal( 'section' ); @@ -118,7 +120,8 @@ class EditPage { $text = ''; if( !$this->mTitle->exists() ) { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - # If this is a system message, get the default text. + $wgMessageCache->loadAllMessages(); + # If this is a system message, get the default text. $text = wfMsgWeirdKey ( $this->mTitle->getText() ) ; } else { # If requested, preload some text. @@ -152,39 +155,43 @@ class EditPage { $oldrev = $undorev ? $undorev->getPrevious() : null; } - #Sanity check, make sure it's the right page. + # Sanity check, make sure it's the right page, + # the revisions exist and they were not deleted. # Otherwise, $text will be left as-is. - if ( !is_null($undorev) && !is_null($oldrev) && $undorev->getPage()==$oldrev->getPage() && $undorev->getPage()==$this->mArticle->getID() ) { + if( !is_null( $undorev ) && !is_null( $oldrev ) && + $undorev->getPage() == $oldrev->getPage() && + $undorev->getPage() == $this->mArticle->getID() && + !$undorev->isDeleted( Revision::DELETED_TEXT ) && + !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) { $undorev_text = $undorev->getText(); $oldrev_text = $oldrev->getText(); $currev_text = $text; - #No use doing a merge if it's just a straight revert. if ( $currev_text != $undorev_text ) { - $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text); + $result = wfMerge( $undorev_text, $oldrev_text, $currev_text, $text ); } else { + # No use doing a merge if it's just a straight revert. $text = $oldrev_text; $result = true; } + if( $result ) { + # Inform the user of our success and set an automatic edit summary + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) ); + $firstrev = $oldrev->getNext(); + # If we just undid one rev, use an autosummary + if( $firstrev->mId == $undo ) { + $this->summary = wfMsgForContent('undo-summary', $undo, $undorev->getUserText()); + } + $this->formtype = 'diff'; + } else { + # Warn the user that something went wrong + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); + } } else { // Failed basic sanity checks. // Older revisions may have been removed since the link // was created, or we may simply have got bogus input. - $result = false; - } - - if( $result ) { - # Inform the user of our success and set an automatic edit summary - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) ); - $firstrev = $oldrev->getNext(); - # If we just undid one rev, use an autosummary - if ( $firstrev->mId == $undo ) { - $this->summary = wfMsgForContent('undo-summary', $undo, $undorev->getUserText()); - } - $this->formtype = 'diff'; - } else { - # Warn the user that something went wrong - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-norev' ) ); } } else if( $section != '' ) { if( $section == 'new' ) { @@ -205,7 +212,7 @@ class EditPage { * @param $preload String: the title of the page. * @return string The contents of the page. */ - private function getPreloadedText($preload) { + protected function getPreloadedText($preload) { if ( $preload === '' ) return ''; else { @@ -319,6 +326,25 @@ class EditPage { $this->mMetaData = $s ; } + protected function wasDeletedSinceLastEdit() { + /* Note that we rely on the logging table, which hasn't been always there, + * but that doesn't matter, because this only applies to brand new + * deletes. + */ + if ( $this->deletedSinceEdit ) + return true; + if ( $this->mTitle->isDeleted() ) { + $this->lastDelete = $this->getLastDelete(); + if ( !is_null($this->lastDelete) ) { + $deletetime = $this->lastDelete->log_timestamp; + if ( ($deletetime - $this->starttime) > 0 ) { + $this->deletedSinceEdit = true; + } + } + } + return $this->deletedSinceEdit; + } + function submit() { $this->edit(); } @@ -355,6 +381,8 @@ class EditPage { return; } + $wgOut->addScriptFile( 'edit.js' ); + if( wfReadOnly() ) { $this->readOnlyPage( $this->getContent() ); wfProfileOut( __METHOD__ ); @@ -362,8 +390,9 @@ class EditPage { } $permErrors = $this->mTitle->getUserPermissionsErrors('edit', $wgUser); + if( !$this->mTitle->exists() ) { - $permErrors = array_merge( $permErrors, + $permErrors = array_merge( $permErrors, wfArrayDiff2( $this->mTitle->getUserPermissionsErrors('create', $wgUser), $permErrors ) ); } @@ -387,17 +416,13 @@ class EditPage { } } $permErrors = wfArrayDiff2( $permErrors, $remove ); - + if ( $permErrors ) { wfDebug( __METHOD__.": User can't edit\n" ); - $this->readOnlyPage( $this->getContent(), true, $permErrors ); + $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' ); wfProfileOut( __METHOD__ ); return; } else { - if( $wgRequest->getVal( 'action' ) == 'editredlink' ) { - $wgOut->redirect( $this->mTitle->getFullUrl( 'action=edit' ) ); - return; - } if ( $this->save ) { $this->formtype = 'save'; } else if ( $this->preview ) { @@ -422,31 +447,10 @@ class EditPage { $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage(); - /* Notice that we can't use isDeleted, because it returns true if article is ever deleted - * no matter it's current state - */ - $this->deletedSinceEdit = false; - if ( $this->edittime != '' ) { - /* Note that we rely on logging table, which hasn't been always there, - * but that doesn't matter, because this only applies to brand new - * deletes. This is done on every preview and save request. Move it further down - * to only perform it on saves - */ - if ( $this->mTitle->isDeleted() ) { - $this->lastDelete = $this->getLastDelete(); - if ( !is_null($this->lastDelete) ) { - $deletetime = $this->lastDelete->log_timestamp; - if ( ($deletetime - $this->starttime) > 0 ) { - $this->deletedSinceEdit = true; - } - } - } - } - # Show applicable editing introductions if( $this->formtype == 'initial' || $this->firsttime ) $this->showIntro(); - + if( $this->mTitle->isTalkPage() ) { $wgOut->addWikiMsg( 'talkpagetext' ); } @@ -473,7 +477,7 @@ class EditPage { wfProfileOut( __METHOD__ ); return; } - if( !$this->mTitle->getArticleId() ) + if( !$this->mTitle->getArticleId() ) wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) ); } @@ -485,17 +489,17 @@ class EditPage { /** * Show a read-only error * Parameters are the same as OutputPage:readOnlyPage() - * Redirect to the article page if action=editredlink + * Redirect to the article page if redlink=1 */ - function readOnlyPage( $source = null, $protected = false, $reasons = array() ) { + function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) { global $wgRequest, $wgOut; - if ( $wgRequest->getVal( 'action' ) === 'editredlink' ) { + if ( $wgRequest->getBool( 'redlink' ) ) { // The edit page was reached via a red link. - // Redirect to the article page and let them click the edit tab if + // Redirect to the article page and let them click the edit tab if // they really want a permission error. $wgOut->redirect( $this->mTitle->getFullUrl() ); } else { - $wgOut->readOnlyPage( $source, $protected, $reasons ); + $wgOut->readOnlyPage( $source, $protected, $reasons, $action ); } } @@ -504,7 +508,7 @@ class EditPage { * * @return bool */ - private function previewOnOpen() { + protected function previewOnOpen() { global $wgRequest, $wgUser; if( $wgRequest->getVal( 'preview' ) == 'yes' ) { // Explicit override from request @@ -535,15 +539,21 @@ class EditPage { $fname = 'EditPage::importFormData'; wfProfileIn( $fname ); + # Section edit can come from either the form or a link + $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) ); + if( $request->wasPosted() ) { # These fields need to be checked for encoding. # Also remove trailing whitespace, but don't remove _initial_ # whitespace from the text boxes. This may be significant formatting. $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' ); $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' ); - $this->mMetaData = rtrim( $request->getText( 'metadata' ) ); + $this->mMetaData = rtrim( $request->getText( 'metadata' ) ); # Truncate for whole multibyte characters. +5 bytes for ellipsis - $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 ); + $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 ); + + # Remove extra headings from summaries and new sections. + $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary); $this->edittime = $request->getVal( 'wpEdittime' ); $this->starttime = $request->getVal( 'wpStarttime' ); @@ -580,7 +590,7 @@ class EditPage { $this->preview = true; } } - $this->save = ! ( $this->preview OR $this->diff ); + $this->save = !$this->preview && !$this->diff; if( !preg_match( '/^\d{14}$/', $this->edittime )) { $this->edittime = null; } @@ -601,7 +611,7 @@ class EditPage { $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ); } - $this->autoSumm = $request->getText( 'wpAutoSummary' ); + $this->autoSumm = $request->getText( 'wpAutoSummary' ); } else { # Not a posted form? Start with nothing. wfDebug( "$fname: Not a posted form.\n" ); @@ -618,13 +628,14 @@ class EditPage { $this->minoredit = false; $this->watchthis = false; $this->recreate = false; + + if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) { + $this->summary = $request->getVal( 'preloadtitle' ); + } } $this->oldid = $request->getInt( 'oldid' ); - # Section edit can come from either the form or a link - $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) ); - $this->live = $request->getCheck( 'live' ); $this->editintro = $request->getText( 'editintro' ); @@ -649,7 +660,7 @@ class EditPage { /** * Show all applicable editing introductions */ - private function showIntro() { + protected function showIntro() { global $wgOut, $wgUser; if( $this->suppressIntro ) return; @@ -662,7 +673,7 @@ class EditPage { $ip = User::isIP( $username ); if ( $id == 0 && !$ip ) { - $wgOut->wrapWikiMsg( '