X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=0cdc21c131d6c28882784356ed4fe8ae6c7aaa40;hb=c07e337da68a87e7e877c65194778f4b098bf7c2;hp=8bb9a78a42b63a07c210d74f9c8c8d4cf237e366;hpb=cd8b5fad98fc32bb84b6600c4e268362a26f4fba;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 8bb9a78a42..0cdc21c131 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -16,28 +16,30 @@ * usually the same, but they are now allowed to be different. */ class EditPage { - const AS_SUCCESS_UPDATE = 200; + const AS_SUCCESS_UPDATE = 200; const AS_SUCCESS_NEW_ARTICLE = 201; - const AS_HOOK_ERROR = 210; - const AS_FILTERING = 211; + const AS_HOOK_ERROR = 210; + const AS_FILTERING = 211; const AS_HOOK_ERROR_EXPECTED = 212; const AS_BLOCKED_PAGE_FOR_USER = 215; - const AS_CONTENT_TOO_BIG = 216; - const AS_USER_CANNOT_EDIT = 217; + const AS_CONTENT_TOO_BIG = 216; + const AS_USER_CANNOT_EDIT = 217; const AS_READ_ONLY_PAGE_ANON = 218; const AS_READ_ONLY_PAGE_LOGGED = 219; - const AS_READ_ONLY_PAGE = 220; - const AS_RATE_LIMITED = 221; + const AS_READ_ONLY_PAGE = 220; + const AS_RATE_LIMITED = 221; const AS_ARTICLE_WAS_DELETED = 222; const AS_NO_CREATE_PERMISSION = 223; - const AS_BLANK_ARTICLE = 224; - const AS_CONFLICT_DETECTED = 225; - const AS_SUMMARY_NEEDED = 226; - const AS_TEXTBOX_EMPTY = 228; - const AS_MAX_ARTICLE_SIZE_EXCEDED = 229; - const AS_OK = 230; - const AS_END = 231; - const AS_SPAM_ERROR = 232; + const AS_BLANK_ARTICLE = 224; + const AS_CONFLICT_DETECTED = 225; + const AS_SUMMARY_NEEDED = 226; + const AS_TEXTBOX_EMPTY = 228; + const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229; + const AS_OK = 230; + const AS_END = 231; + const AS_SPAM_ERROR = 232; + const AS_IMAGE_REDIRECT_ANON = 233; + const AS_IMAGE_REDIRECT_LOGGED = 234; var $mArticle; var $mTitle; @@ -86,7 +88,6 @@ class EditPage { * @param $article */ function EditPage( $article ) { - global $wgTitle; $this->mArticle =& $article; $this->mTitle = $article->getTitle(); @@ -101,8 +102,9 @@ class EditPage { /** * Fetch initial editing page content. + * @private */ - private function getContent( $def_text = '' ) { + function getContent( $def_text = '' ) { global $wgOut, $wgRequest, $wgParser; # Get variables from query string :P @@ -333,14 +335,13 @@ class EditPage { * the newly-edited page. */ function edit() { - global $wgOut, $wgUser, $wgRequest, $wgTitle; + global $wgOut, $wgUser, $wgRequest; - if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) ) + if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) return; - $fname = 'EditPage::edit'; - wfProfileIn( $fname ); - wfDebug( "$fname: enter\n" ); + wfProfileIn( __METHOD__ ); + wfDebug( __METHOD__.": enter\n" ); // this is not an article $wgOut->setArticleFlag(false); @@ -350,13 +351,28 @@ class EditPage { if( $this->live ) { $this->livePreview(); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); + return; + } + + if( wfReadOnly() ) { + $wgOut->readOnlyPage( $this->getContent() ); + wfProfileOut( __METHOD__ ); return; } $permErrors = $this->mTitle->getUserPermissionsErrors('edit', $wgUser); - if( !$this->mTitle->exists() ) - $permErrors += array_diff( $this->mTitle->getUserPermissionsErrors('create', $wgUser), $permErrors ); + if( !$this->mTitle->exists() ) { + # We can't use array_diff here, because that considers ANY TWO + # ARRAYS TO BE EQUAL. Thanks, PHP. + $createErrors = $this->mTitle->getUserPermissionsErrors('create', $wgUser); + foreach( $createErrors as $error ) { + # in_array() actually *does* work as expected. + if( !in_array( $error, $permErrors ) ) { + $permErrors[] = $error; + } + } + } # Ignore some permissions errors. $remove = array(); @@ -377,14 +393,12 @@ class EditPage { } } } - # array_diff returns elements in $permErrors that are not in $remove. $permErrors = array_diff( $permErrors, $remove ); - if ( !empty($permErrors) ) - { - wfDebug( "$fname: User can't edit\n" ); + if ( !empty($permErrors) ) { + wfDebug( __METHOD__.": User can't edit\n" ); $wgOut->readOnlyPage( $this->getContent(), true, $permErrors ); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return; } else { if ( $this->save ) { @@ -404,7 +418,7 @@ class EditPage { } } - wfProfileIn( "$fname-business-end" ); + wfProfileIn( __METHOD__."-business-end" ); $this->isConflict = false; // css / js subpages of user pages get a special treatment @@ -447,8 +461,8 @@ class EditPage { if ( 'save' == $this->formtype ) { if ( !$this->attemptSave() ) { - wfProfileOut( "$fname-business-end" ); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__."-business-end" ); + wfProfileOut( __METHOD__ ); return; } } @@ -458,8 +472,8 @@ class EditPage { if ( 'initial' == $this->formtype || $this->firsttime ) { if ($this->initialiseForm() === false) { $this->noSuchSectionPage(); - wfProfileOut( "$fname-business-end" ); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__."-business-end" ); + wfProfileOut( __METHOD__ ); return; } if( !$this->mTitle->getArticleId() ) @@ -467,8 +481,8 @@ class EditPage { } $this->showEditForm(); - wfProfileOut( "$fname-business-end" ); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__."-business-end" ); + wfProfileOut( __METHOD__ ); } /** @@ -673,9 +687,9 @@ class EditPage { * Attempt submission (no UI) * @return one of the constants describing the result */ - function internalAttemptSave( &$result ) { + function internalAttemptSave( &$result, $bot = false ) { global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser; - global $wgMaxArticleSize, $wgTitle; + global $wgMaxArticleSize; $fname = 'EditPage::attemptSave'; wfProfileIn( $fname ); @@ -687,6 +701,17 @@ class EditPage { return self::AS_HOOK_ERROR; } + # Check image redirect + if ( $this->mTitle->getNamespace() == NS_IMAGE && + Title::newFromRedirect( $this->textbox1 ) instanceof Title && + !$wgUser->isAllowed( 'upload' ) ) { + if( $wgUser->isAnon() ) { + return self::AS_IMAGE_REDIRECT_ANON; + } else { + return self::AS_IMAGE_REDIRECT_LOGGED; + } + } + # Reintegrate metadata if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ; $this->mMetaData = '' ; @@ -716,7 +741,7 @@ class EditPage { wfProfileOut( $fname ); return self::AS_HOOK_ERROR_EXPECTED; } - if ( $wgUser->isBlockedFrom( $wgTitle, false ) ) { + if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) { # Check block state against master, thus 'false'. wfProfileOut( "$fname-checks" ); wfProfileOut( $fname ); @@ -777,7 +802,7 @@ class EditPage { } # Don't save a new article if it's blank. - if ( ( '' == $this->textbox1 ) ) { + if ( '' == $this->textbox1 ) { wfProfileOut( $fname ); return self::AS_BLANK_ARTICLE; } @@ -786,13 +811,13 @@ class EditPage { if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError ) ) ) { # Error messages etc. could be handled within the hook... wfProfileOut( $fname ); - return false; + return self::AS_HOOK_ERROR; } $isComment = ( $this->section == 'new' ); $this->mArticle->insertNewArticle( $this->textbox1, $this->summary, - $this->minoredit, $this->watchthis, false, $isComment); + $this->minoredit, $this->watchthis, false, $isComment, $bot); wfProfileOut( $fname ); return self::AS_SUCCESS_NEW_ARTICLE; @@ -869,7 +894,7 @@ class EditPage { if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError ) ) ) { # Error messages etc. could be handled within the hook... wfProfileOut( $fname ); - return false; + return self::AS_HOOK_ERROR; } # Handle the user preference to force summaries here, but not for null edits @@ -931,12 +956,12 @@ class EditPage { if ( $this->kblength > $wgMaxArticleSize ) { $this->tooBig = true; wfProfileOut( $fname ); - return self::AS_MAX_ARTICLE_SIZE_EXCEDED; + return self::AS_MAX_ARTICLE_SIZE_EXCEEDED; } # update the article here if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit, - $this->watchthis, '', $sectionanchor ) ) { + $this->watchthis, $bot, $sectionanchor ) ) { wfProfileOut( $fname ); return self::AS_SUCCESS_UPDATE; } else { @@ -996,7 +1021,6 @@ class EditPage { $this->textbox1 = $this->getContent(); $this->edittime = $this->mArticle->getTimestamp(); } else { - if( $this->section != '' ) { if( $this->section == 'new' ) { $s = wfMsg('editingcomment', $wgTitle->getPrefixedText() ); @@ -1032,7 +1056,7 @@ class EditPage { $wgOut->addWikiText( '
' . wfMsg( 'missingcommentheader' ) . '
' ); } - if( !$this->hookError == '' ) { + if( $this->hookError !== '' ) { $wgOut->addWikiText( $this->hookError ); } @@ -1056,9 +1080,9 @@ class EditPage { } if( wfReadOnly() ) { - $wgOut->addWikiText( wfMsg( 'readonlywarning' ) ); + $wgOut->addHTML( '
'.wfMsgWikiHTML( 'readonlywarning' ).'
' ); } elseif( $wgUser->isAnon() && $this->formtype != 'preview' ) { - $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) ); + $wgOut->addHTML( '
'.wfMsgWikiHTML( 'anoneditwarning' ).'
' ); } else { if( $this->isCssJsSubpage && $this->formtype != 'preview' ) { # Check the skin exists @@ -1080,7 +1104,7 @@ class EditPage { if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' ) $notice = ''; } else { - # Then it must be protected based on static groups (regular) + # Then it must be protected based on static groups (regular) $notice = wfMsg( 'protectedpagewarning' ); } $wgOut->addWikiText( $notice ); @@ -1097,6 +1121,9 @@ class EditPage { } $wgOut->addWikiText( $notice ); } + if( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) != array() ){ + $wgOut->addWikiText( wfMsg( 'titleprotectedwarning' ) ); + } if ( $this->kblength === false ) { $this->kblength = (int)(strlen( $this->textbox1 ) / 1024); @@ -1341,7 +1368,7 @@ END $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) ); $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' ); - $wgOut->addHTML( "" ); } $wgOut->addHTML( $this->editFormTextBottom ); @@ -1448,17 +1475,12 @@ END if ( $this->mTriedSave && !$this->mTokenOk ) { if ( $this->mTokenOkExceptSuffix ) { - $msg = 'token_suffix_mismatch'; + $note = wfMsg( 'token_suffix_mismatch' ); } else { - $msg = 'session_fail_preview'; + $note = wfMsg( 'session_fail_preview' ); } } else { - $msg = 'previewnote'; - } - $previewhead = '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

\n" . - "
" . $wgOut->parse( wfMsg( $msg ) ) . "
\n"; - if ( $this->isConflict ) { - $previewhead.='

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; + $note = wfMsg( 'previewnote' ); } $parserOptions = ParserOptions::newFromUser( $wgUser ); @@ -1484,8 +1506,7 @@ END $parserOptions->setTidy(true); $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions ); $wgOut->addHTML( $parserOutput->mText ); - wfProfileOut( $fname ); - return $previewhead; + $previewHTML = ''; } else { $toparse = $this->textbox1; @@ -1505,15 +1526,30 @@ END $wgOut->addParserOutputNoText( $parserOutput ); # ParserOutput might have altered the page title, so reset it - $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) ); + # Also, use the title defined by DISPLAYTITLE magic word when present + if( ( $dt = $parserOutput->getDisplayTitle() ) !== false ) { + $wgOut->setPageTitle( wfMsg( 'editing', $dt ) ); + } else { + $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) ); + } foreach ( $parserOutput->getTemplates() as $ns => $template) foreach ( array_keys( $template ) as $dbk) $this->mPreviewTemplates[] = Title::makeTitle($ns, $dbk); - wfProfileOut( $fname ); - return $previewhead . $previewHTML; + if ( count( $parserOutput->getWarnings() ) ) { + $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); + } + } + + $previewhead = '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

\n" . + "
" . $wgOut->parse( $note ) . "
\n"; + if ( $this->isConflict ) { + $previewhead.='

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; } + + wfProfileOut( $fname ); + return $previewhead . $previewHTML; } /** @@ -1588,9 +1624,11 @@ END $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setArticleRelated( false ); + $wgOut->addHtml( '
' ); $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) ); if ( $match ) - $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "{$match}" ) ); + $wgOut->addWikiText( wfMsg( 'spamprotectionmatch',wfEscapeWikiText( $match ) ) ); + $wgOut->addHtml( '
' ); $wgOut->returnToMain( false, $wgTitle ); } @@ -1928,7 +1966,8 @@ END 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']', ); $buttons['diff'] = wfElement('input', $temp, ''); - + + wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons ) ); return $buttons; } @@ -2141,27 +2180,26 @@ END * @return bool false if output is done, true if the rest of the form should be displayed */ function attemptSave() { - global $wgUser, $wgOut, $wgTitle; + global $wgUser, $wgOut, $wgTitle, $wgRequest; $resultDetails = false; - $value = $this->internalAttemptSave( $resultDetails ); + $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) ); if( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) { $this->didSave = true; } - switch ($value) - { + switch ($value) { case self::AS_HOOK_ERROR_EXPECTED: case self::AS_CONTENT_TOO_BIG: case self::AS_ARTICLE_WAS_DELETED: case self::AS_CONFLICT_DETECTED: case self::AS_SUMMARY_NEEDED: case self::AS_TEXTBOX_EMPTY: - case self::AS_MAX_ARTICLE_SIZE_EXCEDED: + case self::AS_MAX_ARTICLE_SIZE_EXCEEDED: case self::AS_END: return true; - + case self::AS_HOOK_ERROR: case self::AS_FILTERING: case self::AS_SUCCESS_NEW_ARTICLE: @@ -2176,6 +2214,10 @@ END $this->blockedPage(); return false; + case self::AS_IMAGE_REDIRECT_ANON: + $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); + return false; + case self::AS_READ_ONLY_PAGE_ANON: $this->userNotLoggedInPage(); return false; @@ -2196,6 +2238,10 @@ END case self::AS_BLANK_ARTICLE: $wgOut->redirect( $wgTitle->getFullURL() ); return false; + + case self::AS_IMAGE_REDIRECT_LOGGED: + $wgOut->permissionRequired( 'upload' ); + return false; } } }