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