Add class="error" for "longpageerror"
[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->section) || !$this->edittime || !$this->starttime ) {
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;
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 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
1300 }
1301
1302 $wgOut->addHTML( $this->editFormPageTop );
1303
1304 if ( $wgUser->getOption( 'previewontop' ) ) {
1305 $this->displayPreviewArea( $previewOutput, true );
1306 }
1307
1308
1309 $wgOut->addHTML( $this->editFormTextTop );
1310
1311 # if this is a comment, show a subject line at the top, which is also the edit summary.
1312 # Otherwise, show a summary field at the bottom
1313 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
1314
1315 # If a blank edit summary was previously provided, and the appropriate
1316 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1317 # user being bounced back more than once in the event that a summary
1318 # is not required.
1319 #####
1320 # For a bit more sophisticated detection of blank summaries, hash the
1321 # automatic one and pass that in the hidden field wpAutoSummary.
1322 $summaryhiddens = '';
1323 if ( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
1324 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
1325 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
1326 if ( $this->section == 'new' ) {
1327 $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 />";
1328 $editsummary = "<div class='editOptions'>\n";
1329 global $wgParser;
1330 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
1331 $subjectpreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">".wfMsg('subject-preview').$colonSep.$sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
1332 $summarypreview = '';
1333 } else {
1334 $commentsubject = '';
1335 $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 />";
1336 $summarypreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">".wfMsg('summary-preview').$colonSep.$sk->commentBlock( $this->summary, $this->mTitle )."</div>\n" : '';
1337 $subjectpreview = '';
1338 }
1339
1340 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1341 if ( !$this->preview && !$this->diff ) {
1342 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1343 }
1344 $templates = $this->getTemplates();
1345 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
1346
1347 $hiddencats = $this->mArticle->getHiddenCategories();
1348 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1349
1350 global $wgUseMetadataEdit ;
1351 if ( $wgUseMetadataEdit ) {
1352 $metadata = $this->mMetaData ;
1353 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1354 $top = wfMsgWikiHtml( 'metadata_help' );
1355 /* ToDo: Replace with clean code */
1356 $ew = $wgUser->getOption( 'editwidth' );
1357 if ( $ew ) $ew = " style=\"width:100%\"";
1358 else $ew = '';
1359 $cols = $wgUser->getIntOption( 'cols' );
1360 /* /ToDo */
1361 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1362 }
1363 else $metadata = "" ;
1364
1365 $recreate = '';
1366 if ( $this->wasDeletedSinceLastEdit() ) {
1367 if ( 'save' != $this->formtype ) {
1368 $wgOut->addWikiMsg('deletedwhileediting');
1369 } else {
1370 // Hide the toolbar and edit area, use can click preview to get it back
1371 // Add an confirmation checkbox and explanation.
1372 $toolbar = '';
1373 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ));
1374 $recreate .=
1375 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1376 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1377 }
1378 }
1379
1380 $tabindex = 2;
1381
1382 $checkboxes = self::getCheckboxes( $tabindex, $sk,
1383 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
1384
1385 $checkboxhtml = implode( $checkboxes, "\n" );
1386
1387 $buttons = $this->getEditButtons( $tabindex );
1388 $buttonshtml = implode( $buttons, "\n" );
1389
1390 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1391 ? '' : Xml::hidden( 'safemode', '1' );
1392
1393 $wgOut->addHTML( <<<END
1394 {$toolbar}
1395 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1396 END
1397 );
1398
1399 if ( is_callable( $formCallback ) ) {
1400 call_user_func_array( $formCallback, array( &$wgOut ) );
1401 }
1402
1403 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1404
1405 // Put these up at the top to ensure they aren't lost on early form submission
1406 $this->showFormBeforeText();
1407
1408 $wgOut->addHTML( <<<END
1409 {$recreate}
1410 {$commentsubject}
1411 {$subjectpreview}
1412 {$this->editFormTextBeforeContent}
1413 END
1414 );
1415 $this->showTextbox1( $classes );
1416
1417 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1418 $wgOut->addHTML( <<<END
1419 {$this->editFormTextAfterWarn}
1420 {$metadata}
1421 {$editsummary}
1422 {$summarypreview}
1423 {$checkboxhtml}
1424 {$safemodehtml}
1425 END
1426 );
1427
1428 $wgOut->addHTML(
1429 "<div class='editButtons'>
1430 {$buttonshtml}
1431 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1432 </div><!-- editButtons -->
1433 </div><!-- editOptions -->");
1434
1435 /**
1436 * To make it harder for someone to slip a user a page
1437 * which submits an edit form to the wiki without their
1438 * knowledge, a random token is associated with the login
1439 * session. If it's not passed back with the submission,
1440 * we won't save the page, or render user JavaScript and
1441 * CSS previews.
1442 *
1443 * For anon editors, who may not have a session, we just
1444 * include the constant suffix to prevent editing from
1445 * broken text-mangling proxies.
1446 */
1447 $token = htmlspecialchars( $wgUser->editToken() );
1448 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1449
1450 $this->showEditTools();
1451
1452 $wgOut->addHTML( <<<END
1453 {$this->editFormTextAfterTools}
1454 <div class='templatesUsed'>
1455 {$formattedtemplates}
1456 </div>
1457 <div class='hiddencats'>
1458 {$formattedhiddencats}
1459 </div>
1460 END
1461 );
1462
1463 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1464 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1465
1466 $de = new DifferenceEngine( $this->mTitle );
1467 $de->setText( $this->textbox2, $this->textbox1 );
1468 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1469
1470 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1471 $this->showTextbox2();
1472 }
1473 $wgOut->addHTML( $this->editFormTextBottom );
1474 $wgOut->addHTML( "</form>\n" );
1475 if ( !$wgUser->getOption( 'previewontop' ) ) {
1476 $this->displayPreviewArea( $previewOutput, false );
1477 }
1478
1479 wfProfileOut( $fname );
1480 }
1481
1482 protected function showFormBeforeText() {
1483 global $wgOut;
1484 $wgOut->addHTML( "
1485 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1486 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1487 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1488 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1489 }
1490
1491 protected function showTextbox1( $classes ) {
1492 $attribs = array( 'tabindex' => 1 );
1493
1494 if ( $this->wasDeletedSinceLastEdit() )
1495 $attribs['type'] = 'hidden';
1496 if ( !empty($classes) )
1497 $attribs['class'] = implode(' ',$classes);
1498
1499 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1500 }
1501
1502 protected function showTextbox2() {
1503 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
1504 }
1505
1506 protected function showTextbox( $content, $name, $attribs = array() ) {
1507 global $wgOut, $wgUser;
1508
1509 $wikitext = $this->safeUnicodeOutput( $content );
1510 if ( $wikitext !== '' ) {
1511 // Ensure there's a newline at the end, otherwise adding lines
1512 // is awkward.
1513 // But don't add a newline if the ext is empty, or Firefox in XHTML
1514 // mode will show an extra newline. A bit annoying.
1515 $wikitext .= "\n";
1516 }
1517
1518 $attribs['accesskey'] = ',';
1519 $attribs['id'] = $name;
1520
1521 if ( $wgUser->getOption( 'editwidth' ) )
1522 $attribs['style'] = 'width: 100%';
1523
1524 $wgOut->addHTML( Xml::textarea(
1525 $name,
1526 $wikitext,
1527 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1528 $attribs ) );
1529 }
1530
1531 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1532 global $wgOut;
1533 $classes = array();
1534 if ( $isOnTop )
1535 $classes[] = 'ontop';
1536
1537 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1538
1539 if ( $this->formtype != 'preview' )
1540 $attribs['style'] = 'display: none;';
1541
1542 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
1543
1544 if ( $this->formtype == 'preview' ) {
1545 $this->showPreview( $previewOutput );
1546 }
1547
1548 $wgOut->addHTML( '</div>' );
1549
1550 if ( $this->formtype == 'diff') {
1551 $this->showDiff();
1552 }
1553 }
1554
1555 /**
1556 * Append preview output to $wgOut.
1557 * Includes category rendering if this is a category page.
1558 *
1559 * @param string $text The HTML to be output for the preview.
1560 */
1561 protected function showPreview( $text ) {
1562 global $wgOut;
1563 if ( $this->mTitle->getNamespace() == NS_CATEGORY) {
1564 $this->mArticle->openShowCategory();
1565 }
1566 # This hook seems slightly odd here, but makes things more
1567 # consistent for extensions.
1568 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1569 $wgOut->addHTML( $text );
1570 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
1571 $this->mArticle->closeShowCategory();
1572 }
1573 }
1574
1575 /**
1576 * Live Preview lets us fetch rendered preview page content and
1577 * add it to the page without refreshing the whole page.
1578 * If not supported by the browser it will fall through to the normal form
1579 * submission method.
1580 *
1581 * This function outputs a script tag to support live preview, and
1582 * returns an onclick handler which should be added to the attributes
1583 * of the preview button
1584 */
1585 function doLivePreviewScript() {
1586 global $wgOut, $wgTitle;
1587 $wgOut->addScriptFile( 'preview.js' );
1588 $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
1589 return "return !lpDoPreview(" .
1590 "editform.wpTextbox1.value," .
1591 '"' . $liveAction . '"' . ")";
1592 }
1593
1594 protected function showEditTools() {
1595 global $wgOut;
1596 $wgOut->addHtml( '<div class="mw-editTools">' );
1597 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1598 $wgOut->addHtml( '</div>' );
1599 }
1600
1601 function getLastDelete() {
1602 $dbr = wfGetDB( DB_SLAVE );
1603 $data = $dbr->selectRow(
1604 array( 'logging', 'user' ),
1605 array( 'log_type',
1606 'log_action',
1607 'log_timestamp',
1608 'log_user',
1609 'log_namespace',
1610 'log_title',
1611 'log_comment',
1612 'log_params',
1613 'user_name', ),
1614 array( 'log_namespace' => $this->mTitle->getNamespace(),
1615 'log_title' => $this->mTitle->getDBkey(),
1616 'log_type' => 'delete',
1617 'log_action' => 'delete',
1618 'user_id=log_user' ),
1619 __METHOD__,
1620 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1621
1622 return $data;
1623 }
1624
1625 /**
1626 * Get the rendered text for previewing.
1627 * @return string
1628 */
1629 function getPreviewText() {
1630 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
1631
1632 wfProfileIn( __METHOD__ );
1633
1634 if ( $this->mTriedSave && !$this->mTokenOk ) {
1635 if ( $this->mTokenOkExceptSuffix ) {
1636 $note = wfMsg( 'token_suffix_mismatch' );
1637 } else {
1638 $note = wfMsg( 'session_fail_preview' );
1639 }
1640 } else {
1641 $note = wfMsg( 'previewnote' );
1642 }
1643
1644 $parserOptions = ParserOptions::newFromUser( $wgUser );
1645 $parserOptions->setEditSection( false );
1646
1647 global $wgRawHtml;
1648 if ( $wgRawHtml && !$this->mTokenOk ) {
1649 // Could be an offsite preview attempt. This is very unsafe if
1650 // HTML is enabled, as it could be an attack.
1651 return $wgOut->parse( "<div class='previewnote'>" .
1652 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1653 }
1654
1655 # don't parse user css/js, show message about preview
1656 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1657
1658 if ( $this->isCssJsSubpage ) {
1659 if (preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
1660 $previewtext = wfMsg('usercsspreview');
1661 } else if (preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
1662 $previewtext = wfMsg('userjspreview');
1663 }
1664 $parserOptions->setTidy(true);
1665 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
1666 $previewHTML = $parserOutput->mText;
1667 } elseif ( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
1668 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
1669 } else {
1670 $toparse = $this->textbox1;
1671
1672 # If we're adding a comment, we need to show the
1673 # summary as the headline
1674 if ( $this->section=="new" && $this->summary!="" ) {
1675 $toparse="== {$this->summary} ==\n\n".$toparse;
1676 }
1677
1678 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
1679
1680 // Parse mediawiki messages with correct target language
1681 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1682 $pos = strrpos( $this->mTitle->getText(), '/' );
1683 if ( $pos !== false ) {
1684 $code = substr( $this->mTitle->getText(), $pos+1 );
1685 switch ($code) {
1686 case $wgLang->getCode():
1687 $obj = $wgLang; break;
1688 case $wgContLang->getCode():
1689 $obj = $wgContLang; break;
1690 default:
1691 $obj = Language::factory( $code );
1692 }
1693 $parserOptions->setTargetLanguage( $obj );
1694 }
1695 }
1696
1697
1698 $parserOptions->setTidy(true);
1699 $parserOptions->enableLimitReport();
1700 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
1701 $this->mTitle, $parserOptions );
1702
1703 $previewHTML = $parserOutput->getText();
1704 $this->mParserOutput = $parserOutput;
1705 $wgOut->addParserOutputNoText( $parserOutput );
1706
1707 if ( count( $parserOutput->getWarnings() ) ) {
1708 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1709 }
1710 }
1711
1712 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1713 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
1714 if ( $this->isConflict ) {
1715 $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1716 }
1717
1718 wfProfileOut( __METHOD__ );
1719 return $previewhead . $previewHTML;
1720 }
1721
1722 function getTemplates() {
1723 if ( $this->preview || $this->section != '' ) {
1724 $templates = array();
1725 if ( !isset($this->mParserOutput) ) return $templates;
1726 foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
1727 foreach( array_keys( $template ) as $dbk ) {
1728 $templates[] = Title::makeTitle($ns, $dbk);
1729 }
1730 }
1731 return $templates;
1732 } else {
1733 return $this->mArticle->getUsedTemplates();
1734 }
1735 }
1736
1737 /**
1738 * Call the stock "user is blocked" page
1739 */
1740 function blockedPage() {
1741 global $wgOut, $wgUser;
1742 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1743
1744 # If the user made changes, preserve them when showing the markup
1745 # (This happens when a user is blocked during edit, for instance)
1746 $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
1747 if ( $first ) {
1748 $source = $this->mTitle->exists() ? $this->getContent() : false;
1749 } else {
1750 $source = $this->textbox1;
1751 }
1752
1753 # Spit out the source or the user's modified version
1754 if ( $source !== false ) {
1755 $rows = $wgUser->getIntOption( 'rows' );
1756 $cols = $wgUser->getIntOption( 'cols' );
1757 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1758 $wgOut->addHtml( '<hr />' );
1759 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
1760 # Why we don't use Xml::element here?
1761 # Is it because if $source is '', it returns <textarea />?
1762 $wgOut->addHtml( Xml::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml::closeElement( 'textarea' ) );
1763 }
1764 }
1765
1766 /**
1767 * Produce the stock "please login to edit pages" page
1768 */
1769 function userNotLoggedInPage() {
1770 global $wgUser, $wgOut, $wgTitle;
1771 $skin = $wgUser->getSkin();
1772
1773 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1774 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1775
1776 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1777 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1778 $wgOut->setArticleRelated( false );
1779
1780 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1781 $wgOut->returnToMain( false, $wgTitle );
1782 }
1783
1784 /**
1785 * Creates a basic error page which informs the user that
1786 * they have attempted to edit a nonexistant section.
1787 */
1788 function noSuchSectionPage() {
1789 global $wgOut, $wgTitle;
1790
1791 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1792 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1793 $wgOut->setArticleRelated( false );
1794
1795 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section );
1796 $wgOut->returnToMain( false, $wgTitle );
1797 }
1798
1799 /**
1800 * Produce the stock "your edit contains spam" page
1801 *
1802 * @param $match Text which triggered one or more filters
1803 */
1804 function spamPage( $match = false ) {
1805 global $wgOut, $wgTitle;
1806
1807 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1808 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1809 $wgOut->setArticleRelated( false );
1810
1811 $wgOut->addHtml( '<div id="spamprotected">' );
1812 $wgOut->addWikiMsg( 'spamprotectiontext' );
1813 if ( $match )
1814 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1815 $wgOut->addHtml( '</div>' );
1816
1817 $wgOut->returnToMain( false, $wgTitle );
1818 }
1819
1820 /**
1821 * @private
1822 * @todo document
1823 */
1824 function mergeChangesInto( &$editText ){
1825 $fname = 'EditPage::mergeChangesInto';
1826 wfProfileIn( $fname );
1827
1828 $db = wfGetDB( DB_MASTER );
1829
1830 // This is the revision the editor started from
1831 $baseRevision = $this->getBaseRevision();
1832 if ( is_null( $baseRevision ) ) {
1833 wfProfileOut( $fname );
1834 return false;
1835 }
1836 $baseText = $baseRevision->getText();
1837
1838 // The current state, we want to merge updates into it
1839 $currentRevision = Revision::loadFromTitle(
1840 $db, $this->mTitle );
1841 if ( is_null( $currentRevision ) ) {
1842 wfProfileOut( $fname );
1843 return false;
1844 }
1845 $currentText = $currentRevision->getText();
1846
1847 $result = '';
1848 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
1849 $editText = $result;
1850 wfProfileOut( $fname );
1851 return true;
1852 } else {
1853 wfProfileOut( $fname );
1854 return false;
1855 }
1856 }
1857
1858 /**
1859 * Check if the browser is on a blacklist of user-agents known to
1860 * mangle UTF-8 data on form submission. Returns true if Unicode
1861 * should make it through, false if it's known to be a problem.
1862 * @return bool
1863 * @private
1864 */
1865 function checkUnicodeCompliantBrowser() {
1866 global $wgBrowserBlackList;
1867 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1868 // No User-Agent header sent? Trust it by default...
1869 return true;
1870 }
1871 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1872 foreach ( $wgBrowserBlackList as $browser ) {
1873 if ( preg_match($browser, $currentbrowser) ) {
1874 return false;
1875 }
1876 }
1877 return true;
1878 }
1879
1880 /**
1881 * @deprecated use $wgParser->stripSectionName()
1882 */
1883 function pseudoParseSectionAnchor( $text ) {
1884 global $wgParser;
1885 return $wgParser->stripSectionName( $text );
1886 }
1887
1888 /**
1889 * Format an anchor fragment as it would appear for a given section name
1890 * @param string $text
1891 * @return string
1892 * @private
1893 */
1894 function sectionAnchor( $text ) {
1895 global $wgParser;
1896 return $wgParser->guessSectionNameFromWikiText( $text );
1897 }
1898
1899 /**
1900 * Shows a bulletin board style toolbar for common editing functions.
1901 * It can be disabled in the user preferences.
1902 * The necessary JavaScript code can be found in skins/common/edit.js.
1903 *
1904 * @return string
1905 */
1906 static function getEditToolbar() {
1907 global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
1908
1909 /**
1910 * toolarray an array of arrays which each include the filename of
1911 * the button image (without path), the opening tag, the closing tag,
1912 * and optionally a sample text that is inserted between the two when no
1913 * selection is highlighted.
1914 * The tip text is shown when the user moves the mouse over the button.
1915 *
1916 * Already here are accesskeys (key), which are not used yet until someone
1917 * can figure out a way to make them work in IE. However, we should make
1918 * sure these keys are not defined on the edit page.
1919 */
1920 $toolarray = array(
1921 array(
1922 'image' => $wgLang->getImageFile('button-bold'),
1923 'id' => 'mw-editbutton-bold',
1924 'open' => '\'\'\'',
1925 'close' => '\'\'\'',
1926 'sample' => wfMsg('bold_sample'),
1927 'tip' => wfMsg('bold_tip'),
1928 'key' => 'B'
1929 ),
1930 array(
1931 'image' => $wgLang->getImageFile('button-italic'),
1932 'id' => 'mw-editbutton-italic',
1933 'open' => '\'\'',
1934 'close' => '\'\'',
1935 'sample' => wfMsg('italic_sample'),
1936 'tip' => wfMsg('italic_tip'),
1937 'key' => 'I'
1938 ),
1939 array(
1940 'image' => $wgLang->getImageFile('button-link'),
1941 'id' => 'mw-editbutton-link',
1942 'open' => '[[',
1943 'close' => ']]',
1944 'sample' => wfMsg('link_sample'),
1945 'tip' => wfMsg('link_tip'),
1946 'key' => 'L'
1947 ),
1948 array(
1949 'image' => $wgLang->getImageFile('button-extlink'),
1950 'id' => 'mw-editbutton-extlink',
1951 'open' => '[',
1952 'close' => ']',
1953 'sample' => wfMsg('extlink_sample'),
1954 'tip' => wfMsg('extlink_tip'),
1955 'key' => 'X'
1956 ),
1957 array(
1958 'image' => $wgLang->getImageFile('button-headline'),
1959 'id' => 'mw-editbutton-headline',
1960 'open' => "\n== ",
1961 'close' => " ==\n",
1962 'sample' => wfMsg('headline_sample'),
1963 'tip' => wfMsg('headline_tip'),
1964 'key' => 'H'
1965 ),
1966 array(
1967 'image' => $wgLang->getImageFile('button-image'),
1968 'id' => 'mw-editbutton-image',
1969 'open' => '[['.$wgContLang->getNsText(NS_IMAGE).':',
1970 'close' => ']]',
1971 'sample' => wfMsg('image_sample'),
1972 'tip' => wfMsg('image_tip'),
1973 'key' => 'D'
1974 ),
1975 array(
1976 'image' => $wgLang->getImageFile('button-media'),
1977 'id' => 'mw-editbutton-media',
1978 'open' => '[['.$wgContLang->getNsText(NS_MEDIA).':',
1979 'close' => ']]',
1980 'sample' => wfMsg('media_sample'),
1981 'tip' => wfMsg('media_tip'),
1982 'key' => 'M'
1983 ),
1984 array(
1985 'image' => $wgLang->getImageFile('button-math'),
1986 'id' => 'mw-editbutton-math',
1987 'open' => "<math>",
1988 'close' => "</math>",
1989 'sample' => wfMsg('math_sample'),
1990 'tip' => wfMsg('math_tip'),
1991 'key' => 'C'
1992 ),
1993 array(
1994 'image' => $wgLang->getImageFile('button-nowiki'),
1995 'id' => 'mw-editbutton-nowiki',
1996 'open' => "<nowiki>",
1997 'close' => "</nowiki>",
1998 'sample' => wfMsg('nowiki_sample'),
1999 'tip' => wfMsg('nowiki_tip'),
2000 'key' => 'N'
2001 ),
2002 array(
2003 'image' => $wgLang->getImageFile('button-sig'),
2004 'id' => 'mw-editbutton-signature',
2005 'open' => '--~~~~',
2006 'close' => '',
2007 'sample' => '',
2008 'tip' => wfMsg('sig_tip'),
2009 'key' => 'Y'
2010 ),
2011 array(
2012 'image' => $wgLang->getImageFile('button-hr'),
2013 'id' => 'mw-editbutton-hr',
2014 'open' => "\n----\n",
2015 'close' => '',
2016 'sample' => '',
2017 'tip' => wfMsg('hr_tip'),
2018 'key' => 'R'
2019 )
2020 );
2021 $toolbar = "<div id='toolbar'>\n";
2022 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
2023
2024 foreach($toolarray as $tool) {
2025 $params = array(
2026 $image = $wgStylePath.'/common/images/'.$tool['image'],
2027 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2028 // Older browsers show a "speedtip" type message only for ALT.
2029 // Ideally these should be different, realistically they
2030 // probably don't need to be.
2031 $tip = $tool['tip'],
2032 $open = $tool['open'],
2033 $close = $tool['close'],
2034 $sample = $tool['sample'],
2035 $cssId = $tool['id'],
2036 );
2037
2038 $paramList = implode( ',',
2039 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2040 $toolbar.="addButton($paramList);\n";
2041 }
2042
2043 $toolbar.="/*]]>*/\n</script>";
2044 $toolbar.="\n</div>";
2045 return $toolbar;
2046 }
2047
2048 /**
2049 * Returns an array of html code of the following checkboxes:
2050 * minor and watch
2051 *
2052 * @param $tabindex Current tabindex
2053 * @param $skin Skin object
2054 * @param $checked Array of checkbox => bool, where bool indicates the checked
2055 * status of the checkbox
2056 *
2057 * @return array
2058 */
2059 public static function getCheckboxes( &$tabindex, $skin, $checked ) {
2060 global $wgUser;
2061
2062 $checkboxes = array();
2063
2064 $checkboxes['minor'] = '';
2065 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
2066 if ( $wgUser->isAllowed('minoredit') ) {
2067 $attribs = array(
2068 'tabindex' => ++$tabindex,
2069 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2070 'id' => 'wpMinoredit',
2071 );
2072 $checkboxes['minor'] =
2073 Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2074 "&nbsp;<label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
2075 }
2076
2077 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
2078 $checkboxes['watch'] = '';
2079 if ( $wgUser->isLoggedIn() ) {
2080 $attribs = array(
2081 'tabindex' => ++$tabindex,
2082 'accesskey' => wfMsg( 'accesskey-watch' ),
2083 'id' => 'wpWatchthis',
2084 );
2085 $checkboxes['watch'] =
2086 Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2087 "&nbsp;<label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
2088 }
2089 return $checkboxes;
2090 }
2091
2092 /**
2093 * Returns an array of html code of the following buttons:
2094 * save, diff, preview and live
2095 *
2096 * @param $tabindex Current tabindex
2097 *
2098 * @return array
2099 */
2100 public function getEditButtons(&$tabindex) {
2101 global $wgLivePreview, $wgUser;
2102
2103 $buttons = array();
2104
2105 $temp = array(
2106 'id' => 'wpSave',
2107 'name' => 'wpSave',
2108 'type' => 'submit',
2109 'tabindex' => ++$tabindex,
2110 'value' => wfMsg('savearticle'),
2111 'accesskey' => wfMsg('accesskey-save'),
2112 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2113 );
2114 $buttons['save'] = Xml::element('input', $temp, '');
2115
2116 ++$tabindex; // use the same for preview and live preview
2117 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
2118 $temp = array(
2119 'id' => 'wpPreview',
2120 'name' => 'wpPreview',
2121 'type' => 'submit',
2122 'tabindex' => $tabindex,
2123 'value' => wfMsg('showpreview'),
2124 'accesskey' => '',
2125 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2126 'style' => 'display: none;',
2127 );
2128 $buttons['preview'] = Xml::element('input', $temp, '');
2129
2130 $temp = array(
2131 'id' => 'wpLivePreview',
2132 'name' => 'wpLivePreview',
2133 'type' => 'submit',
2134 'tabindex' => $tabindex,
2135 'value' => wfMsg('showlivepreview'),
2136 'accesskey' => wfMsg('accesskey-preview'),
2137 'title' => '',
2138 'onclick' => $this->doLivePreviewScript(),
2139 );
2140 $buttons['live'] = Xml::element('input', $temp, '');
2141 } else {
2142 $temp = array(
2143 'id' => 'wpPreview',
2144 'name' => 'wpPreview',
2145 'type' => 'submit',
2146 'tabindex' => $tabindex,
2147 'value' => wfMsg('showpreview'),
2148 'accesskey' => wfMsg('accesskey-preview'),
2149 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2150 );
2151 $buttons['preview'] = Xml::element('input', $temp, '');
2152 $buttons['live'] = '';
2153 }
2154
2155 $temp = array(
2156 'id' => 'wpDiff',
2157 'name' => 'wpDiff',
2158 'type' => 'submit',
2159 'tabindex' => ++$tabindex,
2160 'value' => wfMsg('showdiff'),
2161 'accesskey' => wfMsg('accesskey-diff'),
2162 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2163 );
2164 $buttons['diff'] = Xml::element('input', $temp, '');
2165
2166 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons ) );
2167 return $buttons;
2168 }
2169
2170 /**
2171 * Output preview text only. This can be sucked into the edit page
2172 * via JavaScript, and saves the server time rendering the skin as
2173 * well as theoretically being more robust on the client (doesn't
2174 * disturb the edit box's undo history, won't eat your text on
2175 * failure, etc).
2176 *
2177 * @todo This doesn't include category or interlanguage links.
2178 * Would need to enhance it a bit, <s>maybe wrap them in XML
2179 * or something...</s> that might also require more skin
2180 * initialization, so check whether that's a problem.
2181 */
2182 function livePreview() {
2183 global $wgOut;
2184 $wgOut->disable();
2185 header( 'Content-type: text/xml; charset=utf-8' );
2186 header( 'Cache-control: no-cache' );
2187
2188 $previewText = $this->getPreviewText();
2189 #$categories = $skin->getCategoryLinks();
2190
2191 $s =
2192 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2193 Xml::tags( 'livepreview', null,
2194 Xml::element( 'preview', null, $previewText )
2195 #. Xml::element( 'category', null, $categories )
2196 );
2197 echo $s;
2198 }
2199
2200
2201 /**
2202 * Get a diff between the current contents of the edit box and the
2203 * version of the page we're editing from.
2204 *
2205 * If this is a section edit, we'll replace the section as for final
2206 * save and then make a comparison.
2207 */
2208 function showDiff() {
2209 $oldtext = $this->mArticle->fetchContent();
2210 $newtext = $this->mArticle->replaceSection(
2211 $this->section, $this->textbox1, $this->summary, $this->edittime );
2212 $newtext = $this->mArticle->preSaveTransform( $newtext );
2213 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2214 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2215 if ( $oldtext !== false || $newtext != '' ) {
2216 $de = new DifferenceEngine( $this->mTitle );
2217 $de->setText( $oldtext, $newtext );
2218 $difftext = $de->getDiff( $oldtitle, $newtitle );
2219 $de->showDiffStyle();
2220 } else {
2221 $difftext = '';
2222 }
2223
2224 global $wgOut;
2225 $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
2226 }
2227
2228 /**
2229 * Filter an input field through a Unicode de-armoring process if it
2230 * came from an old browser with known broken Unicode editing issues.
2231 *
2232 * @param WebRequest $request
2233 * @param string $field
2234 * @return string
2235 * @private
2236 */
2237 function safeUnicodeInput( $request, $field ) {
2238 $text = rtrim( $request->getText( $field ) );
2239 return $request->getBool( 'safemode' )
2240 ? $this->unmakesafe( $text )
2241 : $text;
2242 }
2243
2244 /**
2245 * Filter an output field through a Unicode armoring process if it is
2246 * going to an old browser with known broken Unicode editing issues.
2247 *
2248 * @param string $text
2249 * @return string
2250 * @private
2251 */
2252 function safeUnicodeOutput( $text ) {
2253 global $wgContLang;
2254 $codedText = $wgContLang->recodeForEdit( $text );
2255 return $this->checkUnicodeCompliantBrowser()
2256 ? $codedText
2257 : $this->makesafe( $codedText );
2258 }
2259
2260 /**
2261 * A number of web browsers are known to corrupt non-ASCII characters
2262 * in a UTF-8 text editing environment. To protect against this,
2263 * detected browsers will be served an armored version of the text,
2264 * with non-ASCII chars converted to numeric HTML character references.
2265 *
2266 * Preexisting such character references will have a 0 added to them
2267 * to ensure that round-trips do not alter the original data.
2268 *
2269 * @param string $invalue
2270 * @return string
2271 * @private
2272 */
2273 function makesafe( $invalue ) {
2274 // Armor existing references for reversability.
2275 $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
2276
2277 $bytesleft = 0;
2278 $result = "";
2279 $working = 0;
2280 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2281 $bytevalue = ord( $invalue{$i} );
2282 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2283 $result .= chr( $bytevalue );
2284 $bytesleft = 0;
2285 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2286 $working = $working << 6;
2287 $working += ($bytevalue & 0x3F);
2288 $bytesleft--;
2289 if ( $bytesleft <= 0 ) {
2290 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2291 }
2292 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2293 $working = $bytevalue & 0x1F;
2294 $bytesleft = 1;
2295 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2296 $working = $bytevalue & 0x0F;
2297 $bytesleft = 2;
2298 } else { //1111 0xxx
2299 $working = $bytevalue & 0x07;
2300 $bytesleft = 3;
2301 }
2302 }
2303 return $result;
2304 }
2305
2306 /**
2307 * Reverse the previously applied transliteration of non-ASCII characters
2308 * back to UTF-8. Used to protect data from corruption by broken web browsers
2309 * as listed in $wgBrowserBlackList.
2310 *
2311 * @param string $invalue
2312 * @return string
2313 * @private
2314 */
2315 function unmakesafe( $invalue ) {
2316 $result = "";
2317 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2318 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
2319 $i += 3;
2320 $hexstring = "";
2321 do {
2322 $hexstring .= $invalue{$i};
2323 $i++;
2324 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2325
2326 // Do some sanity checks. These aren't needed for reversability,
2327 // but should help keep the breakage down if the editor
2328 // breaks one of the entities whilst editing.
2329 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2330 $codepoint = hexdec($hexstring);
2331 $result .= codepointToUtf8( $codepoint );
2332 } else {
2333 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2334 }
2335 } else {
2336 $result .= substr( $invalue, $i, 1 );
2337 }
2338 }
2339 // reverse the transform that we made for reversability reasons.
2340 return strtr( $result, array( "&#x0" => "&#x" ) );
2341 }
2342
2343 function noCreatePermission() {
2344 global $wgOut;
2345 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2346 $wgOut->addWikiMsg( 'nocreatetext' );
2347 }
2348
2349 /**
2350 * If there are rows in the deletion log for this page, show them,
2351 * along with a nice little note for the user
2352 *
2353 * @param OutputPage $out
2354 */
2355 protected function showDeletionLog( $out ) {
2356 global $wgUser;
2357 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2358 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
2359 $count = $pager->getNumRows();
2360 if ( $count > 0 ) {
2361 $pager->mLimit = 10;
2362 $out->addHtml( '<div class="mw-warning-with-logexcerpt">' );
2363 $out->addWikiMsg( 'recreate-deleted-warn' );
2364 $out->addHTML(
2365 $loglist->beginLogEventsList() .
2366 $pager->getBody() .
2367 $loglist->endLogEventsList()
2368 );
2369 if($count > 10){
2370 $out->addHtml( $wgUser->getSkin()->link(
2371 SpecialPage::getTitleFor( 'Log' ),
2372 wfMsgHtml( 'deletelog-fulllog' ),
2373 array(),
2374 array(
2375 'type' => 'delete',
2376 'page' => $this->mTitle->getPrefixedText() ) ) );
2377 }
2378 $out->addHtml( '</div>' );
2379 return true;
2380 }
2381
2382 return false;
2383 }
2384
2385 /**
2386 * Attempt submission
2387 * @return bool false if output is done, true if the rest of the form should be displayed
2388 */
2389 function attemptSave() {
2390 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2391
2392 $resultDetails = false;
2393 $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
2394
2395 if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
2396 $this->didSave = true;
2397 }
2398
2399 switch ($value) {
2400 case self::AS_HOOK_ERROR_EXPECTED:
2401 case self::AS_CONTENT_TOO_BIG:
2402 case self::AS_ARTICLE_WAS_DELETED:
2403 case self::AS_CONFLICT_DETECTED:
2404 case self::AS_SUMMARY_NEEDED:
2405 case self::AS_TEXTBOX_EMPTY:
2406 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
2407 case self::AS_END:
2408 return true;
2409
2410 case self::AS_HOOK_ERROR:
2411 case self::AS_FILTERING:
2412 case self::AS_SUCCESS_NEW_ARTICLE:
2413 case self::AS_SUCCESS_UPDATE:
2414 return false;
2415
2416 case self::AS_SPAM_ERROR:
2417 $this->spamPage ( $resultDetails['spam'] );
2418 return false;
2419
2420 case self::AS_BLOCKED_PAGE_FOR_USER:
2421 $this->blockedPage();
2422 return false;
2423
2424 case self::AS_IMAGE_REDIRECT_ANON:
2425 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2426 return false;
2427
2428 case self::AS_READ_ONLY_PAGE_ANON:
2429 $this->userNotLoggedInPage();
2430 return false;
2431
2432 case self::AS_READ_ONLY_PAGE_LOGGED:
2433 case self::AS_READ_ONLY_PAGE:
2434 $wgOut->readOnlyPage();
2435 return false;
2436
2437 case self::AS_RATE_LIMITED:
2438 $wgOut->rateLimited();
2439 return false;
2440
2441 case self::AS_NO_CREATE_PERMISSION;
2442 $this->noCreatePermission();
2443 return;
2444
2445 case self::AS_BLANK_ARTICLE:
2446 $wgOut->redirect( $wgTitle->getFullURL() );
2447 return false;
2448
2449 case self::AS_IMAGE_REDIRECT_LOGGED:
2450 $wgOut->permissionRequired( 'upload' );
2451 return false;
2452 }
2453 }
2454
2455 function getBaseRevision() {
2456 if ( $this->mBaseRevision == false ) {
2457 $db = wfGetDB( DB_MASTER );
2458 $baseRevision = Revision::loadFromTimestamp(
2459 $db, $this->mTitle, $this->edittime );
2460 return $this->mBaseRevision = $baseRevision;
2461 } else {
2462 return $this->mBaseRevision;
2463 }
2464 }
2465 }