From: Brion Vibber Date: Sat, 2 Aug 2003 20:43:11 +0000 (+0000) Subject: Extract the edit page interface functions out of Article and into separate X-Git-Tag: 1.1.0~364 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=e3bbb66de82c9555c40816b750065106fd9466c6;p=lhc%2Fweb%2Fwiklou.git Extract the edit page interface functions out of Article and into separate EditPage class/file. Trying to streamline these things into managable hunks of source... --- diff --git a/includes/Article.php b/includes/Article.php index 03a0386200..bd625990d1 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2,6 +2,9 @@ # Class representing a Wikipedia article and history. # See design.doc for an overview. +# Note: edit user interface and cache support functions have been +# moved to separate EditPage and CacheManager classes. + class Article { /* private */ var $mContent, $mContentLoaded; /* private */ var $mUser, $mTimestamp, $mUserText; @@ -319,307 +322,6 @@ class Article { wfProfileOut(); } - # This is the function that gets called for "action=edit". - - function edit() - { - global $wgOut, $wgUser, $wgTitle; - global $wpTextbox1, $wpSummary, $wpSave, $wpPreview; - global $wpMinoredit, $wpEdittime, $wpTextbox2; - - $fields = array( "wpTextbox1", "wpSummary", "wpTextbox2" ); - wfCleanFormFields( $fields ); - - if ( ! $wgTitle->userCanEdit() ) { - $this->view(); - return; - } - if ( $wgUser->isBlocked() ) { - $this->blockedIPpage(); - return; - } - if ( wfReadOnly() ) { - if( isset( $wpSave ) or isset( $wpPreview ) ) { - $this->editForm( "preview" ); - } else { - $wgOut->readOnlyPage(); - } - return; - } - if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave ); - if ( isset( $wpSave ) ) { - $this->editForm( "save" ); - } else if ( isset( $wpPreview ) ) { - $this->editForm( "preview" ); - } else { # First time through - $this->editForm( "initial" ); - } - } - - # Since there is only one text field on the edit form, - # pressing will cause the form to be submitted, but - # the submit button value won't appear in the query, so we - # Fake it here before going back to edit(). This is kind of - # ugly, but it helps some old URLs to still work. - - function submit() - { - global $wpSave, $wpPreview; - if ( ! isset( $wpPreview ) ) { $wpSave = 1; } - - $this->edit(); - } - - # The edit form is self-submitting, so that when things like - # preview and edit conflicts occur, we get the same form back - # with the extra stuff added. Only when the final submission - # is made and all is well do we actually save and redirect to - # the newly-edited page. - - function editForm( $formtype ) - { - global $wgOut, $wgUser, $wgTitle; - global $wpTextbox1, $wpSummary, $wpWatchthis; - global $wpSave, $wpPreview; - global $wpMinoredit, $wpEdittime, $wpTextbox2, $wpSection; - global $oldid, $redirect, $section; - global $wgLang; - - if(isset($wpSection)) { $section=$wpSection; } else { $wpSection=$section; } - - $sk = $wgUser->getSkin(); - $isConflict = false; - $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview - - if(!$wgTitle->getArticleID()) { # new article - - $wgOut->addWikiText(wfmsg("newarticletext")); - - } - - # Attempt submission here. This will check for edit conflicts, - # and redundantly check for locked database, blocked IPs, etc. - # that edit() already checked just in case someone tries to sneak - # in the back door with a hand-edited submission URL. - - if ( "save" == $formtype ) { - if ( $wgUser->isBlocked() ) { - $this->blockedIPpage(); - return; - } - if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; - } - # If article is new, insert it. - - $aid = $wgTitle->getArticleID(); - if ( 0 == $aid ) { - # we need to strip Windoze linebreaks because some browsers - # append them and the string comparison fails - if ( ( "" == $wpTextbox1 ) || - ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) { - $wgOut->redirect( wfLocalUrl( - $wgTitle->getPrefixedURL() ) ); - return; - } - $this->mCountAdjustment = $this->isCountable( $wpTextbox1 ); - $this->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis ); - return; - } - # Article exists. Check for edit conflict. - # Don't check for conflict when appending a comment - this should always work - - $this->clear(); # Force reload of dates, etc. - if ( $section!="new" && ( $this->getTimestamp() != $wpEdittime ) ) { - $isConflict = true; - } - $u = $wgUser->getID(); - - # Supress edit conflict with self - - if ( ( 0 != $u ) && ( $this->getUser() == $u ) ) { - $isConflict = false; - } else { - # switch from section editing to normal editing in edit conflict - if($isConflict) { - $section="";$wpSection=""; - } - - } - if ( ! $isConflict ) { - # All's well: update the article here - $this->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection ); - return; - } - } - # First time through: get contents, set time for conflict - # checking, etc. - - if ( "initial" == $formtype ) { - $wpEdittime = $this->getTimestamp(); - $wpTextbox1 = $this->getContent(true); - $wpSummary = ""; - } - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleFlag( false ); - - if ( $isConflict ) { - $s = str_replace( "$1", $wgTitle->getPrefixedText(), - wfMsg( "editconflict" ) ); - $wgOut->setPageTitle( $s ); - $wgOut->addHTML( wfMsg( "explainconflict" ) ); - - $wpTextbox2 = $wpTextbox1; - $wpTextbox1 = $this->getContent(true); - $wpEdittime = $this->getTimestamp(); - } else { - $s = str_replace( "$1", $wgTitle->getPrefixedText(), - wfMsg( "editing" ) ); - - if($section!="") { - if($section=="new") { - $s.=wfMsg("commentedit"); - } else { - $s.=wfMsg("sectionedit"); - } - } - $wgOut->setPageTitle( $s ); - if ( $oldid ) { - $this->setOldSubtitle(); - $wgOut->addHTML( wfMsg( "editingold" ) ); - } - } - - if( wfReadOnly() ) { - $wgOut->addHTML( "" . - wfMsg( "readonlywarning" ) . - "" ); - } - if( $wgTitle->isProtected() ) { - $wgOut->addHTML( "" . wfMsg( "protectedpagewarning" ) . - "
\n" ); - } - - $kblength = (int)(strlen( $wpTextbox1 ) / 1024); - if( $kblength > 29 ) { - $wgOut->addHTML( "" . - str_replace( '$1', $kblength , wfMsg( "longpagewarning" ) ) - . "" ); - } - - $rows = $wgUser->getOption( "rows" ); - $cols = $wgUser->getOption( "cols" ); - - $ew = $wgUser->getOption( "editwidth" ); - if ( $ew ) $ew = " style=\"width:100%\""; - else $ew = "" ; - - $q = "action=submit"; - if ( "no" == $redirect ) { $q .= "&redirect=no"; } - $action = wfEscapeHTML( wfLocalUrl( $wgTitle->getPrefixedURL(), $q ) ); - - $summary = wfMsg( "summary" ); - $subject = wfMsg("subject"); - $minor = wfMsg( "minoredit" ); - $watchthis = wfMsg ("watchthis"); - $save = wfMsg( "savearticle" ); - $prev = wfMsg( "showpreview" ); - - $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedURL(), - wfMsg( "cancel" ) ); - $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ), - wfMsg( "edithelp" ) ); - $copywarn = str_replace( "$1", $sk->makeKnownLink( - wfMsg( "copyrightpage" ) ), wfMsg( "copyrightwarning" ) ); - - $wpTextbox1 = wfEscapeHTML( $wpTextbox1 ); - $wpTextbox2 = wfEscapeHTML( $wpTextbox2 ); - $wpSummary = wfEscapeHTML( $wpSummary ); - - // activate checkboxes if user wants them to be always active - if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1; - if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1; - - // activate checkbox also if user is already watching the page, - // require wpWatchthis to be unset so that second condition is not - // checked unnecessarily - if (!$wpWatchthis && !$wpPreview && $wgTitle->userIsWatching()) $wpWatchthis=1; - - if ( 0 != $wgUser->getID() ) { - $checkboxhtml= - "{$minor}". - "{$watchthis}
"; - - } else { - $checkboxhtml=""; - } - - - if ( "preview" == $formtype) { - - $previewhead="

