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