3 # Splitting edit page/HTML interface from Article...
4 # The actual database and text munging is still in Article,
5 # but it should get easier to call those from alternate
12 function EditPage( $article ) {
13 $this->mArticle
=& $article;
15 $this->mTitle
=& $wgTitle;
18 # This is the function that gets called for "action=edit".
22 global $wgOut, $wgUser, $wgWhitelistEdit;
23 global $wpTextbox1, $wpSummary, $wpSave, $wpPreview;
24 global $wpMinoredit, $wpEdittime, $wpTextbox2;
25 global $wpSection , $wpWatchthis;
26 $wpTextbox1 = $_REQUEST["wpTextbox1"];
27 $wpSummary = $_REQUEST["wpSummary"];
28 $wpSave = $_REQUEST["wpSave"];
29 $wpPreview = $_REQUEST["wpPreview"];
30 $wpMinoredit= $_REQUEST["wpMinoredit"];
31 $wpEdittime = $_REQUEST["wpEdittime"];
32 $wpTextbox2 = $_REQUEST["wpTextbox2"];
33 $wpWatchthis = $_REQUEST["wpWatchthis"];
34 $wpSection = $_REQUEST["wpSection"];
36 $fields = array( "wpTextbox1", "wpSummary", "wpTextbox2" );
37 wfCleanFormFields( $fields );
39 if ( ! $this->mTitle
->userCanEdit() ) {
40 $this->mArticle
->view();
43 if ( $wgUser->isBlocked() ) {
44 $this->blockedIPpage();
47 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
48 $this->userNotLoggedInPage();
52 if( isset( $wpSave ) or isset( $wpPreview ) ) {
53 $this->editForm( "preview" );
55 $wgOut->readOnlyPage( $this->mArticle
->getContent() );
59 if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave );
60 if ( isset( $wpSave ) ) {
61 $this->editForm( "save" );
62 } else if ( isset( $wpPreview ) ) {
63 $this->editForm( "preview" );
64 } else { # First time through
65 $this->editForm( "initial" );
69 # Since there is only one text field on the edit form,
70 # pressing <enter> will cause the form to be submitted, but
71 # the submit button value won't appear in the query, so we
72 # Fake it here before going back to edit(). This is kind of
73 # ugly, but it helps some old URLs to still work.
77 global $wpSave, $wpPreview;
78 if ( ! isset( $wpPreview ) ) { $wpSave = 1; }
83 # The edit form is self-submitting, so that when things like
84 # preview and edit conflicts occur, we get the same form back
85 # with the extra stuff added. Only when the final submission
86 # is made and all is well do we actually save and redirect to
87 # the newly-edited page.
89 function editForm( $formtype )
91 global $wgOut, $wgUser;
92 global $wpTextbox1, $wpSummary, $wpWatchthis;
93 global $wpSave, $wpPreview;
94 global $wpMinoredit, $wpEdittime, $wpTextbox2, $wpSection;
95 global $oldid, $redirect, $section;
98 if(isset($wpSection)) { $section=$wpSection; } else { $wpSection=$section; }
100 $sk = $wgUser->getSkin();
102 $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview
104 if(!$this->mTitle
->getArticleID()) { # new article
106 $wgOut->addWikiText(wfmsg("newarticletext"));
110 # Attempt submission here. This will check for edit conflicts,
111 # and redundantly check for locked database, blocked IPs, etc.
112 # that edit() already checked just in case someone tries to sneak
113 # in the back door with a hand-edited submission URL.
115 if ( "save" == $formtype ) {
116 if ( $wgUser->isBlocked() ) {
117 $this->blockedIPpage();
120 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
121 $this->userNotLoggedInPage();
124 if ( wfReadOnly() ) {
125 $wgOut->readOnlyPage();
128 # If article is new, insert it.
130 $aid = $this->mTitle
->getArticleID();
132 # we need to strip Windoze linebreaks because some browsers
133 # append them and the string comparison fails
134 if ( ( "" == $wpTextbox1 ) ||
135 ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) {
136 $wgOut->redirect( wfLocalUrl(
137 $this->mTitle
->getPrefixedURL() ) );
140 $this->mCountAdjustment
= $this->mArticle
->isCountable( $wpTextbox1 );
141 $this->mArticle
->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
144 # Article exists. Check for edit conflict.
145 # Don't check for conflict when appending a comment - this should always work
147 $this->mArticle
->clear(); # Force reload of dates, etc.
148 if ( $section!="new" && ( $this->mArticle
->getTimestamp() != $wpEdittime ) ) {
151 $u = $wgUser->getID();
153 # Supress edit conflict with self
155 if ( ( 0 != $u ) && ( $this->mArticle
->getUser() == $u ) ) {
158 # switch from section editing to normal editing in edit conflict
160 $section="";$wpSection="";
164 if ( ! $isConflict ) {
165 # All's well: update the article here
166 if($this->mArticle
->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection ))
172 # First time through: get contents, set time for conflict
175 if ( "initial" == $formtype ) {
176 $wpEdittime = $this->mArticle
->getTimestamp();
177 $wpTextbox1 = $this->mArticle
->getContent(true);
180 $wgOut->setRobotpolicy( "noindex,nofollow" );
181 $wgOut->setArticleFlag( false );
184 $s = wfMsg( "editconflict", $this->mTitle
->getPrefixedText() );
185 $wgOut->setPageTitle( $s );
186 $wgOut->addHTML( wfMsg( "explainconflict" ) );
188 $wpTextbox2 = $wpTextbox1;
189 $wpTextbox1 = $this->mArticle
->getContent(true);
190 $wpEdittime = $this->mArticle
->getTimestamp();
192 $s = wfMsg( "editing", $this->mTitle
->getPrefixedText() );
195 if($section=="new") {
196 $s.=wfMsg("commentedit");
198 $s.=wfMsg("sectionedit");
201 $wgOut->setPageTitle( $s );
203 $this->mArticle
->setOldSubtitle();
204 $wgOut->addHTML( wfMsg( "editingold" ) );
209 $wgOut->addHTML( "<strong>" .
210 wfMsg( "readonlywarning" ) .
213 if( $this->mTitle
->isProtected() ) {
214 $wgOut->addHTML( "<strong>" . wfMsg( "protectedpagewarning" ) .
215 "</strong><br />\n" );
218 $kblength = (int)(strlen( $wpTextbox1 ) / 1024);
219 if( $kblength > 29 ) {
220 $wgOut->addHTML( "<strong>" .
221 wfMsg( "longpagewarning", $kblength )
225 $rows = $wgUser->getOption( "rows" );
226 $cols = $wgUser->getOption( "cols" );
228 $ew = $wgUser->getOption( "editwidth" );
229 if ( $ew ) $ew = " style=\"width:100%\"";
232 $q = "action=submit";
233 if ( "no" == $redirect ) { $q .= "&redirect=no"; }
234 $action = wfEscapeHTML( wfLocalUrl( $this->mTitle
->getPrefixedURL(), $q ) );
236 $summary = wfMsg( "summary" );
237 $subject = wfMsg("subject");
238 $minor = wfMsg( "minoredit" );
239 $watchthis = wfMsg ("watchthis");
240 $save = wfMsg( "savearticle" );
241 $prev = wfMsg( "showpreview" );
243 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedURL(),
245 $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ),
246 wfMsg( "edithelp" ) );
247 $copywarn = wfMsg( "copyrightwarning", $sk->makeKnownLink(
248 wfMsg( "copyrightpage" ) ) );
250 $wpTextbox1 = wfEscapeHTML( $wpTextbox1 );
251 $wpTextbox2 = wfEscapeHTML( $wpTextbox2 );
252 $wpSummary = wfEscapeHTML( $wpSummary );
254 // activate checkboxes if user wants them to be always active
255 if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1;
256 if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1;
258 // activate checkbox also if user is already watching the page,
259 // require wpWatchthis to be unset so that second condition is not
260 // checked unnecessarily
261 if (!$wpWatchthis && !$wpPreview && $this->mTitle
->userIsWatching()) $wpWatchthis=1;
263 if ( 0 != $wgUser->getID() ) {
265 "<input tabindex=3 type=checkbox value=1 name='wpMinoredit'".($wpMinoredit?
" checked":"")." id='wpMinoredit'>".
266 "<label for='wpMinoredit'>{$minor}</label>".
267 "<input tabindex=4 type=checkbox name='wpWatchthis'".($wpWatchthis?
" checked":"")." id='wpWatchthis'>".
268 "<label for='wpWatchthis'>{$watchthis}</label><br>";
275 if ( "preview" == $formtype) {
277 $previewhead="<h2>" . wfMsg( "preview" ) . "</h2>\n<p><large><center><font color=\"#cc0000\">" .
278 wfMsg( "note" ) . wfMsg( "previewnote" ) . "</font></center></large><P>\n";
280 $previewhead.="<h2>" . wfMsg( "previewconflict" ) .
283 $previewtext = wfUnescapeHTML( $wpTextbox1 );
285 if($wgUser->getOption("previewontop")) {
286 $wgOut->addHTML($previewhead);
287 $wgOut->addWikiText( $this->mArticle
->preSaveTransform( $previewtext ) ."\n\n");
289 $wgOut->addHTML( "<br clear=\"all\" />\n" );
292 # if this is a comment, show a subject line at the top, which is also the edit summary.
293 # Otherwise, show a summary field at the bottom
294 if($section=="new") {
296 $commentsubject="{$subject}: <input tabindex=1 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
299 $editsummary="{$summary}: <input tabindex=3 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
303 <form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
304 enctype=\"application/x-www-form-urlencoded\">
306 <textarea tabindex=2 name=\"wpTextbox1\" rows={$rows}
307 cols={$cols}{$ew} wrap=\"virtual\">" .
308 $wgLang->recodeForEdit( $wpTextbox1 ) .
313 <input tabindex=5 type=submit value=\"{$save}\" name=\"wpSave\">
314 <input tabindex=6 type=submit value=\"{$prev}\" name=\"wpPreview\">
315 <em>{$cancel}</em> | <em>{$edithelp}</em>
317 <input type=hidden value=\"{$section}\" name=\"wpSection\">
318 <input type=hidden value=\"{$wpEdittime}\" name=\"wpEdittime\">\n" );
321 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
322 DifferenceEngine
::showDiff( $wpTextbox2, $wpTextbox1,
323 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
325 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
326 <textarea tabindex=6 name=\"wpTextbox2\" rows={$rows} cols={$cols} wrap=virtual>"
327 . $wgLang->recodeForEdit( $wpTextbox2 ) .
331 $wgOut->addHTML( "</form>\n" );
332 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
333 $wgOut->addHTML($previewhead);
334 $wgOut->addWikiText( $this->mArticle
->preSaveTransform( $previewtext ) );
339 function blockedIPpage()
341 global $wgOut, $wgUser, $wgLang;
343 $wgOut->setPageTitle( wfMsg( "blockedtitle" ) );
344 $wgOut->setRobotpolicy( "noindex,nofollow" );
345 $wgOut->setArticleFlag( false );
347 $id = $wgUser->blockedBy();
348 $reason = $wgUser->blockedFor();
350 $name = User
::whoIs( $id );
351 $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
352 ":{$name}|{$name}]]";
354 $wgOut->addWikiText( wfMsg( "blockedtext", $link, $reason ) );
355 $wgOut->returnToMain( false );
360 function userNotLoggedInPage()
362 global $wgOut, $wgUser, $wgLang;
364 $wgOut->setPageTitle( wfMsg( "whitelistedittitle" ) );
365 $wgOut->setRobotpolicy( "noindex,nofollow" );
366 $wgOut->setArticleFlag( false );
368 $wgOut->addWikiText( wfMsg( "whitelistedittext" ) );
369 $wgOut->returnToMain( false );