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