X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=0cdc21c131d6c28882784356ed4fe8ae6c7aaa40;hb=c07e337da68a87e7e877c65194778f4b098bf7c2;hp=ba0482e945a4453ce62cc830ba0b37b9fb134a18;hpb=9f52185cec2416605af287b898ac1c5c95e37ac1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index ba0482e945..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( '