" . wfMsg( "preview" ) . "

\n

" . - wfMsg( "note" ) . wfMsg( "previewnote" ) . "

\n"; - if ( $isConflict ) { - $previewhead.="

" . wfMsg( "previewconflict" ) . - "

\n"; - } - $previewtext = wfUnescapeHTML( $wpTextbox1 ); - - if($wgUser->getOption("previewontop")) { - $wgOut->addHTML($previewhead); - $wgOut->addWikiText( $this->preSaveTransform( $previewtext ) ."\n\n"); - } - $wgOut->addHTML( "
\n" ); - } - - # if this is a comment, show a subject line at the top, which is also the edit summary. - # Otherwise, show a summary field at the bottom - if($section=="new") { - - $commentsubject="{$subject}:
"; - } else { - - $editsummary="{$summary}:
"; - } - - $wgOut->addHTML( " -
-{$commentsubject} - -
{$editsummary} -{$checkboxhtml} - - -{$cancel} | {$edithelp} -

{$copywarn} - -\n" ); - - if ( $isConflict ) { - $wgOut->addHTML( "

" . wfMsg( "yourdiff" ) . "

\n" ); - DifferenceEngine::showDiff( $wpTextbox2, $wpTextbox1, - wfMsg( "yourtext" ), wfMsg( "storedversion" ) ); - - $wgOut->addHTML( "

