Add an ID if 'missingsummary' is triggered to allow styling of the summary line
[lhc/web/wiklou.git] / includes / EditPage.php
1 <?php
2 /**
3 * Contains the EditPage class
4 * @file
5 */
6
7 /**
8 * The edit page/HTML interface (split from Article)
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
11 * interfaces.
12 *
13 * EditPage cares about two distinct titles:
14 * $wgTitle is the page that forms submit to, links point to,
15 * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
16 * page in the database that is actually being edited. These are
17 * usually the same, but they are now allowed to be different.
18 */
19 class EditPage {
20 const AS_SUCCESS_UPDATE = 200;
21 const AS_SUCCESS_NEW_ARTICLE = 201;
22 const AS_HOOK_ERROR = 210;
23 const AS_FILTERING = 211;
24 const AS_HOOK_ERROR_EXPECTED = 212;
25 const AS_BLOCKED_PAGE_FOR_USER = 215;
26 const AS_CONTENT_TOO_BIG = 216;
27 const AS_USER_CANNOT_EDIT = 217;
28 const AS_READ_ONLY_PAGE_ANON = 218;
29 const AS_READ_ONLY_PAGE_LOGGED = 219;
30 const AS_READ_ONLY_PAGE = 220;
31 const AS_RATE_LIMITED = 221;
32 const AS_ARTICLE_WAS_DELETED = 222;
33 const AS_NO_CREATE_PERMISSION = 223;
34 const AS_BLANK_ARTICLE = 224;
35 const AS_CONFLICT_DETECTED = 225;
36 const AS_SUMMARY_NEEDED = 226;
37 const AS_TEXTBOX_EMPTY = 228;
38 const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
39 const AS_OK = 230;
40 const AS_END = 231;
41 const AS_SPAM_ERROR = 232;
42 const AS_IMAGE_REDIRECT_ANON = 233;
43 const AS_IMAGE_REDIRECT_LOGGED = 234;
44
45 var $mArticle;
46 var $mTitle;
47 var $action;
48 var $mMetaData = '';
49 var $isConflict = false;
50 var $isCssJsSubpage = false;
51 var $deletedSinceEdit = false;
52 var $formtype;
53 var $firsttime;
54 var $lastDelete;
55 var $mTokenOk = false;
56 var $mTokenOkExceptSuffix = false;
57 var $mTriedSave = false;
58 var $tooBig = false;
59 var $kblength = false;
60 var $missingComment = false;
61 var $missingSummary = false;
62 var $allowBlankSummary = false;
63 var $autoSumm = '';
64 var $hookError = '';
65 #var $mPreviewTemplates;
66 var $mParserOutput;
67 var $mBaseRevision = false;
68
69 # Form values
70 var $save = false, $preview = false, $diff = false;
71 var $minoredit = false, $watchthis = false, $recreate = false;
72 var $textbox1 = '', $textbox2 = '', $summary = '';
73 var $edittime = '', $section = '', $starttime = '';
74 var $oldid = 0, $editintro = '', $scrolltop = null;
75
76 # Placeholders for text injection by hooks (must be HTML)
77 # extensions should take care to _append_ to the present value
78 public $editFormPageTop; // Before even the preview
79 public $editFormTextTop;
80 public $editFormTextBeforeContent;
81 public $editFormTextAfterWarn;
82 public $editFormTextAfterTools;
83 public $editFormTextBottom;
84
85 /* $didSave should be set to true whenever an article was succesfully altered. */
86 public $didSave = false;
87 public $undidRev = 0;
88
89 public $suppressIntro = false;
90
91 /**
92 * @todo document
93 * @param $article
94 */
95 function EditPage( $article ) {
96 $this->mArticle =& $article;
97 $this->mTitle = $article->getTitle();
98 $this->action = 'submit';
99
100 # Placeholders for text injection by hooks (empty per default)
101 $this->editFormPageTop =
102 $this->editFormTextTop =
103 $this->editFormTextBeforeContent =
104 $this->editFormTextAfterWarn =
105 $this->editFormTextAfterTools =
106 $this->editFormTextBottom = "";
107 }
108
109 function getArticle() {
110 return $this->mArticle;
111 }
112
113 /**
114 * Fetch initial editing page content.
115 * @private
116 */
117 function getContent( $def_text = '' ) {
118 global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
119
120 wfProfileIn( __METHOD__ );
121 # Get variables from query string :P
122 $section = $wgRequest->getVal( 'section' );
123 $preload = $wgRequest->getVal( 'preload' );
124 $undoafter = $wgRequest->getVal( 'undoafter' );
125 $undo = $wgRequest->getVal( 'undo' );
126
127 $text = '';
128 // For message page not locally set, use the i18n message.
129 // For other non-existent articles, use preload text if any.
130 if ( !$this->mTitle->exists() ) {
131 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
132 # If this is a system message, get the default text.
133 list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
134 $wgMessageCache->loadAllMessages( $lang );
135 $text = wfMsgGetKey( $message, false, $lang, false );
136 if( wfEmptyMsg( $message, $text ) )
137 $text = '';
138 } else {
139 # If requested, preload some text.
140 $text = $this->getPreloadedText( $preload );
141 }
142 // For existing pages, get text based on "undo" or section parameters.
143 } else {
144 $text = $this->mArticle->getContent();
145 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
146 # If they got undoafter and undo round the wrong way, switch them
147 list( $undo, $undoafter ) = array( $undoafter, $undo );
148 }
149 if ( $undo > 0 && $undo > $undoafter ) {
150 # Undoing a specific edit overrides section editing; section-editing
151 # doesn't work with undoing.
152 if ( $undoafter ) {
153 $undorev = Revision::newFromId($undo);
154 $oldrev = Revision::newFromId($undoafter);
155 } else {
156 $undorev = Revision::newFromId($undo);
157 $oldrev = $undorev ? $undorev->getPrevious() : null;
158 }
159
160 # Sanity check, make sure it's the right page,
161 # the revisions exist and they were not deleted.
162 # Otherwise, $text will be left as-is.
163 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
164 $undorev->getPage() == $oldrev->getPage() &&
165 $undorev->getPage() == $this->mArticle->getID() &&
166 !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
167 !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
168
169 $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
170 if ( $undotext === false ) {
171 # Warn the user that something went wrong
172 $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
173 } else {
174 $text = $undotext;
175 # Inform the user of our success and set an automatic edit summary
176 $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
177 $firstrev = $oldrev->getNext();
178 # If we just undid one rev, use an autosummary
179 if ( $firstrev->mId == $undo ) {
180 $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
181 $this->undidRev = $undo;
182 }
183 $this->formtype = 'diff';
184 }
185 } else {
186 // Failed basic sanity checks.
187 // Older revisions may have been removed since the link
188 // was created, or we may simply have got bogus input.
189 $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
190 }
191 } else if ( $section != '' ) {
192 if ( $section == 'new' ) {
193 $text = $this->getPreloadedText( $preload );
194 } else {
195 $text = $wgParser->getSection( $text, $section, $def_text );
196 }
197 }
198 }
199
200 wfProfileOut( __METHOD__ );
201 return $text;
202 }
203
204 /**
205 * Get the contents of a page from its title and remove includeonly tags
206 *
207 * @param $preload String: the title of the page.
208 * @return string The contents of the page.
209 */
210 protected function getPreloadedText( $preload ) {
211 if ( $preload === '' ) {
212 return '';
213 } else {
214 $preloadTitle = Title::newFromText( $preload );
215 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
216 $rev = Revision::newFromTitle($preloadTitle);
217 if ( is_object( $rev ) ) {
218 $text = $rev->getText();
219 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
220 // its own mini-parser! -ævar
221 $text = preg_replace( '~</?includeonly>~', '', $text );
222 return $text;
223 } else
224 return '';
225 }
226 }
227 }
228
229 /**
230 * This is the function that extracts metadata from the article body on the first view.
231 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
232 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
233 */
234 function extractMetaDataFromArticle () {
235 global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
236 $this->mMetaData = '';
237 if ( !$wgUseMetadataEdit ) return;
238 if ( $wgMetadataWhitelist == '' ) return;
239 $s = '';
240 $t = $this->getContent();
241
242 # MISSING : <nowiki> filtering
243
244 # Categories and language links
245 $t = explode ( "\n" , $t );
246 $catlow = strtolower ( $wgContLang->getNsText( NS_CATEGORY ) );
247 $cat = $ll = array();
248 foreach ( $t AS $key => $x ) {
249 $y = trim ( strtolower ( $x ) );
250 while ( substr ( $y , 0 , 2 ) == '[[' ) {
251 $y = explode ( ']]' , trim ( $x ) );
252 $first = array_shift ( $y );
253 $first = explode ( ':' , $first );
254 $ns = array_shift ( $first );
255 $ns = trim ( str_replace ( '[' , '' , $ns ) );
256 if ( $wgContLang->getLanguageName( $ns ) || strtolower ( $ns ) == $catlow ) {
257 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]';
258 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add;
259 else $ll[] = $add;
260 $x = implode ( ']]' , $y );
261 $t[$key] = $x;
262 $y = trim ( strtolower ( $x ) );
263 } else {
264 $x = implode ( ']]' , $y );
265 $y = trim ( strtolower ( $x ) );
266 }
267 }
268 }
269 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n";
270 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n";
271 $t = implode ( "\n" , $t );
272
273 # Load whitelist
274 $sat = array () ; # stand-alone-templates; must be lowercase
275 $wl_title = Title::newFromText ( $wgMetadataWhitelist );
276 $wl_article = new Article ( $wl_title );
277 $wl = explode ( "\n" , $wl_article->getContent() );
278 foreach ( $wl AS $x ) {
279 $isentry = false;
280 $x = trim ( $x );
281 while ( substr ( $x , 0 , 1 ) == '*' ) {
282 $isentry = true;
283 $x = trim ( substr ( $x , 1 ) );
284 }
285 if ( $isentry ) {
286 $sat[] = strtolower ( $x );
287 }
288
289 }
290
291 # Templates, but only some
292 $t = explode ( '{{' , $t );
293 $tl = array () ;
294 foreach ( $t AS $key => $x ) {
295 $y = explode ( '}}' , $x , 2 );
296 if ( count ( $y ) == 2 ) {
297 $z = $y[0];
298 $z = explode ( '|' , $z );
299 $tn = array_shift ( $z );
300 if ( in_array ( strtolower ( $tn ) , $sat ) ) {
301 $tl[] = '{{' . $y[0] . '}}';
302 $t[$key] = $y[1];
303 $y = explode ( '}}' , $y[1] , 2 );
304 }
305 else $t[$key] = '{{' . $x;
306 }
307 else if ( $key != 0 ) $t[$key] = '{{' . $x;
308 else $t[$key] = $x;
309 }
310 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl );
311 $t = implode ( '' , $t );
312
313 $t = str_replace ( "\n\n\n" , "\n" , $t );
314 $this->mArticle->mContent = $t;
315 $this->mMetaData = $s;
316 }
317
318 /*
319 * Check if a page was deleted while the user was editing it, before submit.
320 * Note that we rely on the logging table, which hasn't been always there,
321 * but that doesn't matter, because this only applies to brand new
322 * deletes.
323 */
324 protected function wasDeletedSinceLastEdit() {
325 if ( $this->deletedSinceEdit )
326 return true;
327 if ( $this->mTitle->isDeleted() ) {
328 $this->lastDelete = $this->getLastDelete();
329 if ( $this->lastDelete ) {
330 $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
331 if ( $deleteTime > $this->starttime ) {
332 $this->deletedSinceEdit = true;
333 }
334 }
335 }
336 return $this->deletedSinceEdit;
337 }
338
339 function submit() {
340 $this->edit();
341 }
342
343 /**
344 * This is the function that gets called for "action=edit". It
345 * sets up various member variables, then passes execution to
346 * another function, usually showEditForm()
347 *
348 * The edit form is self-submitting, so that when things like
349 * preview and edit conflicts occur, we get the same form back
350 * with the extra stuff added. Only when the final submission
351 * is made and all is well do we actually save and redirect to
352 * the newly-edited page.
353 */
354 function edit() {
355 global $wgOut, $wgUser, $wgRequest;
356 // Allow extensions to modify/prevent this form or submission
357 if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) {
358 return;
359 }
360
361 wfProfileIn( __METHOD__ );
362 wfDebug( __METHOD__.": enter\n" );
363
364 // This is not an article
365 $wgOut->setArticleFlag( false );
366
367 $this->importFormData( $wgRequest );
368 $this->firsttime = false;
369
370 if ( $this->live ) {
371 $this->livePreview();
372 wfProfileOut( __METHOD__ );
373 return;
374 }
375
376 if ( wfReadOnly() && $this->save ) {
377 // Force preview
378 $this->save = false;
379 $this->preview = true;
380 }
381
382 $wgOut->addScriptFile( 'edit.js' );
383 $permErrors = $this->getEditPermissionErrors();
384 if ( $permErrors ) {
385 wfDebug( __METHOD__.": User can't edit\n" );
386 $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
387 wfProfileOut( __METHOD__ );
388 return;
389 } else {
390 if ( $this->save ) {
391 $this->formtype = 'save';
392 } else if ( $this->preview ) {
393 $this->formtype = 'preview';
394 } else if ( $this->diff ) {
395 $this->formtype = 'diff';
396 } else { # First time through
397 $this->firsttime = true;
398 if ( $this->previewOnOpen() ) {
399 $this->formtype = 'preview';
400 } else {
401 $this->extractMetaDataFromArticle () ;
402 $this->formtype = 'initial';
403 }
404 }
405 }
406
407 wfProfileIn( __METHOD__."-business-end" );
408
409 $this->isConflict = false;
410 // css / js subpages of user pages get a special treatment
411 $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
412 $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
413
414 # Show applicable editing introductions
415 if ( $this->formtype == 'initial' || $this->firsttime )
416 $this->showIntro();
417
418 if ( $this->mTitle->isTalkPage() ) {
419 $wgOut->addWikiMsg( 'talkpagetext' );
420 }
421
422 # Optional notices on a per-namespace and per-page basis
423 $editnotice_ns = 'editnotice-'.$this->mTitle->getNamespace();
424 $editnotice_page = $editnotice_ns.'-'.$this->mTitle->getDBkey();
425 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
426 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
427 }
428 if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
429 $parts = explode( '/', $this->mTitle->getDBkey() );
430 $editnotice_base = $editnotice_ns;
431 while ( count( $parts ) > 0 ) {
432 $editnotice_base .= '-'.array_shift( $parts );
433 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
434 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
435 }
436 }
437 } else if ( !wfEmptyMsg( $editnotice_page, wfMsgForContent( $editnotice_page ) ) ) {
438 $wgOut->addWikiText( wfMsgForContent( $editnotice_page ) );
439 }
440
441 # Attempt submission here. This will check for edit conflicts,
442 # and redundantly check for locked database, blocked IPs, etc.
443 # that edit() already checked just in case someone tries to sneak
444 # in the back door with a hand-edited submission URL.
445
446 if ( 'save' == $this->formtype ) {
447 if ( !$this->attemptSave() ) {
448 wfProfileOut( __METHOD__."-business-end" );
449 wfProfileOut( __METHOD__ );
450 return;
451 }
452 }
453
454 # First time through: get contents, set time for conflict
455 # checking, etc.
456 if ( 'initial' == $this->formtype || $this->firsttime ) {
457 if ( $this->initialiseForm() === false) {
458 $this->noSuchSectionPage();
459 wfProfileOut( __METHOD__."-business-end" );
460 wfProfileOut( __METHOD__ );
461 return;
462 }
463 if ( !$this->mTitle->getArticleId() )
464 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
465 }
466
467 $this->showEditForm();
468 wfProfileOut( __METHOD__."-business-end" );
469 wfProfileOut( __METHOD__ );
470 }
471
472 protected function getEditPermissionErrors() {
473 global $wgUser;
474 $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
475 # Can this title be created?
476 if ( !$this->mTitle->exists() ) {
477 $permErrors = array_merge( $permErrors,
478 wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
479 }
480 # Ignore some permissions errors when a user is just previewing/viewing diffs
481 $remove = array();
482 foreach( $permErrors as $error ) {
483 if ( ($this->preview || $this->diff) &&
484 ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext') )
485 {
486 $remove[] = $error;
487 }
488 }
489 $permErrors = wfArrayDiff2( $permErrors, $remove );
490 return $permErrors;
491 }
492
493 /**
494 * Show a read-only error
495 * Parameters are the same as OutputPage:readOnlyPage()
496 * Redirect to the article page if redlink=1
497 */
498 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
499 global $wgRequest, $wgOut;
500 if ( $wgRequest->getBool( 'redlink' ) ) {
501 // The edit page was reached via a red link.
502 // Redirect to the article page and let them click the edit tab if
503 // they really want a permission error.
504 $wgOut->redirect( $this->mTitle->getFullUrl() );
505 } else {
506 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
507 }
508 }
509
510 /**
511 * Should we show a preview when the edit form is first shown?
512 *
513 * @return bool
514 */
515 protected function previewOnOpen() {
516 global $wgRequest, $wgUser;
517 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
518 // Explicit override from request
519 return true;
520 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
521 // Explicit override from request
522 return false;
523 } elseif ( $this->section == 'new' ) {
524 // Nothing *to* preview for new sections
525 return false;
526 } elseif ( ( $wgRequest->getVal( 'preload' ) !== '' || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
527 // Standard preference behaviour
528 return true;
529 } elseif ( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) {
530 // Categories are special
531 return true;
532 } else {
533 return false;
534 }
535 }
536
537 /**
538 * @todo document
539 * @param $request
540 */
541 function importFormData( &$request ) {
542 global $wgLang, $wgUser;
543 $fname = 'EditPage::importFormData';
544 wfProfileIn( $fname );
545
546 # Section edit can come from either the form or a link
547 $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
548
549 if ( $request->wasPosted() ) {
550 # These fields need to be checked for encoding.
551 # Also remove trailing whitespace, but don't remove _initial_
552 # whitespace from the text boxes. This may be significant formatting.
553 $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
554 $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
555 $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
556 # Truncate for whole multibyte characters. +5 bytes for ellipsis
557 $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
558
559 # Remove extra headings from summaries and new sections.
560 $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary);
561
562 $this->edittime = $request->getVal( 'wpEdittime' );
563 $this->starttime = $request->getVal( 'wpStarttime' );
564
565 $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
566
567 if ( is_null( $this->edittime ) ) {
568 # If the form is incomplete, force to preview.
569 wfDebug( "$fname: Form data appears to be incomplete\n" );
570 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
571 $this->preview = true;
572 } else {
573 /* Fallback for live preview */
574 $this->preview = $request->getCheck( 'wpPreview' ) || $request->getCheck( 'wpLivePreview' );
575 $this->diff = $request->getCheck( 'wpDiff' );
576
577 // Remember whether a save was requested, so we can indicate
578 // if we forced preview due to session failure.
579 $this->mTriedSave = !$this->preview;
580
581 if ( $this->tokenOk( $request ) ) {
582 # Some browsers will not report any submit button
583 # if the user hits enter in the comment box.
584 # The unmarked state will be assumed to be a save,
585 # if the form seems otherwise complete.
586 wfDebug( "$fname: Passed token check.\n" );
587 } else if ( $this->diff ) {
588 # Failed token check, but only requested "Show Changes".
589 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
590 } else {
591 # Page might be a hack attempt posted from
592 # an external site. Preview instead of saving.
593 wfDebug( "$fname: Failed token check; forcing preview\n" );
594 $this->preview = true;
595 }
596 }
597 $this->save = !$this->preview && !$this->diff;
598 if ( !preg_match( '/^\d{14}$/', $this->edittime )) {
599 $this->edittime = null;
600 }
601
602 if ( !preg_match( '/^\d{14}$/', $this->starttime )) {
603 $this->starttime = null;
604 }
605
606 $this->recreate = $request->getCheck( 'wpRecreate' );
607
608 $this->minoredit = $request->getCheck( 'wpMinoredit' );
609 $this->watchthis = $request->getCheck( 'wpWatchthis' );
610
611 # Don't force edit summaries when a user is editing their own user or talk page
612 if ( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK ) &&
613 $this->mTitle->getText() == $wgUser->getName() )
614 {
615 $this->allowBlankSummary = true;
616 } else {
617 $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ) || !$wgUser->getOption( 'forceeditsummary');
618 }
619
620 $this->autoSumm = $request->getText( 'wpAutoSummary' );
621 } else {
622 # Not a posted form? Start with nothing.
623 wfDebug( "$fname: Not a posted form.\n" );
624 $this->textbox1 = '';
625 $this->textbox2 = '';
626 $this->mMetaData = '';
627 $this->summary = '';
628 $this->edittime = '';
629 $this->starttime = wfTimestampNow();
630 $this->edit = false;
631 $this->preview = false;
632 $this->save = false;
633 $this->diff = false;
634 $this->minoredit = false;
635 $this->watchthis = false;
636 $this->recreate = false;
637
638 if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
639 $this->summary = $request->getVal( 'preloadtitle' );
640 }
641 elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) {
642 $this->summary = $request->getText( 'summary' );
643 }
644
645 if ( $request->getVal( 'minor' ) ) {
646 $this->minoredit = true;
647 }
648 }
649
650 $this->oldid = $request->getInt( 'oldid' );
651
652 $this->live = $request->getCheck( 'live' );
653 $this->editintro = $request->getText( 'editintro' );
654
655 wfProfileOut( $fname );
656 }
657
658 /**
659 * Make sure the form isn't faking a user's credentials.
660 *
661 * @param $request WebRequest
662 * @return bool
663 * @private
664 */
665 function tokenOk( &$request ) {
666 global $wgUser;
667 $token = $request->getVal( 'wpEditToken' );
668 $this->mTokenOk = $wgUser->matchEditToken( $token );
669 $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
670 return $this->mTokenOk;
671 }
672
673 /**
674 * Show all applicable editing introductions
675 */
676 protected function showIntro() {
677 global $wgOut, $wgUser;
678 if ( $this->suppressIntro ) {
679 return;
680 }
681 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
682 if ( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
683 $parts = explode( '/', $this->mTitle->getText(), 2 );
684 $username = $parts[0];
685 $id = User::idFromName( $username );
686 $ip = User::isIP( $username );
687 if ( $id == 0 && !$ip ) {
688 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
689 array( 'userpage-userdoesnotexist', $username ) );
690 }
691 }
692 # Try to add a custom edit intro, or use the standard one if this is not possible.
693 if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
694 if ( $wgUser->isLoggedIn() ) {
695 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
696 } else {
697 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
698 }
699 }
700 # Give a notice if the user is editing a deleted page...
701 if ( !$this->mTitle->exists() ) {
702 $this->showDeletionLog( $wgOut );
703 }
704 }
705
706 /**
707 * Attempt to show a custom editing introduction, if supplied
708 *
709 * @return bool
710 */
711 protected function showCustomIntro() {
712 if ( $this->editintro ) {
713 $title = Title::newFromText( $this->editintro );
714 if ( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
715 global $wgOut;
716 $revision = Revision::newFromTitle( $title );
717 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle );
718 return true;
719 } else {
720 return false;
721 }
722 } else {
723 return false;
724 }
725 }
726
727 /**
728 * Attempt submission (no UI)
729 * @return one of the constants describing the result
730 */
731 function internalAttemptSave( &$result, $bot = false ) {
732 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
733 global $wgMaxArticleSize;
734
735 $fname = 'EditPage::attemptSave';
736 wfProfileIn( $fname );
737 wfProfileIn( "$fname-checks" );
738
739 if ( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
740 {
741 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
742 return self::AS_HOOK_ERROR;
743 }
744
745 # Check image redirect
746 if ( $this->mTitle->getNamespace() == NS_FILE &&
747 Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
748 !$wgUser->isAllowed( 'upload' ) ) {
749 if ( $wgUser->isAnon() ) {
750 return self::AS_IMAGE_REDIRECT_ANON;
751 } else {
752 return self::AS_IMAGE_REDIRECT_LOGGED;
753 }
754 }
755
756 # Reintegrate metadata
757 if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
758 $this->mMetaData = '' ;
759
760 # Check for spam
761 $match = self::matchSpamRegex( $this->summary );
762 if ( $match === false ) {
763 $match = self::matchSpamRegex( $this->textbox1 );
764 }
765 if ( $match !== false ) {
766 $result['spam'] = $match;
767 $ip = wfGetIP();
768 $pdbk = $this->mTitle->getPrefixedDBkey();
769 $match = str_replace( "\n", '', $match );
770 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
771 wfProfileOut( "$fname-checks" );
772 wfProfileOut( $fname );
773 return self::AS_SPAM_ERROR;
774 }
775 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
776 # Error messages or other handling should be performed by the filter function
777 wfProfileOut( "$fname-checks" );
778 wfProfileOut( $fname );
779 return self::AS_FILTERING;
780 }
781 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
782 # Error messages etc. could be handled within the hook...
783 wfProfileOut( "$fname-checks" );
784 wfProfileOut( $fname );
785 return self::AS_HOOK_ERROR;
786 } elseif ( $this->hookError != '' ) {
787 # ...or the hook could be expecting us to produce an error
788 wfProfileOut( "$fname-checks" );
789 wfProfileOut( $fname );
790 return self::AS_HOOK_ERROR_EXPECTED;
791 }
792 if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
793 # Check block state against master, thus 'false'.
794 wfProfileOut( "$fname-checks" );
795 wfProfileOut( $fname );
796 return self::AS_BLOCKED_PAGE_FOR_USER;
797 }
798 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
799 if ( $this->kblength > $wgMaxArticleSize ) {
800 // Error will be displayed by showEditForm()
801 $this->tooBig = true;
802 wfProfileOut( "$fname-checks" );
803 wfProfileOut( $fname );
804 return self::AS_CONTENT_TOO_BIG;
805 }
806
807 if ( !$wgUser->isAllowed('edit') ) {
808 if ( $wgUser->isAnon() ) {
809 wfProfileOut( "$fname-checks" );
810 wfProfileOut( $fname );
811 return self::AS_READ_ONLY_PAGE_ANON;
812 }
813 else {
814 wfProfileOut( "$fname-checks" );
815 wfProfileOut( $fname );
816 return self::AS_READ_ONLY_PAGE_LOGGED;
817 }
818 }
819
820 if ( wfReadOnly() ) {
821 wfProfileOut( "$fname-checks" );
822 wfProfileOut( $fname );
823 return self::AS_READ_ONLY_PAGE;
824 }
825 if ( $wgUser->pingLimiter() ) {
826 wfProfileOut( "$fname-checks" );
827 wfProfileOut( $fname );
828 return self::AS_RATE_LIMITED;
829 }
830
831 # If the article has been deleted while editing, don't save it without
832 # confirmation
833 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
834 wfProfileOut( "$fname-checks" );
835 wfProfileOut( $fname );
836 return self::AS_ARTICLE_WAS_DELETED;
837 }
838
839 wfProfileOut( "$fname-checks" );
840
841 # If article is new, insert it.
842 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
843 if ( 0 == $aid ) {
844 // Late check for create permission, just in case *PARANOIA*
845 if ( !$this->mTitle->userCan( 'create' ) ) {
846 wfDebug( "$fname: no create permission\n" );
847 wfProfileOut( $fname );
848 return self::AS_NO_CREATE_PERMISSION;
849 }
850
851 # Don't save a new article if it's blank.
852 if ( '' == $this->textbox1 ) {
853 wfProfileOut( $fname );
854 return self::AS_BLANK_ARTICLE;
855 }
856
857 // Run post-section-merge edit filter
858 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
859 # Error messages etc. could be handled within the hook...
860 wfProfileOut( $fname );
861 return self::AS_HOOK_ERROR;
862 }
863
864 # Handle the user preference to force summaries here. Check if it's not a redirect.
865 if ( !$this->allowBlankSummary && !Title::newFromRedirect( $this->textbox1 ) ) {
866 if ( md5( $this->summary ) == $this->autoSumm ) {
867 $this->missingSummary = true;
868 wfProfileOut( $fname );
869 return self::AS_SUMMARY_NEEDED;
870 }
871 }
872
873 $isComment = ( $this->section == 'new' );
874
875 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
876 $this->minoredit, $this->watchthis, false, $isComment, $bot );
877
878 wfProfileOut( $fname );
879 return self::AS_SUCCESS_NEW_ARTICLE;
880 }
881
882 # Article exists. Check for edit conflict.
883
884 $this->mArticle->clear(); # Force reload of dates, etc.
885 $this->mArticle->forUpdate( true ); # Lock the article
886
887 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
888
889 if ( $this->mArticle->getTimestamp() != $this->edittime ) {
890 $this->isConflict = true;
891 if ( $this->section == 'new' ) {
892 if ( $this->mArticle->getUserText() == $wgUser->getName() &&
893 $this->mArticle->getComment() == $this->summary ) {
894 // Probably a duplicate submission of a new comment.
895 // This can happen when squid resends a request after
896 // a timeout but the first one actually went through.
897 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
898 } else {
899 // New comment; suppress conflict.
900 $this->isConflict = false;
901 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
902 }
903 }
904 }
905 $userid = $wgUser->getId();
906
907 # Suppress edit conflict with self, except for section edits where merging is required.
908 if ( $this->isConflict && $this->section == '' && $this->userWasLastToEdit($userid,$this->edittime) ) {
909 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
910 $this->isConflict = false;
911 }
912
913 if ( $this->isConflict ) {
914 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
915 $this->mArticle->getTimestamp() . "')\n" );
916 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
917 } else {
918 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
919 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
920 }
921 if ( is_null( $text ) ) {
922 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
923 $this->isConflict = true;
924 $text = $this->textbox1; // do not try to merge here!
925 } else if ( $this->isConflict ) {
926 # Attempt merge
927 if ( $this->mergeChangesInto( $text ) ) {
928 // Successful merge! Maybe we should tell the user the good news?
929 $this->isConflict = false;
930 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
931 } else {
932 $this->section = '';
933 $this->textbox1 = $text;
934 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
935 }
936 }
937
938 if ( $this->isConflict ) {
939 wfProfileOut( $fname );
940 return self::AS_CONFLICT_DETECTED;
941 }
942
943 $oldtext = $this->mArticle->getContent();
944
945 // Run post-section-merge edit filter
946 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
947 # Error messages etc. could be handled within the hook...
948 wfProfileOut( $fname );
949 return self::AS_HOOK_ERROR;
950 }
951
952 # Handle the user preference to force summaries here, but not for null edits
953 if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext,$text)
954 && !Title::newFromRedirect( $text ) ) # check if it's not a redirect
955 {
956 if ( md5( $this->summary ) == $this->autoSumm ) {
957 $this->missingSummary = true;
958 wfProfileOut( $fname );
959 return self::AS_SUMMARY_NEEDED;
960 }
961 }
962
963 # And a similar thing for new sections
964 if ( $this->section == 'new' && !$this->allowBlankSummary ) {
965 if (trim($this->summary) == '') {
966 $this->missingSummary = true;
967 wfProfileOut( $fname );
968 return self::AS_SUMMARY_NEEDED;
969 }
970 }
971
972 # All's well
973 wfProfileIn( "$fname-sectionanchor" );
974 $sectionanchor = '';
975 if ( $this->section == 'new' ) {
976 if ( $this->textbox1 == '' ) {
977 $this->missingComment = true;
978 return self::AS_TEXTBOX_EMPTY;
979 }
980 if ( $this->summary != '' ) {
981 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
982 # This is a new section, so create a link to the new section
983 # in the revision summary.
984 $cleanSummary = $wgParser->stripSectionName( $this->summary );
985 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary );
986 }
987 } elseif ( $this->section != '' ) {
988 # Try to get a section anchor from the section source, redirect to edited section if header found
989 # XXX: might be better to integrate this into Article::replaceSection
990 # for duplicate heading checking and maybe parsing
991 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
992 # we can't deal with anchors, includes, html etc in the header for now,
993 # headline would need to be parsed to improve this
994 if ( $hasmatch and strlen($matches[2]) > 0 ) {
995 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
996 }
997 }
998 wfProfileOut( "$fname-sectionanchor" );
999
1000 // Save errors may fall down to the edit form, but we've now
1001 // merged the section into full text. Clear the section field
1002 // so that later submission of conflict forms won't try to
1003 // replace that into a duplicated mess.
1004 $this->textbox1 = $text;
1005 $this->section = '';
1006
1007 // Check for length errors again now that the section is merged in
1008 $this->kblength = (int)(strlen( $text ) / 1024);
1009 if ( $this->kblength > $wgMaxArticleSize ) {
1010 $this->tooBig = true;
1011 wfProfileOut( $fname );
1012 return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
1013 }
1014
1015 # update the article here
1016 if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
1017 $this->watchthis, $bot, $sectionanchor ) )
1018 {
1019 wfProfileOut( $fname );
1020 return self::AS_SUCCESS_UPDATE;
1021 } else {
1022 $this->isConflict = true;
1023 }
1024 wfProfileOut( $fname );
1025 return self::AS_END;
1026 }
1027
1028 /**
1029 * Check if no edits were made by other users since
1030 * the time a user started editing the page. Limit to
1031 * 50 revisions for the sake of performance.
1032 */
1033 protected function userWasLastToEdit( $id, $edittime ) {
1034 if( !$id ) return false;
1035 $dbw = wfGetDB( DB_MASTER );
1036 $res = $dbw->select( 'revision',
1037 'rev_user',
1038 array(
1039 'rev_page' => $this->mArticle->getId(),
1040 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1041 ),
1042 __METHOD__,
1043 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1044 while( $row = $res->fetchObject() ) {
1045 if( $row->rev_user != $id ) {
1046 return false;
1047 }
1048 }
1049 return true;
1050 }
1051
1052 /**
1053 * Check given input text against $wgSpamRegex, and return the text of the first match.
1054 * @return mixed -- matching string or false
1055 */
1056 public static function matchSpamRegex( $text ) {
1057 global $wgSpamRegex;
1058 if ( $wgSpamRegex ) {
1059 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1060 $regexes = (array)$wgSpamRegex;
1061 foreach( $regexes as $regex ) {
1062 $matches = array();
1063 if ( preg_match( $regex, $text, $matches ) ) {
1064 return $matches[0];
1065 }
1066 }
1067 }
1068 return false;
1069 }
1070
1071 /**
1072 * Initialise form fields in the object
1073 * Called on the first invocation, e.g. when a user clicks an edit link
1074 */
1075 function initialiseForm() {
1076 $this->edittime = $this->mArticle->getTimestamp();
1077 $this->textbox1 = $this->getContent( false );
1078 if ( $this->textbox1 === false ) return false;
1079 wfProxyCheck();
1080 return true;
1081 }
1082
1083 function setHeaders() {
1084 global $wgOut, $wgTitle;
1085 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1086 if ( $this->formtype == 'preview' ) {
1087 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1088 }
1089 if ( $this->isConflict ) {
1090 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1091 } elseif ( $this->section != '' ) {
1092 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1093 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1094 } else {
1095 # Use the title defined by DISPLAYTITLE magic word when present
1096 if ( isset($this->mParserOutput)
1097 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
1098 $title = $dt;
1099 } else {
1100 $title = $wgTitle->getPrefixedText();
1101 }
1102 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1103 }
1104 }
1105
1106 /**
1107 * Send the edit form and related headers to $wgOut
1108 * @param $formCallback Optional callable that takes an OutputPage
1109 * parameter; will be called during form output
1110 * near the top, for captchas and the like.
1111 */
1112 function showEditForm( $formCallback=null ) {
1113 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle, $wgRequest;
1114
1115 # If $wgTitle is null, that means we're in API mode.
1116 # Some hook probably called this function without checking
1117 # for is_null($wgTitle) first. Bail out right here so we don't
1118 # do lots of work just to discard it right after.
1119 if (is_null($wgTitle))
1120 return;
1121
1122 $fname = 'EditPage::showEditForm';
1123 wfProfileIn( $fname );
1124
1125 $sk = $wgUser->getSkin();
1126
1127 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
1128
1129 #need to parse the preview early so that we know which templates are used,
1130 #otherwise users with "show preview after edit box" will get a blank list
1131 #we parse this near the beginning so that setHeaders can do the title
1132 #setting work instead of leaving it in getPreviewText
1133 $previewOutput = '';
1134 if ( $this->formtype == 'preview' ) {
1135 $previewOutput = $this->getPreviewText();
1136 }
1137
1138 $this->setHeaders();
1139
1140 # Enabled article-related sidebar, toplinks, etc.
1141 $wgOut->setArticleRelated( true );
1142
1143 if ( $this->isConflict ) {
1144 $wgOut->addWikiMsg( 'explainconflict' );
1145
1146 $this->textbox2 = $this->textbox1;
1147 $this->textbox1 = $this->getContent();
1148 $this->edittime = $this->mArticle->getTimestamp();
1149 } else {
1150 if ( $this->section != '' && $this->section != 'new' ) {
1151 $matches = array();
1152 if ( !$this->summary && !$this->preview && !$this->diff ) {
1153 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1, $matches );
1154 if ( !empty( $matches[2] ) ) {
1155 global $wgParser;
1156 $this->summary = "/* " .
1157 $wgParser->stripSectionName(trim($matches[2])) .
1158 " */ ";
1159 }
1160 }
1161 }
1162
1163 if ( $this->missingComment ) {
1164 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1165 }
1166
1167 if ( $this->missingSummary && $this->section != 'new' ) {
1168 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1169 }
1170
1171 if ( $this->missingSummary && $this->section == 'new' ) {
1172 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1173 }
1174
1175 if ( $this->hookError !== '' ) {
1176 $wgOut->addWikiText( $this->hookError );
1177 }
1178
1179 if ( !$this->checkUnicodeCompliantBrowser() ) {
1180 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1181 }
1182 if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) {
1183 // Let sysop know that this will make private content public if saved
1184
1185 if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
1186 $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
1187 } else if ( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1188 $wgOut->addWikiMsg( 'rev-deleted-text-view' );
1189 }
1190
1191 if ( !$this->mArticle->mRevision->isCurrent() ) {
1192 $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
1193 $wgOut->addWikiMsg( 'editingold' );
1194 }
1195 }
1196 }
1197
1198 if ( wfReadOnly() ) {
1199 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1200 } elseif ( $wgUser->isAnon() && $this->formtype != 'preview' ) {
1201 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
1202 } else {
1203 if ( $this->isCssJsSubpage ) {
1204 # Check the skin exists
1205 if ( $this->isValidCssJsSubpage ) {
1206 if ( $this->formtype !== 'preview' ) {
1207 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
1208 }
1209 } else {
1210 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1211 }
1212 }
1213 }
1214
1215 $classes = array(); // Textarea CSS
1216 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1217 # Show a warning if editing an interface message
1218 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
1219 } elseif ( $this->mTitle->isProtected( 'edit' ) ) {
1220 # Is the title semi-protected?
1221 if ( $this->mTitle->isSemiProtected() ) {
1222 $noticeMsg = 'semiprotectedpagewarning';
1223 $classes[] = 'mw-textarea-sprotected';
1224 } else {
1225 # Then it must be protected based on static groups (regular)
1226 $noticeMsg = 'protectedpagewarning';
1227 $classes[] = 'mw-textarea-protected';
1228 }
1229 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
1230 $wgOut->addWikiMsg( $noticeMsg );
1231 LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '', 1 );
1232 $wgOut->addHTML( "</div>\n" );
1233 }
1234 if ( $this->mTitle->isCascadeProtected() ) {
1235 # Is this page under cascading protection from some source pages?
1236 list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
1237 $notice = "<div class='mw-cascadeprotectedwarning'>$1\n";
1238 $cascadeSourcesCount = count( $cascadeSources );
1239 if ( $cascadeSourcesCount > 0 ) {
1240 # Explain, and list the titles responsible
1241 foreach( $cascadeSources as $page ) {
1242 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1243 }
1244 }
1245 $notice .= '</div>';
1246 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1247 }
1248 if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
1249 $wgOut->wrapWikiMsg( '<div class="mw-titleprotectedwarning">$1</div>', 'titleprotectedwarning' );
1250 }
1251
1252 if ( $this->kblength === false ) {
1253 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
1254 }
1255 if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
1256 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
1257 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) );
1258 $wgOut->addHTML( "</div>\n" );
1259 } elseif ( $this->kblength > 29 ) {
1260 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1261 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) );
1262 $wgOut->addHTML( "</div>\n" );
1263 }
1264
1265 $q = 'action='.$this->action;
1266 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1267 $action = $wgTitle->escapeLocalURL( $q );
1268
1269 $summary = wfMsg( 'summary' );
1270 $subject = wfMsg( 'subject' );
1271
1272 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
1273 wfMsgExt('cancel', array('parseinline')) );
1274 $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1275 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1276 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1277 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1278 htmlspecialchars( wfMsg( 'newwindow' ) );
1279
1280 global $wgRightsText;
1281 if ( $wgRightsText ) {
1282 $copywarnMsg = array( 'copyrightwarning',
1283 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1284 $wgRightsText );
1285 } else {
1286 $copywarnMsg = array( 'copyrightwarning2',
1287 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1288 }
1289
1290 if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
1291 # prepare toolbar for edit buttons
1292 $toolbar = EditPage::getEditToolbar();
1293 } else {
1294 $toolbar = '';
1295 }
1296
1297 // activate checkboxes if user wants them to be always active
1298 if ( !$this->preview && !$this->diff ) {
1299 # Sort out the "watch" checkbox
1300 if ( $wgUser->getOption( 'watchdefault' ) ) {
1301 # Watch all edits
1302 $this->watchthis = true;
1303 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1304 # Watch creations
1305 $this->watchthis = true;
1306 } elseif ( $this->mTitle->userIsWatching() ) {
1307 # Already watched
1308 $this->watchthis = true;
1309 }
1310
1311 # May be overriden by request parameters
1312 if( $wgRequest->getBool( 'watchthis' ) ) {
1313 $this->watchthis = true;
1314 }
1315
1316 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
1317 }
1318
1319 $wgOut->addHTML( $this->editFormPageTop );
1320
1321 if ( $wgUser->getOption( 'previewontop' ) ) {
1322 $this->displayPreviewArea( $previewOutput, true );
1323 }
1324
1325
1326 $wgOut->addHTML( $this->editFormTextTop );
1327
1328 # if this is a comment, show a subject line at the top, which is also the edit summary.
1329 # Otherwise, show a summary field at the bottom
1330 $summarytext = $wgContLang->recodeForEdit( $this->summary );
1331
1332 # If a blank edit summary was previously provided, and the appropriate
1333 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1334 # user being bounced back more than once in the event that a summary
1335 # is not required.
1336 #####
1337 # For a bit more sophisticated detection of blank summaries, hash the
1338 # automatic one and pass that in the hidden field wpAutoSummary.
1339 $summaryhiddens = '';
1340 if ( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
1341 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
1342 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
1343 if ( $this->section == 'new' ) {
1344 $commentsubject = '';
1345 if ( !$wgRequest->getBool( 'nosummary' ) ) {
1346 # Add an ID if 'missingsummary' is triggered to allow styling of the summary line
1347 $summaryMissedID = $this->missingSummary ? ' mw-summarymissed' : '';
1348
1349 $commentsubject =
1350 Xml::tags( 'label', array( 'for' => 'wpSummary' ), $subject );
1351 $commentsubject =
1352 Xml::tags( 'span', array( 'id' => "wpSummaryLabel$summaryMissedID" ), $commentsubject );
1353 $commentsubject .= '&nbsp;';
1354 $commentsubject .= Xml::input( 'wpSummary',
1355 60,
1356 $summarytext,
1357 array(
1358 'id' => 'wpSummary',
1359 'maxlength' => '200',
1360 'tabindex' => '1'
1361 ) );
1362 }
1363 $editsummary = "<div class='editOptions'>\n";
1364 global $wgParser;
1365 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
1366 $subjectpreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">". wfMsg('subject-preview') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
1367 $summarypreview = '';
1368 } else {
1369 $commentsubject = '';
1370
1371 # Add an ID if 'missingsummary' is triggered to allow styling of the summary line
1372 $summaryMissedID = $this->missingSummary ? ' mw-summarymissed' : '';
1373
1374 $editsummary = Xml::tags( 'label', array( 'for' => 'wpSummary' ), $summary );
1375 $editsummary = Xml::tags( 'span', array( 'id' => "wpSummaryLabel$summaryMissedID" ), $editsummary ) . ' ';
1376
1377 $editsummary .= Xml::input( 'wpSummary',
1378 60,
1379 $summarytext,
1380 array(
1381 'id' => 'wpSummary',
1382 'maxlength' => '200',
1383 'tabindex' => '1'
1384 ) );
1385
1386 // No idea where this is closed.
1387 $editsummary = Xml::openElement( 'div', array( 'class' => 'editOptions' ) )
1388 . $editsummary . '<br/>';
1389
1390 $summarypreview = '';
1391 if ( $summarytext && $this->preview ) {
1392 $summarypreview =
1393 Xml::tags( 'div',
1394 array( 'class' => 'mw-summary-preview' ),
1395 wfMsg( 'summary-preview' ) .
1396 $sk->commentBlock( $this->summary, $this->mTitle )
1397 );
1398 }
1399 $subjectpreview = '';
1400 }
1401 $commentsubject .= $summaryhiddens;
1402
1403 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1404 if ( !$this->preview && !$this->diff ) {
1405 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1406 }
1407 $templates = $this->getTemplates();
1408 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
1409
1410 $hiddencats = $this->mArticle->getHiddenCategories();
1411 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1412
1413 global $wgUseMetadataEdit ;
1414 if ( $wgUseMetadataEdit ) {
1415 $metadata = $this->mMetaData ;
1416 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1417 $top = wfMsgWikiHtml( 'metadata_help' );
1418 /* ToDo: Replace with clean code */
1419 $ew = $wgUser->getOption( 'editwidth' );
1420 if ( $ew ) $ew = " style=\"width:100%\"";
1421 else $ew = '';
1422 $cols = $wgUser->getIntOption( 'cols' );
1423 /* /ToDo */
1424 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1425 }
1426 else $metadata = "" ;
1427
1428 $recreate = '';
1429 if ( $this->wasDeletedSinceLastEdit() ) {
1430 if ( 'save' != $this->formtype ) {
1431 $wgOut->wrapWikiMsg(
1432 '<div class="error mw-deleted-while-editing">$1</div>',
1433 'deletedwhileediting' );
1434 } else {
1435 // Hide the toolbar and edit area, user can click preview to get it back
1436 // Add an confirmation checkbox and explanation.
1437 $toolbar = '';
1438 $recreate = '<div class="mw-confirm-recreate">' .
1439 $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ) ) .
1440 Xml::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1441 array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1442 ) . '</div>';
1443 }
1444 }
1445
1446 $tabindex = 2;
1447
1448 $checkboxes = $this->getCheckboxes( $tabindex, $sk,
1449 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
1450
1451 $checkboxhtml = implode( $checkboxes, "\n" );
1452
1453 $buttons = $this->getEditButtons( $tabindex );
1454 $buttonshtml = implode( $buttons, "\n" );
1455
1456 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1457 ? '' : Xml::hidden( 'safemode', '1' );
1458
1459 $wgOut->addHTML( <<<END
1460 {$toolbar}
1461 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1462 END
1463 );
1464
1465 if ( is_callable( $formCallback ) ) {
1466 call_user_func_array( $formCallback, array( &$wgOut ) );
1467 }
1468
1469 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1470
1471 // Put these up at the top to ensure they aren't lost on early form submission
1472 $this->showFormBeforeText();
1473
1474 $wgOut->addHTML( <<<END
1475 {$recreate}
1476 {$commentsubject}
1477 {$subjectpreview}
1478 {$this->editFormTextBeforeContent}
1479 END
1480 );
1481 $this->showTextbox1( $classes );
1482
1483 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1484 $wgOut->addHTML( <<<END
1485 {$this->editFormTextAfterWarn}
1486 {$metadata}
1487 {$editsummary}
1488 {$summarypreview}
1489 {$checkboxhtml}
1490 {$safemodehtml}
1491 END
1492 );
1493
1494 $wgOut->addHTML(
1495 "<div class='editButtons'>
1496 {$buttonshtml}
1497 <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>
1498 </div><!-- editButtons -->
1499 </div><!-- editOptions -->");
1500
1501 /**
1502 * To make it harder for someone to slip a user a page
1503 * which submits an edit form to the wiki without their
1504 * knowledge, a random token is associated with the login
1505 * session. If it's not passed back with the submission,
1506 * we won't save the page, or render user JavaScript and
1507 * CSS previews.
1508 *
1509 * For anon editors, who may not have a session, we just
1510 * include the constant suffix to prevent editing from
1511 * broken text-mangling proxies.
1512 */
1513 $token = htmlspecialchars( $wgUser->editToken() );
1514 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1515
1516 $this->showEditTools();
1517
1518 $wgOut->addHTML( <<<END
1519 {$this->editFormTextAfterTools}
1520 <div class='templatesUsed'>
1521 {$formattedtemplates}
1522 </div>
1523 <div class='hiddencats'>
1524 {$formattedhiddencats}
1525 </div>
1526 END
1527 );
1528
1529 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1530 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1531
1532 $de = new DifferenceEngine( $this->mTitle );
1533 $de->setText( $this->textbox2, $this->textbox1 );
1534 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1535
1536 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1537 $this->showTextbox2();
1538 }
1539 $wgOut->addHTML( $this->editFormTextBottom );
1540 $wgOut->addHTML( "</form>\n" );
1541 if ( !$wgUser->getOption( 'previewontop' ) ) {
1542 $this->displayPreviewArea( $previewOutput, false );
1543 }
1544
1545 wfProfileOut( $fname );
1546 }
1547
1548 protected function showFormBeforeText() {
1549 global $wgOut;
1550 $wgOut->addHTML( "
1551 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1552 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1553 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1554 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1555 }
1556
1557 protected function showTextbox1( $classes ) {
1558 $attribs = array( 'tabindex' => 1 );
1559
1560 if ( $this->wasDeletedSinceLastEdit() )
1561 $attribs['type'] = 'hidden';
1562 if ( !empty($classes) )
1563 $attribs['class'] = implode(' ',$classes);
1564
1565 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1566 }
1567
1568 protected function showTextbox2() {
1569 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
1570 }
1571
1572 protected function showTextbox( $content, $name, $attribs = array() ) {
1573 global $wgOut, $wgUser;
1574
1575 $wikitext = $this->safeUnicodeOutput( $content );
1576 if ( $wikitext !== '' ) {
1577 // Ensure there's a newline at the end, otherwise adding lines
1578 // is awkward.
1579 // But don't add a newline if the ext is empty, or Firefox in XHTML
1580 // mode will show an extra newline. A bit annoying.
1581 $wikitext .= "\n";
1582 }
1583
1584 $attribs['accesskey'] = ',';
1585 $attribs['id'] = $name;
1586
1587 if ( $wgUser->getOption( 'editwidth' ) )
1588 $attribs['style'] = 'width: 100%';
1589
1590 $wgOut->addHTML( Xml::textarea(
1591 $name,
1592 $wikitext,
1593 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1594 $attribs ) );
1595 }
1596
1597 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1598 global $wgOut;
1599 $classes = array();
1600 if ( $isOnTop )
1601 $classes[] = 'ontop';
1602
1603 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1604
1605 if ( $this->formtype != 'preview' )
1606 $attribs['style'] = 'display: none;';
1607
1608 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
1609
1610 if ( $this->formtype == 'preview' ) {
1611 $this->showPreview( $previewOutput );
1612 }
1613
1614 $wgOut->addHTML( '</div>' );
1615
1616 if ( $this->formtype == 'diff') {
1617 $this->showDiff();
1618 }
1619 }
1620
1621 /**
1622 * Append preview output to $wgOut.
1623 * Includes category rendering if this is a category page.
1624 *
1625 * @param string $text The HTML to be output for the preview.
1626 */
1627 protected function showPreview( $text ) {
1628 global $wgOut;
1629 if ( $this->mTitle->getNamespace() == NS_CATEGORY) {
1630 $this->mArticle->openShowCategory();
1631 }
1632 # This hook seems slightly odd here, but makes things more
1633 # consistent for extensions.
1634 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1635 $wgOut->addHTML( $text );
1636 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
1637 $this->mArticle->closeShowCategory();
1638 }
1639 }
1640
1641 /**
1642 * Live Preview lets us fetch rendered preview page content and
1643 * add it to the page without refreshing the whole page.
1644 * If not supported by the browser it will fall through to the normal form
1645 * submission method.
1646 *
1647 * This function outputs a script tag to support live preview, and
1648 * returns an onclick handler which should be added to the attributes
1649 * of the preview button
1650 */
1651 function doLivePreviewScript() {
1652 global $wgOut, $wgTitle;
1653 $wgOut->addScriptFile( 'preview.js' );
1654 $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
1655 return "return !lpDoPreview(" .
1656 "editform.wpTextbox1.value," .
1657 '"' . $liveAction . '"' . ")";
1658 }
1659
1660 protected function showEditTools() {
1661 global $wgOut;
1662 $wgOut->addHTML( '<div class="mw-editTools">' );
1663 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1664 $wgOut->addHTML( '</div>' );
1665 }
1666
1667 function getLastDelete() {
1668 $dbr = wfGetDB( DB_SLAVE );
1669 $data = $dbr->selectRow(
1670 array( 'logging', 'user' ),
1671 array( 'log_type',
1672 'log_action',
1673 'log_timestamp',
1674 'log_user',
1675 'log_namespace',
1676 'log_title',
1677 'log_comment',
1678 'log_params',
1679 'user_name', ),
1680 array( 'log_namespace' => $this->mTitle->getNamespace(),
1681 'log_title' => $this->mTitle->getDBkey(),
1682 'log_type' => 'delete',
1683 'log_action' => 'delete',
1684 'user_id=log_user' ),
1685 __METHOD__,
1686 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1687
1688 return $data;
1689 }
1690
1691 /**
1692 * Get the rendered text for previewing.
1693 * @return string
1694 */
1695 function getPreviewText() {
1696 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
1697
1698 wfProfileIn( __METHOD__ );
1699
1700 if ( $this->mTriedSave && !$this->mTokenOk ) {
1701 if ( $this->mTokenOkExceptSuffix ) {
1702 $note = wfMsg( 'token_suffix_mismatch' );
1703 } else {
1704 $note = wfMsg( 'session_fail_preview' );
1705 }
1706 } else {
1707 $note = wfMsg( 'previewnote' );
1708 }
1709
1710 $parserOptions = ParserOptions::newFromUser( $wgUser );
1711 $parserOptions->setEditSection( false );
1712 $parserOptions->setIsPreview( true );
1713 $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
1714
1715 global $wgRawHtml;
1716 if ( $wgRawHtml && !$this->mTokenOk ) {
1717 // Could be an offsite preview attempt. This is very unsafe if
1718 // HTML is enabled, as it could be an attack.
1719 return $wgOut->parse( "<div class='previewnote'>" .
1720 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1721 }
1722
1723 # don't parse user css/js, show message about preview
1724 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1725
1726 if ( $this->isCssJsSubpage ) {
1727 if (preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
1728 $previewtext = wfMsg('usercsspreview');
1729 } else if (preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
1730 $previewtext = wfMsg('userjspreview');
1731 }
1732 $parserOptions->setTidy(true);
1733 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
1734 $previewHTML = $parserOutput->mText;
1735 } elseif ( $rt = Title::newFromRedirectArray( $this->textbox1 ) ) {
1736 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
1737 } else {
1738 $toparse = $this->textbox1;
1739
1740 # If we're adding a comment, we need to show the
1741 # summary as the headline
1742 if ( $this->section=="new" && $this->summary!="" ) {
1743 $toparse="== {$this->summary} ==\n\n".$toparse;
1744 }
1745
1746 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
1747
1748 // Parse mediawiki messages with correct target language
1749 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1750 list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
1751 $obj = wfGetLangObj( $lang );
1752 $parserOptions->setTargetLanguage( $obj );
1753 }
1754
1755
1756 $parserOptions->setTidy(true);
1757 $parserOptions->enableLimitReport();
1758 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
1759 $this->mTitle, $parserOptions );
1760
1761 $previewHTML = $parserOutput->getText();
1762 $this->mParserOutput = $parserOutput;
1763 $wgOut->addParserOutputNoText( $parserOutput );
1764
1765 if ( count( $parserOutput->getWarnings() ) ) {
1766 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1767 }
1768 }
1769
1770 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1771 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
1772 if ( $this->isConflict ) {
1773 $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1774 }
1775
1776 wfProfileOut( __METHOD__ );
1777 return $previewhead . $previewHTML;
1778 }
1779
1780 function getTemplates() {
1781 if ( $this->preview || $this->section != '' ) {
1782 $templates = array();
1783 if ( !isset($this->mParserOutput) ) return $templates;
1784 foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
1785 foreach( array_keys( $template ) as $dbk ) {
1786 $templates[] = Title::makeTitle($ns, $dbk);
1787 }
1788 }
1789 return $templates;
1790 } else {
1791 return $this->mArticle->getUsedTemplates();
1792 }
1793 }
1794
1795 /**
1796 * Call the stock "user is blocked" page
1797 */
1798 function blockedPage() {
1799 global $wgOut, $wgUser;
1800 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1801
1802 # If the user made changes, preserve them when showing the markup
1803 # (This happens when a user is blocked during edit, for instance)
1804 $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
1805 if ( $first ) {
1806 $source = $this->mTitle->exists() ? $this->getContent() : false;
1807 } else {
1808 $source = $this->textbox1;
1809 }
1810
1811 # Spit out the source or the user's modified version
1812 if ( $source !== false ) {
1813 $rows = $wgUser->getIntOption( 'rows' );
1814 $cols = $wgUser->getIntOption( 'cols' );
1815 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1816 $wgOut->addHTML( '<hr />' );
1817 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
1818 # Why we don't use Xml::element here?
1819 # Is it because if $source is '', it returns <textarea />?
1820 $wgOut->addHTML( Xml::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml::closeElement( 'textarea' ) );
1821 }
1822 }
1823
1824 /**
1825 * Produce the stock "please login to edit pages" page
1826 */
1827 function userNotLoggedInPage() {
1828 global $wgUser, $wgOut, $wgTitle;
1829 $skin = $wgUser->getSkin();
1830
1831 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1832 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1833
1834 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1835 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1836 $wgOut->setArticleRelated( false );
1837
1838 $wgOut->addHTML( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1839 $wgOut->returnToMain( false, $wgTitle );
1840 }
1841
1842 /**
1843 * Creates a basic error page which informs the user that
1844 * they have attempted to edit a nonexistent section.
1845 */
1846 function noSuchSectionPage() {
1847 global $wgOut, $wgTitle;
1848
1849 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1850 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1851 $wgOut->setArticleRelated( false );
1852
1853 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section );
1854 $wgOut->returnToMain( false, $wgTitle );
1855 }
1856
1857 /**
1858 * Produce the stock "your edit contains spam" page
1859 *
1860 * @param $match Text which triggered one or more filters
1861 */
1862 function spamPage( $match = false ) {
1863 global $wgOut, $wgTitle;
1864
1865 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1866 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1867 $wgOut->setArticleRelated( false );
1868
1869 $wgOut->addHTML( '<div id="spamprotected">' );
1870 $wgOut->addWikiMsg( 'spamprotectiontext' );
1871 if ( $match )
1872 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1873 $wgOut->addHTML( '</div>' );
1874
1875 $wgOut->returnToMain( false, $wgTitle );
1876 }
1877
1878 /**
1879 * @private
1880 * @todo document
1881 */
1882 function mergeChangesInto( &$editText ){
1883 $fname = 'EditPage::mergeChangesInto';
1884 wfProfileIn( $fname );
1885
1886 $db = wfGetDB( DB_MASTER );
1887
1888 // This is the revision the editor started from
1889 $baseRevision = $this->getBaseRevision();
1890 if ( is_null( $baseRevision ) ) {
1891 wfProfileOut( $fname );
1892 return false;
1893 }
1894 $baseText = $baseRevision->getText();
1895
1896 // The current state, we want to merge updates into it
1897 $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
1898 if ( is_null( $currentRevision ) ) {
1899 wfProfileOut( $fname );
1900 return false;
1901 }
1902 $currentText = $currentRevision->getText();
1903
1904 $result = '';
1905 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
1906 $editText = $result;
1907 wfProfileOut( $fname );
1908 return true;
1909 } else {
1910 wfProfileOut( $fname );
1911 return false;
1912 }
1913 }
1914
1915 /**
1916 * Check if the browser is on a blacklist of user-agents known to
1917 * mangle UTF-8 data on form submission. Returns true if Unicode
1918 * should make it through, false if it's known to be a problem.
1919 * @return bool
1920 * @private
1921 */
1922 function checkUnicodeCompliantBrowser() {
1923 global $wgBrowserBlackList;
1924 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1925 // No User-Agent header sent? Trust it by default...
1926 return true;
1927 }
1928 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1929 foreach ( $wgBrowserBlackList as $browser ) {
1930 if ( preg_match($browser, $currentbrowser) ) {
1931 return false;
1932 }
1933 }
1934 return true;
1935 }
1936
1937 /**
1938 * @deprecated use $wgParser->stripSectionName()
1939 */
1940 function pseudoParseSectionAnchor( $text ) {
1941 global $wgParser;
1942 return $wgParser->stripSectionName( $text );
1943 }
1944
1945 /**
1946 * Format an anchor fragment as it would appear for a given section name
1947 * @param string $text
1948 * @return string
1949 * @private
1950 */
1951 function sectionAnchor( $text ) {
1952 global $wgParser;
1953 return $wgParser->guessSectionNameFromWikiText( $text );
1954 }
1955
1956 /**
1957 * Shows a bulletin board style toolbar for common editing functions.
1958 * It can be disabled in the user preferences.
1959 * The necessary JavaScript code can be found in skins/common/edit.js.
1960 *
1961 * @return string
1962 */
1963 static function getEditToolbar() {
1964 global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
1965
1966 /**
1967 * toolarray an array of arrays which each include the filename of
1968 * the button image (without path), the opening tag, the closing tag,
1969 * and optionally a sample text that is inserted between the two when no
1970 * selection is highlighted.
1971 * The tip text is shown when the user moves the mouse over the button.
1972 *
1973 * Already here are accesskeys (key), which are not used yet until someone
1974 * can figure out a way to make them work in IE. However, we should make
1975 * sure these keys are not defined on the edit page.
1976 */
1977 $toolarray = array(
1978 array(
1979 'image' => $wgLang->getImageFile('button-bold'),
1980 'id' => 'mw-editbutton-bold',
1981 'open' => '\'\'\'',
1982 'close' => '\'\'\'',
1983 'sample' => wfMsg('bold_sample'),
1984 'tip' => wfMsg('bold_tip'),
1985 'key' => 'B'
1986 ),
1987 array(
1988 'image' => $wgLang->getImageFile('button-italic'),
1989 'id' => 'mw-editbutton-italic',
1990 'open' => '\'\'',
1991 'close' => '\'\'',
1992 'sample' => wfMsg('italic_sample'),
1993 'tip' => wfMsg('italic_tip'),
1994 'key' => 'I'
1995 ),
1996 array(
1997 'image' => $wgLang->getImageFile('button-link'),
1998 'id' => 'mw-editbutton-link',
1999 'open' => '[[',
2000 'close' => ']]',
2001 'sample' => wfMsg('link_sample'),
2002 'tip' => wfMsg('link_tip'),
2003 'key' => 'L'
2004 ),
2005 array(
2006 'image' => $wgLang->getImageFile('button-extlink'),
2007 'id' => 'mw-editbutton-extlink',
2008 'open' => '[',
2009 'close' => ']',
2010 'sample' => wfMsg('extlink_sample'),
2011 'tip' => wfMsg('extlink_tip'),
2012 'key' => 'X'
2013 ),
2014 array(
2015 'image' => $wgLang->getImageFile('button-headline'),
2016 'id' => 'mw-editbutton-headline',
2017 'open' => "\n== ",
2018 'close' => " ==\n",
2019 'sample' => wfMsg('headline_sample'),
2020 'tip' => wfMsg('headline_tip'),
2021 'key' => 'H'
2022 ),
2023 array(
2024 'image' => $wgLang->getImageFile('button-image'),
2025 'id' => 'mw-editbutton-image',
2026 'open' => '[['.$wgContLang->getNsText(NS_FILE).':',
2027 'close' => ']]',
2028 'sample' => wfMsg('image_sample'),
2029 'tip' => wfMsg('image_tip'),
2030 'key' => 'D'
2031 ),
2032 array(
2033 'image' => $wgLang->getImageFile('button-media'),
2034 'id' => 'mw-editbutton-media',
2035 'open' => '[['.$wgContLang->getNsText(NS_MEDIA).':',
2036 'close' => ']]',
2037 'sample' => wfMsg('media_sample'),
2038 'tip' => wfMsg('media_tip'),
2039 'key' => 'M'
2040 ),
2041 array(
2042 'image' => $wgLang->getImageFile('button-math'),
2043 'id' => 'mw-editbutton-math',
2044 'open' => "<math>",
2045 'close' => "</math>",
2046 'sample' => wfMsg('math_sample'),
2047 'tip' => wfMsg('math_tip'),
2048 'key' => 'C'
2049 ),
2050 array(
2051 'image' => $wgLang->getImageFile('button-nowiki'),
2052 'id' => 'mw-editbutton-nowiki',
2053 'open' => "<nowiki>",
2054 'close' => "</nowiki>",
2055 'sample' => wfMsg('nowiki_sample'),
2056 'tip' => wfMsg('nowiki_tip'),
2057 'key' => 'N'
2058 ),
2059 array(
2060 'image' => $wgLang->getImageFile('button-sig'),
2061 'id' => 'mw-editbutton-signature',
2062 'open' => '--~~~~',
2063 'close' => '',
2064 'sample' => '',
2065 'tip' => wfMsg('sig_tip'),
2066 'key' => 'Y'
2067 ),
2068 array(
2069 'image' => $wgLang->getImageFile('button-hr'),
2070 'id' => 'mw-editbutton-hr',
2071 'open' => "\n----\n",
2072 'close' => '',
2073 'sample' => '',
2074 'tip' => wfMsg('hr_tip'),
2075 'key' => 'R'
2076 )
2077 );
2078 $toolbar = "<div id='toolbar'>\n";
2079 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
2080
2081 foreach($toolarray as $tool) {
2082 $params = array(
2083 $image = $wgStylePath.'/common/images/'.$tool['image'],
2084 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2085 // Older browsers show a "speedtip" type message only for ALT.
2086 // Ideally these should be different, realistically they
2087 // probably don't need to be.
2088 $tip = $tool['tip'],
2089 $open = $tool['open'],
2090 $close = $tool['close'],
2091 $sample = $tool['sample'],
2092 $cssId = $tool['id'],
2093 );
2094
2095 $paramList = implode( ',',
2096 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2097 $toolbar.="addButton($paramList);\n";
2098 }
2099
2100 $toolbar.="/*]]>*/\n</script>";
2101 $toolbar.="\n</div>";
2102 return $toolbar;
2103 }
2104
2105 /**
2106 * Returns an array of html code of the following checkboxes:
2107 * minor and watch
2108 *
2109 * @param $tabindex Current tabindex
2110 * @param $skin Skin object
2111 * @param $checked Array of checkbox => bool, where bool indicates the checked
2112 * status of the checkbox
2113 *
2114 * @return array
2115 */
2116 public function getCheckboxes( &$tabindex, $skin, $checked ) {
2117 global $wgUser;
2118
2119 $checkboxes = array();
2120
2121 $checkboxes['minor'] = '';
2122 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
2123 if ( $wgUser->isAllowed('minoredit') ) {
2124 $attribs = array(
2125 'tabindex' => ++$tabindex,
2126 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2127 'id' => 'wpMinoredit',
2128 );
2129 $checkboxes['minor'] =
2130 Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2131 "&nbsp;<label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
2132 }
2133
2134 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
2135 $checkboxes['watch'] = '';
2136 if ( $wgUser->isLoggedIn() ) {
2137 $attribs = array(
2138 'tabindex' => ++$tabindex,
2139 'accesskey' => wfMsg( 'accesskey-watch' ),
2140 'id' => 'wpWatchthis',
2141 );
2142 $checkboxes['watch'] =
2143 Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2144 "&nbsp;<label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
2145 }
2146 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2147 return $checkboxes;
2148 }
2149
2150 /**
2151 * Returns an array of html code of the following buttons:
2152 * save, diff, preview and live
2153 *
2154 * @param $tabindex Current tabindex
2155 *
2156 * @return array
2157 */
2158 public function getEditButtons(&$tabindex) {
2159 global $wgLivePreview, $wgUser;
2160
2161 $buttons = array();
2162
2163 $temp = array(
2164 'id' => 'wpSave',
2165 'name' => 'wpSave',
2166 'type' => 'submit',
2167 'tabindex' => ++$tabindex,
2168 'value' => wfMsg('savearticle'),
2169 'accesskey' => wfMsg('accesskey-save'),
2170 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2171 );
2172 $buttons['save'] = Xml::element('input', $temp, '');
2173
2174 ++$tabindex; // use the same for preview and live preview
2175 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
2176 $temp = array(
2177 'id' => 'wpPreview',
2178 'name' => 'wpPreview',
2179 'type' => 'submit',
2180 'tabindex' => $tabindex,
2181 'value' => wfMsg('showpreview'),
2182 'accesskey' => '',
2183 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2184 'style' => 'display: none;',
2185 );
2186 $buttons['preview'] = Xml::element('input', $temp, '');
2187
2188 $temp = array(
2189 'id' => 'wpLivePreview',
2190 'name' => 'wpLivePreview',
2191 'type' => 'submit',
2192 'tabindex' => $tabindex,
2193 'value' => wfMsg('showlivepreview'),
2194 'accesskey' => wfMsg('accesskey-preview'),
2195 'title' => '',
2196 'onclick' => $this->doLivePreviewScript(),
2197 );
2198 $buttons['live'] = Xml::element('input', $temp, '');
2199 } else {
2200 $temp = array(
2201 'id' => 'wpPreview',
2202 'name' => 'wpPreview',
2203 'type' => 'submit',
2204 'tabindex' => $tabindex,
2205 'value' => wfMsg('showpreview'),
2206 'accesskey' => wfMsg('accesskey-preview'),
2207 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2208 );
2209 $buttons['preview'] = Xml::element('input', $temp, '');
2210 $buttons['live'] = '';
2211 }
2212
2213 $temp = array(
2214 'id' => 'wpDiff',
2215 'name' => 'wpDiff',
2216 'type' => 'submit',
2217 'tabindex' => ++$tabindex,
2218 'value' => wfMsg('showdiff'),
2219 'accesskey' => wfMsg('accesskey-diff'),
2220 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2221 );
2222 $buttons['diff'] = Xml::element('input', $temp, '');
2223
2224 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2225 return $buttons;
2226 }
2227
2228 /**
2229 * Output preview text only. This can be sucked into the edit page
2230 * via JavaScript, and saves the server time rendering the skin as
2231 * well as theoretically being more robust on the client (doesn't
2232 * disturb the edit box's undo history, won't eat your text on
2233 * failure, etc).
2234 *
2235 * @todo This doesn't include category or interlanguage links.
2236 * Would need to enhance it a bit, <s>maybe wrap them in XML
2237 * or something...</s> that might also require more skin
2238 * initialization, so check whether that's a problem.
2239 */
2240 function livePreview() {
2241 global $wgOut;
2242 $wgOut->disable();
2243 header( 'Content-type: text/xml; charset=utf-8' );
2244 header( 'Cache-control: no-cache' );
2245
2246 $previewText = $this->getPreviewText();
2247 #$categories = $skin->getCategoryLinks();
2248
2249 $s =
2250 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2251 Xml::tags( 'livepreview', null,
2252 Xml::element( 'preview', null, $previewText )
2253 #. Xml::element( 'category', null, $categories )
2254 );
2255 echo $s;
2256 }
2257
2258
2259 /**
2260 * Get a diff between the current contents of the edit box and the
2261 * version of the page we're editing from.
2262 *
2263 * If this is a section edit, we'll replace the section as for final
2264 * save and then make a comparison.
2265 */
2266 function showDiff() {
2267 $oldtext = $this->mArticle->fetchContent();
2268 $newtext = $this->mArticle->replaceSection(
2269 $this->section, $this->textbox1, $this->summary, $this->edittime );
2270 $newtext = $this->mArticle->preSaveTransform( $newtext );
2271 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2272 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2273 if ( $oldtext !== false || $newtext != '' ) {
2274 $de = new DifferenceEngine( $this->mTitle );
2275 $de->setText( $oldtext, $newtext );
2276 $difftext = $de->getDiff( $oldtitle, $newtitle );
2277 $de->showDiffStyle();
2278 } else {
2279 $difftext = '';
2280 }
2281
2282 global $wgOut;
2283 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2284 }
2285
2286 /**
2287 * Filter an input field through a Unicode de-armoring process if it
2288 * came from an old browser with known broken Unicode editing issues.
2289 *
2290 * @param WebRequest $request
2291 * @param string $field
2292 * @return string
2293 * @private
2294 */
2295 function safeUnicodeInput( $request, $field ) {
2296 $text = rtrim( $request->getText( $field ) );
2297 return $request->getBool( 'safemode' )
2298 ? $this->unmakesafe( $text )
2299 : $text;
2300 }
2301
2302 /**
2303 * Filter an output field through a Unicode armoring process if it is
2304 * going to an old browser with known broken Unicode editing issues.
2305 *
2306 * @param string $text
2307 * @return string
2308 * @private
2309 */
2310 function safeUnicodeOutput( $text ) {
2311 global $wgContLang;
2312 $codedText = $wgContLang->recodeForEdit( $text );
2313 return $this->checkUnicodeCompliantBrowser()
2314 ? $codedText
2315 : $this->makesafe( $codedText );
2316 }
2317
2318 /**
2319 * A number of web browsers are known to corrupt non-ASCII characters
2320 * in a UTF-8 text editing environment. To protect against this,
2321 * detected browsers will be served an armored version of the text,
2322 * with non-ASCII chars converted to numeric HTML character references.
2323 *
2324 * Preexisting such character references will have a 0 added to them
2325 * to ensure that round-trips do not alter the original data.
2326 *
2327 * @param string $invalue
2328 * @return string
2329 * @private
2330 */
2331 function makesafe( $invalue ) {
2332 // Armor existing references for reversability.
2333 $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
2334
2335 $bytesleft = 0;
2336 $result = "";
2337 $working = 0;
2338 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2339 $bytevalue = ord( $invalue{$i} );
2340 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2341 $result .= chr( $bytevalue );
2342 $bytesleft = 0;
2343 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2344 $working = $working << 6;
2345 $working += ($bytevalue & 0x3F);
2346 $bytesleft--;
2347 if ( $bytesleft <= 0 ) {
2348 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2349 }
2350 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2351 $working = $bytevalue & 0x1F;
2352 $bytesleft = 1;
2353 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2354 $working = $bytevalue & 0x0F;
2355 $bytesleft = 2;
2356 } else { //1111 0xxx
2357 $working = $bytevalue & 0x07;
2358 $bytesleft = 3;
2359 }
2360 }
2361 return $result;
2362 }
2363
2364 /**
2365 * Reverse the previously applied transliteration of non-ASCII characters
2366 * back to UTF-8. Used to protect data from corruption by broken web browsers
2367 * as listed in $wgBrowserBlackList.
2368 *
2369 * @param string $invalue
2370 * @return string
2371 * @private
2372 */
2373 function unmakesafe( $invalue ) {
2374 $result = "";
2375 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2376 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
2377 $i += 3;
2378 $hexstring = "";
2379 do {
2380 $hexstring .= $invalue{$i};
2381 $i++;
2382 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2383
2384 // Do some sanity checks. These aren't needed for reversability,
2385 // but should help keep the breakage down if the editor
2386 // breaks one of the entities whilst editing.
2387 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2388 $codepoint = hexdec($hexstring);
2389 $result .= codepointToUtf8( $codepoint );
2390 } else {
2391 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2392 }
2393 } else {
2394 $result .= substr( $invalue, $i, 1 );
2395 }
2396 }
2397 // reverse the transform that we made for reversability reasons.
2398 return strtr( $result, array( "&#x0" => "&#x" ) );
2399 }
2400
2401 function noCreatePermission() {
2402 global $wgOut;
2403 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2404 $wgOut->addWikiMsg( 'nocreatetext' );
2405 }
2406
2407 /**
2408 * If there are rows in the deletion log for this page, show them,
2409 * along with a nice little note for the user
2410 *
2411 * @param OutputPage $out
2412 */
2413 protected function showDeletionLog( $out ) {
2414 global $wgUser;
2415 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2416 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
2417 $count = $pager->getNumRows();
2418 if ( $count > 0 ) {
2419 $pager->mLimit = 10;
2420 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
2421 $out->addWikiMsg( 'recreate-deleted-warn' );
2422 $out->addHTML(
2423 $loglist->beginLogEventsList() .
2424 $pager->getBody() .
2425 $loglist->endLogEventsList()
2426 );
2427 if($count > 10){
2428 $out->addHTML( $wgUser->getSkin()->link(
2429 SpecialPage::getTitleFor( 'Log' ),
2430 wfMsgHtml( 'deletelog-fulllog' ),
2431 array(),
2432 array(
2433 'type' => 'delete',
2434 'page' => $this->mTitle->getPrefixedText() ) ) );
2435 }
2436 $out->addHTML( '</div>' );
2437 return true;
2438 }
2439
2440 return false;
2441 }
2442
2443 /**
2444 * Attempt submission
2445 * @return bool false if output is done, true if the rest of the form should be displayed
2446 */
2447 function attemptSave() {
2448 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2449
2450 $resultDetails = false;
2451 # Allow bots to exempt some edits from bot flagging
2452 $bot = $wgUser->isAllowed('bot') && $wgRequest->getBool('bot',true);
2453 $value = $this->internalAttemptSave( $resultDetails, $bot );
2454
2455 if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
2456 $this->didSave = true;
2457 }
2458
2459 switch ($value) {
2460 case self::AS_HOOK_ERROR_EXPECTED:
2461 case self::AS_CONTENT_TOO_BIG:
2462 case self::AS_ARTICLE_WAS_DELETED:
2463 case self::AS_CONFLICT_DETECTED:
2464 case self::AS_SUMMARY_NEEDED:
2465 case self::AS_TEXTBOX_EMPTY:
2466 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
2467 case self::AS_END:
2468 return true;
2469
2470 case self::AS_HOOK_ERROR:
2471 case self::AS_FILTERING:
2472 case self::AS_SUCCESS_NEW_ARTICLE:
2473 case self::AS_SUCCESS_UPDATE:
2474 return false;
2475
2476 case self::AS_SPAM_ERROR:
2477 $this->spamPage ( $resultDetails['spam'] );
2478 return false;
2479
2480 case self::AS_BLOCKED_PAGE_FOR_USER:
2481 $this->blockedPage();
2482 return false;
2483
2484 case self::AS_IMAGE_REDIRECT_ANON:
2485 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2486 return false;
2487
2488 case self::AS_READ_ONLY_PAGE_ANON:
2489 $this->userNotLoggedInPage();
2490 return false;
2491
2492 case self::AS_READ_ONLY_PAGE_LOGGED:
2493 case self::AS_READ_ONLY_PAGE:
2494 $wgOut->readOnlyPage();
2495 return false;
2496
2497 case self::AS_RATE_LIMITED:
2498 $wgOut->rateLimited();
2499 return false;
2500
2501 case self::AS_NO_CREATE_PERMISSION;
2502 $this->noCreatePermission();
2503 return;
2504
2505 case self::AS_BLANK_ARTICLE:
2506 $wgOut->redirect( $wgTitle->getFullURL() );
2507 return false;
2508
2509 case self::AS_IMAGE_REDIRECT_LOGGED:
2510 $wgOut->permissionRequired( 'upload' );
2511 return false;
2512 }
2513 }
2514
2515 function getBaseRevision() {
2516 if ( $this->mBaseRevision == false ) {
2517 $db = wfGetDB( DB_MASTER );
2518 $baseRevision = Revision::loadFromTimestamp(
2519 $db, $this->mTitle, $this->edittime );
2520 return $this->mBaseRevision = $baseRevision;
2521 } else {
2522 return $this->mBaseRevision;
2523 }
2524 }
2525 }