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;
26 $fields = array( "wpTextbox1", "wpSummary", "wpTextbox2" );
27 wfCleanFormFields( $fields );
29 if ( ! $this->mTitle
->userCanEdit() ) {
30 $this->mArticle
->view();
33 if ( $wgUser->isBlocked() ) {
34 $this->blockedIPpage();
37 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
38 $this->userNotLoggedInPage();
42 if( isset( $wpSave ) or isset( $wpPreview ) ) {
43 $this->editForm( "preview" );
45 $wgOut->readOnlyPage();
49 if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave );
50 if ( isset( $wpSave ) ) {
51 $this->editForm( "save" );
52 } else if ( isset( $wpPreview ) ) {
53 $this->editForm( "preview" );
54 } else { # First time through
55 $this->editForm( "initial" );
59 # Since there is only one text field on the edit form,
60 # pressing <enter> will cause the form to be submitted, but
61 # the submit button value won't appear in the query, so we
62 # Fake it here before going back to edit(). This is kind of
63 # ugly, but it helps some old URLs to still work.
67 global $wpSave, $wpPreview;
68 if ( ! isset( $wpPreview ) ) { $wpSave = 1; }
73 # The edit form is self-submitting, so that when things like
74 # preview and edit conflicts occur, we get the same form back
75 # with the extra stuff added. Only when the final submission
76 # is made and all is well do we actually save and redirect to
77 # the newly-edited page.
79 function editForm( $formtype )
81 global $wgOut, $wgUser;
82 global $wpTextbox1, $wpSummary, $wpWatchthis;
83 global $wpSave, $wpPreview;
84 global $wpMinoredit, $wpEdittime, $wpTextbox2, $wpSection;
85 global $oldid, $redirect, $section;
88 if(isset($wpSection)) { $section=$wpSection; } else { $wpSection=$section; }
90 $sk = $wgUser->getSkin();
92 $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview
94 if(!$this->mTitle
->getArticleID()) { # new article
96 $wgOut->addWikiText(wfmsg("newarticletext"));
100 # Attempt submission here. This will check for edit conflicts,
101 # and redundantly check for locked database, blocked IPs, etc.
102 # that edit() already checked just in case someone tries to sneak
103 # in the back door with a hand-edited submission URL.
105 if ( "save" == $formtype ) {
106 if ( $wgUser->isBlocked() ) {
107 $this->blockedIPpage();
110 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
111 $this->userNotLoggedInPage();
114 if ( wfReadOnly() ) {
115 $wgOut->readOnlyPage();
118 # If article is new, insert it.
120 $aid = $this->mTitle
->getArticleID();
122 # we need to strip Windoze linebreaks because some browsers
123 # append them and the string comparison fails
124 if ( ( "" == $wpTextbox1 ) ||
125 ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) {
126 $wgOut->redirect( wfLocalUrl(
127 $this->mTitle
->getPrefixedURL() ) );
130 $this->mCountAdjustment
= $this->mArticle
->isCountable( $wpTextbox1 );
131 $this->mArticle
->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
134 # Article exists. Check for edit conflict.
135 # Don't check for conflict when appending a comment - this should always work
137 $this->mArticle
->clear(); # Force reload of dates, etc.
138 if ( $section!="new" && ( $this->mArticle
->getTimestamp() != $wpEdittime ) ) {
141 $u = $wgUser->getID();
143 # Supress edit conflict with self
145 if ( ( 0 != $u ) && ( $this->mArticle
->getUser() == $u ) ) {
148 # switch from section editing to normal editing in edit conflict
150 $section="";$wpSection="";
154 if ( ! $isConflict ) {
155 # All's well: update the article here
156 $this->mArticle
->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection );
160 # First time through: get contents, set time for conflict
163 if ( "initial" == $formtype ) {
164 $wpEdittime = $this->mArticle
->getTimestamp();
165 $wpTextbox1 = $this->mArticle
->getContent(true);
168 $wgOut->setRobotpolicy( "noindex,nofollow" );
169 $wgOut->setArticleFlag( false );
172 $s = str_replace( "$1", $this->mTitle
->getPrefixedText(),
173 wfMsg( "editconflict" ) );
174 $wgOut->setPageTitle( $s );
175 $wgOut->addHTML( wfMsg( "explainconflict" ) );
177 $wpTextbox2 = $wpTextbox1;
178 $wpTextbox1 = $this->mArticle
->getContent(true);
179 $wpEdittime = $this->mArticle
->getTimestamp();
181 $s = str_replace( "$1", $this->mTitle
->getPrefixedText(),
182 wfMsg( "editing" ) );
185 if($section=="new") {
186 $s.=wfMsg("commentedit");
188 $s.=wfMsg("sectionedit");
191 $wgOut->setPageTitle( $s );
193 $this->mArticle
->setOldSubtitle();
194 $wgOut->addHTML( wfMsg( "editingold" ) );
199 $wgOut->addHTML( "<strong>" .
200 wfMsg( "readonlywarning" ) .
203 if( $this->mTitle
->isProtected() ) {
204 $wgOut->addHTML( "<strong>" . wfMsg( "protectedpagewarning" ) .
205 "</strong><br />\n" );
208 $kblength = (int)(strlen( $wpTextbox1 ) / 1024);
209 if( $kblength > 29 ) {
210 $wgOut->addHTML( "<strong>" .
211 str_replace( '$1', $kblength , wfMsg( "longpagewarning" ) )
215 $rows = $wgUser->getOption( "rows" );
216 $cols = $wgUser->getOption( "cols" );
218 $ew = $wgUser->getOption( "editwidth" );
219 if ( $ew ) $ew = " style=\"width:100%\"";
222 $q = "action=submit";
223 if ( "no" == $redirect ) { $q .= "&redirect=no"; }
224 $action = wfEscapeHTML( wfLocalUrl( $this->mTitle
->getPrefixedURL(), $q ) );
226 $summary = wfMsg( "summary" );
227 $subject = wfMsg("subject");
228 $minor = wfMsg( "minoredit" );
229 $watchthis = wfMsg ("watchthis");
230 $save = wfMsg( "savearticle" );
231 $prev = wfMsg( "showpreview" );
233 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedURL(),
235 $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ),
236 wfMsg( "edithelp" ) );
237 $copywarn = str_replace( "$1", $sk->makeKnownLink(
238 wfMsg( "copyrightpage" ) ), wfMsg( "copyrightwarning" ) );
240 $wpTextbox1 = wfEscapeHTML( $wpTextbox1 );
241 $wpTextbox2 = wfEscapeHTML( $wpTextbox2 );
242 $wpSummary = wfEscapeHTML( $wpSummary );
244 // activate checkboxes if user wants them to be always active
245 if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1;
246 if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1;
248 // activate checkbox also if user is already watching the page,
249 // require wpWatchthis to be unset so that second condition is not
250 // checked unnecessarily
251 if (!$wpWatchthis && !$wpPreview && $this->mTitle
->userIsWatching()) $wpWatchthis=1;
253 if ( 0 != $wgUser->getID() ) {
255 "<input tabindex=3 type=checkbox value=1 name='wpMinoredit'".($wpMinoredit?
" checked":"").">{$minor}".
256 "<input tabindex=4 type=checkbox name='wpWatchthis'".($wpWatchthis?
" checked":"").">{$watchthis}<br>";
263 if ( "preview" == $formtype) {
265 $previewhead="<h2>" . wfMsg( "preview" ) . "</h2>\n<p><large><center><font color=\"#cc0000\">" .
266 wfMsg( "note" ) . wfMsg( "previewnote" ) . "</font></center></large><P>\n";
268 $previewhead.="<h2>" . wfMsg( "previewconflict" ) .
271 $previewtext = wfUnescapeHTML( $wpTextbox1 );
273 if($wgUser->getOption("previewontop")) {
274 $wgOut->addHTML($previewhead);
275 $wgOut->addWikiText( $this->mArticle
->preSaveTransform( $previewtext ) ."\n\n");
277 $wgOut->addHTML( "<br clear=\"all\" />\n" );
280 # if this is a comment, show a subject line at the top, which is also the edit summary.
281 # Otherwise, show a summary field at the bottom
282 if($section=="new") {
284 $commentsubject="{$subject}: <input tabindex=1 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
287 $editsummary="{$summary}: <input tabindex=3 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
291 <form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
292 enctype=\"application/x-www-form-urlencoded\">
294 <textarea tabindex=2 name=\"wpTextbox1\" rows={$rows}
295 cols={$cols}{$ew} wrap=\"virtual\">" .
296 $wgLang->recodeForEdit( $wpTextbox1 ) .
301 <input tabindex=5 type=submit value=\"{$save}\" name=\"wpSave\">
302 <input tabindex=6 type=submit value=\"{$prev}\" name=\"wpPreview\">
303 <em>{$cancel}</em> | <em>{$edithelp}</em>
305 <input type=hidden value=\"{$section}\" name=\"wpSection\">
306 <input type=hidden value=\"{$wpEdittime}\" name=\"wpEdittime\">\n" );
309 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
310 DifferenceEngine
::showDiff( $wpTextbox2, $wpTextbox1,
311 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
313 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
314 <textarea tabindex=6 name=\"wpTextbox2\" rows={$rows} cols={$cols} wrap=virtual>"
315 . $wgLang->recodeForEdit( $wpTextbox2 ) .
319 $wgOut->addHTML( "</form>\n" );
320 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
321 $wgOut->addHTML($previewhead);
322 $wgOut->addWikiText( $this->mArticle
->preSaveTransform( $previewtext ) );
327 function blockedIPpage()
329 global $wgOut, $wgUser, $wgLang;
331 $wgOut->setPageTitle( wfMsg( "blockedtitle" ) );
332 $wgOut->setRobotpolicy( "noindex,nofollow" );
333 $wgOut->setArticleFlag( false );
335 $id = $wgUser->blockedBy();
336 $reason = $wgUser->blockedFor();
338 $name = User
::whoIs( $id );
339 $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
340 ":{$name}|{$name}]]";
342 $text = str_replace( "$1", $link, wfMsg( "blockedtext" ) );
343 $text = str_replace( "$2", $reason, $text );
344 $wgOut->addWikiText( $text );
345 $wgOut->returnToMain( false );
350 function userNotLoggedInPage()
352 global $wgOut, $wgUser, $wgLang;
354 $wgOut->setPageTitle( wfMsg( "whitelistedittitle" ) );
355 $wgOut->setRobotpolicy( "noindex,nofollow" );
356 $wgOut->setArticleFlag( false );
358 $wgOut->addWikiText( wfMsg( "whitelistedittext" ) );
359 $wgOut->returnToMain( false );