" . wfMsg( "yourtext" ) . "

-" ); - } - $wgOut->addHTML( "
\n" ); - if($formtype =="preview" && !$wgUser->getOption("previewontop")) { - $wgOut->addHTML($previewhead); - $wgOut->addWikiText( $this->preSaveTransform( $previewtext ) ); - } - - } - # Theoretically we could defer these whole insert and update # functions for after display, but that's taking a big leap # of faith, and we want to be able to report database @@ -1518,27 +1220,6 @@ $wgLang->recodeForEdit( $wpTextbox1 ) . $wgOut->setSubtitle( "({$r})" ); } - function blockedIPpage() - { - global $wgOut, $wgUser, $wgLang; - - $wgOut->setPageTitle( wfMsg( "blockedtitle" ) ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleFlag( false ); - - $id = $wgUser->blockedBy(); - $reason = $wgUser->blockedFor(); - - $name = User::whoIs( $id ); - $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) . - ":{$name}|{$name}]]"; - - $text = str_replace( "$1", $link, wfMsg( "blockedtext" ) ); - $text = str_replace( "$2", $reason, $text ); - $wgOut->addWikiText( $text ); - $wgOut->returnToMain( false ); - } - # This function is called right before saving the wikitext, # so we can do things like signatures and links-in-context. diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 225cacef0e..f5701e4e0b 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -1,5 +1,16 @@ mArticle =& $article; + global $wgTitle; + $this->mTitle =& $wgTitle; + } + + # This is the function that gets called for "action=edit". + + function edit() + { + global $wgOut, $wgUser; + global $wpTextbox1, $wpSummary, $wpSave, $wpPreview; + global $wpMinoredit, $wpEdittime, $wpTextbox2; + + $fields = array( "wpTextbox1", "wpSummary", "wpTextbox2" ); + wfCleanFormFields( $fields ); + + if ( ! $this->mTitle->userCanEdit() ) { + $this->mArticle->view(); + return; + } + if ( $wgUser->isBlocked() ) { + $this->blockedIPpage(); + return; + } + if ( wfReadOnly() ) { + if( isset( $wpSave ) or isset( $wpPreview ) ) { + $this->editForm( "preview" ); + } else { + $wgOut->readOnlyPage(); + } + return; + } + if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave ); + if ( isset( $wpSave ) ) { + $this->editForm( "save" ); + } else if ( isset( $wpPreview ) ) { + $this->editForm( "preview" ); + } else { # First time through + $this->editForm( "initial" ); + } + } + + # Since there is only one text field on the edit form, + # pressing will cause the form to be submitted, but + # the submit button value won't appear in the query, so we + # Fake it here before going back to edit(). This is kind of + # ugly, but it helps some old URLs to still work. + + function submit() + { + global $wpSave, $wpPreview; + if ( ! isset( $wpPreview ) ) { $wpSave = 1; } + + $this->edit(); + } + + # The edit form is self-submitting, so that when things like + # preview and edit conflicts occur, we get the same form back + # with the extra stuff added. Only when the final submission + # is made and all is well do we actually save and redirect to + # the newly-edited page. + + function editForm( $formtype ) + { + global $wgOut, $wgUser; + global $wpTextbox1, $wpSummary, $wpWatchthis; + global $wpSave, $wpPreview; + global $wpMinoredit, $wpEdittime, $wpTextbox2, $wpSection; + global $oldid, $redirect, $section; + global $wgLang; + + if(isset($wpSection)) { $section=$wpSection; } else { $wpSection=$section; } + + $sk = $wgUser->getSkin(); + $isConflict = false; + $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview + + if(!$this->mTitle->getArticleID()) { # new article + + $wgOut->addWikiText(wfmsg("newarticletext")); + + } + + # Attempt submission here. This will check for edit conflicts, + # and redundantly check for locked database, blocked IPs, etc. + # that edit() already checked just in case someone tries to sneak + # in the back door with a hand-edited submission URL. + + if ( "save" == $formtype ) { + if ( $wgUser->isBlocked() ) { + $this->blockedIPpage(); + return; + } + if ( wfReadOnly() ) { + $wgOut->readOnlyPage(); + return; + } + # If article is new, insert it. + + $aid = $this->mTitle->getArticleID(); + if ( 0 == $aid ) { + # we need to strip Windoze linebreaks because some browsers + # append them and the string comparison fails + if ( ( "" == $wpTextbox1 ) || + ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) { + $wgOut->redirect( wfLocalUrl( + $this->mTitle->getPrefixedURL() ) ); + return; + } + $this->mCountAdjustment = $this->mArticle->isCountable( $wpTextbox1 ); + $this->mArticle->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis ); + return; + } + # Article exists. Check for edit conflict. + # Don't check for conflict when appending a comment - this should always work + + $this->mArticle->clear(); # Force reload of dates, etc. + if ( $section!="new" && ( $this->mArticle->getTimestamp() != $wpEdittime ) ) { + $isConflict = true; + } + $u = $wgUser->getID(); + + # Supress edit conflict with self + + if ( ( 0 != $u ) && ( $this->mArticle->getUser() == $u ) ) { + $isConflict = false; + } else { + # switch from section editing to normal editing in edit conflict + if($isConflict) { + $section="";$wpSection=""; + } + + } + if ( ! $isConflict ) { + # All's well: update the article here + $this->mArticle->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection ); + return; + } + } + # First time through: get contents, set time for conflict + # checking, etc. + + if ( "initial" == $formtype ) { + $wpEdittime = $this->mArticle->getTimestamp(); + $wpTextbox1 = $this->mArticle->getContent(true); + $wpSummary = ""; + } + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleFlag( false ); + + if ( $isConflict ) { + $s = str_replace( "$1", $this->mTitle->getPrefixedText(), + wfMsg( "editconflict" ) ); + $wgOut->setPageTitle( $s ); + $wgOut->addHTML( wfMsg( "explainconflict" ) ); + + $wpTextbox2 = $wpTextbox1; + $wpTextbox1 = $this->mArticle->getContent(true); + $wpEdittime = $this->mArticle->getTimestamp(); + } else { + $s = str_replace( "$1", $this->mTitle->getPrefixedText(), + wfMsg( "editing" ) ); + + if($section!="") { + if($section=="new") { + $s.=wfMsg("commentedit"); + } else { + $s.=wfMsg("sectionedit"); + } + } + $wgOut->setPageTitle( $s ); + if ( $oldid ) { + $this->mArticle->setOldSubtitle(); + $wgOut->addHTML( wfMsg( "editingold" ) ); + } + } + + if( wfReadOnly() ) { + $wgOut->addHTML( "" . + wfMsg( "readonlywarning" ) . + "" ); + } + if( $this->mTitle->isProtected() ) { + $wgOut->addHTML( "" . wfMsg( "protectedpagewarning" ) . + "
\n" ); + } + + $kblength = (int)(strlen( $wpTextbox1 ) / 1024); + if( $kblength > 29 ) { + $wgOut->addHTML( "" . + str_replace( '$1', $kblength , wfMsg( "longpagewarning" ) ) + . "" ); + } + + $rows = $wgUser->getOption( "rows" ); + $cols = $wgUser->getOption( "cols" ); + + $ew = $wgUser->getOption( "editwidth" ); + if ( $ew ) $ew = " style=\"width:100%\""; + else $ew = "" ; + + $q = "action=submit"; + if ( "no" == $redirect ) { $q .= "&redirect=no"; } + $action = wfEscapeHTML( wfLocalUrl( $this->mTitle->getPrefixedURL(), $q ) ); + + $summary = wfMsg( "summary" ); + $subject = wfMsg("subject"); + $minor = wfMsg( "minoredit" ); + $watchthis = wfMsg ("watchthis"); + $save = wfMsg( "savearticle" ); + $prev = wfMsg( "showpreview" ); + + $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedURL(), + wfMsg( "cancel" ) ); + $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ), + wfMsg( "edithelp" ) ); + $copywarn = str_replace( "$1", $sk->makeKnownLink( + wfMsg( "copyrightpage" ) ), wfMsg( "copyrightwarning" ) ); + + $wpTextbox1 = wfEscapeHTML( $wpTextbox1 ); + $wpTextbox2 = wfEscapeHTML( $wpTextbox2 ); + $wpSummary = wfEscapeHTML( $wpSummary ); + + // activate checkboxes if user wants them to be always active + if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1; + if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1; + + // activate checkbox also if user is already watching the page, + // require wpWatchthis to be unset so that second condition is not + // checked unnecessarily + if (!$wpWatchthis && !$wpPreview && $this->mTitle->userIsWatching()) $wpWatchthis=1; + + if ( 0 != $wgUser->getID() ) { + $checkboxhtml= + "{$minor}". + "{$watchthis}
"; + + } else { + $checkboxhtml=""; + } + + + if ( "preview" == $formtype) { + + $previewhead="

