Duplicate code
[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
845 // Late check for create permission, just in case *PARANOIA*
846 if ( !$this->mTitle->userCan( 'create' ) ) {
847 wfDebug( "$fname: no create permission\n" );
848 wfProfileOut( $fname );
849 return self::AS_NO_CREATE_PERMISSION;
850 }
851
852 # Don't save a new article if it's blank.
853 if ( '' == $this->textbox1 ) {
854 wfProfileOut( $fname );
855 return self::AS_BLANK_ARTICLE;
856 }
857
858 // Run post-section-merge edit filter
859 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
860 # Error messages etc. could be handled within the hook...
861 wfProfileOut( $fname );
862 return self::AS_HOOK_ERROR;
863 }
864
865 $isComment = ( $this->section == 'new' );
866
867 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
868 $this->minoredit, $this->watchthis, false, $isComment, $bot);
869
870 wfProfileOut( $fname );
871 return self::AS_SUCCESS_NEW_ARTICLE;
872 }
873
874 # Article exists. Check for edit conflict.
875
876 $this->mArticle->clear(); # Force reload of dates, etc.
877 $this->mArticle->forUpdate( true ); # Lock the article
878
879 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
880
881 if ( $this->mArticle->getTimestamp() != $this->edittime ) {
882 $this->isConflict = true;
883 if ( $this->section == 'new' ) {
884 if ( $this->mArticle->getUserText() == $wgUser->getName() &&
885 $this->mArticle->getComment() == $this->summary ) {
886 // Probably a duplicate submission of a new comment.
887 // This can happen when squid resends a request after
888 // a timeout but the first one actually went through.
889 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
890 } else {
891 // New comment; suppress conflict.
892 $this->isConflict = false;
893 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
894 }
895 }
896 }
897 $userid = $wgUser->getId();
898
899 if ( $this->isConflict ) {
900 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
901 $this->mArticle->getTimestamp() . "')\n" );
902 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime);
903 }
904 else {
905 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
906 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary);
907 }
908 if ( is_null( $text ) ) {
909 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
910 $this->isConflict = true;
911 $text = $this->textbox1;
912 }
913
914 # Suppress edit conflict with self, except for section edits where merging is required.
915 if ( ( $this->section == '' ) && ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
916 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
917 $this->isConflict = false;
918 } else {
919 # switch from section editing to normal editing in edit conflict
920 if ( $this->isConflict ) {
921 # Attempt merge
922 if ( $this->mergeChangesInto( $text ) ) {
923 // Successful merge! Maybe we should tell the user the good news?
924 $this->isConflict = false;
925 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
926 } else {
927 $this->section = '';
928 $this->textbox1 = $text;
929 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
930 }
931 }
932 }
933
934 if ( $this->isConflict ) {
935 wfProfileOut( $fname );
936 return self::AS_CONFLICT_DETECTED;
937 }
938
939 $oldtext = $this->mArticle->getContent();
940
941 // Run post-section-merge edit filter
942 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
943 # Error messages etc. could be handled within the hook...
944 wfProfileOut( $fname );
945 return self::AS_HOOK_ERROR;
946 }
947
948 # Handle the user preference to force summaries here, but not for null edits
949 if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext, $text) &&
950 !is_object( Title::newFromRedirect( $text ) ) # check if it's not a redirect
951 ) {
952 if ( md5( $this->summary ) == $this->autoSumm ) {
953 $this->missingSummary = true;
954 wfProfileOut( $fname );
955 return self::AS_SUMMARY_NEEDED;
956 }
957 }
958
959 # And a similar thing for new sections
960 if ( $this->section == 'new' && !$this->allowBlankSummary ) {
961 if (trim($this->summary) == '') {
962 $this->missingSummary = true;
963 wfProfileOut( $fname );
964 return self::AS_SUMMARY_NEEDED;
965 }
966 }
967
968 # All's well
969 wfProfileIn( "$fname-sectionanchor" );
970 $sectionanchor = '';
971 if ( $this->section == 'new' ) {
972 if ( $this->textbox1 == '' ) {
973 $this->missingComment = true;
974 return self::AS_TEXTBOX_EMPTY;
975 }
976 if ( $this->summary != '' ) {
977 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
978 # This is a new section, so create a link to the new section
979 # in the revision summary.
980 $cleanSummary = $wgParser->stripSectionName( $this->summary );
981 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary );
982 }
983 } elseif ( $this->section != '' ) {
984 # Try to get a section anchor from the section source, redirect to edited section if header found
985 # XXX: might be better to integrate this into Article::replaceSection
986 # for duplicate heading checking and maybe parsing
987 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
988 # we can't deal with anchors, includes, html etc in the header for now,
989 # headline would need to be parsed to improve this
990 if ( $hasmatch and strlen($matches[2]) > 0 ) {
991 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
992 }
993 }
994 wfProfileOut( "$fname-sectionanchor" );
995
996 // Save errors may fall down to the edit form, but we've now
997 // merged the section into full text. Clear the section field
998 // so that later submission of conflict forms won't try to
999 // replace that into a duplicated mess.
1000 $this->textbox1 = $text;
1001 $this->section = '';
1002
1003 // Check for length errors again now that the section is merged in
1004 $this->kblength = (int)(strlen( $text ) / 1024);
1005 if ( $this->kblength > $wgMaxArticleSize ) {
1006 $this->tooBig = true;
1007 wfProfileOut( $fname );
1008 return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
1009 }
1010
1011 # update the article here
1012 if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
1013 $this->watchthis, $bot, $sectionanchor ) ) {
1014 wfProfileOut( $fname );
1015 return self::AS_SUCCESS_UPDATE;
1016 } else {
1017 $this->isConflict = true;
1018 }
1019 wfProfileOut( $fname );
1020 return self::AS_END;
1021 }
1022
1023 /**
1024 * Check given input text against $wgSpamRegex, and return the text of the first match.
1025 * @return mixed -- matching string or false
1026 */
1027 public static function matchSpamRegex( $text ) {
1028 global $wgSpamRegex;
1029 if ( $wgSpamRegex ) {
1030 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1031 $regexes = (array)$wgSpamRegex;
1032 foreach( $regexes as $regex ) {
1033 $matches = array();
1034 if ( preg_match( $regex, $text, $matches ) ) {
1035 return $matches[0];
1036 }
1037 }
1038 }
1039 return false;
1040 }
1041
1042 /**
1043 * Initialise form fields in the object
1044 * Called on the first invocation, e.g. when a user clicks an edit link
1045 */
1046 function initialiseForm() {
1047 $this->edittime = $this->mArticle->getTimestamp();
1048 $this->textbox1 = $this->getContent(false);
1049 if ( $this->textbox1 === false) return false;
1050
1051 if ( !$this->mArticle->exists() && $this->mTitle->getNamespace() == NS_MEDIAWIKI )
1052 $this->textbox1 = wfMsgWeirdKey( $this->mTitle->getText() );
1053 wfProxyCheck();
1054 return true;
1055 }
1056
1057 function setHeaders() {
1058 global $wgOut, $wgTitle;
1059 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1060 if ( $this->formtype == 'preview' ) {
1061 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1062 }
1063 if ( $this->isConflict ) {
1064 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1065 } elseif ( $this->section != '' ) {
1066 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1067 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1068 } else {
1069 # Use the title defined by DISPLAYTITLE magic word when present
1070 if ( isset($this->mParserOutput)
1071 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
1072 $title = $dt;
1073 } else {
1074 $title = $wgTitle->getPrefixedText();
1075 }
1076 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1077 }
1078 }
1079
1080 /**
1081 * Send the edit form and related headers to $wgOut
1082 * @param $formCallback Optional callable that takes an OutputPage
1083 * parameter; will be called during form output
1084 * near the top, for captchas and the like.
1085 */
1086 function showEditForm( $formCallback=null ) {
1087 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle;
1088
1089 # If $wgTitle is null, that means we're in API mode.
1090 # Some hook probably called this function without checking
1091 # for is_null($wgTitle) first. Bail out right here so we don't
1092 # do lots of work just to discard it right after.
1093 if (is_null($wgTitle))
1094 return;
1095
1096 $fname = 'EditPage::showEditForm';
1097 wfProfileIn( $fname );
1098
1099 $sk = $wgUser->getSkin();
1100
1101 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
1102
1103 #need to parse the preview early so that we know which templates are used,
1104 #otherwise users with "show preview after edit box" will get a blank list
1105 #we parse this near the beginning so that setHeaders can do the title
1106 #setting work instead of leaving it in getPreviewText
1107 $previewOutput = '';
1108 if ( $this->formtype == 'preview' ) {
1109 $previewOutput = $this->getPreviewText();
1110 }
1111
1112 $this->setHeaders();
1113
1114 # Enabled article-related sidebar, toplinks, etc.
1115 $wgOut->setArticleRelated( true );
1116
1117 if ( $this->isConflict ) {
1118 $wgOut->addWikiMsg( 'explainconflict' );
1119
1120 $this->textbox2 = $this->textbox1;
1121 $this->textbox1 = $this->getContent();
1122 $this->edittime = $this->mArticle->getTimestamp();
1123 } else {
1124 if ( $this->section != '' && $this->section != 'new' ) {
1125 $matches = array();
1126 if ( !$this->summary && !$this->preview && !$this->diff ) {
1127 preg_match( "/^(=+)(.+)\\1/mi",
1128 $this->textbox1,
1129 $matches );
1130 if ( !empty( $matches[2] ) ) {
1131 global $wgParser;
1132 $this->summary = "/* " .
1133 $wgParser->stripSectionName(trim($matches[2])) .
1134 " */ ";
1135 }
1136 }
1137 }
1138
1139 if ( $this->missingComment ) {
1140 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1141 }
1142
1143 if ( $this->missingSummary && $this->section != 'new' ) {
1144 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1145 }
1146
1147 if ( $this->missingSummary && $this->section == 'new' ) {
1148 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1149 }
1150
1151 if ( $this->hookError !== '' ) {
1152 $wgOut->addWikiText( $this->hookError );
1153 }
1154
1155 if ( !$this->checkUnicodeCompliantBrowser() ) {
1156 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1157 }
1158 if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) {
1159 // Let sysop know that this will make private content public if saved
1160
1161 if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
1162 $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
1163 } else if ( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1164 $wgOut->addWikiMsg( 'rev-deleted-text-view' );
1165 }
1166
1167 if ( !$this->mArticle->mRevision->isCurrent() ) {
1168 $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
1169 $wgOut->addWikiMsg( 'editingold' );
1170 }
1171 }
1172 }
1173
1174 if ( wfReadOnly() ) {
1175 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1176 } elseif ( $wgUser->isAnon() && $this->formtype != 'preview' ) {
1177 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
1178 } else {
1179 if ( $this->isCssJsSubpage && $this->formtype != 'preview' ) {
1180 # Check the skin exists
1181 if ( $this->isValidCssJsSubpage ) {
1182 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
1183 } else {
1184 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1185 }
1186 }
1187 }
1188
1189 $classes = array(); // Textarea CSS
1190 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1191 # Show a warning if editing an interface message
1192 $wgOut->addWikiMsg( 'editinginterface' );
1193 } elseif ( $this->mTitle->isProtected( 'edit' ) ) {
1194 # Is the title semi-protected?
1195 if ( $this->mTitle->isSemiProtected() ) {
1196 $noticeMsg = 'semiprotectedpagewarning';
1197 $classes[] = 'mw-textarea-sprotected';
1198 } else {
1199 # Then it must be protected based on static groups (regular)
1200 $noticeMsg = 'protectedpagewarning';
1201 $classes[] = 'mw-textarea-protected';
1202 }
1203 $wgOut->addHTML( "<div id='mw-edit-$noticeMsg'>\n" );
1204 $wgOut->addWikiMsg( $noticeMsg );
1205 LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '', 1 );
1206 $wgOut->addHTML( "</div>\n" );
1207 }
1208 if ( $this->mTitle->isCascadeProtected() ) {
1209 # Is this page under cascading protection from some source pages?
1210 list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
1211 $notice = "$1\n";
1212 if ( count($cascadeSources) > 0 ) {
1213 # Explain, and list the titles responsible
1214 foreach( $cascadeSources as $page ) {
1215 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1216 }
1217 }
1218 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', count($cascadeSources) ) );
1219 }
1220 if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
1221 $wgOut->addWikiMsg( 'titleprotectedwarning' );
1222 }
1223
1224 if ( $this->kblength === false ) {
1225 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
1226 }
1227 if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
1228 $wgOut->addHTML( "<div id='mw-edit-longpageerror'>\n" );
1229 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) );
1230 $wgOut->addHTML( "</div>\n" );
1231 } elseif ( $this->kblength > 29 ) {
1232 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1233 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) );
1234 $wgOut->addHTML( "</div>\n" );
1235 }
1236
1237 $q = 'action='.$this->action;
1238 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1239 $action = $wgTitle->escapeLocalURL( $q );
1240
1241 $colonSep = wfMsg( 'colon-separator' );
1242 $summary = wfMsg( 'summary' ) . $colonSep;
1243 $subject = wfMsg( 'subject' ) . $colonSep;
1244
1245 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
1246 wfMsgExt('cancel', array('parseinline')) );
1247 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1248 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1249 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1250 htmlspecialchars( wfMsg( 'newwindow' ) );
1251
1252 global $wgRightsText;
1253 if ( $wgRightsText ) {
1254 $copywarnMsg = array( 'copyrightwarning',
1255 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1256 $wgRightsText );
1257 } else {
1258 $copywarnMsg = array( 'copyrightwarning2',
1259 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1260 }
1261
1262 if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
1263 # prepare toolbar for edit buttons
1264 $toolbar = EditPage::getEditToolbar();
1265 } else {
1266 $toolbar = '';
1267 }
1268
1269 // activate checkboxes if user wants them to be always active
1270 if ( !$this->preview && !$this->diff ) {
1271 # Sort out the "watch" checkbox
1272 if ( $wgUser->getOption( 'watchdefault' ) ) {
1273 # Watch all edits
1274 $this->watchthis = true;
1275 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1276 # Watch creations
1277 $this->watchthis = true;
1278 } elseif ( $this->mTitle->userIsWatching() ) {
1279 # Already watched
1280 $this->watchthis = true;
1281 }
1282
1283 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
1284 }
1285
1286 $wgOut->addHTML( $this->editFormPageTop );
1287
1288 if ( $wgUser->getOption( 'previewontop' ) ) {
1289 $this->displayPreviewArea( $previewOutput, true );
1290 }
1291
1292
1293 $wgOut->addHTML( $this->editFormTextTop );
1294
1295 # if this is a comment, show a subject line at the top, which is also the edit summary.
1296 # Otherwise, show a summary field at the bottom
1297 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
1298
1299 # If a blank edit summary was previously provided, and the appropriate
1300 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1301 # user being bounced back more than once in the event that a summary
1302 # is not required.
1303 #####
1304 # For a bit more sophisticated detection of blank summaries, hash the
1305 # automatic one and pass that in the hidden field wpAutoSummary.
1306 $summaryhiddens = '';
1307 if ( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
1308 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
1309 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
1310 if ( $this->section == 'new' ) {
1311 $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 />";
1312 $editsummary = "<div class='editOptions'>\n";
1313 global $wgParser;
1314 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
1315 $subjectpreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">".wfMsg('subject-preview').$colonSep.$sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
1316 $summarypreview = '';
1317 } else {
1318 $commentsubject = '';
1319 $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 />";
1320 $summarypreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">".wfMsg('summary-preview').$colonSep.$sk->commentBlock( $this->summary, $this->mTitle )."</div>\n" : '';
1321 $subjectpreview = '';
1322 }
1323
1324 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1325 if ( !$this->preview && !$this->diff ) {
1326 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1327 }
1328 $templates = $this->getTemplates();
1329 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
1330
1331 $hiddencats = $this->mArticle->getHiddenCategories();
1332 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1333
1334 global $wgUseMetadataEdit ;
1335 if ( $wgUseMetadataEdit ) {
1336 $metadata = $this->mMetaData ;
1337 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1338 $top = wfMsgWikiHtml( 'metadata_help' );
1339 /* ToDo: Replace with clean code */
1340 $ew = $wgUser->getOption( 'editwidth' );
1341 if ( $ew ) $ew = " style=\"width:100%\"";
1342 else $ew = '';
1343 $cols = $wgUser->getIntOption( 'cols' );
1344 /* /ToDo */
1345 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1346 }
1347 else $metadata = "" ;
1348
1349 $recreate = '';
1350 if ( $this->wasDeletedSinceLastEdit() ) {
1351 if ( 'save' != $this->formtype ) {
1352 $wgOut->addWikiMsg('deletedwhileediting');
1353 } else {
1354 // Hide the toolbar and edit area, use can click preview to get it back
1355 // Add an confirmation checkbox and explanation.
1356 $toolbar = '';
1357 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ));
1358 $recreate .=
1359 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1360 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1361 }
1362 }
1363
1364 $tabindex = 2;
1365
1366 $checkboxes = self::getCheckboxes( $tabindex, $sk,
1367 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
1368
1369 $checkboxhtml = implode( $checkboxes, "\n" );
1370
1371 $buttons = $this->getEditButtons( $tabindex );
1372 $buttonshtml = implode( $buttons, "\n" );
1373
1374 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1375 ? '' : Xml::hidden( 'safemode', '1' );
1376
1377 $wgOut->addHTML( <<<END
1378 {$toolbar}
1379 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1380 END
1381 );
1382
1383 if ( is_callable( $formCallback ) ) {
1384 call_user_func_array( $formCallback, array( &$wgOut ) );
1385 }
1386
1387 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1388
1389 // Put these up at the top to ensure they aren't lost on early form submission
1390 $this->showFormBeforeText();
1391
1392 $wgOut->addHTML( <<<END
1393 {$recreate}
1394 {$commentsubject}
1395 {$subjectpreview}
1396 {$this->editFormTextBeforeContent}
1397 END
1398 );
1399 $this->showTextbox1( $classes );
1400
1401 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1402 $wgOut->addHTML( <<<END
1403 {$this->editFormTextAfterWarn}
1404 {$metadata}
1405 {$editsummary}
1406 {$summarypreview}
1407 {$checkboxhtml}
1408 {$safemodehtml}
1409 END
1410 );
1411
1412 $wgOut->addHTML(
1413 "<div class='editButtons'>
1414 {$buttonshtml}
1415 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1416 </div><!-- editButtons -->
1417 </div><!-- editOptions -->");
1418
1419 /**
1420 * To make it harder for someone to slip a user a page
1421 * which submits an edit form to the wiki without their
1422 * knowledge, a random token is associated with the login
1423 * session. If it's not passed back with the submission,
1424 * we won't save the page, or render user JavaScript and
1425 * CSS previews.
1426 *
1427 * For anon editors, who may not have a session, we just
1428 * include the constant suffix to prevent editing from
1429 * broken text-mangling proxies.
1430 */
1431 $token = htmlspecialchars( $wgUser->editToken() );
1432 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1433
1434 $this->showEditTools();
1435
1436 $wgOut->addHTML( <<<END
1437 {$this->editFormTextAfterTools}
1438 <div class='templatesUsed'>
1439 {$formattedtemplates}
1440 </div>
1441 <div class='hiddencats'>
1442 {$formattedhiddencats}
1443 </div>
1444 END
1445 );
1446
1447 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1448 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1449
1450 $de = new DifferenceEngine( $this->mTitle );
1451 $de->setText( $this->textbox2, $this->textbox1 );
1452 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1453
1454 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1455 $this->showTextbox2();
1456 }
1457 $wgOut->addHTML( $this->editFormTextBottom );
1458 $wgOut->addHTML( "</form>\n" );
1459 if ( !$wgUser->getOption( 'previewontop' ) ) {
1460 $this->displayPreviewArea( $previewOutput, false );
1461 }
1462
1463 wfProfileOut( $fname );
1464 }
1465
1466 protected function showFormBeforeText() {
1467 global $wgOut;
1468 $wgOut->addHTML( "
1469 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1470 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1471 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1472 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1473 }
1474
1475 protected function showTextbox1( $classes ) {
1476 $attribs = array( 'tabindex' => 1 );
1477
1478 if ( $this->wasDeletedSinceLastEdit() )
1479 $attribs['type'] = 'hidden';
1480 if ( !empty($classes) )
1481 $attribs['class'] = implode(' ',$classes);
1482
1483 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1484 }
1485
1486 protected function showTextbox2() {
1487 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
1488 }
1489
1490 protected function showTextbox( $content, $name, $attribs = array() ) {
1491 global $wgOut, $wgUser;
1492
1493 $wikitext = $this->safeUnicodeOutput( $content );
1494 if ( $wikitext !== '' ) {
1495 // Ensure there's a newline at the end, otherwise adding lines
1496 // is awkward.
1497 // But don't add a newline if the ext is empty, or Firefox in XHTML
1498 // mode will show an extra newline. A bit annoying.
1499 $wikitext .= "\n";
1500 }
1501
1502 $attribs['accesskey'] = ',';
1503 $attribs['id'] = $name;
1504
1505 if ( $wgUser->getOption( 'editwidth' ) )
1506 $attribs['style'] = 'width: 100%';
1507
1508 $wgOut->addHTML( Xml::textarea(
1509 $name,
1510 $wikitext,
1511 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1512 $attribs ) );
1513 }
1514
1515 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1516 global $wgOut;
1517 $classes = array();
1518 if ( $isOnTop )
1519 $classes[] = 'ontop';
1520
1521 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1522
1523 if ( $this->formtype != 'preview' )
1524 $attribs['style'] = 'display: none;';
1525
1526 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
1527
1528 if ( $this->formtype == 'preview' ) {
1529 $this->showPreview( $previewOutput );
1530 }
1531
1532 $wgOut->addHTML( '</div>' );
1533
1534 if ( $this->formtype == 'diff') {
1535 $this->showDiff();
1536 }
1537 }
1538
1539 /**
1540 * Append preview output to $wgOut.
1541 * Includes category rendering if this is a category page.
1542 *
1543 * @param string $text The HTML to be output for the preview.
1544 */
1545 protected function showPreview( $text ) {
1546 global $wgOut;
1547 if ( $this->mTitle->getNamespace() == NS_CATEGORY) {
1548 $this->mArticle->openShowCategory();
1549 }
1550 # This hook seems slightly odd here, but makes things more
1551 # consistent for extensions.
1552 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1553 $wgOut->addHTML( $text );
1554 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
1555 $this->mArticle->closeShowCategory();
1556 }
1557 }
1558
1559 /**
1560 * Live Preview lets us fetch rendered preview page content and
1561 * add it to the page without refreshing the whole page.
1562 * If not supported by the browser it will fall through to the normal form
1563 * submission method.
1564 *
1565 * This function outputs a script tag to support live preview, and
1566 * returns an onclick handler which should be added to the attributes
1567 * of the preview button
1568 */
1569 function doLivePreviewScript() {
1570 global $wgOut, $wgTitle;
1571 $wgOut->addScriptFile( 'preview.js' );
1572 $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
1573 return "return !lpDoPreview(" .
1574 "editform.wpTextbox1.value," .
1575 '"' . $liveAction . '"' . ")";
1576 }
1577
1578 protected function showEditTools() {
1579 global $wgOut;
1580 $wgOut->addHtml( '<div class="mw-editTools">' );
1581 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1582 $wgOut->addHtml( '</div>' );
1583 }
1584
1585 function getLastDelete() {
1586 $dbr = wfGetDB( DB_SLAVE );
1587 $data = $dbr->selectRow(
1588 array( 'logging', 'user' ),
1589 array( 'log_type',
1590 'log_action',
1591 'log_timestamp',
1592 'log_user',
1593 'log_namespace',
1594 'log_title',
1595 'log_comment',
1596 'log_params',
1597 'user_name', ),
1598 array( 'log_namespace' => $this->mTitle->getNamespace(),
1599 'log_title' => $this->mTitle->getDBkey(),
1600 'log_type' => 'delete',
1601 'log_action' => 'delete',
1602 'user_id=log_user' ),
1603 __METHOD__,
1604 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1605
1606 return $data;
1607 }
1608
1609 /**
1610 * Get the rendered text for previewing.
1611 * @return string
1612 */
1613 function getPreviewText() {
1614 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
1615
1616 wfProfileIn( __METHOD__ );
1617
1618 if ( $this->mTriedSave && !$this->mTokenOk ) {
1619 if ( $this->mTokenOkExceptSuffix ) {
1620 $note = wfMsg( 'token_suffix_mismatch' );
1621 } else {
1622 $note = wfMsg( 'session_fail_preview' );
1623 }
1624 } else {
1625 $note = wfMsg( 'previewnote' );
1626 }
1627
1628 $parserOptions = ParserOptions::newFromUser( $wgUser );
1629 $parserOptions->setEditSection( false );
1630
1631 global $wgRawHtml;
1632 if ( $wgRawHtml && !$this->mTokenOk ) {
1633 // Could be an offsite preview attempt. This is very unsafe if
1634 // HTML is enabled, as it could be an attack.
1635 return $wgOut->parse( "<div class='previewnote'>" .
1636 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1637 }
1638
1639 # don't parse user css/js, show message about preview
1640 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1641
1642 if ( $this->isCssJsSubpage ) {
1643 if (preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
1644 $previewtext = wfMsg('usercsspreview');
1645 } else if (preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
1646 $previewtext = wfMsg('userjspreview');
1647 }
1648 $parserOptions->setTidy(true);
1649 $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions );
1650 //$wgOut->addHTML( $parserOutput->mText );
1651 $previewHTML = '';
1652 } elseif ( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
1653 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
1654 } else {
1655 $toparse = $this->textbox1;
1656
1657 # If we're adding a comment, we need to show the
1658 # summary as the headline
1659 if ( $this->section=="new" && $this->summary!="" ) {
1660 $toparse="== {$this->summary} ==\n\n".$toparse;
1661 }
1662
1663 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
1664
1665 // Parse mediawiki messages with correct target language
1666 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1667 $pos = strrpos( $this->mTitle->getText(), '/' );
1668 if ( $pos !== false ) {
1669 $code = substr( $this->mTitle->getText(), $pos+1 );
1670 switch ($code) {
1671 case $wgLang->getCode():
1672 $obj = $wgLang; break;
1673 case $wgContLang->getCode():
1674 $obj = $wgContLang; break;
1675 default:
1676 $obj = Language::factory( $code );
1677 }
1678 $parserOptions->setTargetLanguage( $obj );
1679 }
1680 }
1681
1682
1683 $parserOptions->setTidy(true);
1684 $parserOptions->enableLimitReport();
1685 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
1686 $this->mTitle, $parserOptions );
1687
1688 $previewHTML = $parserOutput->getText();
1689 $this->mParserOutput = $parserOutput;
1690 $wgOut->addParserOutputNoText( $parserOutput );
1691
1692 if ( count( $parserOutput->getWarnings() ) ) {
1693 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1694 }
1695 }
1696
1697 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1698 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
1699 if ( $this->isConflict ) {
1700 $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1701 }
1702
1703 wfProfileOut( __METHOD__ );
1704 return $previewhead . $previewHTML;
1705 }
1706
1707 function getTemplates() {
1708 if ( $this->preview || $this->section != '' ) {
1709 $templates = array();
1710 if ( !isset($this->mParserOutput) ) return $templates;
1711 foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
1712 foreach( array_keys( $template ) as $dbk ) {
1713 $templates[] = Title::makeTitle($ns, $dbk);
1714 }
1715 }
1716 return $templates;
1717 } else {
1718 return $this->mArticle->getUsedTemplates();
1719 }
1720 }
1721
1722 /**
1723 * Call the stock "user is blocked" page
1724 */
1725 function blockedPage() {
1726 global $wgOut, $wgUser;
1727 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1728
1729 # If the user made changes, preserve them when showing the markup
1730 # (This happens when a user is blocked during edit, for instance)
1731 $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
1732 if ( $first ) {
1733 $source = $this->mTitle->exists() ? $this->getContent() : false;
1734 } else {
1735 $source = $this->textbox1;
1736 }
1737
1738 # Spit out the source or the user's modified version
1739 if ( $source !== false ) {
1740 $rows = $wgUser->getIntOption( 'rows' );
1741 $cols = $wgUser->getIntOption( 'cols' );
1742 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1743 $wgOut->addHtml( '<hr />' );
1744 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
1745 # Why we don't use Xml::element here?
1746 # Is it because if $source is '', it returns <textarea />?
1747 $wgOut->addHtml( Xml::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml::closeElement( 'textarea' ) );
1748 }
1749 }
1750
1751 /**
1752 * Produce the stock "please login to edit pages" page
1753 */
1754 function userNotLoggedInPage() {
1755 global $wgUser, $wgOut, $wgTitle;
1756 $skin = $wgUser->getSkin();
1757
1758 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1759 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1760
1761 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1762 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1763 $wgOut->setArticleRelated( false );
1764
1765 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1766 $wgOut->returnToMain( false, $wgTitle );
1767 }
1768
1769 /**
1770 * Creates a basic error page which informs the user that
1771 * they have attempted to edit a nonexistant section.
1772 */
1773 function noSuchSectionPage() {
1774 global $wgOut, $wgTitle;
1775
1776 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1777 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1778 $wgOut->setArticleRelated( false );
1779
1780 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section );
1781 $wgOut->returnToMain( false, $wgTitle );
1782 }
1783
1784 /**
1785 * Produce the stock "your edit contains spam" page
1786 *
1787 * @param $match Text which triggered one or more filters
1788 */
1789 function spamPage( $match = false ) {
1790 global $wgOut, $wgTitle;
1791
1792 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1793 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1794 $wgOut->setArticleRelated( false );
1795
1796 $wgOut->addHtml( '<div id="spamprotected">' );
1797 $wgOut->addWikiMsg( 'spamprotectiontext' );
1798 if ( $match )
1799 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1800 $wgOut->addHtml( '</div>' );
1801
1802 $wgOut->returnToMain( false, $wgTitle );
1803 }
1804
1805 /**
1806 * @private
1807 * @todo document
1808 */
1809 function mergeChangesInto( &$editText ){
1810 $fname = 'EditPage::mergeChangesInto';
1811 wfProfileIn( $fname );
1812
1813 $db = wfGetDB( DB_MASTER );
1814
1815 // This is the revision the editor started from
1816 $baseRevision = $this->getBaseRevision();
1817 if ( is_null( $baseRevision ) ) {
1818 wfProfileOut( $fname );
1819 return false;
1820 }
1821 $baseText = $baseRevision->getText();
1822
1823 // The current state, we want to merge updates into it
1824 $currentRevision = Revision::loadFromTitle(
1825 $db, $this->mTitle );
1826 if ( is_null( $currentRevision ) ) {
1827 wfProfileOut( $fname );
1828 return false;
1829 }
1830 $currentText = $currentRevision->getText();
1831
1832 $result = '';
1833 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
1834 $editText = $result;
1835 wfProfileOut( $fname );
1836 return true;
1837 } else {
1838 wfProfileOut( $fname );
1839 return false;
1840 }
1841 }
1842
1843 /**
1844 * Check if the browser is on a blacklist of user-agents known to
1845 * mangle UTF-8 data on form submission. Returns true if Unicode
1846 * should make it through, false if it's known to be a problem.
1847 * @return bool
1848 * @private
1849 */
1850 function checkUnicodeCompliantBrowser() {
1851 global $wgBrowserBlackList;
1852 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1853 // No User-Agent header sent? Trust it by default...
1854 return true;
1855 }
1856 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1857 foreach ( $wgBrowserBlackList as $browser ) {
1858 if ( preg_match($browser, $currentbrowser) ) {
1859 return false;
1860 }
1861 }
1862 return true;
1863 }
1864
1865 /**
1866 * @deprecated use $wgParser->stripSectionName()
1867 */
1868 function pseudoParseSectionAnchor( $text ) {
1869 global $wgParser;
1870 return $wgParser->stripSectionName( $text );
1871 }
1872
1873 /**
1874 * Format an anchor fragment as it would appear for a given section name
1875 * @param string $text
1876 * @return string
1877 * @private
1878 */
1879 function sectionAnchor( $text ) {
1880 global $wgParser;
1881 return $wgParser->guessSectionNameFromWikiText( $text );
1882 }
1883
1884 /**
1885 * Shows a bulletin board style toolbar for common editing functions.
1886 * It can be disabled in the user preferences.
1887 * The necessary JavaScript code can be found in skins/common/edit.js.
1888 *
1889 * @return string
1890 */
1891 static function getEditToolbar() {
1892 global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
1893
1894 /**
1895 * toolarray an array of arrays which each include the filename of
1896 * the button image (without path), the opening tag, the closing tag,
1897 * and optionally a sample text that is inserted between the two when no
1898 * selection is highlighted.
1899 * The tip text is shown when the user moves the mouse over the button.
1900 *
1901 * Already here are accesskeys (key), which are not used yet until someone
1902 * can figure out a way to make them work in IE. However, we should make
1903 * sure these keys are not defined on the edit page.
1904 */
1905 $toolarray = array(
1906 array(
1907 'image' => $wgLang->getImageFile('button-bold'),
1908 'id' => 'mw-editbutton-bold',
1909 'open' => '\'\'\'',
1910 'close' => '\'\'\'',
1911 'sample' => wfMsg('bold_sample'),
1912 'tip' => wfMsg('bold_tip'),
1913 'key' => 'B'
1914 ),
1915 array(
1916 'image' => $wgLang->getImageFile('button-italic'),
1917 'id' => 'mw-editbutton-italic',
1918 'open' => '\'\'',
1919 'close' => '\'\'',
1920 'sample' => wfMsg('italic_sample'),
1921 'tip' => wfMsg('italic_tip'),
1922 'key' => 'I'
1923 ),
1924 array(
1925 'image' => $wgLang->getImageFile('button-link'),
1926 'id' => 'mw-editbutton-link',
1927 'open' => '[[',
1928 'close' => ']]',
1929 'sample' => wfMsg('link_sample'),
1930 'tip' => wfMsg('link_tip'),
1931 'key' => 'L'
1932 ),
1933 array(
1934 'image' => $wgLang->getImageFile('button-extlink'),
1935 'id' => 'mw-editbutton-extlink',
1936 'open' => '[',
1937 'close' => ']',
1938 'sample' => wfMsg('extlink_sample'),
1939 'tip' => wfMsg('extlink_tip'),
1940 'key' => 'X'
1941 ),
1942 array(
1943 'image' => $wgLang->getImageFile('button-headline'),
1944 'id' => 'mw-editbutton-headline',
1945 'open' => "\n== ",
1946 'close' => " ==\n",
1947 'sample' => wfMsg('headline_sample'),
1948 'tip' => wfMsg('headline_tip'),
1949 'key' => 'H'
1950 ),
1951 array(
1952 'image' => $wgLang->getImageFile('button-image'),
1953 'id' => 'mw-editbutton-image',
1954 'open' => '[['.$wgContLang->getNsText(NS_IMAGE).':',
1955 'close' => ']]',
1956 'sample' => wfMsg('image_sample'),
1957 'tip' => wfMsg('image_tip'),
1958 'key' => 'D'
1959 ),
1960 array(
1961 'image' => $wgLang->getImageFile('button-media'),
1962 'id' => 'mw-editbutton-media',
1963 'open' => '[['.$wgContLang->getNsText(NS_MEDIA).':',
1964 'close' => ']]',
1965 'sample' => wfMsg('media_sample'),
1966 'tip' => wfMsg('media_tip'),
1967 'key' => 'M'
1968 ),
1969 array(
1970 'image' => $wgLang->getImageFile('button-math'),
1971 'id' => 'mw-editbutton-math',
1972 'open' => "<math>",
1973 'close' => "</math>",
1974 'sample' => wfMsg('math_sample'),
1975 'tip' => wfMsg('math_tip'),
1976 'key' => 'C'
1977 ),
1978 array(
1979 'image' => $wgLang->getImageFile('button-nowiki'),
1980 'id' => 'mw-editbutton-nowiki',
1981 'open' => "<nowiki>",
1982 'close' => "</nowiki>",
1983 'sample' => wfMsg('nowiki_sample'),
1984 'tip' => wfMsg('nowiki_tip'),
1985 'key' => 'N'
1986 ),
1987 array(
1988 'image' => $wgLang->getImageFile('button-sig'),
1989 'id' => 'mw-editbutton-signature',
1990 'open' => '--~~~~',
1991 'close' => '',
1992 'sample' => '',
1993 'tip' => wfMsg('sig_tip'),
1994 'key' => 'Y'
1995 ),
1996 array(
1997 'image' => $wgLang->getImageFile('button-hr'),
1998 'id' => 'mw-editbutton-hr',
1999 'open' => "\n----\n",
2000 'close' => '',
2001 'sample' => '',
2002 'tip' => wfMsg('hr_tip'),
2003 'key' => 'R'
2004 )
2005 );
2006 $toolbar = "<div id='toolbar'>\n";
2007 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
2008
2009 foreach($toolarray as $tool) {
2010 $params = array(
2011 $image = $wgStylePath.'/common/images/'.$tool['image'],
2012 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2013 // Older browsers show a "speedtip" type message only for ALT.
2014 // Ideally these should be different, realistically they
2015 // probably don't need to be.
2016 $tip = $tool['tip'],
2017 $open = $tool['open'],
2018 $close = $tool['close'],
2019 $sample = $tool['sample'],
2020 $cssId = $tool['id'],
2021 );
2022
2023 $paramList = implode( ',',
2024 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2025 $toolbar.="addButton($paramList);\n";
2026 }
2027
2028 $toolbar.="/*]]>*/\n</script>";
2029 $toolbar.="\n</div>";
2030 return $toolbar;
2031 }
2032
2033 /**
2034 * Returns an array of html code of the following checkboxes:
2035 * minor and watch
2036 *
2037 * @param $tabindex Current tabindex
2038 * @param $skin Skin object
2039 * @param $checked Array of checkbox => bool, where bool indicates the checked
2040 * status of the checkbox
2041 *
2042 * @return array
2043 */
2044 public static function getCheckboxes( &$tabindex, $skin, $checked ) {
2045 global $wgUser;
2046
2047 $checkboxes = array();
2048
2049 $checkboxes['minor'] = '';
2050 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
2051 if ( $wgUser->isAllowed('minoredit') ) {
2052 $attribs = array(
2053 'tabindex' => ++$tabindex,
2054 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2055 'id' => 'wpMinoredit',
2056 );
2057 $checkboxes['minor'] =
2058 Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2059 "&nbsp;<label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
2060 }
2061
2062 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
2063 $checkboxes['watch'] = '';
2064 if ( $wgUser->isLoggedIn() ) {
2065 $attribs = array(
2066 'tabindex' => ++$tabindex,
2067 'accesskey' => wfMsg( 'accesskey-watch' ),
2068 'id' => 'wpWatchthis',
2069 );
2070 $checkboxes['watch'] =
2071 Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2072 "&nbsp;<label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
2073 }
2074 return $checkboxes;
2075 }
2076
2077 /**
2078 * Returns an array of html code of the following buttons:
2079 * save, diff, preview and live
2080 *
2081 * @param $tabindex Current tabindex
2082 *
2083 * @return array
2084 */
2085 public function getEditButtons(&$tabindex) {
2086 global $wgLivePreview, $wgUser;
2087
2088 $buttons = array();
2089
2090 $temp = array(
2091 'id' => 'wpSave',
2092 'name' => 'wpSave',
2093 'type' => 'submit',
2094 'tabindex' => ++$tabindex,
2095 'value' => wfMsg('savearticle'),
2096 'accesskey' => wfMsg('accesskey-save'),
2097 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2098 );
2099 $buttons['save'] = Xml::element('input', $temp, '');
2100
2101 ++$tabindex; // use the same for preview and live preview
2102 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
2103 $temp = array(
2104 'id' => 'wpPreview',
2105 'name' => 'wpPreview',
2106 'type' => 'submit',
2107 'tabindex' => $tabindex,
2108 'value' => wfMsg('showpreview'),
2109 'accesskey' => '',
2110 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2111 'style' => 'display: none;',
2112 );
2113 $buttons['preview'] = Xml::element('input', $temp, '');
2114
2115 $temp = array(
2116 'id' => 'wpLivePreview',
2117 'name' => 'wpLivePreview',
2118 'type' => 'submit',
2119 'tabindex' => $tabindex,
2120 'value' => wfMsg('showlivepreview'),
2121 'accesskey' => wfMsg('accesskey-preview'),
2122 'title' => '',
2123 'onclick' => $this->doLivePreviewScript(),
2124 );
2125 $buttons['live'] = Xml::element('input', $temp, '');
2126 } else {
2127 $temp = array(
2128 'id' => 'wpPreview',
2129 'name' => 'wpPreview',
2130 'type' => 'submit',
2131 'tabindex' => $tabindex,
2132 'value' => wfMsg('showpreview'),
2133 'accesskey' => wfMsg('accesskey-preview'),
2134 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2135 );
2136 $buttons['preview'] = Xml::element('input', $temp, '');
2137 $buttons['live'] = '';
2138 }
2139
2140 $temp = array(
2141 'id' => 'wpDiff',
2142 'name' => 'wpDiff',
2143 'type' => 'submit',
2144 'tabindex' => ++$tabindex,
2145 'value' => wfMsg('showdiff'),
2146 'accesskey' => wfMsg('accesskey-diff'),
2147 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2148 );
2149 $buttons['diff'] = Xml::element('input', $temp, '');
2150
2151 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons ) );
2152 return $buttons;
2153 }
2154
2155 /**
2156 * Output preview text only. This can be sucked into the edit page
2157 * via JavaScript, and saves the server time rendering the skin as
2158 * well as theoretically being more robust on the client (doesn't
2159 * disturb the edit box's undo history, won't eat your text on
2160 * failure, etc).
2161 *
2162 * @todo This doesn't include category or interlanguage links.
2163 * Would need to enhance it a bit, <s>maybe wrap them in XML
2164 * or something...</s> that might also require more skin
2165 * initialization, so check whether that's a problem.
2166 */
2167 function livePreview() {
2168 global $wgOut;
2169 $wgOut->disable();
2170 header( 'Content-type: text/xml; charset=utf-8' );
2171 header( 'Cache-control: no-cache' );
2172
2173 $previewText = $this->getPreviewText();
2174 #$categories = $skin->getCategoryLinks();
2175
2176 $s =
2177 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2178 Xml::tags( 'livepreview', null,
2179 Xml::element( 'preview', null, $previewText )
2180 #. Xml::element( 'category', null, $categories )
2181 );
2182 echo $s;
2183 }
2184
2185
2186 /**
2187 * Get a diff between the current contents of the edit box and the
2188 * version of the page we're editing from.
2189 *
2190 * If this is a section edit, we'll replace the section as for final
2191 * save and then make a comparison.
2192 */
2193 function showDiff() {
2194 $oldtext = $this->mArticle->fetchContent();
2195 $newtext = $this->mArticle->replaceSection(
2196 $this->section, $this->textbox1, $this->summary, $this->edittime );
2197 $newtext = $this->mArticle->preSaveTransform( $newtext );
2198 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2199 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2200 if ( $oldtext !== false || $newtext != '' ) {
2201 $de = new DifferenceEngine( $this->mTitle );
2202 $de->setText( $oldtext, $newtext );
2203 $difftext = $de->getDiff( $oldtitle, $newtitle );
2204 $de->showDiffStyle();
2205 } else {
2206 $difftext = '';
2207 }
2208
2209 global $wgOut;
2210 $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
2211 }
2212
2213 /**
2214 * Filter an input field through a Unicode de-armoring process if it
2215 * came from an old browser with known broken Unicode editing issues.
2216 *
2217 * @param WebRequest $request
2218 * @param string $field
2219 * @return string
2220 * @private
2221 */
2222 function safeUnicodeInput( $request, $field ) {
2223 $text = rtrim( $request->getText( $field ) );
2224 return $request->getBool( 'safemode' )
2225 ? $this->unmakesafe( $text )
2226 : $text;
2227 }
2228
2229 /**
2230 * Filter an output field through a Unicode armoring process if it is
2231 * going to an old browser with known broken Unicode editing issues.
2232 *
2233 * @param string $text
2234 * @return string
2235 * @private
2236 */
2237 function safeUnicodeOutput( $text ) {
2238 global $wgContLang;
2239 $codedText = $wgContLang->recodeForEdit( $text );
2240 return $this->checkUnicodeCompliantBrowser()
2241 ? $codedText
2242 : $this->makesafe( $codedText );
2243 }
2244
2245 /**
2246 * A number of web browsers are known to corrupt non-ASCII characters
2247 * in a UTF-8 text editing environment. To protect against this,
2248 * detected browsers will be served an armored version of the text,
2249 * with non-ASCII chars converted to numeric HTML character references.
2250 *
2251 * Preexisting such character references will have a 0 added to them
2252 * to ensure that round-trips do not alter the original data.
2253 *
2254 * @param string $invalue
2255 * @return string
2256 * @private
2257 */
2258 function makesafe( $invalue ) {
2259 // Armor existing references for reversability.
2260 $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
2261
2262 $bytesleft = 0;
2263 $result = "";
2264 $working = 0;
2265 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2266 $bytevalue = ord( $invalue{$i} );
2267 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2268 $result .= chr( $bytevalue );
2269 $bytesleft = 0;
2270 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2271 $working = $working << 6;
2272 $working += ($bytevalue & 0x3F);
2273 $bytesleft--;
2274 if ( $bytesleft <= 0 ) {
2275 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2276 }
2277 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2278 $working = $bytevalue & 0x1F;
2279 $bytesleft = 1;
2280 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2281 $working = $bytevalue & 0x0F;
2282 $bytesleft = 2;
2283 } else { //1111 0xxx
2284 $working = $bytevalue & 0x07;
2285 $bytesleft = 3;
2286 }
2287 }
2288 return $result;
2289 }
2290
2291 /**
2292 * Reverse the previously applied transliteration of non-ASCII characters
2293 * back to UTF-8. Used to protect data from corruption by broken web browsers
2294 * as listed in $wgBrowserBlackList.
2295 *
2296 * @param string $invalue
2297 * @return string
2298 * @private
2299 */
2300 function unmakesafe( $invalue ) {
2301 $result = "";
2302 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2303 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
2304 $i += 3;
2305 $hexstring = "";
2306 do {
2307 $hexstring .= $invalue{$i};
2308 $i++;
2309 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2310
2311 // Do some sanity checks. These aren't needed for reversability,
2312 // but should help keep the breakage down if the editor
2313 // breaks one of the entities whilst editing.
2314 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2315 $codepoint = hexdec($hexstring);
2316 $result .= codepointToUtf8( $codepoint );
2317 } else {
2318 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2319 }
2320 } else {
2321 $result .= substr( $invalue, $i, 1 );
2322 }
2323 }
2324 // reverse the transform that we made for reversability reasons.
2325 return strtr( $result, array( "&#x0" => "&#x" ) );
2326 }
2327
2328 function noCreatePermission() {
2329 global $wgOut;
2330 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2331 $wgOut->addWikiMsg( 'nocreatetext' );
2332 }
2333
2334 /**
2335 * If there are rows in the deletion log for this page, show them,
2336 * along with a nice little note for the user
2337 *
2338 * @param OutputPage $out
2339 */
2340 protected function showDeletionLog( $out ) {
2341 global $wgUser;
2342 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2343 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
2344 if ( $pager->getNumRows() > 0 ) {
2345 $out->addHtml( '<div id="mw-recreate-deleted-warn">' );
2346 $out->addWikiMsg( 'recreate-deleted-warn' );
2347 $out->addHTML(
2348 $loglist->beginLogEventsList() .
2349 $pager->getBody() .
2350 $loglist->endLogEventsList()
2351 );
2352 $out->addHtml( '</div>' );
2353 return true;
2354 }
2355 return false;
2356 }
2357
2358 /**
2359 * Attempt submission
2360 * @return bool false if output is done, true if the rest of the form should be displayed
2361 */
2362 function attemptSave() {
2363 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2364
2365 $resultDetails = false;
2366 $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
2367
2368 if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
2369 $this->didSave = true;
2370 }
2371
2372 switch ($value) {
2373 case self::AS_HOOK_ERROR_EXPECTED:
2374 case self::AS_CONTENT_TOO_BIG:
2375 case self::AS_ARTICLE_WAS_DELETED:
2376 case self::AS_CONFLICT_DETECTED:
2377 case self::AS_SUMMARY_NEEDED:
2378 case self::AS_TEXTBOX_EMPTY:
2379 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
2380 case self::AS_END:
2381 return true;
2382
2383 case self::AS_HOOK_ERROR:
2384 case self::AS_FILTERING:
2385 case self::AS_SUCCESS_NEW_ARTICLE:
2386 case self::AS_SUCCESS_UPDATE:
2387 return false;
2388
2389 case self::AS_SPAM_ERROR:
2390 $this->spamPage ( $resultDetails['spam'] );
2391 return false;
2392
2393 case self::AS_BLOCKED_PAGE_FOR_USER:
2394 $this->blockedPage();
2395 return false;
2396
2397 case self::AS_IMAGE_REDIRECT_ANON:
2398 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2399 return false;
2400
2401 case self::AS_READ_ONLY_PAGE_ANON:
2402 $this->userNotLoggedInPage();
2403 return false;
2404
2405 case self::AS_READ_ONLY_PAGE_LOGGED:
2406 case self::AS_READ_ONLY_PAGE:
2407 $wgOut->readOnlyPage();
2408 return false;
2409
2410 case self::AS_RATE_LIMITED:
2411 $wgOut->rateLimited();
2412 return false;
2413
2414 case self::AS_NO_CREATE_PERMISSION;
2415 $this->noCreatePermission();
2416 return;
2417
2418 case self::AS_BLANK_ARTICLE:
2419 $wgOut->redirect( $wgTitle->getFullURL() );
2420 return false;
2421
2422 case self::AS_IMAGE_REDIRECT_LOGGED:
2423 $wgOut->permissionRequired( 'upload' );
2424 return false;
2425 }
2426 }
2427
2428 function getBaseRevision() {
2429 if ( $this->mBaseRevision == false ) {
2430 $db = wfGetDB( DB_MASTER );
2431 $baseRevision = Revision::loadFromTimestamp(
2432 $db, $this->mTitle, $this->edittime );
2433 return $this->mBaseRevision = $baseRevision;
2434 } else {
2435 return $this->mBaseRevision;
2436 }
2437 }
2438 }