X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/mediawiki.git/blobdiff_plain/dc9cc5d707f5a612938cc9371614cc41c328fda2..HEAD:/includes/EditPage.php diff --git a/includes/EditPage.php b/includes/EditPage.php index 3589b52d..eeae7b9d 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1,9 +1,29 @@ mContextTitle is the page that forms submit to, links point to, * redirects go to, etc. $this->mTitle (as well as $mArticle) is the * page in the database that is actually being edited. These are * usually the same, but they are now allowed to be different. + * + * Surgeon General's Warning: prolonged exposure to this class is known to cause + * headaches, which may be fatal. */ class EditPage { - const AS_SUCCESS_UPDATE = 200; - const AS_SUCCESS_NEW_ARTICLE = 201; - 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_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_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_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; - var $action; - var $mMetaData = ''; - var $isConflict = false; - var $isCssJsSubpage = false; - var $deletedSinceEdit = false; - var $formtype; - var $firsttime; - var $lastDelete; - var $mTokenOk = false; - var $mTokenOkExceptSuffix = false; - var $mTriedSave = false; - var $tooBig = false; - var $kblength = false; - var $missingComment = false; - var $missingSummary = false; - var $allowBlankSummary = false; - var $autoSumm = ''; - var $hookError = ''; - #var $mPreviewTemplates; - var $mParserOutput; - var $mBaseRevision = false; + /** + * Used for Unicode support checks + */ + const UNICODE_CHECK = 'â³ð²â¥ððð¾ð¸â´ð¹â¯'; + + /** + * Status: Article successfully updated + */ + const AS_SUCCESS_UPDATE = 200; + + /** + * Status: Article successfully created + */ + const AS_SUCCESS_NEW_ARTICLE = 201; + + /** + * Status: Article update aborted by a hook function + */ + const AS_HOOK_ERROR = 210; + + /** + * Status: A hook function returned an error + */ + const AS_HOOK_ERROR_EXPECTED = 212; + + /** + * Status: User is blocked from editing this page + */ + const AS_BLOCKED_PAGE_FOR_USER = 215; + + /** + * Status: Content too big (> $wgMaxArticleSize) + */ + const AS_CONTENT_TOO_BIG = 216; + + /** + * Status: this anonymous user is not allowed to edit this page + */ + const AS_READ_ONLY_PAGE_ANON = 218; + + /** + * Status: this logged in user is not allowed to edit this page + */ + const AS_READ_ONLY_PAGE_LOGGED = 219; + + /** + * Status: wiki is in readonly mode (wfReadOnly() == true) + */ + const AS_READ_ONLY_PAGE = 220; + + /** + * Status: rate limiter for action 'edit' was tripped + */ + const AS_RATE_LIMITED = 221; + + /** + * Status: article was deleted while editing and param wpRecreate == false or form + * was not posted + */ + const AS_ARTICLE_WAS_DELETED = 222; + + /** + * Status: user tried to create this page, but is not allowed to do that + * ( Title->userCan('create') == false ) + */ + const AS_NO_CREATE_PERMISSION = 223; + + /** + * Status: user tried to create a blank page and wpIgnoreBlankArticle == false + */ + const AS_BLANK_ARTICLE = 224; + + /** + * Status: (non-resolvable) edit conflict + */ + const AS_CONFLICT_DETECTED = 225; + + /** + * Status: no edit summary given and the user has forceeditsummary set and the user is not + * editing in his own userspace or talkspace and wpIgnoreBlankSummary == false + */ + const AS_SUMMARY_NEEDED = 226; + + /** + * Status: user tried to create a new section without content + */ + const AS_TEXTBOX_EMPTY = 228; + + /** + * Status: article is too big (> $wgMaxArticleSize), after merging in the new section + */ + const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229; + + /** + * Status: WikiPage::doEdit() was unsuccessful + */ + const AS_END = 231; + + /** + * Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex + */ + const AS_SPAM_ERROR = 232; + + /** + * Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false) + */ + const AS_IMAGE_REDIRECT_ANON = 233; + + /** + * Status: logged in user is not allowed to upload (User::isAllowed('upload') == false) + */ + const AS_IMAGE_REDIRECT_LOGGED = 234; + + /** + * Status: user tried to modify the content model, but is not allowed to do that + * ( User::isAllowed('editcontentmodel') == false ) + */ + const AS_NO_CHANGE_CONTENT_MODEL = 235; + + /** + * Status: user tried to create self-redirect (redirect to the same article) and + * wpIgnoreSelfRedirect == false + */ + const AS_SELF_REDIRECT = 236; + + /** + * Status: an error relating to change tagging. Look at the message key for + * more details + */ + const AS_CHANGE_TAG_ERROR = 237; + + /** + * Status: can't parse content + */ + const AS_PARSE_ERROR = 240; + + /** + * Status: when changing the content model is disallowed due to + * $wgContentHandlerUseDB being false + */ + const AS_CANNOT_USE_CUSTOM_MODEL = 241; + + /** + * Status: edit rejected because browser doesn't support Unicode. + */ + const AS_UNICODE_NOT_SUPPORTED = 242; + + /** + * HTML id and name for the beginning of the edit form. + */ + const EDITFORM_ID = 'editform'; + + /** + * Prefix of key for cookie used to pass post-edit state. + * The revision id edited is added after this + */ + const POST_EDIT_COOKIE_KEY_PREFIX = 'PostEditRevision'; + + /** + * Duration of PostEdit cookie, in seconds. + * The cookie will be removed instantly if the JavaScript runs. + * + * Otherwise, though, we don't want the cookies to accumulate. + * RFC 2109 ( https://www.ietf.org/rfc/rfc2109.txt ) specifies a possible + * limit of only 20 cookies per domain. This still applies at least to some + * versions of IE without full updates: + * https://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx + * + * A value of 20 minutes should be enough to take into account slow loads and minor + * clock skew while still avoiding cookie accumulation when JavaScript is turned off. + */ + const POST_EDIT_COOKIE_DURATION = 1200; + + /** + * @deprecated for public usage since 1.30 use EditPage::getArticle() + * @var Article + */ + public $mArticle; + /** @var WikiPage */ + private $page; + + /** + * @deprecated for public usage since 1.30 use EditPage::getTitle() + * @var Title + */ + public $mTitle; + + /** @var null|Title */ + private $mContextTitle = null; + + /** @var string */ + public $action = 'submit'; + + /** @var bool */ + public $isConflict = false; + + /** + * @deprecated since 1.30 use Title::isCssJsSubpage() + * @var bool + */ + public $isCssJsSubpage = false; + + /** + * @deprecated since 1.30 use Title::isCssSubpage() + * @var bool + */ + public $isCssSubpage = false; + + /** + * @deprecated since 1.30 use Title::isJsSubpage() + * @var bool + */ + public $isJsSubpage = false; + + /** + * @deprecated since 1.30 + * @var bool + */ + public $isWrongCaseCssJsPage = false; + + /** @var bool New page or new section */ + public $isNew = false; + + /** @var bool */ + public $deletedSinceEdit; + + /** @var string */ + public $formtype; + + /** @var bool */ + public $firsttime; + + /** @var bool|stdClass */ + public $lastDelete; + + /** @var bool */ + public $mTokenOk = false; + + /** @var bool */ + public $mTokenOkExceptSuffix = false; + + /** @var bool */ + public $mTriedSave = false; + + /** @var bool */ + public $incompleteForm = false; + + /** @var bool */ + public $tooBig = false; + + /** @var bool */ + public $missingComment = false; + + /** @var bool */ + public $missingSummary = false; + + /** @var bool */ + public $allowBlankSummary = false; + + /** @var bool */ + protected $blankArticle = false; + + /** @var bool */ + protected $allowBlankArticle = false; + + /** @var bool */ + protected $selfRedirect = false; + + /** @var bool */ + protected $allowSelfRedirect = false; + + /** @var string */ + public $autoSumm = ''; + + /** @var string */ + public $hookError = ''; + + /** @var ParserOutput */ + public $mParserOutput; + + /** @var bool Has a summary been preset using GET parameter &summary= ? */ + public $hasPresetSummary = false; + + /** @var Revision|bool */ + public $mBaseRevision = false; + + /** @var bool */ + public $mShowSummaryField = true; # Form values - var $save = false, $preview = false, $diff = false; - var $minoredit = false, $watchthis = false, $recreate = false; - var $textbox1 = '', $textbox2 = '', $summary = ''; - var $edittime = '', $section = '', $starttime = ''; - var $oldid = 0, $editintro = '', $scrolltop = null; + + /** @var bool */ + public $save = false; + + /** @var bool */ + public $preview = false; + + /** @var bool */ + public $diff = false; + + /** @var bool */ + public $minoredit = false; + + /** @var bool */ + public $watchthis = false; + + /** @var bool */ + public $recreate = false; + + /** @var string */ + public $textbox1 = ''; + + /** @var string */ + public $textbox2 = ''; + + /** @var string */ + public $summary = ''; + + /** @var bool */ + public $nosummary = false; + + /** @var string */ + public $edittime = ''; + + /** @var int */ + private $editRevId = null; + + /** @var string */ + public $section = ''; + + /** @var string */ + public $sectiontitle = ''; + + /** @var string */ + public $starttime = ''; + + /** @var int */ + public $oldid = 0; + + /** @var int */ + public $parentRevId = 0; + + /** @var string */ + public $editintro = ''; + + /** @var null */ + public $scrolltop = null; + + /** @var bool */ + public $bot = true; + + /** @var string */ + public $contentModel; + + /** @var null|string */ + public $contentFormat = null; + + /** @var null|array */ + private $changeTags = null; # Placeholders for text injection by hooks (must be HTML) # extensions should take care to _append_ to the present value - public $editFormPageTop; // Before even the preview - public $editFormTextTop; - public $editFormTextBeforeContent; - public $editFormTextAfterWarn; - public $editFormTextAfterTools; - public $editFormTextBottom; - - /* $didSave should be set to true whenever an article was succesfully altered. */ + + /** @var string Before even the preview */ + public $editFormPageTop = ''; + public $editFormTextTop = ''; + public $editFormTextBeforeContent = ''; + public $editFormTextAfterWarn = ''; + public $editFormTextAfterTools = ''; + public $editFormTextBottom = ''; + public $editFormTextAfterContent = ''; + public $previewTextAfterContent = ''; + public $mPreloadContent = null; + + /* $didSave should be set to true whenever an article was successfully altered. */ public $didSave = false; public $undidRev = 0; public $suppressIntro = false; + /** @var bool */ + protected $edit; + + /** @var bool|int */ + protected $contentLength = false; + /** - * @todo document - * @param $article + * @var bool Set in ApiEditPage, based on ContentHandler::allowsDirectApiEditing */ - function EditPage( $article ) { - $this->mArticle =& $article; - $this->mTitle = $article->getTitle(); - $this->action = 'submit'; - - # Placeholders for text injection by hooks (empty per default) - $this->editFormPageTop = - $this->editFormTextTop = - $this->editFormTextBeforeContent = - $this->editFormTextAfterWarn = - $this->editFormTextAfterTools = - $this->editFormTextBottom = ""; - } - - function getArticle() { - return $this->mArticle; - } + private $enableApiEditOverride = false; /** - * Fetch initial editing page content. - * @private + * @var IContextSource */ - function getContent( $def_text = '' ) { - global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache; + protected $context; - wfProfileIn( __METHOD__ ); - # Get variables from query string :P - $section = $wgRequest->getVal( 'section' ); - $preload = $wgRequest->getVal( 'preload' ); - $undoafter = $wgRequest->getVal( 'undoafter' ); - $undo = $wgRequest->getVal( 'undo' ); + /** + * @var bool Whether an old revision is edited + */ + private $isOldRev = false; - $text = ''; - // For message page not locally set, use the i18n message. - // For other non-existent articles, use preload text if any. - if ( !$this->mTitle->exists() ) { - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - # If this is a system message, get the default text. - list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) ); - $wgMessageCache->loadAllMessages( $lang ); - $text = wfMsgGetKey( $message, false, $lang, false ); - if( wfEmptyMsg( $message, $text ) ) - $text = ''; - } else { - # If requested, preload some text. - $text = $this->getPreloadedText( $preload ); - } - // For existing pages, get text based on "undo" or section parameters. - } else { - $text = $this->mArticle->getContent(); - if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) { - # If they got undoafter and undo round the wrong way, switch them - list( $undo, $undoafter ) = array( $undoafter, $undo ); - } - if ( $undo > 0 && $undo > $undoafter ) { - # Undoing a specific edit overrides section editing; section-editing - # doesn't work with undoing. - if ( $undoafter ) { - $undorev = Revision::newFromId($undo); - $oldrev = Revision::newFromId($undoafter); - } else { - $undorev = Revision::newFromId($undo); - $oldrev = $undorev ? $undorev->getPrevious() : null; - } + /** + * @var string|null What the user submitted in the 'wpUnicodeCheck' field + */ + private $unicodeCheck; - # 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() && - !$undorev->isDeleted( Revision::DELETED_TEXT ) && - !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) { - - $undotext = $this->mArticle->getUndoText( $undorev, $oldrev ); - if ( $undotext === false ) { - # Warn the user that something went wrong - $this->editFormPageTop .= $wgOut->parse( '