" . wfMsg( "preview" ) . "

\n

" . + wfMsg( "note" ) . wfMsg( "previewnote" ) . "

\n"; + if ( $isConflict ) { + $previewhead.="

" . wfMsg( "previewconflict" ) . + "

\n"; + } + $previewtext = wfUnescapeHTML( $wpTextbox1 ); + + if($wgUser->getOption("previewontop")) { + $wgOut->addHTML($previewhead); + $wgOut->addWikiText( $this->mArticle->preSaveTransform( $previewtext ) ."\n\n"); + } + $wgOut->addHTML( "
\n" ); + } + + # if this is a comment, show a subject line at the top, which is also the edit summary. + # Otherwise, show a summary field at the bottom + if($section=="new") { + + $commentsubject="{$subject}:
"; + } else { + + $editsummary="{$summary}:
"; + } + + $wgOut->addHTML( " +
+{$commentsubject} + +
{$editsummary} +{$checkboxhtml} + + +{$cancel} | {$edithelp} +

{$copywarn} + +\n" ); + + if ( $isConflict ) { + $wgOut->addHTML( "

" . wfMsg( "yourdiff" ) . "

\n" ); + DifferenceEngine::showDiff( $wpTextbox2, $wpTextbox1, + wfMsg( "yourtext" ), wfMsg( "storedversion" ) ); + + $wgOut->addHTML( "

