d2ee7d82a3fe63f13e497bef263f23bcead5932d
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;
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();
38 if( isset( $wpSave ) or isset( $wpPreview ) ) {
39 $this->editForm( "preview" );
41 $wgOut->readOnlyPage();
45 if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave );
46 if ( isset( $wpSave ) ) {
47 $this->editForm( "save" );
48 } else if ( isset( $wpPreview ) ) {
49 $this->editForm( "preview" );
50 } else { # First time through
51 $this->editForm( "initial" );
55 # Since there is only one text field on the edit form,
56 # pressing <enter> will cause the form to be submitted, but
57 # the submit button value won't appear in the query, so we
58 # Fake it here before going back to edit(). This is kind of
59 # ugly, but it helps some old URLs to still work.
63 global $wpSave, $wpPreview;
64 if ( ! isset( $wpPreview ) ) { $wpSave = 1; }
69 # The edit form is self-submitting, so that when things like
70 # preview and edit conflicts occur, we get the same form back
71 # with the extra stuff added. Only when the final submission
72 # is made and all is well do we actually save and redirect to
73 # the newly-edited page.
75 function editForm( $formtype )
77 global $wgOut, $wgUser;
78 global $wpTextbox1, $wpSummary, $wpWatchthis;
79 global $wpSave, $wpPreview;
80 global $wpMinoredit, $wpEdittime, $wpTextbox2, $wpSection;
81 global $oldid, $redirect, $section;
84 if(isset($wpSection)) { $section=$wpSection; } else { $wpSection=$section; }
86 $sk = $wgUser->getSkin();
88 $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview
90 if(!$this->mTitle
->getArticleID()) { # new article
92 $wgOut->addWikiText(wfmsg("newarticletext"));
96 # Attempt submission here. This will check for edit conflicts,
97 # and redundantly check for locked database, blocked IPs, etc.
98 # that edit() already checked just in case someone tries to sneak
99 # in the back door with a hand-edited submission URL.
101 if ( "save" == $formtype ) {
102 if ( $wgUser->isBlocked() ) {
103 $this->blockedIPpage();
106 if ( wfReadOnly() ) {
107 $wgOut->readOnlyPage();
110 # If article is new, insert it.
112 $aid = $this->mTitle
->getArticleID();
114 # we need to strip Windoze linebreaks because some browsers
115 # append them and the string comparison fails
116 if ( ( "" == $wpTextbox1 ) ||
117 ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) {
118 $wgOut->redirect( wfLocalUrl(
119 $this->mTitle
->getPrefixedURL() ) );
122 $this->mCountAdjustment
= $this->mArticle
->isCountable( $wpTextbox1 );
123 $this->mArticle
->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
126 # Article exists. Check for edit conflict.
127 # Don't check for conflict when appending a comment - this should always work
129 $this->mArticle
->clear(); # Force reload of dates, etc.
130 if ( $section!="new" && ( $this->mArticle
->getTimestamp() != $wpEdittime ) ) {
133 $u = $wgUser->getID();
135 # Supress edit conflict with self
137 if ( ( 0 != $u ) && ( $this->mArticle
->getUser() == $u ) ) {
140 # switch from section editing to normal editing in edit conflict
142 $section="";$wpSection="";
146 if ( ! $isConflict ) {
147 # All's well: update the article here
148 $this->mArticle
->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection );
152 # First time through: get contents, set time for conflict
155 if ( "initial" == $formtype ) {
156 $wpEdittime = $this->mArticle
->getTimestamp();
157 $wpTextbox1 = $this->mArticle
->getContent(true);
160 $wgOut->setRobotpolicy( "noindex,nofollow" );
161 $wgOut->setArticleFlag( false );
164 $s = str_replace( "$1", $this->mTitle
->getPrefixedText(),
165 wfMsg( "editconflict" ) );
166 $wgOut->setPageTitle( $s );
167 $wgOut->addHTML( wfMsg( "explainconflict" ) );
169 $wpTextbox2 = $wpTextbox1;
170 $wpTextbox1 = $this->mArticle
->getContent(true);
171 $wpEdittime = $this->mArticle
->getTimestamp();
173 $s = str_replace( "$1", $this->mTitle
->getPrefixedText(),
174 wfMsg( "editing" ) );
177 if($section=="new") {
178 $s.=wfMsg("commentedit");
180 $s.=wfMsg("sectionedit");
183 $wgOut->setPageTitle( $s );
185 $this->mArticle
->setOldSubtitle();
186 $wgOut->addHTML( wfMsg( "editingold" ) );
191 $wgOut->addHTML( "<strong>" .
192 wfMsg( "readonlywarning" ) .
195 if( $this->mTitle
->isProtected() ) {
196 $wgOut->addHTML( "<strong>" . wfMsg( "protectedpagewarning" ) .
197 "</strong><br />\n" );
200 $kblength = (int)(strlen( $wpTextbox1 ) / 1024);
201 if( $kblength > 29 ) {
202 $wgOut->addHTML( "<strong>" .
203 str_replace( '$1', $kblength , wfMsg( "longpagewarning" ) )
207 $rows = $wgUser->getOption( "rows" );
208 $cols = $wgUser->getOption( "cols" );
210 $ew = $wgUser->getOption( "editwidth" );
211 if ( $ew ) $ew = " style=\"width:100%\"";
214 $q = "action=submit";
215 if ( "no" == $redirect ) { $q .= "&redirect=no"; }
216 $action = wfEscapeHTML( wfLocalUrl( $this->mTitle
->getPrefixedURL(), $q ) );
218 $summary = wfMsg( "summary" );
219 $subject = wfMsg("subject");
220 $minor = wfMsg( "minoredit" );
221 $watchthis = wfMsg ("watchthis");
222 $save = wfMsg( "savearticle" );
223 $prev = wfMsg( "showpreview" );
225 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedURL(),
227 $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ),
228 wfMsg( "edithelp" ) );
229 $copywarn = str_replace( "$1", $sk->makeKnownLink(
230 wfMsg( "copyrightpage" ) ), wfMsg( "copyrightwarning" ) );
232 $wpTextbox1 = wfEscapeHTML( $wpTextbox1 );
233 $wpTextbox2 = wfEscapeHTML( $wpTextbox2 );
234 $wpSummary = wfEscapeHTML( $wpSummary );
236 // activate checkboxes if user wants them to be always active
237 if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1;
238 if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1;
240 // activate checkbox also if user is already watching the page,
241 // require wpWatchthis to be unset so that second condition is not
242 // checked unnecessarily
243 if (!$wpWatchthis && !$wpPreview && $this->mTitle
->userIsWatching()) $wpWatchthis=1;
245 if ( 0 != $wgUser->getID() ) {
247 "<input tabindex=3 type=checkbox value=1 name='wpMinoredit'".($wpMinoredit?
" checked":"").">{$minor}".
248 "<input tabindex=4 type=checkbox name='wpWatchthis'".($wpWatchthis?
" checked":"").">{$watchthis}<br>";
255 if ( "preview" == $formtype) {
257 $previewhead="<h2>" . wfMsg( "preview" ) . "</h2>\n<p><large><center><font color=\"#cc0000\">" .
258 wfMsg( "note" ) . wfMsg( "previewnote" ) . "</font></center></large><P>\n";
260 $previewhead.="<h2>" . wfMsg( "previewconflict" ) .
263 $previewtext = wfUnescapeHTML( $wpTextbox1 );
265 if($wgUser->getOption("previewontop")) {
266 $wgOut->addHTML($previewhead);
267 $wgOut->addWikiText( $this->mArticle
->preSaveTransform( $previewtext ) ."\n\n");
269 $wgOut->addHTML( "<br clear=\"all\" />\n" );
272 # if this is a comment, show a subject line at the top, which is also the edit summary.
273 # Otherwise, show a summary field at the bottom
274 if($section=="new") {
276 $commentsubject="{$subject}: <input tabindex=1 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
279 $editsummary="{$summary}: <input tabindex=3 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
283 <form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
284 enctype=\"application/x-www-form-urlencoded\">
286 <textarea tabindex=2 name=\"wpTextbox1\" rows={$rows}
287 cols={$cols}{$ew} wrap=\"virtual\">" .
288 $wgLang->recodeForEdit( $wpTextbox1 ) .
293 <input tabindex=5 type=submit value=\"{$save}\" name=\"wpSave\">
294 <input tabindex=6 type=submit value=\"{$prev}\" name=\"wpPreview\">
295 <em>{$cancel}</em> | <em>{$edithelp}</em>
297 <input type=hidden value=\"{$section}\" name=\"wpSection\">
298 <input type=hidden value=\"{$wpEdittime}\" name=\"wpEdittime\">\n" );
301 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
302 DifferenceEngine
::showDiff( $wpTextbox2, $wpTextbox1,
303 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
305 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
306 <textarea tabindex=6 name=\"wpTextbox2\" rows={$rows} cols={$cols} wrap=virtual>"
307 . $wgLang->recodeForEdit( $wpTextbox2 ) .
311 $wgOut->addHTML( "</form>\n" );
312 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
313 $wgOut->addHTML($previewhead);
314 $wgOut->addWikiText( $this->mArticle
->preSaveTransform( $previewtext ) );
319 function blockedIPpage()
321 global $wgOut, $wgUser, $wgLang;
323 $wgOut->setPageTitle( wfMsg( "blockedtitle" ) );
324 $wgOut->setRobotpolicy( "noindex,nofollow" );
325 $wgOut->setArticleFlag( false );
327 $id = $wgUser->blockedBy();
328 $reason = $wgUser->blockedFor();
330 $name = User
::whoIs( $id );
331 $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
332 ":{$name}|{$name}]]";
334 $text = str_replace( "$1", $link, wfMsg( "blockedtext" ) );
335 $text = str_replace( "$2", $reason, $text );
336 $wgOut->addWikiText( $text );
337 $wgOut->returnToMain( false );