* 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;
* @param $article
*/
function EditPage( $article ) {
- global $wgTitle;
$this->mArticle =& $article;
$this->mTitle = $article->getTitle();
/**
* 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
* 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);
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();
}
}
}
- # 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 ) {
}
}
- wfProfileIn( "$fname-business-end" );
+ wfProfileIn( __METHOD__."-business-end" );
$this->isConflict = false;
// css / js subpages of user pages get a special treatment
if ( 'save' == $this->formtype ) {
if ( !$this->attemptSave() ) {
- wfProfileOut( "$fname-business-end" );
- wfProfileOut( $fname );
+ wfProfileOut( __METHOD__."-business-end" );
+ wfProfileOut( __METHOD__ );
return;
}
}
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() )
}
$this->showEditForm();
- wfProfileOut( "$fname-business-end" );
- wfProfileOut( $fname );
+ wfProfileOut( __METHOD__."-business-end" );
+ wfProfileOut( __METHOD__ );
}
/**
* 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 );
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 = '' ;
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 );
}
# Don't save a new article if it's blank.
- if ( ( '' == $this->textbox1 ) ) {
+ if ( '' == $this->textbox1 ) {
wfProfileOut( $fname );
return self::AS_BLANK_ARTICLE;
}
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;
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
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 {
$this->textbox1 = $this->getContent();
$this->edittime = $this->mArticle->getTimestamp();
} else {
-
if( $this->section != '' ) {
if( $this->section == 'new' ) {
$s = wfMsg('editingcomment', $wgTitle->getPrefixedText() );
$wgOut->addWikiText( '<div id="mw-missingcommentheader">' . wfMsg( 'missingcommentheader' ) . '</div>' );
}
- if( !$this->hookError == '' ) {
+ if( $this->hookError !== '' ) {
$wgOut->addWikiText( $this->hookError );
}
}
if( wfReadOnly() ) {
- $wgOut->addWikiText( wfMsg( 'readonlywarning' ) );
+ $wgOut->addHTML( '<div id="mw-read-only-warning">'.wfMsgWikiHTML( 'readonlywarning' ).'</div>' );
} elseif( $wgUser->isAnon() && $this->formtype != 'preview' ) {
- $wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );
+ $wgOut->addHTML( '<div id="mw-anon-edit-warning">'.wfMsgWikiHTML( 'anoneditwarning' ).'</div>' );
} else {
if( $this->isCssJsSubpage && $this->formtype != 'preview' ) {
# Check the skin exists
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 );
}
$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);
$de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
$wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
- $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
+ $wgOut->addHTML( "<textarea tabindex='6' id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}'>"
. htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2 ) ) . "\n</textarea>" );
}
$wgOut->addHTML( $this->editFormTextBottom );
$wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->setArticleRelated( false );
+ $wgOut->addHtml( '<div id="spamprotected">' );
$wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
if ( $match )
- $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
+ $wgOut->addWikiText( wfMsg( 'spamprotectionmatch',wfEscapeWikiText( $match ) ) );
+ $wgOut->addHtml( '</div>' );
$wgOut->returnToMain( false, $wgTitle );
}
'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
);
$buttons['diff'] = wfElement('input', $temp, '');
-
+
+ wfRunHooks( 'EditPageBeforeEditButtons', array( &$buttons ) );
return $buttons;
}
* @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:
$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;
case self::AS_BLANK_ARTICLE:
$wgOut->redirect( $wgTitle->getFullURL() );
return false;
+
+ case self::AS_IMAGE_REDIRECT_LOGGED:
+ $wgOut->permissionRequired( 'upload' );
+ return false;
}
}
}