" . wfMsg( "yourtext" ) . "

+" ); + } + $wgOut->addHTML( "
\n" ); + if($formtype =="preview" && !$wgUser->getOption("previewontop")) { + $wgOut->addHTML($previewhead); + $wgOut->addWikiText( $this->mArticle->preSaveTransform( $previewtext ) ); + } + + } + + function blockedIPpage() + { + global $wgOut, $wgUser, $wgLang; + + $wgOut->setPageTitle( wfMsg( "blockedtitle" ) ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleFlag( false ); + + $id = $wgUser->blockedBy(); + $reason = $wgUser->blockedFor(); + + $name = User::whoIs( $id ); + $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) . + ":{$name}|{$name}]]"; + + $text = str_replace( "$1", $link, wfMsg( "blockedtext" ) ); + $text = str_replace( "$2", $reason, $text ); + $wgOut->addWikiText( $text ); + $wgOut->returnToMain( false ); + } + + +} + +?> diff --git a/wiki.phtml b/wiki.phtml index 31d4537581..98895a2c16 100644 --- a/wiki.phtml +++ b/wiki.phtml @@ -53,19 +53,30 @@ if ( -1 == $wgTitle->getNamespace() ) { } else { $wgArticle = new Article(); - if ( "view" == $action ) { $wgArticle->view(); } - else if ( "edit" == $action ) { $wgArticle->edit(); } - else if ( "submit" == $action ) { $wgArticle->submit(); } - else if ( "print" == $action ) { $wgArticle->view(); } - else if ( "watch" == $action ) { $wgArticle->watch(); } - else if ( "unwatch" == $action ) { $wgArticle->unwatch(); } - else if ( "history" == $action ) { $wgArticle->history(); } - else if ( "delete" == $action ) { $wgArticle->delete(); } - else if ( "revert" == $action ) { $wgArticle->revert(); } - else if ( "rollback" == $action ) { $wgArticle->rollback(); } - else if ( "protect" == $action ) { $wgArticle->protect(); } - else if ( "unprotect" == $action ) { $wgArticle->unprotect(); } - else { $wgOut->errorpage( "nosuchaction", "nosuchactiontext" ); } + switch( $action ) { + case "view": + case "watch": + case "unwatch": + case "history": + case "delete": + case "revert": + case "rollback": + case "protect": + case "unprotect": + $wgArticle->$action(); + break; + case "print": + $wgArticle->view(); + break; + case "edit": + case "submit": + include_once( "$IP/EditPage.php" ); + $editor = new EditPage( $wgArticle ); + $editor->$action(); + break; + default: + $wgOut->errorpage( "nosuchaction", "nosuchactiontext" ); + } } $wgOut->output();