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