* Short-circuit userWasLastToEdit()
[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 $fname = 'EditPage::importFormData';
550 wfProfileIn( $fname );
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( "$fname: 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( "$fname: Passed token check.\n" );
593 } else if ( $this->diff ) {
594 # Failed token check, but only requested "Show Changes".
595 wfDebug( "$fname: 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( "$fname: 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( "$fname: 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 elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) {
648 $this->summary = $request->getText( 'summary' );
649 }
650
651 if ( $request->getVal( 'minor' ) ) {
652 $this->minoredit = true;
653 }
654 }
655
656 $this->oldid = $request->getInt( 'oldid' );
657
658 $this->live = $request->getCheck( 'live' );
659 $this->editintro = $request->getText( 'editintro' );
660
661 wfProfileOut( $fname );
662 }
663
664 /**
665 * Make sure the form isn't faking a user's credentials.
666 *
667 * @param $request WebRequest
668 * @return bool
669 * @private
670 */
671 function tokenOk( &$request ) {
672 global $wgUser;
673 $token = $request->getVal( 'wpEditToken' );
674 $this->mTokenOk = $wgUser->matchEditToken( $token );
675 $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
676 return $this->mTokenOk;
677 }
678
679 /**
680 * Show all applicable editing introductions
681 */
682 protected function showIntro() {
683 global $wgOut, $wgUser;
684 if ( $this->suppressIntro ) {
685 return;
686 }
687 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
688 if ( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
689 $parts = explode( '/', $this->mTitle->getText(), 2 );
690 $username = $parts[0];
691 $id = User::idFromName( $username );
692 $ip = User::isIP( $username );
693 if ( $id == 0 && !$ip ) {
694 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
695 array( 'userpage-userdoesnotexist', $username ) );
696 }
697 }
698 # Try to add a custom edit intro, or use the standard one if this is not possible.
699 if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
700 if ( $wgUser->isLoggedIn() ) {
701 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
702 } else {
703 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
704 }
705 }
706 # Give a notice if the user is editing a deleted page...
707 if ( !$this->mTitle->exists() ) {
708 $this->showDeletionLog( $wgOut );
709 }
710 }
711
712 /**
713 * Attempt to show a custom editing introduction, if supplied
714 *
715 * @return bool
716 */
717 protected function showCustomIntro() {
718 if ( $this->editintro ) {
719 $title = Title::newFromText( $this->editintro );
720 if ( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
721 global $wgOut;
722 $revision = Revision::newFromTitle( $title );
723 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle );
724 return true;
725 } else {
726 return false;
727 }
728 } else {
729 return false;
730 }
731 }
732
733 /**
734 * Attempt submission (no UI)
735 * @return one of the constants describing the result
736 */
737 function internalAttemptSave( &$result, $bot = false ) {
738 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
739 global $wgMaxArticleSize;
740
741 $fname = 'EditPage::attemptSave';
742 wfProfileIn( $fname );
743 wfProfileIn( "$fname-checks" );
744
745 if ( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
746 {
747 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
748 return self::AS_HOOK_ERROR;
749 }
750
751 # Check image redirect
752 if ( $this->mTitle->getNamespace() == NS_FILE &&
753 Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
754 !$wgUser->isAllowed( 'upload' ) ) {
755 if ( $wgUser->isAnon() ) {
756 return self::AS_IMAGE_REDIRECT_ANON;
757 } else {
758 return self::AS_IMAGE_REDIRECT_LOGGED;
759 }
760 }
761
762 # Reintegrate metadata
763 if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
764 $this->mMetaData = '' ;
765
766 # Check for spam
767 $match = self::matchSpamRegex( $this->summary );
768 if ( $match === false ) {
769 $match = self::matchSpamRegex( $this->textbox1 );
770 }
771 if ( $match !== false ) {
772 $result['spam'] = $match;
773 $ip = wfGetIP();
774 $pdbk = $this->mTitle->getPrefixedDBkey();
775 $match = str_replace( "\n", '', $match );
776 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
777 wfProfileOut( "$fname-checks" );
778 wfProfileOut( $fname );
779 return self::AS_SPAM_ERROR;
780 }
781 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
782 # Error messages or other handling should be performed by the filter function
783 wfProfileOut( "$fname-checks" );
784 wfProfileOut( $fname );
785 return self::AS_FILTERING;
786 }
787 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
788 # Error messages etc. could be handled within the hook...
789 wfProfileOut( "$fname-checks" );
790 wfProfileOut( $fname );
791 return self::AS_HOOK_ERROR;
792 } elseif ( $this->hookError != '' ) {
793 # ...or the hook could be expecting us to produce an error
794 wfProfileOut( "$fname-checks" );
795 wfProfileOut( $fname );
796 return self::AS_HOOK_ERROR_EXPECTED;
797 }
798 if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
799 # Check block state against master, thus 'false'.
800 wfProfileOut( "$fname-checks" );
801 wfProfileOut( $fname );
802 return self::AS_BLOCKED_PAGE_FOR_USER;
803 }
804 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
805 if ( $this->kblength > $wgMaxArticleSize ) {
806 // Error will be displayed by showEditForm()
807 $this->tooBig = true;
808 wfProfileOut( "$fname-checks" );
809 wfProfileOut( $fname );
810 return self::AS_CONTENT_TOO_BIG;
811 }
812
813 if ( !$wgUser->isAllowed('edit') ) {
814 if ( $wgUser->isAnon() ) {
815 wfProfileOut( "$fname-checks" );
816 wfProfileOut( $fname );
817 return self::AS_READ_ONLY_PAGE_ANON;
818 }
819 else {
820 wfProfileOut( "$fname-checks" );
821 wfProfileOut( $fname );
822 return self::AS_READ_ONLY_PAGE_LOGGED;
823 }
824 }
825
826 if ( wfReadOnly() ) {
827 wfProfileOut( "$fname-checks" );
828 wfProfileOut( $fname );
829 return self::AS_READ_ONLY_PAGE;
830 }
831 if ( $wgUser->pingLimiter() ) {
832 wfProfileOut( "$fname-checks" );
833 wfProfileOut( $fname );
834 return self::AS_RATE_LIMITED;
835 }
836
837 # If the article has been deleted while editing, don't save it without
838 # confirmation
839 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
840 wfProfileOut( "$fname-checks" );
841 wfProfileOut( $fname );
842 return self::AS_ARTICLE_WAS_DELETED;
843 }
844
845 wfProfileOut( "$fname-checks" );
846
847 # If article is new, insert it.
848 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
849 if ( 0 == $aid ) {
850 // Late check for create permission, just in case *PARANOIA*
851 if ( !$this->mTitle->userCan( 'create' ) ) {
852 wfDebug( "$fname: no create permission\n" );
853 wfProfileOut( $fname );
854 return self::AS_NO_CREATE_PERMISSION;
855 }
856
857 # Don't save a new article if it's blank.
858 if ( '' == $this->textbox1 ) {
859 wfProfileOut( $fname );
860 return self::AS_BLANK_ARTICLE;
861 }
862
863 // Run post-section-merge edit filter
864 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
865 # Error messages etc. could be handled within the hook...
866 wfProfileOut( $fname );
867 return self::AS_HOOK_ERROR;
868 }
869
870 $isComment = ( $this->section == 'new' );
871
872 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
873 $this->minoredit, $this->watchthis, false, $isComment, $bot);
874
875 wfProfileOut( $fname );
876 return self::AS_SUCCESS_NEW_ARTICLE;
877 }
878
879 # Article exists. Check for edit conflict.
880
881 $this->mArticle->clear(); # Force reload of dates, etc.
882 $this->mArticle->forUpdate( true ); # Lock the article
883
884 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
885
886 if ( $this->mArticle->getTimestamp() != $this->edittime ) {
887 $this->isConflict = true;
888 if ( $this->section == 'new' ) {
889 if ( $this->mArticle->getUserText() == $wgUser->getName() &&
890 $this->mArticle->getComment() == $this->summary ) {
891 // Probably a duplicate submission of a new comment.
892 // This can happen when squid resends a request after
893 // a timeout but the first one actually went through.
894 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
895 } else {
896 // New comment; suppress conflict.
897 $this->isConflict = false;
898 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
899 }
900 }
901 }
902 $userid = $wgUser->getId();
903
904 # Suppress edit conflict with self, except for section edits where merging is required.
905 if ( $this->isConflict && $this->section == '' && $this->userWasLastToEdit($userid,$this->edittime) ) {
906 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
907 $this->isConflict = false;
908 }
909
910 if ( $this->isConflict ) {
911 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
912 $this->mArticle->getTimestamp() . "')\n" );
913 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
914 } else {
915 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
916 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
917 }
918 if ( is_null( $text ) ) {
919 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
920 $this->isConflict = true;
921 $text = $this->textbox1;
922 }
923
924 if ( $this->isConflict ) {
925 # Attempt merge
926 if ( $this->mergeChangesInto( $text ) ) {
927 // Successful merge! Maybe we should tell the user the good news?
928 $this->isConflict = false;
929 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
930 } else {
931 $this->section = '';
932 $this->textbox1 = $text;
933 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
934 }
935 }
936
937 if ( $this->isConflict ) {
938 wfProfileOut( $fname );
939 return self::AS_CONFLICT_DETECTED;
940 }
941
942 $oldtext = $this->mArticle->getContent();
943
944 // Run post-section-merge edit filter
945 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
946 # Error messages etc. could be handled within the hook...
947 wfProfileOut( $fname );
948 return self::AS_HOOK_ERROR;
949 }
950
951 # Handle the user preference to force summaries here, but not for null edits
952 if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext, $text) &&
953 !is_object( Title::newFromRedirect( $text ) ) # check if it's not a redirect
954 ) {
955 if ( md5( $this->summary ) == $this->autoSumm ) {
956 $this->missingSummary = true;
957 wfProfileOut( $fname );
958 return self::AS_SUMMARY_NEEDED;
959 }
960 }
961
962 # And a similar thing for new sections
963 if ( $this->section == 'new' && !$this->allowBlankSummary ) {
964 if (trim($this->summary) == '') {
965 $this->missingSummary = true;
966 wfProfileOut( $fname );
967 return self::AS_SUMMARY_NEEDED;
968 }
969 }
970
971 # All's well
972 wfProfileIn( "$fname-sectionanchor" );
973 $sectionanchor = '';
974 if ( $this->section == 'new' ) {
975 if ( $this->textbox1 == '' ) {
976 $this->missingComment = true;
977 return self::AS_TEXTBOX_EMPTY;
978 }
979 if ( $this->summary != '' ) {
980 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
981 # This is a new section, so create a link to the new section
982 # in the revision summary.
983 $cleanSummary = $wgParser->stripSectionName( $this->summary );
984 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary );
985 }
986 } elseif ( $this->section != '' ) {
987 # Try to get a section anchor from the section source, redirect to edited section if header found
988 # XXX: might be better to integrate this into Article::replaceSection
989 # for duplicate heading checking and maybe parsing
990 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
991 # we can't deal with anchors, includes, html etc in the header for now,
992 # headline would need to be parsed to improve this
993 if ( $hasmatch and strlen($matches[2]) > 0 ) {
994 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
995 }
996 }
997 wfProfileOut( "$fname-sectionanchor" );
998
999 // Save errors may fall down to the edit form, but we've now
1000 // merged the section into full text. Clear the section field
1001 // so that later submission of conflict forms won't try to
1002 // replace that into a duplicated mess.
1003 $this->textbox1 = $text;
1004 $this->section = '';
1005
1006 // Check for length errors again now that the section is merged in
1007 $this->kblength = (int)(strlen( $text ) / 1024);
1008 if ( $this->kblength > $wgMaxArticleSize ) {
1009 $this->tooBig = true;
1010 wfProfileOut( $fname );
1011 return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
1012 }
1013
1014 # update the article here
1015 if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
1016 $this->watchthis, $bot, $sectionanchor ) )
1017 {
1018 wfProfileOut( $fname );
1019 return self::AS_SUCCESS_UPDATE;
1020 } else {
1021 $this->isConflict = true;
1022 }
1023 wfProfileOut( $fname );
1024 return self::AS_END;
1025 }
1026
1027 /**
1028 * Check if no edits were made by other users since
1029 * the time a user started editing the page. Limit to
1030 * 50 revisions for the sake of performance.
1031 */
1032 protected function userWasLastToEdit( $id, $edittime ) {
1033 if( !$id ) return false;
1034 $dbw = wfGetDB( DB_MASTER );
1035 $res = $dbw->select( 'revision',
1036 'rev_user',
1037 array(
1038 'rev_page' => $this->mArticle->getId(),
1039 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1040 ),
1041 __METHOD__,
1042 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1043 while( $row = $res->fetchObject() ) {
1044 if( $row->rev_user != $id ) {
1045 return false;
1046 }
1047 }
1048 return true;
1049 }
1050
1051 /**
1052 * Check given input text against $wgSpamRegex, and return the text of the first match.
1053 * @return mixed -- matching string or false
1054 */
1055 public static function matchSpamRegex( $text ) {
1056 global $wgSpamRegex;
1057 if ( $wgSpamRegex ) {
1058 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1059 $regexes = (array)$wgSpamRegex;
1060 foreach( $regexes as $regex ) {
1061 $matches = array();
1062 if ( preg_match( $regex, $text, $matches ) ) {
1063 return $matches[0];
1064 }
1065 }
1066 }
1067 return false;
1068 }
1069
1070 /**
1071 * Initialise form fields in the object
1072 * Called on the first invocation, e.g. when a user clicks an edit link
1073 */
1074 function initialiseForm() {
1075 $this->edittime = $this->mArticle->getTimestamp();
1076 $this->textbox1 = $this->getContent( false );
1077 if ( $this->textbox1 === false ) return false;
1078 wfProxyCheck();
1079 return true;
1080 }
1081
1082 function setHeaders() {
1083 global $wgOut, $wgTitle;
1084 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1085 if ( $this->formtype == 'preview' ) {
1086 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1087 }
1088 if ( $this->isConflict ) {
1089 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1090 } elseif ( $this->section != '' ) {
1091 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1092 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1093 } else {
1094 # Use the title defined by DISPLAYTITLE magic word when present
1095 if ( isset($this->mParserOutput)
1096 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
1097 $title = $dt;
1098 } else {
1099 $title = $wgTitle->getPrefixedText();
1100 }
1101 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1102 }
1103 }
1104
1105 /**
1106 * Send the edit form and related headers to $wgOut
1107 * @param $formCallback Optional callable that takes an OutputPage
1108 * parameter; will be called during form output
1109 * near the top, for captchas and the like.
1110 */
1111 function showEditForm( $formCallback=null ) {
1112 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle, $wgRequest;
1113
1114 # If $wgTitle is null, that means we're in API mode.
1115 # Some hook probably called this function without checking
1116 # for is_null($wgTitle) first. Bail out right here so we don't
1117 # do lots of work just to discard it right after.
1118 if (is_null($wgTitle))
1119 return;
1120
1121 $fname = 'EditPage::showEditForm';
1122 wfProfileIn( $fname );
1123
1124 $sk = $wgUser->getSkin();
1125
1126 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
1127
1128 #need to parse the preview early so that we know which templates are used,
1129 #otherwise users with "show preview after edit box" will get a blank list
1130 #we parse this near the beginning so that setHeaders can do the title
1131 #setting work instead of leaving it in getPreviewText
1132 $previewOutput = '';
1133 if ( $this->formtype == 'preview' ) {
1134 $previewOutput = $this->getPreviewText();
1135 }
1136
1137 $this->setHeaders();
1138
1139 # Enabled article-related sidebar, toplinks, etc.
1140 $wgOut->setArticleRelated( true );
1141
1142 if ( $this->isConflict ) {
1143 $wgOut->addWikiMsg( 'explainconflict' );
1144
1145 $this->textbox2 = $this->textbox1;
1146 $this->textbox1 = $this->getContent();
1147 $this->edittime = $this->mArticle->getTimestamp();
1148 } else {
1149 if ( $this->section != '' && $this->section != 'new' ) {
1150 $matches = array();
1151 if ( !$this->summary && !$this->preview && !$this->diff ) {
1152 preg_match( "/^(=+)(.+)\\1/mi",
1153 $this->textbox1,
1154 $matches );
1155 if ( !empty( $matches[2] ) ) {
1156 global $wgParser;
1157 $this->summary = "/* " .
1158 $wgParser->stripSectionName(trim($matches[2])) .
1159 " */ ";
1160 }
1161 }
1162 }
1163
1164 if ( $this->missingComment ) {
1165 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1166 }
1167
1168 if ( $this->missingSummary && $this->section != 'new' ) {
1169 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1170 }
1171
1172 if ( $this->missingSummary && $this->section == 'new' ) {
1173 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1174 }
1175
1176 if ( $this->hookError !== '' ) {
1177 $wgOut->addWikiText( $this->hookError );
1178 }
1179
1180 if ( !$this->checkUnicodeCompliantBrowser() ) {
1181 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1182 }
1183 if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) {
1184 // Let sysop know that this will make private content public if saved
1185
1186 if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
1187 $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
1188 } else if ( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1189 $wgOut->addWikiMsg( 'rev-deleted-text-view' );
1190 }
1191
1192 if ( !$this->mArticle->mRevision->isCurrent() ) {
1193 $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
1194 $wgOut->addWikiMsg( 'editingold' );
1195 }
1196 }
1197 }
1198
1199 if ( wfReadOnly() ) {
1200 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1201 } elseif ( $wgUser->isAnon() && $this->formtype != 'preview' ) {
1202 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
1203 } else {
1204 if ( $this->isCssJsSubpage ) {
1205 # Check the skin exists
1206 if ( $this->isValidCssJsSubpage ) {
1207 if ( $this->formtype !== 'preview' ) {
1208 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
1209 }
1210 } else {
1211 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1212 }
1213 }
1214 }
1215
1216 $classes = array(); // Textarea CSS
1217 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1218 # Show a warning if editing an interface message
1219 $wgOut->addWikiMsg( 'editinginterface' );
1220 } elseif ( $this->mTitle->isProtected( 'edit' ) ) {
1221 # Is the title semi-protected?
1222 if ( $this->mTitle->isSemiProtected() ) {
1223 $noticeMsg = 'semiprotectedpagewarning';
1224 $classes[] = 'mw-textarea-sprotected';
1225 } else {
1226 # Then it must be protected based on static groups (regular)
1227 $noticeMsg = 'protectedpagewarning';
1228 $classes[] = 'mw-textarea-protected';
1229 }
1230 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
1231 $wgOut->addWikiMsg( $noticeMsg );
1232 LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '', 1 );
1233 $wgOut->addHTML( "</div>\n" );
1234 }
1235 if ( $this->mTitle->isCascadeProtected() ) {
1236 # Is this page under cascading protection from some source pages?
1237 list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
1238 $notice = "$1\n";
1239 if ( count($cascadeSources) > 0 ) {
1240 # Explain, and list the titles responsible
1241 foreach( $cascadeSources as $page ) {
1242 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1243 }
1244 }
1245 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', count($cascadeSources) ) );
1246 }
1247 if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
1248 $wgOut->addWikiMsg( 'titleprotectedwarning' );
1249 }
1250
1251 if ( $this->kblength === false ) {
1252 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
1253 }
1254 if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
1255 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
1256 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) );
1257 $wgOut->addHTML( "</div>\n" );
1258 } elseif ( $this->kblength > 29 ) {
1259 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1260 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) );
1261 $wgOut->addHTML( "</div>\n" );
1262 }
1263
1264 $q = 'action='.$this->action;
1265 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1266 $action = $wgTitle->escapeLocalURL( $q );
1267
1268 $summary = wfMsg( 'summary' );
1269 $subject = wfMsg( 'subject' );
1270
1271 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
1272 wfMsgExt('cancel', array('parseinline')) );
1273 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1274 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1275 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1276 htmlspecialchars( wfMsg( 'newwindow' ) );
1277
1278 global $wgRightsText;
1279 if ( $wgRightsText ) {
1280 $copywarnMsg = array( 'copyrightwarning',
1281 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1282 $wgRightsText );
1283 } else {
1284 $copywarnMsg = array( 'copyrightwarning2',
1285 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1286 }
1287
1288 if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
1289 # prepare toolbar for edit buttons
1290 $toolbar = EditPage::getEditToolbar();
1291 } else {
1292 $toolbar = '';
1293 }
1294
1295 // activate checkboxes if user wants them to be always active
1296 if ( !$this->preview && !$this->diff ) {
1297 # Sort out the "watch" checkbox
1298 if ( $wgUser->getOption( 'watchdefault' ) ) {
1299 # Watch all edits
1300 $this->watchthis = true;
1301 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1302 # Watch creations
1303 $this->watchthis = true;
1304 } elseif ( $this->mTitle->userIsWatching() ) {
1305 # Already watched
1306 $this->watchthis = true;
1307 }
1308
1309 # May be overriden by request parameters
1310 if( $wgRequest->getBool( 'watchthis' ) ) {
1311 $this->watchthis = true;
1312 }
1313
1314 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
1315 }
1316
1317 $wgOut->addHTML( $this->editFormPageTop );
1318
1319 if ( $wgUser->getOption( 'previewontop' ) ) {
1320 $this->displayPreviewArea( $previewOutput, true );
1321 }
1322
1323
1324 $wgOut->addHTML( $this->editFormTextTop );
1325
1326 # if this is a comment, show a subject line at the top, which is also the edit summary.
1327 # Otherwise, show a summary field at the bottom
1328 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
1329
1330 # If a blank edit summary was previously provided, and the appropriate
1331 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1332 # user being bounced back more than once in the event that a summary
1333 # is not required.
1334 #####
1335 # For a bit more sophisticated detection of blank summaries, hash the
1336 # automatic one and pass that in the hidden field wpAutoSummary.
1337 $summaryhiddens = '';
1338 if ( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
1339 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
1340 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
1341 if ( $this->section == 'new' ) {
1342 $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 />";
1343 $editsummary = "<div class='editOptions'>\n";
1344 global $wgParser;
1345 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
1346 $subjectpreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">". wfMsg('subject-preview') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
1347 $summarypreview = '';
1348 } else {
1349 $commentsubject = '';
1350 $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 />";
1351 $summarypreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">". wfMsg('summary-preview') .$sk->commentBlock( $this->summary, $this->mTitle )."</div>\n" : '';
1352 $subjectpreview = '';
1353 }
1354
1355 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1356 if ( !$this->preview && !$this->diff ) {
1357 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1358 }
1359 $templates = $this->getTemplates();
1360 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
1361
1362 $hiddencats = $this->mArticle->getHiddenCategories();
1363 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1364
1365 global $wgUseMetadataEdit ;
1366 if ( $wgUseMetadataEdit ) {
1367 $metadata = $this->mMetaData ;
1368 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1369 $top = wfMsgWikiHtml( 'metadata_help' );
1370 /* ToDo: Replace with clean code */
1371 $ew = $wgUser->getOption( 'editwidth' );
1372 if ( $ew ) $ew = " style=\"width:100%\"";
1373 else $ew = '';
1374 $cols = $wgUser->getIntOption( 'cols' );
1375 /* /ToDo */
1376 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1377 }
1378 else $metadata = "" ;
1379
1380 $recreate = '';
1381 if ( $this->wasDeletedSinceLastEdit() ) {
1382 if ( 'save' != $this->formtype ) {
1383 $wgOut->addWikiMsg('deletedwhileediting');
1384 } else {
1385 // Hide the toolbar and edit area, use can click preview to get it back
1386 // Add an confirmation checkbox and explanation.
1387 $toolbar = '';
1388 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ));
1389 $recreate .=
1390 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1391 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1392 }
1393 }
1394
1395 $tabindex = 2;
1396
1397 $checkboxes = $this->getCheckboxes( $tabindex, $sk,
1398 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
1399
1400 $checkboxhtml = implode( $checkboxes, "\n" );
1401
1402 $buttons = $this->getEditButtons( $tabindex );
1403 $buttonshtml = implode( $buttons, "\n" );
1404
1405 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1406 ? '' : Xml::hidden( 'safemode', '1' );
1407
1408 $wgOut->addHTML( <<<END
1409 {$toolbar}
1410 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1411 END
1412 );
1413
1414 if ( is_callable( $formCallback ) ) {
1415 call_user_func_array( $formCallback, array( &$wgOut ) );
1416 }
1417
1418 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1419
1420 // Put these up at the top to ensure they aren't lost on early form submission
1421 $this->showFormBeforeText();
1422
1423 $wgOut->addHTML( <<<END
1424 {$recreate}
1425 {$commentsubject}
1426 {$subjectpreview}
1427 {$this->editFormTextBeforeContent}
1428 END
1429 );
1430 $this->showTextbox1( $classes );
1431
1432 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1433 $wgOut->addHTML( <<<END
1434 {$this->editFormTextAfterWarn}
1435 {$metadata}
1436 {$editsummary}
1437 {$summarypreview}
1438 {$checkboxhtml}
1439 {$safemodehtml}
1440 END
1441 );
1442
1443 $wgOut->addHTML(
1444 "<div class='editButtons'>
1445 {$buttonshtml}
1446 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1447 </div><!-- editButtons -->
1448 </div><!-- editOptions -->");
1449
1450 /**
1451 * To make it harder for someone to slip a user a page
1452 * which submits an edit form to the wiki without their
1453 * knowledge, a random token is associated with the login
1454 * session. If it's not passed back with the submission,
1455 * we won't save the page, or render user JavaScript and
1456 * CSS previews.
1457 *
1458 * For anon editors, who may not have a session, we just
1459 * include the constant suffix to prevent editing from
1460 * broken text-mangling proxies.
1461 */
1462 $token = htmlspecialchars( $wgUser->editToken() );
1463 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1464
1465 $this->showEditTools();
1466
1467 $wgOut->addHTML( <<<END
1468 {$this->editFormTextAfterTools}
1469 <div class='templatesUsed'>
1470 {$formattedtemplates}
1471 </div>
1472 <div class='hiddencats'>
1473 {$formattedhiddencats}
1474 </div>
1475 END
1476 );
1477
1478 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1479 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1480
1481 $de = new DifferenceEngine( $this->mTitle );
1482 $de->setText( $this->textbox2, $this->textbox1 );
1483 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1484
1485 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1486 $this->showTextbox2();
1487 }
1488 $wgOut->addHTML( $this->editFormTextBottom );
1489 $wgOut->addHTML( "</form>\n" );
1490 if ( !$wgUser->getOption( 'previewontop' ) ) {
1491 $this->displayPreviewArea( $previewOutput, false );
1492 }
1493
1494 wfProfileOut( $fname );
1495 }
1496
1497 protected function showFormBeforeText() {
1498 global $wgOut;
1499 $wgOut->addHTML( "
1500 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1501 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1502 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1503 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1504 }
1505
1506 protected function showTextbox1( $classes ) {
1507 $attribs = array( 'tabindex' => 1 );
1508
1509 if ( $this->wasDeletedSinceLastEdit() )
1510 $attribs['type'] = 'hidden';
1511 if ( !empty($classes) )
1512 $attribs['class'] = implode(' ',$classes);
1513
1514 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1515 }
1516
1517 protected function showTextbox2() {
1518 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
1519 }
1520
1521 protected function showTextbox( $content, $name, $attribs = array() ) {
1522 global $wgOut, $wgUser;
1523
1524 $wikitext = $this->safeUnicodeOutput( $content );
1525 if ( $wikitext !== '' ) {
1526 // Ensure there's a newline at the end, otherwise adding lines
1527 // is awkward.
1528 // But don't add a newline if the ext is empty, or Firefox in XHTML
1529 // mode will show an extra newline. A bit annoying.
1530 $wikitext .= "\n";
1531 }
1532
1533 $attribs['accesskey'] = ',';
1534 $attribs['id'] = $name;
1535
1536 if ( $wgUser->getOption( 'editwidth' ) )
1537 $attribs['style'] = 'width: 100%';
1538
1539 $wgOut->addHTML( Xml::textarea(
1540 $name,
1541 $wikitext,
1542 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1543 $attribs ) );
1544 }
1545
1546 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1547 global $wgOut;
1548 $classes = array();
1549 if ( $isOnTop )
1550 $classes[] = 'ontop';
1551
1552 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1553
1554 if ( $this->formtype != 'preview' )
1555 $attribs['style'] = 'display: none;';
1556
1557 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
1558
1559 if ( $this->formtype == 'preview' ) {
1560 $this->showPreview( $previewOutput );
1561 }
1562
1563 $wgOut->addHTML( '</div>' );
1564
1565 if ( $this->formtype == 'diff') {
1566 $this->showDiff();
1567 }
1568 }
1569
1570 /**
1571 * Append preview output to $wgOut.
1572 * Includes category rendering if this is a category page.
1573 *
1574 * @param string $text The HTML to be output for the preview.
1575 */
1576 protected function showPreview( $text ) {
1577 global $wgOut;
1578 if ( $this->mTitle->getNamespace() == NS_CATEGORY) {
1579 $this->mArticle->openShowCategory();
1580 }
1581 # This hook seems slightly odd here, but makes things more
1582 # consistent for extensions.
1583 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1584 $wgOut->addHTML( $text );
1585 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
1586 $this->mArticle->closeShowCategory();
1587 }
1588 }
1589
1590 /**
1591 * Live Preview lets us fetch rendered preview page content and
1592 * add it to the page without refreshing the whole page.
1593 * If not supported by the browser it will fall through to the normal form
1594 * submission method.
1595 *
1596 * This function outputs a script tag to support live preview, and
1597 * returns an onclick handler which should be added to the attributes
1598 * of the preview button
1599 */
1600 function doLivePreviewScript() {
1601 global $wgOut, $wgTitle;
1602 $wgOut->addScriptFile( 'preview.js' );
1603 $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
1604 return "return !lpDoPreview(" .
1605 "editform.wpTextbox1.value," .
1606 '"' . $liveAction . '"' . ")";
1607 }
1608
1609 protected function showEditTools() {
1610 global $wgOut;
1611 $wgOut->addHTML( '<div class="mw-editTools">' );
1612 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1613 $wgOut->addHTML( '</div>' );
1614 }
1615
1616 function getLastDelete() {
1617 $dbr = wfGetDB( DB_SLAVE );
1618 $data = $dbr->selectRow(
1619 array( 'logging', 'user' ),
1620 array( 'log_type',
1621 'log_action',
1622 'log_timestamp',
1623 'log_user',
1624 'log_namespace',
1625 'log_title',
1626 'log_comment',
1627 'log_params',
1628 'user_name', ),
1629 array( 'log_namespace' => $this->mTitle->getNamespace(),
1630 'log_title' => $this->mTitle->getDBkey(),
1631 'log_type' => 'delete',
1632 'log_action' => 'delete',
1633 'user_id=log_user' ),
1634 __METHOD__,
1635 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1636
1637 return $data;
1638 }
1639
1640 /**
1641 * Get the rendered text for previewing.
1642 * @return string
1643 */
1644 function getPreviewText() {
1645 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
1646
1647 wfProfileIn( __METHOD__ );
1648
1649 if ( $this->mTriedSave && !$this->mTokenOk ) {
1650 if ( $this->mTokenOkExceptSuffix ) {
1651 $note = wfMsg( 'token_suffix_mismatch' );
1652 } else {
1653 $note = wfMsg( 'session_fail_preview' );
1654 }
1655 } else {
1656 $note = wfMsg( 'previewnote' );
1657 }
1658
1659 $parserOptions = ParserOptions::newFromUser( $wgUser );
1660 $parserOptions->setEditSection( false );
1661
1662 global $wgRawHtml;
1663 if ( $wgRawHtml && !$this->mTokenOk ) {
1664 // Could be an offsite preview attempt. This is very unsafe if
1665 // HTML is enabled, as it could be an attack.
1666 return $wgOut->parse( "<div class='previewnote'>" .
1667 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1668 }
1669
1670 # don't parse user css/js, show message about preview
1671 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1672
1673 if ( $this->isCssJsSubpage ) {
1674 if (preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
1675 $previewtext = wfMsg('usercsspreview');
1676 } else if (preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
1677 $previewtext = wfMsg('userjspreview');
1678 }
1679 $parserOptions->setTidy(true);
1680 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
1681 $previewHTML = $parserOutput->mText;
1682 } elseif ( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
1683 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
1684 } else {
1685 $toparse = $this->textbox1;
1686
1687 # If we're adding a comment, we need to show the
1688 # summary as the headline
1689 if ( $this->section=="new" && $this->summary!="" ) {
1690 $toparse="== {$this->summary} ==\n\n".$toparse;
1691 }
1692
1693 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
1694
1695 // Parse mediawiki messages with correct target language
1696 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1697 list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
1698 $obj = wfGetLangObj( $lang );
1699 $parserOptions->setTargetLanguage( $obj );
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 nonexistent 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_FILE).':',
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 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 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2095 return $checkboxes;
2096 }
2097
2098 /**
2099 * Returns an array of html code of the following buttons:
2100 * save, diff, preview and live
2101 *
2102 * @param $tabindex Current tabindex
2103 *
2104 * @return array
2105 */
2106 public function getEditButtons(&$tabindex) {
2107 global $wgLivePreview, $wgUser;
2108
2109 $buttons = array();
2110
2111 $temp = array(
2112 'id' => 'wpSave',
2113 'name' => 'wpSave',
2114 'type' => 'submit',
2115 'tabindex' => ++$tabindex,
2116 'value' => wfMsg('savearticle'),
2117 'accesskey' => wfMsg('accesskey-save'),
2118 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2119 );
2120 $buttons['save'] = Xml::element('input', $temp, '');
2121
2122 ++$tabindex; // use the same for preview and live preview
2123 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
2124 $temp = array(
2125 'id' => 'wpPreview',
2126 'name' => 'wpPreview',
2127 'type' => 'submit',
2128 'tabindex' => $tabindex,
2129 'value' => wfMsg('showpreview'),
2130 'accesskey' => '',
2131 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2132 'style' => 'display: none;',
2133 );
2134 $buttons['preview'] = Xml::element('input', $temp, '');
2135
2136 $temp = array(
2137 'id' => 'wpLivePreview',
2138 'name' => 'wpLivePreview',
2139 'type' => 'submit',
2140 'tabindex' => $tabindex,
2141 'value' => wfMsg('showlivepreview'),
2142 'accesskey' => wfMsg('accesskey-preview'),
2143 'title' => '',
2144 'onclick' => $this->doLivePreviewScript(),
2145 );
2146 $buttons['live'] = Xml::element('input', $temp, '');
2147 } else {
2148 $temp = array(
2149 'id' => 'wpPreview',
2150 'name' => 'wpPreview',
2151 'type' => 'submit',
2152 'tabindex' => $tabindex,
2153 'value' => wfMsg('showpreview'),
2154 'accesskey' => wfMsg('accesskey-preview'),
2155 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2156 );
2157 $buttons['preview'] = Xml::element('input', $temp, '');
2158 $buttons['live'] = '';
2159 }
2160
2161 $temp = array(
2162 'id' => 'wpDiff',
2163 'name' => 'wpDiff',
2164 'type' => 'submit',
2165 'tabindex' => ++$tabindex,
2166 'value' => wfMsg('showdiff'),
2167 'accesskey' => wfMsg('accesskey-diff'),
2168 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2169 );
2170 $buttons['diff'] = Xml::element('input', $temp, '');
2171
2172 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2173 return $buttons;
2174 }
2175
2176 /**
2177 * Output preview text only. This can be sucked into the edit page
2178 * via JavaScript, and saves the server time rendering the skin as
2179 * well as theoretically being more robust on the client (doesn't
2180 * disturb the edit box's undo history, won't eat your text on
2181 * failure, etc).
2182 *
2183 * @todo This doesn't include category or interlanguage links.
2184 * Would need to enhance it a bit, <s>maybe wrap them in XML
2185 * or something...</s> that might also require more skin
2186 * initialization, so check whether that's a problem.
2187 */
2188 function livePreview() {
2189 global $wgOut;
2190 $wgOut->disable();
2191 header( 'Content-type: text/xml; charset=utf-8' );
2192 header( 'Cache-control: no-cache' );
2193
2194 $previewText = $this->getPreviewText();
2195 #$categories = $skin->getCategoryLinks();
2196
2197 $s =
2198 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2199 Xml::tags( 'livepreview', null,
2200 Xml::element( 'preview', null, $previewText )
2201 #. Xml::element( 'category', null, $categories )
2202 );
2203 echo $s;
2204 }
2205
2206
2207 /**
2208 * Get a diff between the current contents of the edit box and the
2209 * version of the page we're editing from.
2210 *
2211 * If this is a section edit, we'll replace the section as for final
2212 * save and then make a comparison.
2213 */
2214 function showDiff() {
2215 $oldtext = $this->mArticle->fetchContent();
2216 $newtext = $this->mArticle->replaceSection(
2217 $this->section, $this->textbox1, $this->summary, $this->edittime );
2218 $newtext = $this->mArticle->preSaveTransform( $newtext );
2219 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2220 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2221 if ( $oldtext !== false || $newtext != '' ) {
2222 $de = new DifferenceEngine( $this->mTitle );
2223 $de->setText( $oldtext, $newtext );
2224 $difftext = $de->getDiff( $oldtitle, $newtitle );
2225 $de->showDiffStyle();
2226 } else {
2227 $difftext = '';
2228 }
2229
2230 global $wgOut;
2231 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2232 }
2233
2234 /**
2235 * Filter an input field through a Unicode de-armoring process if it
2236 * came from an old browser with known broken Unicode editing issues.
2237 *
2238 * @param WebRequest $request
2239 * @param string $field
2240 * @return string
2241 * @private
2242 */
2243 function safeUnicodeInput( $request, $field ) {
2244 $text = rtrim( $request->getText( $field ) );
2245 return $request->getBool( 'safemode' )
2246 ? $this->unmakesafe( $text )
2247 : $text;
2248 }
2249
2250 /**
2251 * Filter an output field through a Unicode armoring process if it is
2252 * going to an old browser with known broken Unicode editing issues.
2253 *
2254 * @param string $text
2255 * @return string
2256 * @private
2257 */
2258 function safeUnicodeOutput( $text ) {
2259 global $wgContLang;
2260 $codedText = $wgContLang->recodeForEdit( $text );
2261 return $this->checkUnicodeCompliantBrowser()
2262 ? $codedText
2263 : $this->makesafe( $codedText );
2264 }
2265
2266 /**
2267 * A number of web browsers are known to corrupt non-ASCII characters
2268 * in a UTF-8 text editing environment. To protect against this,
2269 * detected browsers will be served an armored version of the text,
2270 * with non-ASCII chars converted to numeric HTML character references.
2271 *
2272 * Preexisting such character references will have a 0 added to them
2273 * to ensure that round-trips do not alter the original data.
2274 *
2275 * @param string $invalue
2276 * @return string
2277 * @private
2278 */
2279 function makesafe( $invalue ) {
2280 // Armor existing references for reversability.
2281 $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
2282
2283 $bytesleft = 0;
2284 $result = "";
2285 $working = 0;
2286 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2287 $bytevalue = ord( $invalue{$i} );
2288 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2289 $result .= chr( $bytevalue );
2290 $bytesleft = 0;
2291 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2292 $working = $working << 6;
2293 $working += ($bytevalue & 0x3F);
2294 $bytesleft--;
2295 if ( $bytesleft <= 0 ) {
2296 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2297 }
2298 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2299 $working = $bytevalue & 0x1F;
2300 $bytesleft = 1;
2301 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2302 $working = $bytevalue & 0x0F;
2303 $bytesleft = 2;
2304 } else { //1111 0xxx
2305 $working = $bytevalue & 0x07;
2306 $bytesleft = 3;
2307 }
2308 }
2309 return $result;
2310 }
2311
2312 /**
2313 * Reverse the previously applied transliteration of non-ASCII characters
2314 * back to UTF-8. Used to protect data from corruption by broken web browsers
2315 * as listed in $wgBrowserBlackList.
2316 *
2317 * @param string $invalue
2318 * @return string
2319 * @private
2320 */
2321 function unmakesafe( $invalue ) {
2322 $result = "";
2323 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2324 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
2325 $i += 3;
2326 $hexstring = "";
2327 do {
2328 $hexstring .= $invalue{$i};
2329 $i++;
2330 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2331
2332 // Do some sanity checks. These aren't needed for reversability,
2333 // but should help keep the breakage down if the editor
2334 // breaks one of the entities whilst editing.
2335 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2336 $codepoint = hexdec($hexstring);
2337 $result .= codepointToUtf8( $codepoint );
2338 } else {
2339 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2340 }
2341 } else {
2342 $result .= substr( $invalue, $i, 1 );
2343 }
2344 }
2345 // reverse the transform that we made for reversability reasons.
2346 return strtr( $result, array( "&#x0" => "&#x" ) );
2347 }
2348
2349 function noCreatePermission() {
2350 global $wgOut;
2351 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2352 $wgOut->addWikiMsg( 'nocreatetext' );
2353 }
2354
2355 /**
2356 * If there are rows in the deletion log for this page, show them,
2357 * along with a nice little note for the user
2358 *
2359 * @param OutputPage $out
2360 */
2361 protected function showDeletionLog( $out ) {
2362 global $wgUser;
2363 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2364 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
2365 $count = $pager->getNumRows();
2366 if ( $count > 0 ) {
2367 $pager->mLimit = 10;
2368 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
2369 $out->addWikiMsg( 'recreate-deleted-warn' );
2370 $out->addHTML(
2371 $loglist->beginLogEventsList() .
2372 $pager->getBody() .
2373 $loglist->endLogEventsList()
2374 );
2375 if($count > 10){
2376 $out->addHTML( $wgUser->getSkin()->link(
2377 SpecialPage::getTitleFor( 'Log' ),
2378 wfMsgHtml( 'deletelog-fulllog' ),
2379 array(),
2380 array(
2381 'type' => 'delete',
2382 'page' => $this->mTitle->getPrefixedText() ) ) );
2383 }
2384 $out->addHTML( '</div>' );
2385 return true;
2386 }
2387
2388 return false;
2389 }
2390
2391 /**
2392 * Attempt submission
2393 * @return bool false if output is done, true if the rest of the form should be displayed
2394 */
2395 function attemptSave() {
2396 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2397
2398 $resultDetails = false;
2399 $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
2400
2401 if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
2402 $this->didSave = true;
2403 }
2404
2405 switch ($value) {
2406 case self::AS_HOOK_ERROR_EXPECTED:
2407 case self::AS_CONTENT_TOO_BIG:
2408 case self::AS_ARTICLE_WAS_DELETED:
2409 case self::AS_CONFLICT_DETECTED:
2410 case self::AS_SUMMARY_NEEDED:
2411 case self::AS_TEXTBOX_EMPTY:
2412 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
2413 case self::AS_END:
2414 return true;
2415
2416 case self::AS_HOOK_ERROR:
2417 case self::AS_FILTERING:
2418 case self::AS_SUCCESS_NEW_ARTICLE:
2419 case self::AS_SUCCESS_UPDATE:
2420 return false;
2421
2422 case self::AS_SPAM_ERROR:
2423 $this->spamPage ( $resultDetails['spam'] );
2424 return false;
2425
2426 case self::AS_BLOCKED_PAGE_FOR_USER:
2427 $this->blockedPage();
2428 return false;
2429
2430 case self::AS_IMAGE_REDIRECT_ANON:
2431 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2432 return false;
2433
2434 case self::AS_READ_ONLY_PAGE_ANON:
2435 $this->userNotLoggedInPage();
2436 return false;
2437
2438 case self::AS_READ_ONLY_PAGE_LOGGED:
2439 case self::AS_READ_ONLY_PAGE:
2440 $wgOut->readOnlyPage();
2441 return false;
2442
2443 case self::AS_RATE_LIMITED:
2444 $wgOut->rateLimited();
2445 return false;
2446
2447 case self::AS_NO_CREATE_PERMISSION;
2448 $this->noCreatePermission();
2449 return;
2450
2451 case self::AS_BLANK_ARTICLE:
2452 $wgOut->redirect( $wgTitle->getFullURL() );
2453 return false;
2454
2455 case self::AS_IMAGE_REDIRECT_LOGGED:
2456 $wgOut->permissionRequired( 'upload' );
2457 return false;
2458 }
2459 }
2460
2461 function getBaseRevision() {
2462 if ( $this->mBaseRevision == false ) {
2463 $db = wfGetDB( DB_MASTER );
2464 $baseRevision = Revision::loadFromTimestamp(
2465 $db, $this->mTitle, $this->edittime );
2466 return $this->mBaseRevision = $baseRevision;
2467 } else {
2468 return $this->mBaseRevision;
2469 }
2470 }
2471 }