(bug 19441) Updated date formatting for Lithuanian
[mediawiki.git] / includes / EditPage.php
blobdd934d8e1c90d67e3ffcc8abb2d588087b1b5bc2
1 <?php
2 /**
3 * Contains the EditPage class
4 * @file
5 */
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.
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.
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;
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;
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;
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;
85 /* $didSave should be set to true whenever an article was succesfully altered. */
86 public $didSave = false;
87 public $undidRev = 0;
89 public $suppressIntro = false;
91 /**
92 * @todo document
93 * @param $article
95 function EditPage( $article ) {
96 $this->mArticle =& $article;
97 $this->mTitle = $article->getTitle();
98 $this->action = 'submit';
100 # Placeholders for text injection by hooks (empty per default)
101 $this->editFormPageTop =
102 $this->editFormTextTop =
103 $this->editFormTextBeforeContent =
104 $this->editFormTextAfterWarn =
105 $this->editFormTextAfterTools =
106 $this->editFormTextBottom =
107 $this->mPreloadText = "";
110 function getArticle() {
111 return $this->mArticle;
115 * Fetch initial editing page content.
116 * @private
118 function getContent( $def_text = '' ) {
119 global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
121 wfProfileIn( __METHOD__ );
122 # Get variables from query string :P
123 $section = $wgRequest->getVal( 'section' );
124 $preload = $wgRequest->getVal( 'preload' );
125 $undoafter = $wgRequest->getVal( 'undoafter' );
126 $undo = $wgRequest->getVal( 'undo' );
128 $text = '';
129 // For message page not locally set, use the i18n message.
130 // For other non-existent articles, use preload text if any.
131 if ( !$this->mTitle->exists() ) {
132 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
133 # If this is a system message, get the default text.
134 list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
135 $wgMessageCache->loadAllMessages( $lang );
136 $text = wfMsgGetKey( $message, false, $lang, false );
137 if( wfEmptyMsg( $message, $text ) )
138 $text = '';
139 } else {
140 # If requested, preload some text.
141 $text = $this->getPreloadedText( $preload );
143 // For existing pages, get text based on "undo" or section parameters.
144 } else {
145 $text = $this->mArticle->getContent();
146 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
147 # If they got undoafter and undo round the wrong way, switch them
148 list( $undo, $undoafter ) = array( $undoafter, $undo );
150 if ( $undo > 0 && $undo > $undoafter ) {
151 # Undoing a specific edit overrides section editing; section-editing
152 # doesn't work with undoing.
153 if ( $undoafter ) {
154 $undorev = Revision::newFromId($undo);
155 $oldrev = Revision::newFromId($undoafter);
156 } else {
157 $undorev = Revision::newFromId($undo);
158 $oldrev = $undorev ? $undorev->getPrevious() : null;
161 # Sanity check, make sure it's the right page,
162 # the revisions exist and they were not deleted.
163 # Otherwise, $text will be left as-is.
164 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
165 $undorev->getPage() == $oldrev->getPage() &&
166 $undorev->getPage() == $this->mArticle->getID() &&
167 !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
168 !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
170 $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
171 if ( $undotext === false ) {
172 # Warn the user that something went wrong
173 $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
174 } else {
175 $text = $undotext;
176 # Inform the user of our success and set an automatic edit summary
177 $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
178 $firstrev = $oldrev->getNext();
179 # If we just undid one rev, use an autosummary
180 if ( $firstrev->mId == $undo ) {
181 $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
182 $this->undidRev = $undo;
184 $this->formtype = 'diff';
186 } else {
187 // Failed basic sanity checks.
188 // Older revisions may have been removed since the link
189 // was created, or we may simply have got bogus input.
190 $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
192 } else if ( $section != '' ) {
193 if ( $section == 'new' ) {
194 $text = $this->getPreloadedText( $preload );
195 } else {
196 $text = $wgParser->getSection( $text, $section, $def_text );
201 wfProfileOut( __METHOD__ );
202 return $text;
205 /** Use this method before edit() to preload some text into the edit box */
206 public function setPreloadedText( $text ) {
207 $this->mPreloadText = $text;
211 * Get the contents of a page from its title and remove includeonly tags
213 * @param $preload String: the title of the page.
214 * @return string The contents of the page.
216 protected function getPreloadedText( $preload ) {
217 if ( !empty($this->mPreloadText) ) {
218 return $this->mPreloadText;
219 } elseif ( $preload === '' ) {
220 return '';
221 } else {
222 $preloadTitle = Title::newFromText( $preload );
223 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
224 $rev = Revision::newFromTitle($preloadTitle);
225 if ( is_object( $rev ) ) {
226 $text = $rev->getText();
227 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
228 // its own mini-parser! -ævar
229 $text = preg_replace( '~</?includeonly>~', '', $text );
230 return $text;
231 } else
232 return '';
238 * This is the function that extracts metadata from the article body on the first view.
239 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
240 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
242 function extractMetaDataFromArticle () {
243 global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
244 $this->mMetaData = '';
245 if ( !$wgUseMetadataEdit ) return;
246 if ( $wgMetadataWhitelist == '' ) return;
247 $s = '';
248 $t = $this->getContent();
250 # MISSING : <nowiki> filtering
252 # Categories and language links
253 $t = explode ( "\n" , $t );
254 $catlow = strtolower ( $wgContLang->getNsText( NS_CATEGORY ) );
255 $cat = $ll = array();
256 foreach ( $t AS $key => $x ) {
257 $y = trim ( strtolower ( $x ) );
258 while ( substr ( $y , 0 , 2 ) == '[[' ) {
259 $y = explode ( ']]' , trim ( $x ) );
260 $first = array_shift ( $y );
261 $first = explode ( ':' , $first );
262 $ns = array_shift ( $first );
263 $ns = trim ( str_replace ( '[' , '' , $ns ) );
264 if ( $wgContLang->getLanguageName( $ns ) || strtolower ( $ns ) == $catlow ) {
265 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]';
266 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add;
267 else $ll[] = $add;
268 $x = implode ( ']]' , $y );
269 $t[$key] = $x;
270 $y = trim ( strtolower ( $x ) );
271 } else {
272 $x = implode ( ']]' , $y );
273 $y = trim ( strtolower ( $x ) );
277 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n";
278 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n";
279 $t = implode ( "\n" , $t );
281 # Load whitelist
282 $sat = array () ; # stand-alone-templates; must be lowercase
283 $wl_title = Title::newFromText ( $wgMetadataWhitelist );
284 $wl_article = new Article ( $wl_title );
285 $wl = explode ( "\n" , $wl_article->getContent() );
286 foreach ( $wl AS $x ) {
287 $isentry = false;
288 $x = trim ( $x );
289 while ( substr ( $x , 0 , 1 ) == '*' ) {
290 $isentry = true;
291 $x = trim ( substr ( $x , 1 ) );
293 if ( $isentry ) {
294 $sat[] = strtolower ( $x );
299 # Templates, but only some
300 $t = explode ( '{{' , $t );
301 $tl = array () ;
302 foreach ( $t AS $key => $x ) {
303 $y = explode ( '}}' , $x , 2 );
304 if ( count ( $y ) == 2 ) {
305 $z = $y[0];
306 $z = explode ( '|' , $z );
307 $tn = array_shift ( $z );
308 if ( in_array ( strtolower ( $tn ) , $sat ) ) {
309 $tl[] = '{{' . $y[0] . '}}';
310 $t[$key] = $y[1];
311 $y = explode ( '}}' , $y[1] , 2 );
313 else $t[$key] = '{{' . $x;
315 else if ( $key != 0 ) $t[$key] = '{{' . $x;
316 else $t[$key] = $x;
318 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl );
319 $t = implode ( '' , $t );
321 $t = str_replace ( "\n\n\n" , "\n" , $t );
322 $this->mArticle->mContent = $t;
323 $this->mMetaData = $s;
327 * Check if a page was deleted while the user was editing it, before submit.
328 * Note that we rely on the logging table, which hasn't been always there,
329 * but that doesn't matter, because this only applies to brand new
330 * deletes.
332 protected function wasDeletedSinceLastEdit() {
333 if ( $this->deletedSinceEdit )
334 return true;
335 if ( $this->mTitle->isDeletedQuick() ) {
336 $this->lastDelete = $this->getLastDelete();
337 if ( $this->lastDelete ) {
338 $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
339 if ( $deleteTime > $this->starttime ) {
340 $this->deletedSinceEdit = true;
344 return $this->deletedSinceEdit;
347 function submit() {
348 $this->edit();
352 * This is the function that gets called for "action=edit". It
353 * sets up various member variables, then passes execution to
354 * another function, usually showEditForm()
356 * The edit form is self-submitting, so that when things like
357 * preview and edit conflicts occur, we get the same form back
358 * with the extra stuff added. Only when the final submission
359 * is made and all is well do we actually save and redirect to
360 * the newly-edited page.
362 function edit() {
363 global $wgOut, $wgRequest;
364 // Allow extensions to modify/prevent this form or submission
365 if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) {
366 return;
369 wfProfileIn( __METHOD__ );
370 wfDebug( __METHOD__.": enter\n" );
372 // This is not an article
373 $wgOut->setArticleFlag( false );
375 $this->importFormData( $wgRequest );
376 $this->firsttime = false;
378 if ( $this->live ) {
379 $this->livePreview();
380 wfProfileOut( __METHOD__ );
381 return;
384 if ( wfReadOnly() && $this->save ) {
385 // Force preview
386 $this->save = false;
387 $this->preview = true;
390 $wgOut->addScriptFile( 'edit.js' );
391 $permErrors = $this->getEditPermissionErrors();
392 if ( $permErrors ) {
393 wfDebug( __METHOD__.": User can't edit\n" );
394 $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
395 wfProfileOut( __METHOD__ );
396 return;
397 } else {
398 if ( $this->save ) {
399 $this->formtype = 'save';
400 } else if ( $this->preview ) {
401 $this->formtype = 'preview';
402 } else if ( $this->diff ) {
403 $this->formtype = 'diff';
404 } else { # First time through
405 $this->firsttime = true;
406 if ( $this->previewOnOpen() ) {
407 $this->formtype = 'preview';
408 } else {
409 $this->extractMetaDataFromArticle () ;
410 $this->formtype = 'initial';
415 // If they used redlink=1 and the page exists, redirect to the main article
416 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
417 $wgOut->redirect( $this->mTitle->getFullURL() );
420 wfProfileIn( __METHOD__."-business-end" );
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();
427 # Show applicable editing introductions
428 if ( $this->formtype == 'initial' || $this->firsttime )
429 $this->showIntro();
431 if ( $this->mTitle->isTalkPage() ) {
432 $wgOut->addWikiMsg( 'talkpagetext' );
435 # Optional notices on a per-namespace and per-page basis
436 $editnotice_ns = 'editnotice-'.$this->mTitle->getNamespace();
437 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
438 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
440 if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
441 $parts = explode( '/', $this->mTitle->getDBkey() );
442 $editnotice_base = $editnotice_ns;
443 while ( count( $parts ) > 0 ) {
444 $editnotice_base .= '-'.array_shift( $parts );
445 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
446 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
451 # Attempt submission here. This will check for edit conflicts,
452 # and redundantly check for locked database, blocked IPs, etc.
453 # that edit() already checked just in case someone tries to sneak
454 # in the back door with a hand-edited submission URL.
456 if ( 'save' == $this->formtype ) {
457 if ( !$this->attemptSave() ) {
458 wfProfileOut( __METHOD__."-business-end" );
459 wfProfileOut( __METHOD__ );
460 return;
464 # First time through: get contents, set time for conflict
465 # checking, etc.
466 if ( 'initial' == $this->formtype || $this->firsttime ) {
467 if ( $this->initialiseForm() === false) {
468 $this->noSuchSectionPage();
469 wfProfileOut( __METHOD__."-business-end" );
470 wfProfileOut( __METHOD__ );
471 return;
473 if ( !$this->mTitle->getArticleId() )
474 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
477 $this->showEditForm();
478 wfProfileOut( __METHOD__."-business-end" );
479 wfProfileOut( __METHOD__ );
482 protected function getEditPermissionErrors() {
483 global $wgUser;
484 $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
485 # Can this title be created?
486 if ( !$this->mTitle->exists() ) {
487 $permErrors = array_merge( $permErrors,
488 wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
490 # Ignore some permissions errors when a user is just previewing/viewing diffs
491 $remove = array();
492 foreach( $permErrors as $error ) {
493 if ( ($this->preview || $this->diff) &&
494 ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext') )
496 $remove[] = $error;
499 $permErrors = wfArrayDiff2( $permErrors, $remove );
500 return $permErrors;
504 * Show a read-only error
505 * Parameters are the same as OutputPage:readOnlyPage()
506 * Redirect to the article page if redlink=1
508 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
509 global $wgRequest, $wgOut;
510 if ( $wgRequest->getBool( 'redlink' ) ) {
511 // The edit page was reached via a red link.
512 // Redirect to the article page and let them click the edit tab if
513 // they really want a permission error.
514 $wgOut->redirect( $this->mTitle->getFullUrl() );
515 } else {
516 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
521 * Should we show a preview when the edit form is first shown?
523 * @return bool
525 protected function previewOnOpen() {
526 global $wgRequest, $wgUser;
527 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
528 // Explicit override from request
529 return true;
530 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
531 // Explicit override from request
532 return false;
533 } elseif ( $this->section == 'new' ) {
534 // Nothing *to* preview for new sections
535 return false;
536 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
537 // Standard preference behaviour
538 return true;
539 } elseif ( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) {
540 // Categories are special
541 return true;
542 } else {
543 return false;
548 * @todo document
549 * @param $request
551 function importFormData( &$request ) {
552 global $wgLang, $wgUser;
553 $fname = 'EditPage::importFormData';
554 wfProfileIn( $fname );
556 # Section edit can come from either the form or a link
557 $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
559 if ( $request->wasPosted() ) {
560 # These fields need to be checked for encoding.
561 # Also remove trailing whitespace, but don't remove _initial_
562 # whitespace from the text boxes. This may be significant formatting.
563 $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
564 $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
565 $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
566 # Truncate for whole multibyte characters. +5 bytes for ellipsis
567 $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
569 # Remove extra headings from summaries and new sections.
570 $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary);
572 $this->edittime = $request->getVal( 'wpEdittime' );
573 $this->starttime = $request->getVal( 'wpStarttime' );
575 $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
577 if ( is_null( $this->edittime ) ) {
578 # If the form is incomplete, force to preview.
579 wfDebug( "$fname: Form data appears to be incomplete\n" );
580 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
581 $this->preview = true;
582 } else {
583 /* Fallback for live preview */
584 $this->preview = $request->getCheck( 'wpPreview' ) || $request->getCheck( 'wpLivePreview' );
585 $this->diff = $request->getCheck( 'wpDiff' );
587 // Remember whether a save was requested, so we can indicate
588 // if we forced preview due to session failure.
589 $this->mTriedSave = !$this->preview;
591 if ( $this->tokenOk( $request ) ) {
592 # Some browsers will not report any submit button
593 # if the user hits enter in the comment box.
594 # The unmarked state will be assumed to be a save,
595 # if the form seems otherwise complete.
596 wfDebug( "$fname: Passed token check.\n" );
597 } else if ( $this->diff ) {
598 # Failed token check, but only requested "Show Changes".
599 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
600 } else {
601 # Page might be a hack attempt posted from
602 # an external site. Preview instead of saving.
603 wfDebug( "$fname: Failed token check; forcing preview\n" );
604 $this->preview = true;
607 $this->save = !$this->preview && !$this->diff;
608 if ( !preg_match( '/^\d{14}$/', $this->edittime )) {
609 $this->edittime = null;
612 if ( !preg_match( '/^\d{14}$/', $this->starttime )) {
613 $this->starttime = null;
616 $this->recreate = $request->getCheck( 'wpRecreate' );
618 $this->minoredit = $request->getCheck( 'wpMinoredit' );
619 $this->watchthis = $request->getCheck( 'wpWatchthis' );
621 # Don't force edit summaries when a user is editing their own user or talk page
622 if ( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK ) &&
623 $this->mTitle->getText() == $wgUser->getName() )
625 $this->allowBlankSummary = true;
626 } else {
627 $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ) || !$wgUser->getOption( 'forceeditsummary');
630 $this->autoSumm = $request->getText( 'wpAutoSummary' );
631 } else {
632 # Not a posted form? Start with nothing.
633 wfDebug( "$fname: Not a posted form.\n" );
634 $this->textbox1 = '';
635 $this->textbox2 = '';
636 $this->mMetaData = '';
637 $this->summary = '';
638 $this->edittime = '';
639 $this->starttime = wfTimestampNow();
640 $this->edit = false;
641 $this->preview = false;
642 $this->save = false;
643 $this->diff = false;
644 $this->minoredit = false;
645 $this->watchthis = false;
646 $this->recreate = false;
648 if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
649 $this->summary = $request->getVal( 'preloadtitle' );
651 elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) {
652 $this->summary = $request->getText( 'summary' );
655 if ( $request->getVal( 'minor' ) ) {
656 $this->minoredit = true;
660 $this->oldid = $request->getInt( 'oldid' );
662 $this->live = $request->getCheck( 'live' );
663 $this->editintro = $request->getText( 'editintro' );
665 wfProfileOut( $fname );
669 * Make sure the form isn't faking a user's credentials.
671 * @param $request WebRequest
672 * @return bool
673 * @private
675 function tokenOk( &$request ) {
676 global $wgUser;
677 $token = $request->getVal( 'wpEditToken' );
678 $this->mTokenOk = $wgUser->matchEditToken( $token );
679 $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
680 return $this->mTokenOk;
684 * Show all applicable editing introductions
686 protected function showIntro() {
687 global $wgOut, $wgUser;
688 if ( $this->suppressIntro ) {
689 return;
692 $namespace = $this->mTitle->getNamespace();
694 if ( $namespace == NS_MEDIAWIKI ) {
695 # Show a warning if editing an interface message
696 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
699 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
700 if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
701 $parts = explode( '/', $this->mTitle->getText(), 2 );
702 $username = $parts[0];
703 $id = User::idFromName( $username );
704 $ip = User::isIP( $username );
705 if ( $id == 0 && !$ip ) {
706 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
707 array( 'userpage-userdoesnotexist', $username ) );
710 # Try to add a custom edit intro, or use the standard one if this is not possible.
711 if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
712 if ( $wgUser->isLoggedIn() ) {
713 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
714 } else {
715 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
718 # Give a notice if the user is editing a deleted/moved page...
719 if ( !$this->mTitle->exists() ) {
720 $this->showLogs( $wgOut );
725 * Attempt to show a custom editing introduction, if supplied
727 * @return bool
729 protected function showCustomIntro() {
730 if ( $this->editintro ) {
731 $title = Title::newFromText( $this->editintro );
732 if ( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
733 global $wgOut;
734 $revision = Revision::newFromTitle( $title );
735 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle );
736 return true;
737 } else {
738 return false;
740 } else {
741 return false;
746 * Attempt submission (no UI)
747 * @return one of the constants describing the result
749 function internalAttemptSave( &$result, $bot = false ) {
750 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
751 global $wgMaxArticleSize;
753 $fname = 'EditPage::attemptSave';
754 wfProfileIn( $fname );
755 wfProfileIn( "$fname-checks" );
757 if ( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
759 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
760 return self::AS_HOOK_ERROR;
763 # Check image redirect
764 if ( $this->mTitle->getNamespace() == NS_FILE &&
765 Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
766 !$wgUser->isAllowed( 'upload' ) ) {
767 if ( $wgUser->isAnon() ) {
768 return self::AS_IMAGE_REDIRECT_ANON;
769 } else {
770 return self::AS_IMAGE_REDIRECT_LOGGED;
774 # Reintegrate metadata
775 if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
776 $this->mMetaData = '' ;
778 # Check for spam
779 $match = self::matchSummarySpamRegex( $this->summary );
780 if ( $match === false ) {
781 $match = self::matchSpamRegex( $this->textbox1 );
783 if ( $match !== false ) {
784 $result['spam'] = $match;
785 $ip = wfGetIP();
786 $pdbk = $this->mTitle->getPrefixedDBkey();
787 $match = str_replace( "\n", '', $match );
788 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
789 wfProfileOut( "$fname-checks" );
790 wfProfileOut( $fname );
791 return self::AS_SPAM_ERROR;
793 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
794 # Error messages or other handling should be performed by the filter function
795 wfProfileOut( "$fname-checks" );
796 wfProfileOut( $fname );
797 return self::AS_FILTERING;
799 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
800 # Error messages etc. could be handled within the hook...
801 wfProfileOut( "$fname-checks" );
802 wfProfileOut( $fname );
803 return self::AS_HOOK_ERROR;
804 } elseif ( $this->hookError != '' ) {
805 # ...or the hook could be expecting us to produce an error
806 wfProfileOut( "$fname-checks" );
807 wfProfileOut( $fname );
808 return self::AS_HOOK_ERROR_EXPECTED;
810 if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
811 # Check block state against master, thus 'false'.
812 wfProfileOut( "$fname-checks" );
813 wfProfileOut( $fname );
814 return self::AS_BLOCKED_PAGE_FOR_USER;
816 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
817 if ( $this->kblength > $wgMaxArticleSize ) {
818 // Error will be displayed by showEditForm()
819 $this->tooBig = true;
820 wfProfileOut( "$fname-checks" );
821 wfProfileOut( $fname );
822 return self::AS_CONTENT_TOO_BIG;
825 if ( !$wgUser->isAllowed('edit') ) {
826 if ( $wgUser->isAnon() ) {
827 wfProfileOut( "$fname-checks" );
828 wfProfileOut( $fname );
829 return self::AS_READ_ONLY_PAGE_ANON;
831 else {
832 wfProfileOut( "$fname-checks" );
833 wfProfileOut( $fname );
834 return self::AS_READ_ONLY_PAGE_LOGGED;
838 if ( wfReadOnly() ) {
839 wfProfileOut( "$fname-checks" );
840 wfProfileOut( $fname );
841 return self::AS_READ_ONLY_PAGE;
843 if ( $wgUser->pingLimiter() ) {
844 wfProfileOut( "$fname-checks" );
845 wfProfileOut( $fname );
846 return self::AS_RATE_LIMITED;
849 # If the article has been deleted while editing, don't save it without
850 # confirmation
851 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
852 wfProfileOut( "$fname-checks" );
853 wfProfileOut( $fname );
854 return self::AS_ARTICLE_WAS_DELETED;
857 wfProfileOut( "$fname-checks" );
859 # If article is new, insert it.
860 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
861 if ( 0 == $aid ) {
862 // Late check for create permission, just in case *PARANOIA*
863 if ( !$this->mTitle->userCan( 'create' ) ) {
864 wfDebug( "$fname: no create permission\n" );
865 wfProfileOut( $fname );
866 return self::AS_NO_CREATE_PERMISSION;
869 # Don't save a new article if it's blank.
870 if ( '' == $this->textbox1 ) {
871 wfProfileOut( $fname );
872 return self::AS_BLANK_ARTICLE;
875 // Run post-section-merge edit filter
876 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
877 # Error messages etc. could be handled within the hook...
878 wfProfileOut( $fname );
879 return self::AS_HOOK_ERROR;
882 # Handle the user preference to force summaries here. Check if it's not a redirect.
883 if ( !$this->allowBlankSummary && !Title::newFromRedirect( $this->textbox1 ) ) {
884 if ( md5( $this->summary ) == $this->autoSumm ) {
885 $this->missingSummary = true;
886 wfProfileOut( $fname );
887 return self::AS_SUMMARY_NEEDED;
891 $isComment = ( $this->section == 'new' );
893 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
894 $this->minoredit, $this->watchthis, false, $isComment, $bot );
896 wfProfileOut( $fname );
897 return self::AS_SUCCESS_NEW_ARTICLE;
900 # Article exists. Check for edit conflict.
902 $this->mArticle->clear(); # Force reload of dates, etc.
903 $this->mArticle->forUpdate( true ); # Lock the article
905 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
907 if ( $this->mArticle->getTimestamp() != $this->edittime ) {
908 $this->isConflict = true;
909 if ( $this->section == 'new' ) {
910 if ( $this->mArticle->getUserText() == $wgUser->getName() &&
911 $this->mArticle->getComment() == $this->summary ) {
912 // Probably a duplicate submission of a new comment.
913 // This can happen when squid resends a request after
914 // a timeout but the first one actually went through.
915 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
916 } else {
917 // New comment; suppress conflict.
918 $this->isConflict = false;
919 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
923 $userid = $wgUser->getId();
925 # Suppress edit conflict with self, except for section edits where merging is required.
926 if ( $this->isConflict && $this->section == '' && $this->userWasLastToEdit($userid,$this->edittime) ) {
927 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
928 $this->isConflict = false;
931 if ( $this->isConflict ) {
932 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
933 $this->mArticle->getTimestamp() . "')\n" );
934 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
935 } else {
936 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
937 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
939 if ( is_null( $text ) ) {
940 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
941 $this->isConflict = true;
942 $text = $this->textbox1; // do not try to merge here!
943 } else if ( $this->isConflict ) {
944 # Attempt merge
945 if ( $this->mergeChangesInto( $text ) ) {
946 // Successful merge! Maybe we should tell the user the good news?
947 $this->isConflict = false;
948 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
949 } else {
950 $this->section = '';
951 $this->textbox1 = $text;
952 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
956 if ( $this->isConflict ) {
957 wfProfileOut( $fname );
958 return self::AS_CONFLICT_DETECTED;
961 $oldtext = $this->mArticle->getContent();
963 // Run post-section-merge edit filter
964 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
965 # Error messages etc. could be handled within the hook...
966 wfProfileOut( $fname );
967 return self::AS_HOOK_ERROR;
970 # Handle the user preference to force summaries here, but not for null edits
971 if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext,$text)
972 && !Title::newFromRedirect( $text ) ) # check if it's not a redirect
974 if ( md5( $this->summary ) == $this->autoSumm ) {
975 $this->missingSummary = true;
976 wfProfileOut( $fname );
977 return self::AS_SUMMARY_NEEDED;
981 # And a similar thing for new sections
982 if ( $this->section == 'new' && !$this->allowBlankSummary ) {
983 if (trim($this->summary) == '') {
984 $this->missingSummary = true;
985 wfProfileOut( $fname );
986 return self::AS_SUMMARY_NEEDED;
990 # All's well
991 wfProfileIn( "$fname-sectionanchor" );
992 $sectionanchor = '';
993 if ( $this->section == 'new' ) {
994 if ( $this->textbox1 == '' ) {
995 $this->missingComment = true;
996 return self::AS_TEXTBOX_EMPTY;
998 if ( $this->summary != '' ) {
999 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
1000 # This is a new section, so create a link to the new section
1001 # in the revision summary.
1002 $cleanSummary = $wgParser->stripSectionName( $this->summary );
1003 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary );
1005 } elseif ( $this->section != '' ) {
1006 # Try to get a section anchor from the section source, redirect to edited section if header found
1007 # XXX: might be better to integrate this into Article::replaceSection
1008 # for duplicate heading checking and maybe parsing
1009 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
1010 # we can't deal with anchors, includes, html etc in the header for now,
1011 # headline would need to be parsed to improve this
1012 if ( $hasmatch and strlen($matches[2]) > 0 ) {
1013 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
1016 wfProfileOut( "$fname-sectionanchor" );
1018 // Save errors may fall down to the edit form, but we've now
1019 // merged the section into full text. Clear the section field
1020 // so that later submission of conflict forms won't try to
1021 // replace that into a duplicated mess.
1022 $this->textbox1 = $text;
1023 $this->section = '';
1025 // Check for length errors again now that the section is merged in
1026 $this->kblength = (int)(strlen( $text ) / 1024);
1027 if ( $this->kblength > $wgMaxArticleSize ) {
1028 $this->tooBig = true;
1029 wfProfileOut( $fname );
1030 return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
1033 # update the article here
1034 if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
1035 $this->watchthis, $bot, $sectionanchor ) )
1037 wfProfileOut( $fname );
1038 return self::AS_SUCCESS_UPDATE;
1039 } else {
1040 $this->isConflict = true;
1042 wfProfileOut( $fname );
1043 return self::AS_END;
1047 * Check if no edits were made by other users since
1048 * the time a user started editing the page. Limit to
1049 * 50 revisions for the sake of performance.
1051 protected function userWasLastToEdit( $id, $edittime ) {
1052 if( !$id ) return false;
1053 $dbw = wfGetDB( DB_MASTER );
1054 $res = $dbw->select( 'revision',
1055 'rev_user',
1056 array(
1057 'rev_page' => $this->mArticle->getId(),
1058 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1060 __METHOD__,
1061 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1062 while( $row = $res->fetchObject() ) {
1063 if( $row->rev_user != $id ) {
1064 return false;
1067 return true;
1071 * Check given input text against $wgSpamRegex, and return the text of the first match.
1072 * @return mixed -- matching string or false
1074 public static function matchSpamRegex( $text ) {
1075 global $wgSpamRegex;
1076 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1077 $regexes = (array)$wgSpamRegex;
1078 return self::matchSpamRegexInternal( $text, $regexes );
1082 * Check given input text against $wgSpamRegex, and return the text of the first match.
1083 * @return mixed -- matching string or false
1085 public static function matchSummarySpamRegex( $text ) {
1086 global $wgSummarySpamRegex;
1087 $regexes = (array)$wgSummarySpamRegex;
1088 return self::matchSpamRegexInternal( $text, $regexes );
1091 protected static function matchSpamRegexInternal( $text, $regexes ) {
1092 foreach( $regexes as $regex ) {
1093 $matches = array();
1094 if( preg_match( $regex, $text, $matches ) ) {
1095 return $matches[0];
1098 return false;
1102 * Initialise form fields in the object
1103 * Called on the first invocation, e.g. when a user clicks an edit link
1105 function initialiseForm() {
1106 $this->edittime = $this->mArticle->getTimestamp();
1107 $this->textbox1 = $this->getContent( false );
1108 if ( $this->textbox1 === false ) return false;
1109 wfProxyCheck();
1110 return true;
1113 function setHeaders() {
1114 global $wgOut, $wgTitle;
1115 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1116 if ( $this->formtype == 'preview' ) {
1117 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1119 if ( $this->isConflict ) {
1120 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1121 } elseif ( $this->section != '' ) {
1122 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1123 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1124 } else {
1125 # Use the title defined by DISPLAYTITLE magic word when present
1126 if ( isset($this->mParserOutput)
1127 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
1128 $title = $dt;
1129 } else {
1130 $title = $wgTitle->getPrefixedText();
1132 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1137 * Send the edit form and related headers to $wgOut
1138 * @param $formCallback Optional callable that takes an OutputPage
1139 * parameter; will be called during form output
1140 * near the top, for captchas and the like.
1142 function showEditForm( $formCallback=null ) {
1143 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle, $wgRequest;
1145 # If $wgTitle is null, that means we're in API mode.
1146 # Some hook probably called this function without checking
1147 # for is_null($wgTitle) first. Bail out right here so we don't
1148 # do lots of work just to discard it right after.
1149 if (is_null($wgTitle))
1150 return;
1152 $fname = 'EditPage::showEditForm';
1153 wfProfileIn( $fname );
1155 $sk = $wgUser->getSkin();
1157 #need to parse the preview early so that we know which templates are used,
1158 #otherwise users with "show preview after edit box" will get a blank list
1159 #we parse this near the beginning so that setHeaders can do the title
1160 #setting work instead of leaving it in getPreviewText
1161 $previewOutput = '';
1162 if ( $this->formtype == 'preview' ) {
1163 $previewOutput = $this->getPreviewText();
1166 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
1168 $this->setHeaders();
1170 # Enabled article-related sidebar, toplinks, etc.
1171 $wgOut->setArticleRelated( true );
1173 if ( $this->isConflict ) {
1174 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
1176 $this->textbox2 = $this->textbox1;
1177 $this->textbox1 = $this->getContent();
1178 $this->edittime = $this->mArticle->getTimestamp();
1179 } else {
1180 if ( $this->section != '' && $this->section != 'new' ) {
1181 $matches = array();
1182 if ( !$this->summary && !$this->preview && !$this->diff ) {
1183 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1, $matches );
1184 if ( !empty( $matches[2] ) ) {
1185 global $wgParser;
1186 $this->summary = "/* " .
1187 $wgParser->stripSectionName(trim($matches[2])) .
1188 " */ ";
1193 if ( $this->missingComment ) {
1194 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1197 if ( $this->missingSummary && $this->section != 'new' ) {
1198 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1201 if ( $this->missingSummary && $this->section == 'new' ) {
1202 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1205 if ( $this->hookError !== '' ) {
1206 $wgOut->addWikiText( $this->hookError );
1209 if ( !$this->checkUnicodeCompliantBrowser() ) {
1210 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1212 if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) {
1213 // Let sysop know that this will make private content public if saved
1215 if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
1216 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
1217 } else if ( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1218 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
1221 if ( !$this->mArticle->mRevision->isCurrent() ) {
1222 $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
1223 $wgOut->addWikiMsg( 'editingold' );
1228 if ( wfReadOnly() ) {
1229 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1230 } elseif ( $wgUser->isAnon() && $this->formtype != 'preview' ) {
1231 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
1232 } else {
1233 if ( $this->isCssJsSubpage ) {
1234 # Check the skin exists
1235 if ( $this->isValidCssJsSubpage ) {
1236 if ( $this->formtype !== 'preview' ) {
1237 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
1239 } else {
1240 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1245 $classes = array(); // Textarea CSS
1246 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1247 } elseif ( $this->mTitle->isProtected( 'edit' ) ) {
1248 # Is the title semi-protected?
1249 if ( $this->mTitle->isSemiProtected() ) {
1250 $noticeMsg = 'semiprotectedpagewarning';
1251 $classes[] = 'mw-textarea-sprotected';
1252 } else {
1253 # Then it must be protected based on static groups (regular)
1254 $noticeMsg = 'protectedpagewarning';
1255 $classes[] = 'mw-textarea-protected';
1257 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
1258 $wgOut->addWikiMsg( $noticeMsg );
1259 LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '', 1 );
1260 $wgOut->addHTML( "</div>\n" );
1262 if ( $this->mTitle->isCascadeProtected() ) {
1263 # Is this page under cascading protection from some source pages?
1264 list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
1265 $notice = "<div class='mw-cascadeprotectedwarning'>$1\n";
1266 $cascadeSourcesCount = count( $cascadeSources );
1267 if ( $cascadeSourcesCount > 0 ) {
1268 # Explain, and list the titles responsible
1269 foreach( $cascadeSources as $page ) {
1270 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1273 $notice .= '</div>';
1274 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1276 if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
1277 $wgOut->wrapWikiMsg( '<div class="mw-titleprotectedwarning">$1</div>', 'titleprotectedwarning' );
1280 if ( $this->kblength === false ) {
1281 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
1283 if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
1284 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
1285 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) );
1286 $wgOut->addHTML( "</div>\n" );
1287 } elseif ( $this->kblength > 29 ) {
1288 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1289 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) );
1290 $wgOut->addHTML( "</div>\n" );
1293 $action = $wgTitle->escapeLocalURL( array( 'action' => $this->action ) );
1295 $summary = wfMsgExt( 'summary', 'parseinline' );
1296 $subject = wfMsgExt( 'subject', 'parseinline' );
1298 $cancel = $sk->link(
1299 $wgTitle,
1300 wfMsgExt( 'cancel', array( 'parseinline' ) ),
1301 array(),
1302 array(),
1303 array( 'known', 'noclasses' )
1305 $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1306 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1307 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1308 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1309 htmlspecialchars( wfMsg( 'newwindow' ) );
1311 global $wgRightsText;
1312 if ( $wgRightsText ) {
1313 $copywarnMsg = array( 'copyrightwarning',
1314 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1315 $wgRightsText );
1316 } else {
1317 $copywarnMsg = array( 'copyrightwarning2',
1318 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1320 // Allow for site and per-namespace customization of contribution/copyright notice.
1321 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle, &$copywarnMsg ) );
1323 if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
1324 # prepare toolbar for edit buttons
1325 $toolbar = EditPage::getEditToolbar();
1326 } else {
1327 $toolbar = '';
1330 // activate checkboxes if user wants them to be always active
1331 if ( !$this->preview && !$this->diff ) {
1332 # Sort out the "watch" checkbox
1333 if ( $wgUser->getOption( 'watchdefault' ) ) {
1334 # Watch all edits
1335 $this->watchthis = true;
1336 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1337 # Watch creations
1338 $this->watchthis = true;
1339 } elseif ( $this->mTitle->userIsWatching() ) {
1340 # Already watched
1341 $this->watchthis = true;
1344 # May be overriden by request parameters
1345 if( $wgRequest->getBool( 'watchthis' ) ) {
1346 $this->watchthis = true;
1349 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
1352 $wgOut->addHTML( $this->editFormPageTop );
1354 if ( $wgUser->getOption( 'previewontop' ) ) {
1355 $this->displayPreviewArea( $previewOutput, true );
1359 $wgOut->addHTML( $this->editFormTextTop );
1361 # if this is a comment, show a subject line at the top, which is also the edit summary.
1362 # Otherwise, show a summary field at the bottom
1363 $summarytext = $wgContLang->recodeForEdit( $this->summary );
1365 # If a blank edit summary was previously provided, and the appropriate
1366 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1367 # user being bounced back more than once in the event that a summary
1368 # is not required.
1369 #####
1370 # For a bit more sophisticated detection of blank summaries, hash the
1371 # automatic one and pass that in the hidden field wpAutoSummary.
1372 $summaryhiddens = '';
1373 if ( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
1374 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
1375 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
1376 if ( $this->section == 'new' ) {
1377 $commentsubject = '';
1378 if ( !$wgRequest->getBool( 'nosummary' ) ) {
1379 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1380 $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
1382 $commentsubject =
1383 Xml::tags( 'label', array( 'for' => 'wpSummary' ), $subject );
1384 $commentsubject =
1385 Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
1386 $commentsubject );
1387 $commentsubject .= '&nbsp;';
1388 $commentsubject .= Xml::input( 'wpSummary',
1390 $summarytext,
1391 array(
1392 'id' => 'wpSummary',
1393 'maxlength' => '200',
1394 'tabindex' => '1'
1395 ) );
1397 $editsummary = "<div class='editOptions'>\n";
1398 global $wgParser;
1399 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
1400 $subjectpreview = $summarytext && $this->preview ?
1401 "<div class=\"mw-summary-preview\">". wfMsgExt('subject-preview', 'parseinline') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
1402 $summarypreview = '';
1403 } else {
1404 $commentsubject = '';
1406 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1407 $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
1409 $editsummary = Xml::tags( 'label', array( 'for' => 'wpSummary' ), $summary );
1410 $editsummary = Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
1411 $editsummary ) . ' ';
1413 $editsummary .= Xml::input( 'wpSummary',
1415 $summarytext,
1416 array(
1417 'id' => 'wpSummary',
1418 'maxlength' => '200',
1419 'tabindex' => '1'
1420 ) );
1422 // No idea where this is closed.
1423 $editsummary = Xml::openElement( 'div', array( 'class' => 'editOptions' ) )
1424 . $editsummary . '<br/>';
1426 $summarypreview = '';
1427 if ( $summarytext && $this->preview ) {
1428 $summarypreview =
1429 Xml::tags( 'div',
1430 array( 'class' => 'mw-summary-preview' ),
1431 wfMsgExt( 'summary-preview', 'parseinline' ) .
1432 $sk->commentBlock( $this->summary, $this->mTitle )
1435 $subjectpreview = '';
1437 $commentsubject .= $summaryhiddens;
1439 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1440 if ( !$this->preview && !$this->diff ) {
1441 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1443 $templates = $this->getTemplates();
1444 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
1446 $hiddencats = $this->mArticle->getHiddenCategories();
1447 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1449 global $wgUseMetadataEdit ;
1450 if ( $wgUseMetadataEdit ) {
1451 $metadata = $this->mMetaData ;
1452 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1453 $top = wfMsgWikiHtml( 'metadata_help' );
1454 /* ToDo: Replace with clean code */
1455 $ew = $wgUser->getOption( 'editwidth' );
1456 if ( $ew ) $ew = " style=\"width:100%\"";
1457 else $ew = '';
1458 $cols = $wgUser->getIntOption( 'cols' );
1459 /* /ToDo */
1460 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1462 else $metadata = "" ;
1464 $recreate = '';
1465 if ( $this->wasDeletedSinceLastEdit() ) {
1466 if ( 'save' != $this->formtype ) {
1467 $wgOut->wrapWikiMsg(
1468 "<div class='error mw-deleted-while-editing'>\n$1</div>",
1469 'deletedwhileediting' );
1470 } else {
1471 // Hide the toolbar and edit area, user can click preview to get it back
1472 // Add an confirmation checkbox and explanation.
1473 $toolbar = '';
1474 $recreate = '<div class="mw-confirm-recreate">' .
1475 $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ) ) .
1476 Xml::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1477 array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1478 ) . '</div>';
1482 $tabindex = 2;
1484 $checkboxes = $this->getCheckboxes( $tabindex, $sk,
1485 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
1487 $checkboxhtml = implode( $checkboxes, "\n" );
1489 $buttons = $this->getEditButtons( $tabindex );
1490 $buttonshtml = implode( $buttons, "\n" );
1492 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1493 ? '' : Xml::hidden( 'safemode', '1' );
1495 $wgOut->addHTML( <<<END
1496 {$toolbar}
1497 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1501 if ( is_callable( $formCallback ) ) {
1502 call_user_func_array( $formCallback, array( &$wgOut ) );
1505 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1507 // Put these up at the top to ensure they aren't lost on early form submission
1508 $this->showFormBeforeText();
1510 $wgOut->addHTML( <<<END
1511 {$recreate}
1512 {$commentsubject}
1513 {$subjectpreview}
1514 {$this->editFormTextBeforeContent}
1517 $this->showTextbox1( $classes );
1519 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1520 $wgOut->addHTML( <<<END
1521 {$this->editFormTextAfterWarn}
1522 {$metadata}
1523 {$editsummary}
1524 {$summarypreview}
1525 {$checkboxhtml}
1526 {$safemodehtml}
1530 $wgOut->addHTML(
1531 "<div class='editButtons'>
1532 {$buttonshtml}
1533 <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>
1534 </div><!-- editButtons -->
1535 </div><!-- editOptions -->");
1538 * To make it harder for someone to slip a user a page
1539 * which submits an edit form to the wiki without their
1540 * knowledge, a random token is associated with the login
1541 * session. If it's not passed back with the submission,
1542 * we won't save the page, or render user JavaScript and
1543 * CSS previews.
1545 * For anon editors, who may not have a session, we just
1546 * include the constant suffix to prevent editing from
1547 * broken text-mangling proxies.
1549 $token = htmlspecialchars( $wgUser->editToken() );
1550 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1552 $this->showTosSummary();
1553 $this->showEditTools();
1555 $wgOut->addHTML( <<<END
1556 {$this->editFormTextAfterTools}
1557 <div class='templatesUsed'>
1558 {$formattedtemplates}
1559 </div>
1560 <div class='hiddencats'>
1561 {$formattedhiddencats}
1562 </div>
1566 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1567 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1569 $de = new DifferenceEngine( $this->mTitle );
1570 $de->setText( $this->textbox2, $this->textbox1 );
1571 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1573 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1574 $this->showTextbox2();
1576 $wgOut->addHTML( $this->editFormTextBottom );
1577 $wgOut->addHTML( "</form>\n" );
1578 if ( !$wgUser->getOption( 'previewontop' ) ) {
1579 $this->displayPreviewArea( $previewOutput, false );
1582 wfProfileOut( $fname );
1585 protected function showFormBeforeText() {
1586 global $wgOut;
1587 $wgOut->addHTML( "
1588 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1589 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1590 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1591 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1594 protected function showTextbox1( $classes ) {
1595 $attribs = array( 'tabindex' => 1 );
1597 if ( $this->wasDeletedSinceLastEdit() )
1598 $attribs['type'] = 'hidden';
1599 if ( !empty($classes) )
1600 $attribs['class'] = implode(' ',$classes);
1602 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1605 protected function showTextbox2() {
1606 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
1609 protected function showTextbox( $content, $name, $attribs = array() ) {
1610 global $wgOut, $wgUser;
1612 $wikitext = $this->safeUnicodeOutput( $content );
1613 if ( $wikitext !== '' ) {
1614 // Ensure there's a newline at the end, otherwise adding lines
1615 // is awkward.
1616 // But don't add a newline if the ext is empty, or Firefox in XHTML
1617 // mode will show an extra newline. A bit annoying.
1618 $wikitext .= "\n";
1621 $attribs['accesskey'] = ',';
1622 $attribs['id'] = $name;
1624 if ( $wgUser->getOption( 'editwidth' ) )
1625 $attribs['style'] = 'width: 100%';
1627 $wgOut->addHTML( Xml::textarea(
1628 $name,
1629 $wikitext,
1630 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1631 $attribs ) );
1634 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1635 global $wgOut;
1636 $classes = array();
1637 if ( $isOnTop )
1638 $classes[] = 'ontop';
1640 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1642 if ( $this->formtype != 'preview' )
1643 $attribs['style'] = 'display: none;';
1645 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
1647 if ( $this->formtype == 'preview' ) {
1648 $this->showPreview( $previewOutput );
1651 $wgOut->addHTML( '</div>' );
1653 if ( $this->formtype == 'diff') {
1654 $this->showDiff();
1659 * Append preview output to $wgOut.
1660 * Includes category rendering if this is a category page.
1662 * @param string $text The HTML to be output for the preview.
1664 protected function showPreview( $text ) {
1665 global $wgOut;
1666 if ( $this->mTitle->getNamespace() == NS_CATEGORY) {
1667 $this->mArticle->openShowCategory();
1669 # This hook seems slightly odd here, but makes things more
1670 # consistent for extensions.
1671 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1672 $wgOut->addHTML( $text );
1673 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
1674 $this->mArticle->closeShowCategory();
1679 * Live Preview lets us fetch rendered preview page content and
1680 * add it to the page without refreshing the whole page.
1681 * If not supported by the browser it will fall through to the normal form
1682 * submission method.
1684 * This function outputs a script tag to support live preview, and
1685 * returns an onclick handler which should be added to the attributes
1686 * of the preview button
1688 function doLivePreviewScript() {
1689 global $wgOut, $wgTitle;
1690 $wgOut->addScriptFile( 'preview.js' );
1691 $liveAction = $wgTitle->getLocalUrl( array(
1692 'action' => $this->action,
1693 'wpPreview' => 'true',
1694 'live' => 'true'
1695 ) );
1696 return "return !lpDoPreview(" .
1697 "editform.wpTextbox1.value," .
1698 '"' . $liveAction . '"' . ")";
1701 protected function showTosSummary() {
1702 $msg = 'editpage-tos-summary';
1703 // Give a chance for site and per-namespace customizations of
1704 // terms of service summary link that might exist separately
1705 // from the copyright notice.
1707 // This will display between the save button and the edit tools,
1708 // so should remain short!
1709 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle, &$msg ) );
1710 $text = wfMsg( $msg );
1711 if( $text != '-' ) {
1712 global $wgOut;
1713 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1714 $wgOut->addWikiMsgArray( $msg, array() );
1715 $wgOut->addHTML( '</div>' );
1719 protected function showEditTools() {
1720 global $wgOut;
1721 $wgOut->addHTML( '<div class="mw-editTools">' );
1722 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1723 $wgOut->addHTML( '</div>' );
1726 protected function getLastDelete() {
1727 $dbr = wfGetDB( DB_SLAVE );
1728 $data = $dbr->selectRow(
1729 array( 'logging', 'user' ),
1730 array( 'log_type',
1731 'log_action',
1732 'log_timestamp',
1733 'log_user',
1734 'log_namespace',
1735 'log_title',
1736 'log_comment',
1737 'log_params',
1738 'log_deleted',
1739 'user_name' ),
1740 array( 'log_namespace' => $this->mTitle->getNamespace(),
1741 'log_title' => $this->mTitle->getDBkey(),
1742 'log_type' => 'delete',
1743 'log_action' => 'delete',
1744 'user_id=log_user' ),
1745 __METHOD__,
1746 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
1748 // Quick paranoid permission checks...
1749 if( is_object($data) ) {
1750 if( $data->log_deleted & LogPage::DELETED_USER )
1751 $data->user_name = wfMsgHtml('rev-deleted-user');
1752 if( $data->log_deleted & LogPage::DELETED_COMMENT )
1753 $data->log_comment = wfMsgHtml('rev-deleted-comment');
1755 return $data;
1759 * Get the rendered text for previewing.
1760 * @return string
1762 function getPreviewText() {
1763 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
1765 wfProfileIn( __METHOD__ );
1767 if ( $this->mTriedSave && !$this->mTokenOk ) {
1768 if ( $this->mTokenOkExceptSuffix ) {
1769 $note = wfMsg( 'token_suffix_mismatch' );
1770 } else {
1771 $note = wfMsg( 'session_fail_preview' );
1773 } else {
1774 $note = wfMsg( 'previewnote' );
1777 $parserOptions = ParserOptions::newFromUser( $wgUser );
1778 $parserOptions->setEditSection( false );
1779 $parserOptions->setIsPreview( true );
1780 $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
1782 global $wgRawHtml;
1783 if ( $wgRawHtml && !$this->mTokenOk ) {
1784 // Could be an offsite preview attempt. This is very unsafe if
1785 // HTML is enabled, as it could be an attack.
1786 return $wgOut->parse( "<div class='previewnote'>" .
1787 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1790 # don't parse user css/js, show message about preview
1791 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1793 if ( $this->isCssJsSubpage ) {
1794 if (preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
1795 $previewtext = wfMsg('usercsspreview');
1796 } else if (preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
1797 $previewtext = wfMsg('userjspreview');
1799 $parserOptions->setTidy(true);
1800 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
1801 $previewHTML = $parserOutput->mText;
1802 } elseif ( $rt = Title::newFromRedirectArray( $this->textbox1 ) ) {
1803 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
1804 } else {
1805 $toparse = $this->textbox1;
1807 # If we're adding a comment, we need to show the
1808 # summary as the headline
1809 if ( $this->section=="new" && $this->summary!="" ) {
1810 $toparse="== {$this->summary} ==\n\n".$toparse;
1813 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
1815 // Parse mediawiki messages with correct target language
1816 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1817 list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
1818 $obj = wfGetLangObj( $lang );
1819 $parserOptions->setTargetLanguage( $obj );
1823 $parserOptions->setTidy(true);
1824 $parserOptions->enableLimitReport();
1825 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
1826 $this->mTitle, $parserOptions );
1828 $previewHTML = $parserOutput->getText();
1829 $this->mParserOutput = $parserOutput;
1830 $wgOut->addParserOutputNoText( $parserOutput );
1832 if ( count( $parserOutput->getWarnings() ) ) {
1833 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1837 if( $this->isConflict ) {
1838 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1839 } else {
1840 $conflict = '<hr />';
1843 $previewhead = "<div class='previewnote'>\n" .
1844 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
1845 $wgOut->parse( $note ) . $conflict . "</div>\n";
1847 wfProfileOut( __METHOD__ );
1848 return $previewhead . $previewHTML;
1851 function getTemplates() {
1852 if ( $this->preview || $this->section != '' ) {
1853 $templates = array();
1854 if ( !isset($this->mParserOutput) ) return $templates;
1855 foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
1856 foreach( array_keys( $template ) as $dbk ) {
1857 $templates[] = Title::makeTitle($ns, $dbk);
1860 return $templates;
1861 } else {
1862 return $this->mArticle->getUsedTemplates();
1867 * Call the stock "user is blocked" page
1869 function blockedPage() {
1870 global $wgOut, $wgUser;
1871 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1873 # If the user made changes, preserve them when showing the markup
1874 # (This happens when a user is blocked during edit, for instance)
1875 $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
1876 if ( $first ) {
1877 $source = $this->mTitle->exists() ? $this->getContent() : false;
1878 } else {
1879 $source = $this->textbox1;
1882 # Spit out the source or the user's modified version
1883 if ( $source !== false ) {
1884 $rows = $wgUser->getIntOption( 'rows' );
1885 $cols = $wgUser->getIntOption( 'cols' );
1886 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1887 $wgOut->addHTML( '<hr />' );
1888 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
1889 # Why we don't use Xml::element here?
1890 # Is it because if $source is '', it returns <textarea />?
1891 $wgOut->addHTML( Xml::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml::closeElement( 'textarea' ) );
1896 * Produce the stock "please login to edit pages" page
1898 function userNotLoggedInPage() {
1899 global $wgUser, $wgOut, $wgTitle;
1900 $skin = $wgUser->getSkin();
1902 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1903 $loginLink = $skin->link(
1904 $loginTitle,
1905 wfMsgHtml( 'loginreqlink' ),
1906 array(),
1907 array( 'returnto' => $wgTitle->getPrefixedText() ),
1908 array( 'known', 'noclasses' )
1911 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1912 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1913 $wgOut->setArticleRelated( false );
1915 $wgOut->addHTML( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1916 $wgOut->returnToMain( false, $wgTitle );
1920 * Creates a basic error page which informs the user that
1921 * they have attempted to edit a nonexistent section.
1923 function noSuchSectionPage() {
1924 global $wgOut, $wgTitle;
1926 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1927 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1928 $wgOut->setArticleRelated( false );
1930 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section );
1931 $wgOut->returnToMain( false, $wgTitle );
1935 * Produce the stock "your edit contains spam" page
1937 * @param $match Text which triggered one or more filters
1939 function spamPage( $match = false ) {
1940 global $wgOut, $wgTitle;
1942 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1943 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1944 $wgOut->setArticleRelated( false );
1946 $wgOut->addHTML( '<div id="spamprotected">' );
1947 $wgOut->addWikiMsg( 'spamprotectiontext' );
1948 if ( $match )
1949 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1950 $wgOut->addHTML( '</div>' );
1952 $wgOut->returnToMain( false, $wgTitle );
1956 * @private
1957 * @todo document
1959 function mergeChangesInto( &$editText ){
1960 $fname = 'EditPage::mergeChangesInto';
1961 wfProfileIn( $fname );
1963 $db = wfGetDB( DB_MASTER );
1965 // This is the revision the editor started from
1966 $baseRevision = $this->getBaseRevision();
1967 if ( is_null( $baseRevision ) ) {
1968 wfProfileOut( $fname );
1969 return false;
1971 $baseText = $baseRevision->getText();
1973 // The current state, we want to merge updates into it
1974 $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
1975 if ( is_null( $currentRevision ) ) {
1976 wfProfileOut( $fname );
1977 return false;
1979 $currentText = $currentRevision->getText();
1981 $result = '';
1982 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
1983 $editText = $result;
1984 wfProfileOut( $fname );
1985 return true;
1986 } else {
1987 wfProfileOut( $fname );
1988 return false;
1993 * Check if the browser is on a blacklist of user-agents known to
1994 * mangle UTF-8 data on form submission. Returns true if Unicode
1995 * should make it through, false if it's known to be a problem.
1996 * @return bool
1997 * @private
1999 function checkUnicodeCompliantBrowser() {
2000 global $wgBrowserBlackList;
2001 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2002 // No User-Agent header sent? Trust it by default...
2003 return true;
2005 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2006 foreach ( $wgBrowserBlackList as $browser ) {
2007 if ( preg_match($browser, $currentbrowser) ) {
2008 return false;
2011 return true;
2015 * @deprecated use $wgParser->stripSectionName()
2017 function pseudoParseSectionAnchor( $text ) {
2018 global $wgParser;
2019 return $wgParser->stripSectionName( $text );
2023 * Format an anchor fragment as it would appear for a given section name
2024 * @param string $text
2025 * @return string
2026 * @private
2028 function sectionAnchor( $text ) {
2029 global $wgParser;
2030 return $wgParser->guessSectionNameFromWikiText( $text );
2034 * Shows a bulletin board style toolbar for common editing functions.
2035 * It can be disabled in the user preferences.
2036 * The necessary JavaScript code can be found in skins/common/edit.js.
2038 * @return string
2040 static function getEditToolbar() {
2041 global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
2044 * toolarray an array of arrays which each include the filename of
2045 * the button image (without path), the opening tag, the closing tag,
2046 * and optionally a sample text that is inserted between the two when no
2047 * selection is highlighted.
2048 * The tip text is shown when the user moves the mouse over the button.
2050 * Already here are accesskeys (key), which are not used yet until someone
2051 * can figure out a way to make them work in IE. However, we should make
2052 * sure these keys are not defined on the edit page.
2054 $toolarray = array(
2055 array(
2056 'image' => $wgLang->getImageFile('button-bold'),
2057 'id' => 'mw-editbutton-bold',
2058 'open' => '\'\'\'',
2059 'close' => '\'\'\'',
2060 'sample' => wfMsg('bold_sample'),
2061 'tip' => wfMsg('bold_tip'),
2062 'key' => 'B'
2064 array(
2065 'image' => $wgLang->getImageFile('button-italic'),
2066 'id' => 'mw-editbutton-italic',
2067 'open' => '\'\'',
2068 'close' => '\'\'',
2069 'sample' => wfMsg('italic_sample'),
2070 'tip' => wfMsg('italic_tip'),
2071 'key' => 'I'
2073 array(
2074 'image' => $wgLang->getImageFile('button-link'),
2075 'id' => 'mw-editbutton-link',
2076 'open' => '[[',
2077 'close' => ']]',
2078 'sample' => wfMsg('link_sample'),
2079 'tip' => wfMsg('link_tip'),
2080 'key' => 'L'
2082 array(
2083 'image' => $wgLang->getImageFile('button-extlink'),
2084 'id' => 'mw-editbutton-extlink',
2085 'open' => '[',
2086 'close' => ']',
2087 'sample' => wfMsg('extlink_sample'),
2088 'tip' => wfMsg('extlink_tip'),
2089 'key' => 'X'
2091 array(
2092 'image' => $wgLang->getImageFile('button-headline'),
2093 'id' => 'mw-editbutton-headline',
2094 'open' => "\n== ",
2095 'close' => " ==\n",
2096 'sample' => wfMsg('headline_sample'),
2097 'tip' => wfMsg('headline_tip'),
2098 'key' => 'H'
2100 array(
2101 'image' => $wgLang->getImageFile('button-image'),
2102 'id' => 'mw-editbutton-image',
2103 'open' => '[['.$wgContLang->getNsText(NS_FILE).':',
2104 'close' => ']]',
2105 'sample' => wfMsg('image_sample'),
2106 'tip' => wfMsg('image_tip'),
2107 'key' => 'D'
2109 array(
2110 'image' => $wgLang->getImageFile('button-media'),
2111 'id' => 'mw-editbutton-media',
2112 'open' => '[['.$wgContLang->getNsText(NS_MEDIA).':',
2113 'close' => ']]',
2114 'sample' => wfMsg('media_sample'),
2115 'tip' => wfMsg('media_tip'),
2116 'key' => 'M'
2118 array(
2119 'image' => $wgLang->getImageFile('button-math'),
2120 'id' => 'mw-editbutton-math',
2121 'open' => "<math>",
2122 'close' => "</math>",
2123 'sample' => wfMsg('math_sample'),
2124 'tip' => wfMsg('math_tip'),
2125 'key' => 'C'
2127 array(
2128 'image' => $wgLang->getImageFile('button-nowiki'),
2129 'id' => 'mw-editbutton-nowiki',
2130 'open' => "<nowiki>",
2131 'close' => "</nowiki>",
2132 'sample' => wfMsg('nowiki_sample'),
2133 'tip' => wfMsg('nowiki_tip'),
2134 'key' => 'N'
2136 array(
2137 'image' => $wgLang->getImageFile('button-sig'),
2138 'id' => 'mw-editbutton-signature',
2139 'open' => '--~~~~',
2140 'close' => '',
2141 'sample' => '',
2142 'tip' => wfMsg('sig_tip'),
2143 'key' => 'Y'
2145 array(
2146 'image' => $wgLang->getImageFile('button-hr'),
2147 'id' => 'mw-editbutton-hr',
2148 'open' => "\n----\n",
2149 'close' => '',
2150 'sample' => '',
2151 'tip' => wfMsg('hr_tip'),
2152 'key' => 'R'
2155 $toolbar = "<div id='toolbar'>\n";
2156 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
2158 foreach($toolarray as $tool) {
2159 $params = array(
2160 $image = $wgStylePath.'/common/images/'.$tool['image'],
2161 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2162 // Older browsers show a "speedtip" type message only for ALT.
2163 // Ideally these should be different, realistically they
2164 // probably don't need to be.
2165 $tip = $tool['tip'],
2166 $open = $tool['open'],
2167 $close = $tool['close'],
2168 $sample = $tool['sample'],
2169 $cssId = $tool['id'],
2172 $paramList = implode( ',',
2173 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2174 $toolbar.="addButton($paramList);\n";
2177 $toolbar.="/*]]>*/\n</script>";
2178 $toolbar.="\n</div>";
2180 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2182 return $toolbar;
2186 * Returns an array of html code of the following checkboxes:
2187 * minor and watch
2189 * @param $tabindex Current tabindex
2190 * @param $skin Skin object
2191 * @param $checked Array of checkbox => bool, where bool indicates the checked
2192 * status of the checkbox
2194 * @return array
2196 public function getCheckboxes( &$tabindex, $skin, $checked ) {
2197 global $wgUser;
2199 $checkboxes = array();
2201 $checkboxes['minor'] = '';
2202 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
2203 if ( $wgUser->isAllowed('minoredit') ) {
2204 $attribs = array(
2205 'tabindex' => ++$tabindex,
2206 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2207 'id' => 'wpMinoredit',
2209 $checkboxes['minor'] =
2210 Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2211 "&nbsp;<label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
2214 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
2215 $checkboxes['watch'] = '';
2216 if ( $wgUser->isLoggedIn() ) {
2217 $attribs = array(
2218 'tabindex' => ++$tabindex,
2219 'accesskey' => wfMsg( 'accesskey-watch' ),
2220 'id' => 'wpWatchthis',
2222 $checkboxes['watch'] =
2223 Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2224 "&nbsp;<label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
2226 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2227 return $checkboxes;
2231 * Returns an array of html code of the following buttons:
2232 * save, diff, preview and live
2234 * @param $tabindex Current tabindex
2236 * @return array
2238 public function getEditButtons(&$tabindex) {
2239 global $wgLivePreview, $wgUser;
2241 $buttons = array();
2243 $temp = array(
2244 'id' => 'wpSave',
2245 'name' => 'wpSave',
2246 'type' => 'submit',
2247 'tabindex' => ++$tabindex,
2248 'value' => wfMsg('savearticle'),
2249 'accesskey' => wfMsg('accesskey-save'),
2250 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2252 $buttons['save'] = Xml::element('input', $temp, '');
2254 ++$tabindex; // use the same for preview and live preview
2255 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
2256 $temp = array(
2257 'id' => 'wpPreview',
2258 'name' => 'wpPreview',
2259 'type' => 'submit',
2260 'tabindex' => $tabindex,
2261 'value' => wfMsg('showpreview'),
2262 'accesskey' => '',
2263 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2264 'style' => 'display: none;',
2266 $buttons['preview'] = Xml::element('input', $temp, '');
2268 $temp = array(
2269 'id' => 'wpLivePreview',
2270 'name' => 'wpLivePreview',
2271 'type' => 'submit',
2272 'tabindex' => $tabindex,
2273 'value' => wfMsg('showlivepreview'),
2274 'accesskey' => wfMsg('accesskey-preview'),
2275 'title' => '',
2276 'onclick' => $this->doLivePreviewScript(),
2278 $buttons['live'] = Xml::element('input', $temp, '');
2279 } else {
2280 $temp = array(
2281 'id' => 'wpPreview',
2282 'name' => 'wpPreview',
2283 'type' => 'submit',
2284 'tabindex' => $tabindex,
2285 'value' => wfMsg('showpreview'),
2286 'accesskey' => wfMsg('accesskey-preview'),
2287 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2289 $buttons['preview'] = Xml::element('input', $temp, '');
2290 $buttons['live'] = '';
2293 $temp = array(
2294 'id' => 'wpDiff',
2295 'name' => 'wpDiff',
2296 'type' => 'submit',
2297 'tabindex' => ++$tabindex,
2298 'value' => wfMsg('showdiff'),
2299 'accesskey' => wfMsg('accesskey-diff'),
2300 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2302 $buttons['diff'] = Xml::element('input', $temp, '');
2304 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2305 return $buttons;
2309 * Output preview text only. This can be sucked into the edit page
2310 * via JavaScript, and saves the server time rendering the skin as
2311 * well as theoretically being more robust on the client (doesn't
2312 * disturb the edit box's undo history, won't eat your text on
2313 * failure, etc).
2315 * @todo This doesn't include category or interlanguage links.
2316 * Would need to enhance it a bit, <s>maybe wrap them in XML
2317 * or something...</s> that might also require more skin
2318 * initialization, so check whether that's a problem.
2320 function livePreview() {
2321 global $wgOut;
2322 $wgOut->disable();
2323 header( 'Content-type: text/xml; charset=utf-8' );
2324 header( 'Cache-control: no-cache' );
2326 $previewText = $this->getPreviewText();
2327 #$categories = $skin->getCategoryLinks();
2329 $s =
2330 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2331 Xml::tags( 'livepreview', null,
2332 Xml::element( 'preview', null, $previewText )
2333 #. Xml::element( 'category', null, $categories )
2335 echo $s;
2340 * Get a diff between the current contents of the edit box and the
2341 * version of the page we're editing from.
2343 * If this is a section edit, we'll replace the section as for final
2344 * save and then make a comparison.
2346 function showDiff() {
2347 $oldtext = $this->mArticle->fetchContent();
2348 $newtext = $this->mArticle->replaceSection(
2349 $this->section, $this->textbox1, $this->summary, $this->edittime );
2350 $newtext = $this->mArticle->preSaveTransform( $newtext );
2351 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2352 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2353 if ( $oldtext !== false || $newtext != '' ) {
2354 $de = new DifferenceEngine( $this->mTitle );
2355 $de->setText( $oldtext, $newtext );
2356 $difftext = $de->getDiff( $oldtitle, $newtitle );
2357 $de->showDiffStyle();
2358 } else {
2359 $difftext = '';
2362 global $wgOut;
2363 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2367 * Filter an input field through a Unicode de-armoring process if it
2368 * came from an old browser with known broken Unicode editing issues.
2370 * @param WebRequest $request
2371 * @param string $field
2372 * @return string
2373 * @private
2375 function safeUnicodeInput( $request, $field ) {
2376 $text = rtrim( $request->getText( $field ) );
2377 return $request->getBool( 'safemode' )
2378 ? $this->unmakesafe( $text )
2379 : $text;
2383 * Filter an output field through a Unicode armoring process if it is
2384 * going to an old browser with known broken Unicode editing issues.
2386 * @param string $text
2387 * @return string
2388 * @private
2390 function safeUnicodeOutput( $text ) {
2391 global $wgContLang;
2392 $codedText = $wgContLang->recodeForEdit( $text );
2393 return $this->checkUnicodeCompliantBrowser()
2394 ? $codedText
2395 : $this->makesafe( $codedText );
2399 * A number of web browsers are known to corrupt non-ASCII characters
2400 * in a UTF-8 text editing environment. To protect against this,
2401 * detected browsers will be served an armored version of the text,
2402 * with non-ASCII chars converted to numeric HTML character references.
2404 * Preexisting such character references will have a 0 added to them
2405 * to ensure that round-trips do not alter the original data.
2407 * @param string $invalue
2408 * @return string
2409 * @private
2411 function makesafe( $invalue ) {
2412 // Armor existing references for reversability.
2413 $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
2415 $bytesleft = 0;
2416 $result = "";
2417 $working = 0;
2418 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2419 $bytevalue = ord( $invalue{$i} );
2420 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2421 $result .= chr( $bytevalue );
2422 $bytesleft = 0;
2423 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2424 $working = $working << 6;
2425 $working += ($bytevalue & 0x3F);
2426 $bytesleft--;
2427 if ( $bytesleft <= 0 ) {
2428 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2430 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2431 $working = $bytevalue & 0x1F;
2432 $bytesleft = 1;
2433 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2434 $working = $bytevalue & 0x0F;
2435 $bytesleft = 2;
2436 } else { //1111 0xxx
2437 $working = $bytevalue & 0x07;
2438 $bytesleft = 3;
2441 return $result;
2445 * Reverse the previously applied transliteration of non-ASCII characters
2446 * back to UTF-8. Used to protect data from corruption by broken web browsers
2447 * as listed in $wgBrowserBlackList.
2449 * @param string $invalue
2450 * @return string
2451 * @private
2453 function unmakesafe( $invalue ) {
2454 $result = "";
2455 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2456 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
2457 $i += 3;
2458 $hexstring = "";
2459 do {
2460 $hexstring .= $invalue{$i};
2461 $i++;
2462 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2464 // Do some sanity checks. These aren't needed for reversability,
2465 // but should help keep the breakage down if the editor
2466 // breaks one of the entities whilst editing.
2467 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2468 $codepoint = hexdec($hexstring);
2469 $result .= codepointToUtf8( $codepoint );
2470 } else {
2471 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2473 } else {
2474 $result .= substr( $invalue, $i, 1 );
2477 // reverse the transform that we made for reversability reasons.
2478 return strtr( $result, array( "&#x0" => "&#x" ) );
2481 function noCreatePermission() {
2482 global $wgOut;
2483 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2484 $wgOut->addWikiMsg( 'nocreatetext' );
2488 * If there are rows in the deletion/move log for this page, show them,
2489 * along with a nice little note for the user
2491 * @param OutputPage $out
2493 protected function showLogs( $out ) {
2494 global $wgUser;
2495 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2496 $pager = new LogPager( $loglist, array('move', 'delete'), false,
2497 $this->mTitle->getPrefixedText(), '', array( "log_action != 'revision'" ) );
2499 $count = $pager->getNumRows();
2500 if ( $count > 0 ) {
2501 $pager->mLimit = 10;
2502 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
2503 $out->addWikiMsg( 'recreate-moveddeleted-warn' );
2504 $out->addHTML(
2505 $loglist->beginLogEventsList() .
2506 $pager->getBody() .
2507 $loglist->endLogEventsList()
2509 if($count > 10){
2510 $out->addHTML( $wgUser->getSkin()->link(
2511 SpecialPage::getTitleFor( 'Log' ),
2512 wfMsgHtml( 'log-fulllog' ),
2513 array(),
2514 array( 'page' => $this->mTitle->getPrefixedText() ) ) );
2516 $out->addHTML( '</div>' );
2517 return true;
2520 return false;
2524 * Attempt submission
2525 * @return bool false if output is done, true if the rest of the form should be displayed
2527 function attemptSave() {
2528 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2530 $resultDetails = false;
2531 # Allow bots to exempt some edits from bot flagging
2532 $bot = $wgUser->isAllowed('bot') && $wgRequest->getBool('bot',true);
2533 $value = $this->internalAttemptSave( $resultDetails, $bot );
2535 if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
2536 $this->didSave = true;
2539 switch ($value) {
2540 case self::AS_HOOK_ERROR_EXPECTED:
2541 case self::AS_CONTENT_TOO_BIG:
2542 case self::AS_ARTICLE_WAS_DELETED:
2543 case self::AS_CONFLICT_DETECTED:
2544 case self::AS_SUMMARY_NEEDED:
2545 case self::AS_TEXTBOX_EMPTY:
2546 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
2547 case self::AS_END:
2548 return true;
2550 case self::AS_HOOK_ERROR:
2551 case self::AS_FILTERING:
2552 case self::AS_SUCCESS_NEW_ARTICLE:
2553 case self::AS_SUCCESS_UPDATE:
2554 return false;
2556 case self::AS_SPAM_ERROR:
2557 $this->spamPage ( $resultDetails['spam'] );
2558 return false;
2560 case self::AS_BLOCKED_PAGE_FOR_USER:
2561 $this->blockedPage();
2562 return false;
2564 case self::AS_IMAGE_REDIRECT_ANON:
2565 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2566 return false;
2568 case self::AS_READ_ONLY_PAGE_ANON:
2569 $this->userNotLoggedInPage();
2570 return false;
2572 case self::AS_READ_ONLY_PAGE_LOGGED:
2573 case self::AS_READ_ONLY_PAGE:
2574 $wgOut->readOnlyPage();
2575 return false;
2577 case self::AS_RATE_LIMITED:
2578 $wgOut->rateLimited();
2579 return false;
2581 case self::AS_NO_CREATE_PERMISSION;
2582 $this->noCreatePermission();
2583 return;
2585 case self::AS_BLANK_ARTICLE:
2586 $wgOut->redirect( $wgTitle->getFullURL() );
2587 return false;
2589 case self::AS_IMAGE_REDIRECT_LOGGED:
2590 $wgOut->permissionRequired( 'upload' );
2591 return false;
2595 function getBaseRevision() {
2596 if ( $this->mBaseRevision == false ) {
2597 $db = wfGetDB( DB_MASTER );
2598 $baseRevision = Revision::loadFromTimestamp(
2599 $db, $this->mTitle, $this->edittime );
2600 return $this->mBaseRevision = $baseRevision;
2601 } else {
2602 return $this->mBaseRevision;