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