3 * Contains the EditPage class
7 * The edit page/HTML interface (split from Article)
8 * The actual database and text munging is still in Article,
9 * but it should get easier to call those from alternate
12 * EditPage cares about two distinct titles:
13 * $wgTitle is the page that forms submit to, links point to,
14 * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
15 * page in the database that is actually being edited. These are
16 * usually the same, but they are now allowed to be different.
19 const AS_SUCCESS_UPDATE
= 200;
20 const AS_SUCCESS_NEW_ARTICLE
= 201;
21 const AS_HOOK_ERROR
= 210;
22 const AS_FILTERING
= 211;
23 const AS_HOOK_ERROR_EXPECTED
= 212;
24 const AS_BLOCKED_PAGE_FOR_USER
= 215;
25 const AS_CONTENT_TOO_BIG
= 216;
26 const AS_USER_CANNOT_EDIT
= 217;
27 const AS_READ_ONLY_PAGE_ANON
= 218;
28 const AS_READ_ONLY_PAGE_LOGGED
= 219;
29 const AS_READ_ONLY_PAGE
= 220;
30 const AS_RATE_LIMITED
= 221;
31 const AS_ARTICLE_WAS_DELETED
= 222;
32 const AS_NO_CREATE_PERMISSION
= 223;
33 const AS_BLANK_ARTICLE
= 224;
34 const AS_CONFLICT_DETECTED
= 225;
35 const AS_SUMMARY_NEEDED
= 226;
36 const AS_TEXTBOX_EMPTY
= 228;
37 const AS_MAX_ARTICLE_SIZE_EXCEDED
= 229;
40 const AS_SPAM_ERROR
= 232;
45 var $isConflict = false;
46 var $isCssJsSubpage = false;
47 var $deletedSinceEdit = false;
51 var $mTokenOk = false;
52 var $mTokenOkExceptSuffix = false;
53 var $mTriedSave = false;
55 var $kblength = false;
56 var $missingComment = false;
57 var $missingSummary = false;
58 var $allowBlankSummary = false;
61 var $mPreviewTemplates;
64 var $save = false, $preview = false, $diff = false;
65 var $minoredit = false, $watchthis = false, $recreate = false;
66 var $textbox1 = '', $textbox2 = '', $summary = '';
67 var $edittime = '', $section = '', $starttime = '';
68 var $oldid = 0, $editintro = '', $scrolltop = null;
70 # Placeholders for text injection by hooks (must be HTML)
71 # extensions should take care to _append_ to the present value
72 public $editFormPageTop; // Before even the preview
73 public $editFormTextTop;
74 public $editFormTextBeforeContent;
75 public $editFormTextAfterWarn;
76 public $editFormTextAfterTools;
77 public $editFormTextBottom;
79 /* $didSave should be set to true whenever an article was succesfully altered. */
80 public $didSave = false;
82 public $suppressIntro = false;
88 function EditPage( $article ) {
90 $this->mArticle
=& $article;
91 $this->mTitle
= $article->getTitle();
93 # Placeholders for text injection by hooks (empty per default)
94 $this->editFormPageTop
=
95 $this->editFormTextTop
=
96 $this->editFormTextBeforeContent
=
97 $this->editFormTextAfterWarn
=
98 $this->editFormTextAfterTools
=
99 $this->editFormTextBottom
= "";
103 * Fetch initial editing page content.
105 private function getContent( $def_text = '' ) {
106 global $wgOut, $wgRequest, $wgParser;
108 # Get variables from query string :P
109 $section = $wgRequest->getVal( 'section' );
110 $preload = $wgRequest->getVal( 'preload' );
111 $undoafter = $wgRequest->getVal( 'undoafter' );
112 $undo = $wgRequest->getVal( 'undo' );
114 wfProfileIn( __METHOD__
);
117 if( !$this->mTitle
->exists() ) {
118 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
119 # If this is a system message, get the default text.
120 $text = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
122 # If requested, preload some text.
123 $text = $this->getPreloadedText( $preload );
125 # We used to put MediaWiki:Newarticletext here if
126 # $text was empty at this point.
127 # This is now shown above the edit box instead.
129 // FIXME: may be better to use Revision class directly
130 // But don't mess with it just yet. Article knows how to
131 // fetch the page record from the high-priority server,
132 // which is needed to guarantee we don't pick up lagged
135 $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 );
142 if ( $undo > 0 && $undo > $undoafter ) {
143 # Undoing a specific edit overrides section editing; section-editing
144 # doesn't work with undoing.
146 $undorev = Revision
::newFromId($undo);
147 $oldrev = Revision
::newFromId($undoafter);
149 $undorev = Revision
::newFromId($undo);
150 $oldrev = $undorev ?
$undorev->getPrevious() : null;
153 #Sanity check, make sure it's the right page.
154 # Otherwise, $text will be left as-is.
155 if ( !is_null($undorev) && !is_null($oldrev) && $undorev->getPage()==$oldrev->getPage() && $undorev->getPage()==$this->mArticle
->getID() ) {
156 $undorev_text = $undorev->getText();
157 $oldrev_text = $oldrev->getText();
158 $currev_text = $text;
160 #No use doing a merge if it's just a straight revert.
161 if ( $currev_text != $undorev_text ) {
162 $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text);
164 $text = $oldrev_text;
168 // Failed basic sanity checks.
169 // Older revisions may have been removed since the link
170 // was created, or we may simply have got bogus input.
175 # Inform the user of our success and set an automatic edit summary
176 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
177 $firstrev = $oldrev->getNext();
178 # If we just undid one rev, use an autosummary
179 if ( $firstrev->mId
== $undo ) {
180 $this->summary
= wfMsgForContent('undo-summary', $undo, $undorev->getUserText());
182 $this->formtype
= 'diff';
184 # Warn the user that something went wrong
185 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
187 } else if( $section != '' ) {
188 if( $section == 'new' ) {
189 $text = $this->getPreloadedText( $preload );
191 $text = $wgParser->getSection( $text, $section, $def_text );
196 wfProfileOut( __METHOD__
);
201 * Get the contents of a page from its title and remove includeonly tags
203 * @param $preload String: the title of the page.
204 * @return string The contents of the page.
206 private function getPreloadedText($preload) {
207 if ( $preload === '' )
210 $preloadTitle = Title
::newFromText( $preload );
211 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
212 $rev=Revision
::newFromTitle($preloadTitle);
213 if ( is_object( $rev ) ) {
214 $text = $rev->getText();
215 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
216 // its own mini-parser! -ævar
217 $text = preg_replace( '~</?includeonly>~', '', $text );
226 * This is the function that extracts metadata from the article body on the first view.
227 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
228 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
230 function extractMetaDataFromArticle () {
231 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
232 $this->mMetaData
= '' ;
233 if ( !$wgUseMetadataEdit ) return ;
234 if ( $wgMetadataWhitelist == '' ) return ;
236 $t = $this->getContent();
238 # MISSING : <nowiki> filtering
240 # Categories and language links
241 $t = explode ( "\n" , $t ) ;
242 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
243 $cat = $ll = array() ;
244 foreach ( $t AS $key => $x )
246 $y = trim ( strtolower ( $x ) ) ;
247 while ( substr ( $y , 0 , 2 ) == '[[' )
249 $y = explode ( ']]' , trim ( $x ) ) ;
250 $first = array_shift ( $y ) ;
251 $first = explode ( ':' , $first ) ;
252 $ns = array_shift ( $first ) ;
253 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
254 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
256 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
257 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
259 $x = implode ( ']]' , $y ) ;
261 $y = trim ( strtolower ( $x ) ) ;
265 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
266 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
267 $t = implode ( "\n" , $t ) ;
270 $sat = array () ; # stand-alone-templates; must be lowercase
271 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
272 $wl_article = new Article ( $wl_title ) ;
273 $wl = explode ( "\n" , $wl_article->getContent() ) ;
274 foreach ( $wl AS $x )
278 while ( substr ( $x , 0 , 1 ) == '*' )
281 $x = trim ( substr ( $x , 1 ) ) ;
285 $sat[] = strtolower ( $x ) ;
290 # Templates, but only some
291 $t = explode ( '{{' , $t ) ;
293 foreach ( $t AS $key => $x )
295 $y = explode ( '}}' , $x , 2 ) ;
296 if ( count ( $y ) == 2 )
299 $z = explode ( '|' , $z ) ;
300 $tn = array_shift ( $z ) ;
301 if ( in_array ( strtolower ( $tn ) , $sat ) )
303 $tl[] = '{{' . $y[0] . '}}' ;
305 $y = explode ( '}}' , $y[1] , 2 ) ;
307 else $t[$key] = '{{' . $x ;
309 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
312 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
313 $t = implode ( '' , $t ) ;
315 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
316 $this->mArticle
->mContent
= $t ;
317 $this->mMetaData
= $s ;
325 * This is the function that gets called for "action=edit". It
326 * sets up various member variables, then passes execution to
327 * another function, usually showEditForm()
329 * The edit form is self-submitting, so that when things like
330 * preview and edit conflicts occur, we get the same form back
331 * with the extra stuff added. Only when the final submission
332 * is made and all is well do we actually save and redirect to
333 * the newly-edited page.
336 global $wgOut, $wgUser, $wgRequest, $wgTitle;
338 if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) )
341 wfProfileIn( __METHOD__
);
342 wfDebug( __METHOD__
.": enter\n" );
344 // this is not an article
345 $wgOut->setArticleFlag(false);
347 $this->importFormData( $wgRequest );
348 $this->firsttime
= false;
351 $this->livePreview();
352 wfProfileOut( __METHOD__
);
356 $permErrors = $this->mTitle
->getUserPermissionsErrors('edit', $wgUser);
357 if( !$this->mTitle
->exists() ) {
358 # We can't use array_diff here, because that considers ANY TWO
359 # ARRAYS TO BE EQUAL. Thanks, PHP.
360 $createErrors = $this->mTitle
->getUserPermissionsErrors('create', $wgUser);
361 foreach( $createErrors as $error ) {
362 # in_array() actually *does* work as expected.
363 if( !in_array( $error, $permErrors ) ) {
364 $permErrors[] = $error;
369 # Ignore some permissions errors.
371 foreach( $permErrors as $error ) {
372 if ($this->preview ||
$this->diff
&&
373 ($error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext'))
375 // Don't worry about blocks when previewing/diffing
379 if ($error[0] == 'readonlytext')
382 $this->formtype
= 'preview';
383 } elseif ($this->save ||
$this->preview ||
$this->diff
) {
388 $permErrors = array_diff( $permErrors, $remove );
390 if ( !empty($permErrors) ) {
391 wfDebug( __METHOD__
.": User can't edit\n" );
392 $wgOut->readOnlyPage( $this->getContent(), true, $permErrors );
393 wfProfileOut( __METHOD__
);
397 $this->formtype
= 'save';
398 } else if ( $this->preview
) {
399 $this->formtype
= 'preview';
400 } else if ( $this->diff
) {
401 $this->formtype
= 'diff';
402 } else { # First time through
403 $this->firsttime
= true;
404 if( $this->previewOnOpen() ) {
405 $this->formtype
= 'preview';
407 $this->extractMetaDataFromArticle () ;
408 $this->formtype
= 'initial';
413 wfProfileIn( __METHOD__
."-business-end" );
415 $this->isConflict
= false;
416 // css / js subpages of user pages get a special treatment
417 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
418 $this->isValidCssJsSubpage
= $this->mTitle
->isValidCssJsSubpage();
420 /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
421 * no matter it's current state
423 $this->deletedSinceEdit
= false;
424 if ( $this->edittime
!= '' ) {
425 /* Note that we rely on logging table, which hasn't been always there,
426 * but that doesn't matter, because this only applies to brand new
427 * deletes. This is done on every preview and save request. Move it further down
428 * to only perform it on saves
430 if ( $this->mTitle
->isDeleted() ) {
431 $this->lastDelete
= $this->getLastDelete();
432 if ( !is_null($this->lastDelete
) ) {
433 $deletetime = $this->lastDelete
->log_timestamp
;
434 if ( ($deletetime - $this->starttime
) > 0 ) {
435 $this->deletedSinceEdit
= true;
441 # Show applicable editing introductions
442 if( $this->formtype
== 'initial' ||
$this->firsttime
)
445 if( $this->mTitle
->isTalkPage() ) {
446 $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
449 # Attempt submission here. This will check for edit conflicts,
450 # and redundantly check for locked database, blocked IPs, etc.
451 # that edit() already checked just in case someone tries to sneak
452 # in the back door with a hand-edited submission URL.
454 if ( 'save' == $this->formtype
) {
455 if ( !$this->attemptSave() ) {
456 wfProfileOut( __METHOD__
."-business-end" );
457 wfProfileOut( __METHOD__
);
462 # First time through: get contents, set time for conflict
464 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
465 if ($this->initialiseForm() === false) {
466 $this->noSuchSectionPage();
467 wfProfileOut( __METHOD__
."-business-end" );
468 wfProfileOut( __METHOD__
);
471 if( !$this->mTitle
->getArticleId() )
472 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
475 $this->showEditForm();
476 wfProfileOut( __METHOD__
."-business-end" );
477 wfProfileOut( __METHOD__
);
481 * Should we show a preview when the edit form is first shown?
485 private function previewOnOpen() {
486 global $wgRequest, $wgUser;
487 if( $wgRequest->getVal( 'preview' ) == 'yes' ) {
488 // Explicit override from request
490 } elseif( $wgRequest->getVal( 'preview' ) == 'no' ) {
491 // Explicit override from request
493 } elseif( $this->section
== 'new' ) {
494 // Nothing *to* preview for new sections
496 } elseif( ( $wgRequest->getVal( 'preload' ) !== '' ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
497 // Standard preference behaviour
499 } elseif( !$this->mTitle
->exists() && $this->mTitle
->getNamespace() == NS_CATEGORY
) {
500 // Categories are special
511 function importFormData( &$request ) {
512 global $wgLang, $wgUser;
513 $fname = 'EditPage::importFormData';
514 wfProfileIn( $fname );
516 if( $request->wasPosted() ) {
517 # These fields need to be checked for encoding.
518 # Also remove trailing whitespace, but don't remove _initial_
519 # whitespace from the text boxes. This may be significant formatting.
520 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
521 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
522 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
523 # Truncate for whole multibyte characters. +5 bytes for ellipsis
524 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
526 $this->edittime
= $request->getVal( 'wpEdittime' );
527 $this->starttime
= $request->getVal( 'wpStarttime' );
529 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
531 if( is_null( $this->edittime
) ) {
532 # If the form is incomplete, force to preview.
533 wfDebug( "$fname: Form data appears to be incomplete\n" );
534 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
535 $this->preview
= true;
537 /* Fallback for live preview */
538 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
539 $this->diff
= $request->getCheck( 'wpDiff' );
541 // Remember whether a save was requested, so we can indicate
542 // if we forced preview due to session failure.
543 $this->mTriedSave
= !$this->preview
;
545 if ( $this->tokenOk( $request ) ) {
546 # Some browsers will not report any submit button
547 # if the user hits enter in the comment box.
548 # The unmarked state will be assumed to be a save,
549 # if the form seems otherwise complete.
550 wfDebug( "$fname: Passed token check.\n" );
551 } else if ( $this->diff
) {
552 # Failed token check, but only requested "Show Changes".
553 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
555 # Page might be a hack attempt posted from
556 # an external site. Preview instead of saving.
557 wfDebug( "$fname: Failed token check; forcing preview\n" );
558 $this->preview
= true;
561 $this->save
= ! ( $this->preview
OR $this->diff
);
562 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
563 $this->edittime
= null;
566 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
567 $this->starttime
= null;
570 $this->recreate
= $request->getCheck( 'wpRecreate' );
572 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
573 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
575 # Don't force edit summaries when a user is editing their own user or talk page
576 if( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) && $this->mTitle
->getText() == $wgUser->getName() ) {
577 $this->allowBlankSummary
= true;
579 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' );
582 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
584 # Not a posted form? Start with nothing.
585 wfDebug( "$fname: Not a posted form.\n" );
586 $this->textbox1
= '';
587 $this->textbox2
= '';
588 $this->mMetaData
= '';
590 $this->edittime
= '';
591 $this->starttime
= wfTimestampNow();
593 $this->preview
= false;
596 $this->minoredit
= false;
597 $this->watchthis
= false;
598 $this->recreate
= false;
601 $this->oldid
= $request->getInt( 'oldid' );
603 # Section edit can come from either the form or a link
604 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
606 $this->live
= $request->getCheck( 'live' );
607 $this->editintro
= $request->getText( 'editintro' );
609 wfProfileOut( $fname );
613 * Make sure the form isn't faking a user's credentials.
615 * @param $request WebRequest
619 function tokenOk( &$request ) {
621 $token = $request->getVal( 'wpEditToken' );
622 $this->mTokenOk
= $wgUser->matchEditToken( $token );
623 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
624 return $this->mTokenOk
;
628 * Show all applicable editing introductions
630 private function showIntro() {
631 global $wgOut, $wgUser;
632 if( $this->suppressIntro
)
635 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
636 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
637 $parts = explode( '/', $this->mTitle
->getText(), 2 );
638 $username = $parts[0];
639 $id = User
::idFromName( $username );
640 $ip = User
::isIP( $username );
642 if ( $id == 0 && !$ip ) {
643 $wgOut->addWikiText( '<div class="mw-userpage-userdoesnotexist error">' . wfMsg( 'userpage-userdoesnotexist', $username ) . '</div>' );
647 if( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
648 if( $wgUser->isLoggedIn() ) {
649 $wgOut->addWikiText( '<div class="mw-newarticletext">' . wfMsg( 'newarticletext' ) . '</div>' );
651 $wgOut->addWikiText( '<div class="mw-newarticletextanon">' . wfMsg( 'newarticletextanon' ) . '</div>' );
653 $this->showDeletionLog( $wgOut );
658 * Attempt to show a custom editing introduction, if supplied
662 private function showCustomIntro() {
663 if( $this->editintro
) {
664 $title = Title
::newFromText( $this->editintro
);
665 if( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
667 $revision = Revision
::newFromTitle( $title );
668 $wgOut->addSecondaryWikiText( $revision->getText() );
679 * Attempt submission (no UI)
680 * @return one of the constants describing the result
682 function internalAttemptSave( &$result, $bot = false ) {
683 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser;
684 global $wgMaxArticleSize, $wgTitle;
686 $fname = 'EditPage::attemptSave';
687 wfProfileIn( $fname );
688 wfProfileIn( "$fname-checks" );
690 if( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
692 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
693 return self
::AS_HOOK_ERROR
;
696 # Reintegrate metadata
697 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
698 $this->mMetaData
= '' ;
702 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
703 $result['spam'] = $matches[0];
704 wfProfileOut( "$fname-checks" );
705 wfProfileOut( $fname );
706 return self
::AS_SPAM_ERROR
;
708 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
709 # Error messages or other handling should be performed by the filter function
710 wfProfileOut( "$fname-checks" );
711 wfProfileOut( $fname );
712 return self
::AS_FILTERING
;
714 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
) ) ) {
715 # Error messages etc. could be handled within the hook...
716 wfProfileOut( "$fname-checks" );
717 wfProfileOut( $fname );
718 return self
::AS_HOOK_ERROR
;
719 } elseif( $this->hookError
!= '' ) {
720 # ...or the hook could be expecting us to produce an error
721 wfProfileOut( "$fname-checks" );
722 wfProfileOut( $fname );
723 return self
::AS_HOOK_ERROR_EXPECTED
;
725 if ( $wgUser->isBlockedFrom( $wgTitle, false ) ) {
726 # Check block state against master, thus 'false'.
727 wfProfileOut( "$fname-checks" );
728 wfProfileOut( $fname );
729 return self
::AS_BLOCKED_PAGE_FOR_USER
;
731 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
732 if ( $this->kblength
> $wgMaxArticleSize ) {
733 // Error will be displayed by showEditForm()
734 $this->tooBig
= true;
735 wfProfileOut( "$fname-checks" );
736 wfProfileOut( $fname );
737 return self
::AS_CONTENT_TOO_BIG
;
740 if ( !$wgUser->isAllowed('edit') ) {
741 if ( $wgUser->isAnon() ) {
742 wfProfileOut( "$fname-checks" );
743 wfProfileOut( $fname );
744 return self
::AS_READ_ONLY_PAGE_ANON
;
747 wfProfileOut( "$fname-checks" );
748 wfProfileOut( $fname );
749 return self
::AS_READ_ONLY_PAGE_LOGGED
;
753 if ( wfReadOnly() ) {
754 wfProfileOut( "$fname-checks" );
755 wfProfileOut( $fname );
756 return self
::AS_READ_ONLY_PAGE
;
758 if ( $wgUser->pingLimiter() ) {
759 wfProfileOut( "$fname-checks" );
760 wfProfileOut( $fname );
761 return self
::AS_RATE_LIMITED
;
764 # If the article has been deleted while editing, don't save it without
766 if ( $this->deletedSinceEdit
&& !$this->recreate
) {
767 wfProfileOut( "$fname-checks" );
768 wfProfileOut( $fname );
769 return self
::AS_ARTICLE_WAS_DELETED
;
772 wfProfileOut( "$fname-checks" );
774 # If article is new, insert it.
775 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
778 // Late check for create permission, just in case *PARANOIA*
779 if ( !$this->mTitle
->userCan( 'create' ) ) {
780 wfDebug( "$fname: no create permission\n" );
781 wfProfileOut( $fname );
782 return self
::AS_NO_CREATE_PERMISSION
;
785 # Don't save a new article if it's blank.
786 if ( ( '' == $this->textbox1
) ) {
787 wfProfileOut( $fname );
788 return self
::AS_BLANK_ARTICLE
;
791 // Run post-section-merge edit filter
792 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
) ) ) {
793 # Error messages etc. could be handled within the hook...
794 wfProfileOut( $fname );
798 $isComment = ( $this->section
== 'new' );
800 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
801 $this->minoredit
, $this->watchthis
, false, $isComment, $bot);
803 wfProfileOut( $fname );
804 return self
::AS_SUCCESS_NEW_ARTICLE
;
807 # Article exists. Check for edit conflict.
809 $this->mArticle
->clear(); # Force reload of dates, etc.
810 $this->mArticle
->forUpdate( true ); # Lock the article
812 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
814 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
815 $this->isConflict
= true;
816 if( $this->section
== 'new' ) {
817 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
818 $this->mArticle
->getComment() == $this->summary
) {
819 // Probably a duplicate submission of a new comment.
820 // This can happen when squid resends a request after
821 // a timeout but the first one actually went through.
822 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
824 // New comment; suppress conflict.
825 $this->isConflict
= false;
826 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
830 $userid = $wgUser->getID();
832 if ( $this->isConflict
) {
833 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
834 $this->mArticle
->getTimestamp() . "')\n" );
835 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
838 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
839 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
841 if( is_null( $text ) ) {
842 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
843 $this->isConflict
= true;
844 $text = $this->textbox1
;
847 # Suppress edit conflict with self, except for section edits where merging is required.
848 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
849 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
850 $this->isConflict
= false;
852 # switch from section editing to normal editing in edit conflict
853 if($this->isConflict
) {
855 if( $this->mergeChangesInto( $text ) ){
856 // Successful merge! Maybe we should tell the user the good news?
857 $this->isConflict
= false;
858 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
861 $this->textbox1
= $text;
862 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
867 if ( $this->isConflict
) {
868 wfProfileOut( $fname );
869 return self
::AS_CONFLICT_DETECTED
;
872 $oldtext = $this->mArticle
->getContent();
874 // Run post-section-merge edit filter
875 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
) ) ) {
876 # Error messages etc. could be handled within the hook...
877 wfProfileOut( $fname );
881 # Handle the user preference to force summaries here, but not for null edits
882 if( $this->section
!= 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary')
883 && 0 != strcmp($oldtext, $text) && !Article
::getRedirectAutosummary( $text )) {
884 if( md5( $this->summary
) == $this->autoSumm
) {
885 $this->missingSummary
= true;
886 wfProfileOut( $fname );
887 return self
::AS_SUMMARY_NEEDED
;
891 #And a similar thing for new sections
892 if( $this->section
== 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary' ) ) {
893 if (trim($this->summary
) == '') {
894 $this->missingSummary
= true;
895 wfProfileOut( $fname );
896 return self
::AS_SUMMARY_NEEDED
;
901 wfProfileIn( "$fname-sectionanchor" );
903 if( $this->section
== 'new' ) {
904 if ( $this->textbox1
== '' ) {
905 $this->missingComment
= true;
906 return self
::AS_TEXTBOX_EMPTY
;
908 if( $this->summary
!= '' ) {
909 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary
);
910 # This is a new section, so create a link to the new section
911 # in the revision summary.
912 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
913 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
915 } elseif( $this->section
!= '' ) {
916 # Try to get a section anchor from the section source, redirect to edited section if header found
917 # XXX: might be better to integrate this into Article::replaceSection
918 # for duplicate heading checking and maybe parsing
919 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
920 # we can't deal with anchors, includes, html etc in the header for now,
921 # headline would need to be parsed to improve this
922 if($hasmatch and strlen($matches[2]) > 0) {
923 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
926 wfProfileOut( "$fname-sectionanchor" );
928 // Save errors may fall down to the edit form, but we've now
929 // merged the section into full text. Clear the section field
930 // so that later submission of conflict forms won't try to
931 // replace that into a duplicated mess.
932 $this->textbox1
= $text;
935 // Check for length errors again now that the section is merged in
936 $this->kblength
= (int)(strlen( $text ) / 1024);
937 if ( $this->kblength
> $wgMaxArticleSize ) {
938 $this->tooBig
= true;
939 wfProfileOut( $fname );
940 return self
::AS_MAX_ARTICLE_SIZE_EXCEDED
;
943 # update the article here
944 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
945 $this->watchthis
, $bot, $sectionanchor ) ) {
946 wfProfileOut( $fname );
947 return self
::AS_SUCCESS_UPDATE
;
949 $this->isConflict
= true;
951 wfProfileOut( $fname );
956 * Initialise form fields in the object
957 * Called on the first invocation, e.g. when a user clicks an edit link
959 function initialiseForm() {
960 $this->edittime
= $this->mArticle
->getTimestamp();
962 $this->textbox1
= $this->getContent(false);
963 if ($this->textbox1
=== false) return false;
965 if ( !$this->mArticle
->exists() && $this->mTitle
->getNamespace() == NS_MEDIAWIKI
)
966 $this->textbox1
= wfMsgWeirdKey( $this->mTitle
->getText() );
972 * Send the edit form and related headers to $wgOut
973 * @param $formCallback Optional callable that takes an OutputPage
974 * parameter; will be called during form output
975 * near the top, for captchas and the like.
977 function showEditForm( $formCallback=null ) {
978 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle;
980 $fname = 'EditPage::showEditForm';
981 wfProfileIn( $fname );
983 $sk = $wgUser->getSkin();
985 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
987 $wgOut->setRobotpolicy( 'noindex,nofollow' );
989 # Enabled article-related sidebar, toplinks, etc.
990 $wgOut->setArticleRelated( true );
992 if ( $this->formtype
== 'preview' ) {
993 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
996 if ( $this->isConflict
) {
997 $s = wfMsg( 'editconflict', $wgTitle->getPrefixedText() );
998 $wgOut->setPageTitle( $s );
999 $wgOut->addWikiText( wfMsg( 'explainconflict' ) );
1001 $this->textbox2
= $this->textbox1
;
1002 $this->textbox1
= $this->getContent();
1003 $this->edittime
= $this->mArticle
->getTimestamp();
1005 if( $this->section
!= '' ) {
1006 if( $this->section
== 'new' ) {
1007 $s = wfMsg('editingcomment', $wgTitle->getPrefixedText() );
1009 $s = wfMsg('editingsection', $wgTitle->getPrefixedText() );
1011 if( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1012 preg_match( "/^(=+)(.+)\\1/mi",
1015 if( !empty( $matches[2] ) ) {
1017 $this->summary
= "/* " .
1018 $wgParser->stripSectionName(trim($matches[2])) .
1024 $s = wfMsg( 'editing', $wgTitle->getPrefixedText() );
1026 $wgOut->setPageTitle( $s );
1028 if ( $this->missingComment
) {
1029 $wgOut->addWikiText( '<div id="mw-missingcommenttext">' . wfMsg( 'missingcommenttext' ) . '</div>' );
1032 if( $this->missingSummary
&& $this->section
!= 'new' ) {
1033 $wgOut->addWikiText( '<div id="mw-missingsummary">' . wfMsg( 'missingsummary' ) . '</div>' );
1036 if( $this->missingSummary
&& $this->section
== 'new' ) {
1037 $wgOut->addWikiText( '<div id="mw-missingcommentheader">' . wfMsg( 'missingcommentheader' ) . '</div>' );
1040 if( $this->hookError
!== '' ) {
1041 $wgOut->addWikiText( $this->hookError
);
1044 if ( !$this->checkUnicodeCompliantBrowser() ) {
1045 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
1047 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1048 // Let sysop know that this will make private content public if saved
1050 if( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1051 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
1052 } else if( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1053 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
1056 if( !$this->mArticle
->mRevision
->isCurrent() ) {
1057 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1058 $wgOut->addWikiText( wfMsg( 'editingold' ) );
1063 if( wfReadOnly() ) {
1064 $wgOut->addHTML( '<div id="mw-read-only-warning">'.wfMsgWikiHTML( 'readonlywarning' ).'</div>' );
1065 } elseif( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
1066 $wgOut->addHTML( '<div id="mw-anon-edit-warning">'.wfMsgWikiHTML( 'anoneditwarning' ).'</div>' );
1068 if( $this->isCssJsSubpage
&& $this->formtype
!= 'preview' ) {
1069 # Check the skin exists
1070 if( $this->isValidCssJsSubpage
) {
1071 $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );
1073 $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() ) );
1078 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1079 # Show a warning if editing an interface message
1080 $wgOut->addWikiText( wfMsg( 'editinginterface' ) );
1081 } elseif( $this->mTitle
->isProtected( 'edit' ) ) {
1082 # Is the title semi-protected?
1083 if( $this->mTitle
->isSemiProtected() ) {
1084 $notice = wfMsg( 'semiprotectedpagewarning' );
1085 if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) ||
$notice == '-' )
1088 # Then it must be protected based on static groups (regular)
1089 $notice = wfMsg( 'protectedpagewarning' );
1091 $wgOut->addWikiText( $notice );
1093 if ( $this->mTitle
->isCascadeProtected() ) {
1094 # Is this page under cascading protection from some source pages?
1095 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1096 if ( count($cascadeSources) > 0 ) {
1097 # Explain, and list the titles responsible
1098 $notice = wfMsgExt( 'cascadeprotectedwarning', array('parsemag'), count($cascadeSources) ) . "\n";
1099 foreach( $cascadeSources as $page ) {
1100 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1103 $wgOut->addWikiText( $notice );
1105 if( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) != array() ){
1106 $wgOut->addWikiText( wfMsg( 'titleprotectedwarning' ) );
1109 if ( $this->kblength
=== false ) {
1110 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
1112 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1113 $wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize ) );
1114 } elseif( $this->kblength
> 29 ) {
1115 $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) ) );
1118 #need to parse the preview early so that we know which templates are used,
1119 #otherwise users with "show preview after edit box" will get a blank list
1120 if ( $this->formtype
== 'preview' ) {
1121 $previewOutput = $this->getPreviewText();
1124 $rows = $wgUser->getIntOption( 'rows' );
1125 $cols = $wgUser->getIntOption( 'cols' );
1127 $ew = $wgUser->getOption( 'editwidth' );
1128 if ( $ew ) $ew = " style=\"width:100%\"";
1131 $q = 'action=submit';
1132 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1133 $action = $wgTitle->escapeLocalURL( $q );
1135 $summary = wfMsg('summary');
1136 $subject = wfMsg('subject');
1138 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
1139 wfMsgExt('cancel', array('parseinline')) );
1140 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1141 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1142 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1143 htmlspecialchars( wfMsg( 'newwindow' ) );
1145 global $wgRightsText;
1146 $copywarn = "<div id=\"editpage-copywarn\">\n" .
1147 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
1148 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1149 $wgRightsText ) . "\n</div>";
1151 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
1152 # prepare toolbar for edit buttons
1153 $toolbar = $this->getEditToolbar();
1158 // activate checkboxes if user wants them to be always active
1159 if( !$this->preview
&& !$this->diff
) {
1160 # Sort out the "watch" checkbox
1161 if( $wgUser->getOption( 'watchdefault' ) ) {
1163 $this->watchthis
= true;
1164 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1166 $this->watchthis
= true;
1167 } elseif( $this->mTitle
->userIsWatching() ) {
1169 $this->watchthis
= true;
1172 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
1175 $wgOut->addHTML( $this->editFormPageTop
);
1177 if ( $wgUser->getOption( 'previewontop' ) ) {
1179 if ( 'preview' == $this->formtype
) {
1180 $this->showPreview( $previewOutput );
1182 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1185 if ( 'diff' == $this->formtype
) {
1191 $wgOut->addHTML( $this->editFormTextTop
);
1193 # if this is a comment, show a subject line at the top, which is also the edit summary.
1194 # Otherwise, show a summary field at the bottom
1195 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
1196 if( $this->section
== 'new' ) {
1197 $commentsubject="<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}:</label></span>\n<div class='editOptions'>\n<input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
1199 $subjectpreview = $summarytext && $this->preview ?
"<div class=\"mw-summary-preview\">".wfMsg('subject-preview').':'.$sk->commentBlock( $this->summary
, $this->mTitle
)."</div>\n" : '';
1200 $summarypreview = '';
1202 $commentsubject = '';
1203 $editsummary="<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}:</label></span>\n<div class='editOptions'>\n<input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />";
1204 $summarypreview = $summarytext && $this->preview ?
"<div class=\"mw-summary-preview\">".wfMsg('summary-preview').':'.$sk->commentBlock( $this->summary
, $this->mTitle
)."</div>\n" : '';
1205 $subjectpreview = '';
1208 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1209 if( !$this->preview
&& !$this->diff
) {
1210 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1212 $templates = ($this->preview ||
$this->section
!= '') ?
$this->mPreviewTemplates
: $this->mArticle
->getUsedTemplates();
1213 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview
, $this->section
!= '');
1215 global $wgUseMetadataEdit ;
1216 if ( $wgUseMetadataEdit ) {
1217 $metadata = $this->mMetaData
;
1218 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1219 $top = wfMsgWikiHtml( 'metadata_help' );
1220 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1222 else $metadata = "" ;
1226 if ($this->deletedSinceEdit
) {
1227 if ( 'save' != $this->formtype
) {
1228 $wgOut->addWikiText( wfMsg('deletedwhileediting'));
1230 // Hide the toolbar and edit area, use can click preview to get it back
1231 // Add an confirmation checkbox and explanation.
1233 $hidden = 'type="hidden" style="display:none;"';
1234 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
1236 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1237 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1243 $checkboxes = self
::getCheckboxes( $tabindex, $sk,
1244 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1246 $checkboxhtml = implode( $checkboxes, "\n" );
1248 $buttons = $this->getEditButtons( $tabindex );
1249 $buttonshtml = implode( $buttons, "\n" );
1251 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1252 ?
'' : Xml
::hidden( 'safemode', '1' );
1254 $wgOut->addHTML( <<<END
1256 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1260 if( is_callable( $formCallback ) ) {
1261 call_user_func_array( $formCallback, array( &$wgOut ) );
1264 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1266 // Put these up at the top to ensure they aren't lost on early form submission
1268 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1269 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1270 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1271 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1273 $wgOut->addHTML( <<<END
1277 {$this->editFormTextBeforeContent}
1278 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
1279 cols='{$cols}'{$ew} $hidden>
1281 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) ) .
1286 $wgOut->addWikiText( $copywarn );
1287 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1297 "<div class='editButtons'>
1299 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1300 </div><!-- editButtons -->
1301 </div><!-- editOptions -->");
1303 $wgOut->addHtml( '<div class="mw-editTools">' );
1304 $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
1305 $wgOut->addHtml( '</div>' );
1307 $wgOut->addHTML( $this->editFormTextAfterTools
);
1310 <div class='templatesUsed'>
1311 {$formattedtemplates}
1316 * To make it harder for someone to slip a user a page
1317 * which submits an edit form to the wiki without their
1318 * knowledge, a random token is associated with the login
1319 * session. If it's not passed back with the submission,
1320 * we won't save the page, or render user JavaScript and
1323 * For anon editors, who may not have a session, we just
1324 * include the constant suffix to prevent editing from
1325 * broken text-mangling proxies.
1327 $token = htmlspecialchars( $wgUser->editToken() );
1328 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1331 # If a blank edit summary was previously provided, and the appropriate
1332 # user preference is active, pass a hidden tag here. This will stop the
1333 # user being bounced back more than once in the event that a summary
1335 if( $this->missingSummary
) {
1336 $wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" );
1339 # For a bit more sophisticated detection of blank summaries, hash the
1340 # automatic one and pass that in a hidden field.
1341 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1342 $wgOut->addHtml( wfHidden( 'wpAutoSummary', $autosumm ) );
1344 if ( $this->isConflict
) {
1345 $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
1347 $de = new DifferenceEngine( $this->mTitle
);
1348 $de->setText( $this->textbox2
, $this->textbox1
);
1349 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1351 $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
1352 $wgOut->addHTML( "<textarea tabindex='6' id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}'>"
1353 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1355 $wgOut->addHTML( $this->editFormTextBottom
);
1356 $wgOut->addHTML( "</form>\n" );
1357 if ( !$wgUser->getOption( 'previewontop' ) ) {
1359 if ( $this->formtype
== 'preview') {
1360 $this->showPreview( $previewOutput );
1362 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1365 if ( $this->formtype
== 'diff') {
1371 wfProfileOut( $fname );
1375 * Append preview output to $wgOut.
1376 * Includes category rendering if this is a category page.
1378 * @param string $text The HTML to be output for the preview.
1380 private function showPreview( $text ) {
1383 $wgOut->addHTML( '<div id="wikiPreview">' );
1384 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1385 $this->mArticle
->openShowCategory();
1387 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1388 $wgOut->addHTML( $text );
1389 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1390 $this->mArticle
->closeShowCategory();
1392 $wgOut->addHTML( '</div>' );
1396 * Live Preview lets us fetch rendered preview page content and
1397 * add it to the page without refreshing the whole page.
1398 * If not supported by the browser it will fall through to the normal form
1399 * submission method.
1401 * This function outputs a script tag to support live preview, and
1402 * returns an onclick handler which should be added to the attributes
1403 * of the preview button
1405 function doLivePreviewScript() {
1406 global $wgStylePath, $wgJsMimeType, $wgStyleVersion, $wgOut, $wgTitle;
1407 $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
1408 htmlspecialchars( "$wgStylePath/common/preview.js?$wgStyleVersion" ) .
1409 '"></script>' . "\n" );
1410 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1411 return "return !lpDoPreview(" .
1412 "editform.wpTextbox1.value," .
1413 '"' . $liveAction . '"' . ")";
1416 function getLastDelete() {
1417 $dbr = wfGetDB( DB_SLAVE
);
1418 $fname = 'EditPage::getLastDelete';
1419 $res = $dbr->select(
1420 array( 'logging', 'user' ),
1430 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1431 'log_title' => $this->mTitle
->getDBkey(),
1432 'log_type' => 'delete',
1433 'log_action' => 'delete',
1434 'user_id=log_user' ),
1436 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1438 if($dbr->numRows($res) == 1) {
1439 while ( $x = $dbr->fetchObject ( $res ) )
1441 $dbr->freeResult ( $res ) ;
1451 function getPreviewText() {
1452 global $wgOut, $wgUser, $wgTitle, $wgParser;
1454 $fname = 'EditPage::getPreviewText';
1455 wfProfileIn( $fname );
1457 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1458 if ( $this->mTokenOkExceptSuffix
) {
1459 $note = wfMsg( 'token_suffix_mismatch' );
1461 $note = wfMsg( 'session_fail_preview' );
1464 $note = wfMsg( 'previewnote' );
1467 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1468 $parserOptions->setEditSection( false );
1471 if( $wgRawHtml && !$this->mTokenOk
) {
1472 // Could be an offsite preview attempt. This is very unsafe if
1473 // HTML is enabled, as it could be an attack.
1474 return $wgOut->parse( "<div class='previewnote'>" .
1475 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1478 # don't parse user css/js, show message about preview
1479 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1481 if ( $this->isCssJsSubpage
) {
1482 if(preg_match("/\\.css$/", $this->mTitle
->getText() ) ) {
1483 $previewtext = wfMsg('usercsspreview');
1484 } else if(preg_match("/\\.js$/", $this->mTitle
->getText() ) ) {
1485 $previewtext = wfMsg('userjspreview');
1487 $parserOptions->setTidy(true);
1488 $parserOutput = $wgParser->parse( $previewtext , $this->mTitle
, $parserOptions );
1489 $wgOut->addHTML( $parserOutput->mText
);
1492 $toparse = $this->textbox1
;
1494 # If we're adding a comment, we need to show the
1495 # summary as the headline
1496 if($this->section
=="new" && $this->summary
!="") {
1497 $toparse="== {$this->summary} ==\n\n".$toparse;
1500 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1501 $parserOptions->setTidy(true);
1502 $parserOptions->enableLimitReport();
1503 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ) ."\n\n",
1504 $this->mTitle
, $parserOptions );
1506 $previewHTML = $parserOutput->getText();
1507 $wgOut->addParserOutputNoText( $parserOutput );
1509 # ParserOutput might have altered the page title, so reset it
1510 $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) );
1512 foreach ( $parserOutput->getTemplates() as $ns => $template)
1513 foreach ( array_keys( $template ) as $dbk)
1514 $this->mPreviewTemplates
[] = Title
::makeTitle($ns, $dbk);
1516 if ( count( $parserOutput->getWarnings() ) ) {
1517 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1521 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1522 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
1523 if ( $this->isConflict
) {
1524 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1527 wfProfileOut( $fname );
1528 return $previewhead . $previewHTML;
1532 * Call the stock "user is blocked" page
1534 function blockedPage() {
1535 global $wgOut, $wgUser;
1536 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1538 # If the user made changes, preserve them when showing the markup
1539 # (This happens when a user is blocked during edit, for instance)
1540 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1542 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1544 $source = $this->textbox1
;
1547 # Spit out the source or the user's modified version
1548 if( $source !== false ) {
1549 $rows = $wgUser->getOption( 'rows' );
1550 $cols = $wgUser->getOption( 'cols' );
1551 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1552 $wgOut->addHtml( '<hr />' );
1553 $wgOut->addWikiText( wfMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() ) );
1554 $wgOut->addHtml( wfOpenElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . wfCloseElement( 'textarea' ) );
1559 * Produce the stock "please login to edit pages" page
1561 function userNotLoggedInPage() {
1562 global $wgUser, $wgOut, $wgTitle;
1563 $skin = $wgUser->getSkin();
1565 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1566 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1568 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1569 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1570 $wgOut->setArticleRelated( false );
1572 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1573 $wgOut->returnToMain( false, $wgTitle );
1577 * Creates a basic error page which informs the user that
1578 * they have attempted to edit a nonexistant section.
1580 function noSuchSectionPage() {
1581 global $wgOut, $wgTitle;
1583 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1584 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1585 $wgOut->setArticleRelated( false );
1587 $wgOut->addWikiText( wfMsg( 'nosuchsectiontext', $this->section
) );
1588 $wgOut->returnToMain( false, $wgTitle );
1592 * Produce the stock "your edit contains spam" page
1594 * @param $match Text which triggered one or more filters
1596 function spamPage( $match = false ) {
1597 global $wgOut, $wgTitle;
1599 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1600 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1601 $wgOut->setArticleRelated( false );
1603 $wgOut->addHtml( '<div id="spamprotected">' );
1604 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
1606 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch',wfEscapeWikiText( $match ) ) );
1607 $wgOut->addHtml( '</div>' );
1609 $wgOut->returnToMain( false, $wgTitle );
1616 function mergeChangesInto( &$editText ){
1617 $fname = 'EditPage::mergeChangesInto';
1618 wfProfileIn( $fname );
1620 $db = wfGetDB( DB_MASTER
);
1622 // This is the revision the editor started from
1623 $baseRevision = Revision
::loadFromTimestamp(
1624 $db, $this->mTitle
, $this->edittime
);
1625 if( is_null( $baseRevision ) ) {
1626 wfProfileOut( $fname );
1629 $baseText = $baseRevision->getText();
1631 // The current state, we want to merge updates into it
1632 $currentRevision = Revision
::loadFromTitle(
1633 $db, $this->mTitle
);
1634 if( is_null( $currentRevision ) ) {
1635 wfProfileOut( $fname );
1638 $currentText = $currentRevision->getText();
1641 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1642 $editText = $result;
1643 wfProfileOut( $fname );
1646 wfProfileOut( $fname );
1652 * Check if the browser is on a blacklist of user-agents known to
1653 * mangle UTF-8 data on form submission. Returns true if Unicode
1654 * should make it through, false if it's known to be a problem.
1658 function checkUnicodeCompliantBrowser() {
1659 global $wgBrowserBlackList;
1660 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1661 // No User-Agent header sent? Trust it by default...
1664 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1665 foreach ( $wgBrowserBlackList as $browser ) {
1666 if ( preg_match($browser, $currentbrowser) ) {
1674 * @deprecated use $wgParser->stripSectionName()
1676 function pseudoParseSectionAnchor( $text ) {
1678 return $wgParser->stripSectionName( $text );
1682 * Format an anchor fragment as it would appear for a given section name
1683 * @param string $text
1687 function sectionAnchor( $text ) {
1689 return $wgParser->guessSectionNameFromWikiText( $text );
1693 * Shows a bulletin board style toolbar for common editing functions.
1694 * It can be disabled in the user preferences.
1695 * The necessary JavaScript code can be found in style/wikibits.js.
1697 function getEditToolbar() {
1698 global $wgStylePath, $wgContLang, $wgJsMimeType;
1701 * toolarray an array of arrays which each include the filename of
1702 * the button image (without path), the opening tag, the closing tag,
1703 * and optionally a sample text that is inserted between the two when no
1704 * selection is highlighted.
1705 * The tip text is shown when the user moves the mouse over the button.
1707 * Already here are accesskeys (key), which are not used yet until someone
1708 * can figure out a way to make them work in IE. However, we should make
1709 * sure these keys are not defined on the edit page.
1712 array( 'image' => 'button_bold.png',
1713 'id' => 'mw-editbutton-bold',
1714 'open' => '\\\'\\\'\\\'',
1715 'close' => '\\\'\\\'\\\'',
1716 'sample'=> wfMsg('bold_sample'),
1717 'tip' => wfMsg('bold_tip'),
1720 array( 'image' => 'button_italic.png',
1721 'id' => 'mw-editbutton-italic',
1722 'open' => '\\\'\\\'',
1723 'close' => '\\\'\\\'',
1724 'sample'=> wfMsg('italic_sample'),
1725 'tip' => wfMsg('italic_tip'),
1728 array( 'image' => 'button_link.png',
1729 'id' => 'mw-editbutton-link',
1732 'sample'=> wfMsg('link_sample'),
1733 'tip' => wfMsg('link_tip'),
1736 array( 'image' => 'button_extlink.png',
1737 'id' => 'mw-editbutton-extlink',
1740 'sample'=> wfMsg('extlink_sample'),
1741 'tip' => wfMsg('extlink_tip'),
1744 array( 'image' => 'button_headline.png',
1745 'id' => 'mw-editbutton-headline',
1747 'close' => " ==\\n",
1748 'sample'=> wfMsg('headline_sample'),
1749 'tip' => wfMsg('headline_tip'),
1752 array( 'image' => 'button_image.png',
1753 'id' => 'mw-editbutton-image',
1754 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1756 'sample'=> wfMsg('image_sample'),
1757 'tip' => wfMsg('image_tip'),
1760 array( 'image' => 'button_media.png',
1761 'id' => 'mw-editbutton-media',
1762 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1764 'sample'=> wfMsg('media_sample'),
1765 'tip' => wfMsg('media_tip'),
1768 array( 'image' => 'button_math.png',
1769 'id' => 'mw-editbutton-math',
1771 'close' => "<\\/math>",
1772 'sample'=> wfMsg('math_sample'),
1773 'tip' => wfMsg('math_tip'),
1776 array( 'image' => 'button_nowiki.png',
1777 'id' => 'mw-editbutton-nowiki',
1778 'open' => "<nowiki>",
1779 'close' => "<\\/nowiki>",
1780 'sample'=> wfMsg('nowiki_sample'),
1781 'tip' => wfMsg('nowiki_tip'),
1784 array( 'image' => 'button_sig.png',
1785 'id' => 'mw-editbutton-signature',
1789 'tip' => wfMsg('sig_tip'),
1792 array( 'image' => 'button_hr.png',
1793 'id' => 'mw-editbutton-hr',
1794 'open' => "\\n----\\n",
1797 'tip' => wfMsg('hr_tip'),
1801 $toolbar = "<div id='toolbar'>\n";
1802 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1804 foreach($toolarray as $tool) {
1806 $cssId = $tool['id'];
1807 $image=$wgStylePath.'/common/images/'.$tool['image'];
1808 $open=$tool['open'];
1809 $close=$tool['close'];
1810 $sample = wfEscapeJsString( $tool['sample'] );
1812 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1813 // Older browsers show a "speedtip" type message only for ALT.
1814 // Ideally these should be different, realistically they
1815 // probably don't need to be.
1816 $tip = wfEscapeJsString( $tool['tip'] );
1818 #$key = $tool["key"];
1820 $toolbar.="addButton('$image','$tip','$open','$close','$sample','$cssId');\n";
1823 $toolbar.="/*]]>*/\n</script>";
1824 $toolbar.="\n</div>";
1829 * Returns an array of html code of the following checkboxes:
1832 * @param $tabindex Current tabindex
1833 * @param $skin Skin object
1834 * @param $checked Array of checkbox => bool, where bool indicates the checked
1835 * status of the checkbox
1839 public static function getCheckboxes( &$tabindex, $skin, $checked ) {
1842 $checkboxes = array();
1844 $checkboxes['minor'] = '';
1845 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
1846 if ( $wgUser->isAllowed('minoredit') ) {
1848 'tabindex' => ++
$tabindex,
1849 'accesskey' => wfMsg( 'accesskey-minoredit' ),
1850 'id' => 'wpMinoredit',
1852 $checkboxes['minor'] =
1853 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
1854 " <label for='wpMinoredit'".$skin->tooltipAndAccesskey('minoredit').">{$minorLabel}</label>";
1857 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
1858 $checkboxes['watch'] = '';
1859 if ( $wgUser->isLoggedIn() ) {
1861 'tabindex' => ++
$tabindex,
1862 'accesskey' => wfMsg( 'accesskey-watch' ),
1863 'id' => 'wpWatchthis',
1865 $checkboxes['watch'] =
1866 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
1867 " <label for='wpWatchthis'".$skin->tooltipAndAccesskey('watch').">{$watchLabel}</label>";
1873 * Returns an array of html code of the following buttons:
1874 * save, diff, preview and live
1876 * @param $tabindex Current tabindex
1880 public function getEditButtons(&$tabindex) {
1881 global $wgLivePreview, $wgUser;
1889 'tabindex' => ++
$tabindex,
1890 'value' => wfMsg('savearticle'),
1891 'accesskey' => wfMsg('accesskey-save'),
1892 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
1894 $buttons['save'] = wfElement('input', $temp, '');
1896 ++
$tabindex; // use the same for preview and live preview
1897 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
1899 'id' => 'wpPreview',
1900 'name' => 'wpPreview',
1902 'tabindex' => $tabindex,
1903 'value' => wfMsg('showpreview'),
1905 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
1906 'style' => 'display: none;',
1908 $buttons['preview'] = wfElement('input', $temp, '');
1911 'id' => 'wpLivePreview',
1912 'name' => 'wpLivePreview',
1914 'tabindex' => $tabindex,
1915 'value' => wfMsg('showlivepreview'),
1916 'accesskey' => wfMsg('accesskey-preview'),
1918 'onclick' => $this->doLivePreviewScript(),
1920 $buttons['live'] = wfElement('input', $temp, '');
1923 'id' => 'wpPreview',
1924 'name' => 'wpPreview',
1926 'tabindex' => $tabindex,
1927 'value' => wfMsg('showpreview'),
1928 'accesskey' => wfMsg('accesskey-preview'),
1929 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
1931 $buttons['preview'] = wfElement('input', $temp, '');
1932 $buttons['live'] = '';
1939 'tabindex' => ++
$tabindex,
1940 'value' => wfMsg('showdiff'),
1941 'accesskey' => wfMsg('accesskey-diff'),
1942 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
1944 $buttons['diff'] = wfElement('input', $temp, '');
1950 * Output preview text only. This can be sucked into the edit page
1951 * via JavaScript, and saves the server time rendering the skin as
1952 * well as theoretically being more robust on the client (doesn't
1953 * disturb the edit box's undo history, won't eat your text on
1956 * @todo This doesn't include category or interlanguage links.
1957 * Would need to enhance it a bit, <s>maybe wrap them in XML
1958 * or something...</s> that might also require more skin
1959 * initialization, so check whether that's a problem.
1961 function livePreview() {
1964 header( 'Content-type: text/xml; charset=utf-8' );
1965 header( 'Cache-control: no-cache' );
1967 $previewText = $this->getPreviewText();
1968 #$categories = $skin->getCategoryLinks();
1971 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
1972 Xml
::tags( 'livepreview', null,
1973 Xml
::element( 'preview', null, $previewText )
1974 #. Xml::element( 'category', null, $categories )
1981 * Get a diff between the current contents of the edit box and the
1982 * version of the page we're editing from.
1984 * If this is a section edit, we'll replace the section as for final
1985 * save and then make a comparison.
1987 function showDiff() {
1988 $oldtext = $this->mArticle
->fetchContent();
1989 $newtext = $this->mArticle
->replaceSection(
1990 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
1991 $newtext = $this->mArticle
->preSaveTransform( $newtext );
1992 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
1993 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
1994 if ( $oldtext !== false ||
$newtext != '' ) {
1995 $de = new DifferenceEngine( $this->mTitle
);
1996 $de->setText( $oldtext, $newtext );
1997 $difftext = $de->getDiff( $oldtitle, $newtitle );
1998 $de->showDiffStyle();
2004 $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
2008 * Filter an input field through a Unicode de-armoring process if it
2009 * came from an old browser with known broken Unicode editing issues.
2011 * @param WebRequest $request
2012 * @param string $field
2016 function safeUnicodeInput( $request, $field ) {
2017 $text = rtrim( $request->getText( $field ) );
2018 return $request->getBool( 'safemode' )
2019 ?
$this->unmakesafe( $text )
2024 * Filter an output field through a Unicode armoring process if it is
2025 * going to an old browser with known broken Unicode editing issues.
2027 * @param string $text
2031 function safeUnicodeOutput( $text ) {
2033 $codedText = $wgContLang->recodeForEdit( $text );
2034 return $this->checkUnicodeCompliantBrowser()
2036 : $this->makesafe( $codedText );
2040 * A number of web browsers are known to corrupt non-ASCII characters
2041 * in a UTF-8 text editing environment. To protect against this,
2042 * detected browsers will be served an armored version of the text,
2043 * with non-ASCII chars converted to numeric HTML character references.
2045 * Preexisting such character references will have a 0 added to them
2046 * to ensure that round-trips do not alter the original data.
2048 * @param string $invalue
2052 function makesafe( $invalue ) {
2053 // Armor existing references for reversability.
2054 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2059 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2060 $bytevalue = ord( $invalue{$i} );
2061 if( $bytevalue <= 0x7F ) { //0xxx xxxx
2062 $result .= chr( $bytevalue );
2064 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
2065 $working = $working << 6;
2066 $working +
= ($bytevalue & 0x3F);
2068 if( $bytesleft <= 0 ) {
2069 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2071 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
2072 $working = $bytevalue & 0x1F;
2074 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
2075 $working = $bytevalue & 0x0F;
2077 } else { //1111 0xxx
2078 $working = $bytevalue & 0x07;
2086 * Reverse the previously applied transliteration of non-ASCII characters
2087 * back to UTF-8. Used to protect data from corruption by broken web browsers
2088 * as listed in $wgBrowserBlackList.
2090 * @param string $invalue
2094 function unmakesafe( $invalue ) {
2096 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2097 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
2101 $hexstring .= $invalue{$i};
2103 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2105 // Do some sanity checks. These aren't needed for reversability,
2106 // but should help keep the breakage down if the editor
2107 // breaks one of the entities whilst editing.
2108 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
2109 $codepoint = hexdec($hexstring);
2110 $result .= codepointToUtf8( $codepoint );
2112 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2115 $result .= substr( $invalue, $i, 1 );
2118 // reverse the transform that we made for reversability reasons.
2119 return strtr( $result, array( "�" => "&#x" ) );
2122 function noCreatePermission() {
2124 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2125 $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );
2129 * If there are rows in the deletion log for this page, show them,
2130 * along with a nice little note for the user
2132 * @param OutputPage $out
2134 private function showDeletionLog( $out ) {
2135 $title = $this->mTitle
;
2136 $reader = new LogReader(
2139 'page' => $title->getPrefixedText(),
2144 if( $reader->hasRows() ) {
2145 $out->addHtml( '<div id="mw-recreate-deleted-warn">' );
2146 $out->addWikiText( wfMsg( 'recreate-deleted-warn' ) );
2147 $viewer = new LogViewer( $reader );
2148 $viewer->showList( $out );
2149 $out->addHtml( '</div>' );
2154 * Attempt submission
2155 * @return bool false if output is done, true if the rest of the form should be displayed
2157 function attemptSave() {
2158 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2160 $resultDetails = false;
2161 $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
2163 if( $value == self
::AS_SUCCESS_UPDATE ||
$value == self
::AS_SUCCESS_NEW_ARTICLE
) {
2164 $this->didSave
= true;
2169 case self
::AS_HOOK_ERROR_EXPECTED
:
2170 case self
::AS_CONTENT_TOO_BIG
:
2171 case self
::AS_ARTICLE_WAS_DELETED
:
2172 case self
::AS_CONFLICT_DETECTED
:
2173 case self
::AS_SUMMARY_NEEDED
:
2174 case self
::AS_TEXTBOX_EMPTY
:
2175 case self
::AS_MAX_ARTICLE_SIZE_EXCEDED
:
2179 case self
::AS_HOOK_ERROR
:
2180 case self
::AS_FILTERING
:
2181 case self
::AS_SUCCESS_NEW_ARTICLE
:
2182 case self
::AS_SUCCESS_UPDATE
:
2185 case self
::AS_SPAM_ERROR
:
2186 $this->spamPage ( $resultDetails['spam'] );
2189 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2190 $this->blockedPage();
2193 case self
::AS_READ_ONLY_PAGE_ANON
:
2194 $this->userNotLoggedInPage();
2197 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2198 case self
::AS_READ_ONLY_PAGE
:
2199 $wgOut->readOnlyPage();
2202 case self
::AS_RATE_LIMITED
:
2203 $wgOut->rateLimited();
2206 case self
::AS_NO_CREATE_PERMISSION
;
2207 $this->noCreatePermission();
2210 case self
::AS_BLANK_ARTICLE
:
2211 $wgOut->redirect( $wgTitle->getFullURL() );