3 * Contains the EditPage class
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
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.
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;
41 const AS_SPAM_ERROR
= 232;
42 const AS_IMAGE_REDIRECT_ANON
= 233;
43 const AS_IMAGE_REDIRECT_LOGGED
= 234;
48 var $isConflict = false;
49 var $isCssJsSubpage = false;
50 var $deletedSinceEdit = false;
54 var $mTokenOk = false;
55 var $mTokenOkExceptSuffix = false;
56 var $mTriedSave = false;
58 var $kblength = false;
59 var $missingComment = false;
60 var $missingSummary = false;
61 var $allowBlankSummary = false;
64 var $mPreviewTemplates;
67 var $save = false, $preview = false, $diff = false;
68 var $minoredit = false, $watchthis = false, $recreate = false;
69 var $textbox1 = '', $textbox2 = '', $summary = '';
70 var $edittime = '', $section = '', $starttime = '';
71 var $oldid = 0, $editintro = '', $scrolltop = null;
73 # Placeholders for text injection by hooks (must be HTML)
74 # extensions should take care to _append_ to the present value
75 public $editFormPageTop; // Before even the preview
76 public $editFormTextTop;
77 public $editFormTextBeforeContent;
78 public $editFormTextAfterWarn;
79 public $editFormTextAfterTools;
80 public $editFormTextBottom;
82 /* $didSave should be set to true whenever an article was succesfully altered. */
83 public $didSave = false;
85 public $suppressIntro = false;
91 function EditPage( $article ) {
92 $this->mArticle
=& $article;
93 $this->mTitle
= $article->getTitle();
95 # Placeholders for text injection by hooks (empty per default)
96 $this->editFormPageTop
=
97 $this->editFormTextTop
=
98 $this->editFormTextBeforeContent
=
99 $this->editFormTextAfterWarn
=
100 $this->editFormTextAfterTools
=
101 $this->editFormTextBottom
= "";
105 * Fetch initial editing page content.
108 function getContent( $def_text = '' ) {
109 global $wgOut, $wgRequest, $wgParser, $wgMessageCache;
111 # Get variables from query string :P
112 $section = $wgRequest->getVal( 'section' );
113 $preload = $wgRequest->getVal( 'preload' );
114 $undoafter = $wgRequest->getVal( 'undoafter' );
115 $undo = $wgRequest->getVal( 'undo' );
117 wfProfileIn( __METHOD__
);
120 if( !$this->mTitle
->exists() ) {
121 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
122 $wgMessageCache->loadAllMessages();
123 # If this is a system message, get the default text.
124 $text = wfMsgWeirdKey ( $this->mTitle
->getText() ) ;
126 # If requested, preload some text.
127 $text = $this->getPreloadedText( $preload );
129 # We used to put MediaWiki:Newarticletext here if
130 # $text was empty at this point.
131 # This is now shown above the edit box instead.
133 // FIXME: may be better to use Revision class directly
134 // But don't mess with it just yet. Article knows how to
135 // fetch the page record from the high-priority server,
136 // which is needed to guarantee we don't pick up lagged
139 $text = $this->mArticle
->getContent();
141 if ($undo > 0 && $undoafter > 0 && $undo < $undoafter) {
142 # If they got undoafter and undo round the wrong way, switch them
143 list( $undo, $undoafter ) = array( $undoafter, $undo );
146 if ( $undo > 0 && $undo > $undoafter ) {
147 # Undoing a specific edit overrides section editing; section-editing
148 # doesn't work with undoing.
150 $undorev = Revision
::newFromId($undo);
151 $oldrev = Revision
::newFromId($undoafter);
153 $undorev = Revision
::newFromId($undo);
154 $oldrev = $undorev ?
$undorev->getPrevious() : null;
157 # Sanity check, make sure it's the right page,
158 # the revisions exist and they were not deleted.
159 # Otherwise, $text will be left as-is.
160 if( !is_null( $undorev ) && !is_null( $oldrev ) &&
161 $undorev->getPage() == $oldrev->getPage() &&
162 $undorev->getPage() == $this->mArticle
->getID() &&
163 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
164 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
165 $undorev_text = $undorev->getText();
166 $oldrev_text = $oldrev->getText();
167 $currev_text = $text;
169 if ( $currev_text != $undorev_text ) {
170 $result = wfMerge( $undorev_text, $oldrev_text, $currev_text, $text );
172 # No use doing a merge if it's just a straight revert.
173 $text = $oldrev_text;
177 # Inform the user of our success and set an automatic edit summary
178 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
179 $firstrev = $oldrev->getNext();
180 # If we just undid one rev, use an autosummary
181 if( $firstrev->mId
== $undo ) {
182 $this->summary
= wfMsgForContent('undo-summary', $undo, $undorev->getUserText());
184 $this->formtype
= 'diff';
186 # Warn the user that something went wrong
187 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
190 // Failed basic sanity checks.
191 // Older revisions may have been removed since the link
192 // was created, or we may simply have got bogus input.
193 $this->editFormPageTop
.= $wgOut->parse( wfMsgNoTrans( 'undo-norev' ) );
195 } else if( $section != '' ) {
196 if( $section == 'new' ) {
197 $text = $this->getPreloadedText( $preload );
199 $text = $wgParser->getSection( $text, $section, $def_text );
204 wfProfileOut( __METHOD__
);
209 * Get the contents of a page from its title and remove includeonly tags
211 * @param $preload String: the title of the page.
212 * @return string The contents of the page.
214 private function getPreloadedText($preload) {
215 if ( $preload === '' )
218 $preloadTitle = Title
::newFromText( $preload );
219 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
220 $rev=Revision
::newFromTitle($preloadTitle);
221 if ( is_object( $rev ) ) {
222 $text = $rev->getText();
223 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
224 // its own mini-parser! -ævar
225 $text = preg_replace( '~</?includeonly>~', '', $text );
234 * This is the function that extracts metadata from the article body on the first view.
235 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
236 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
238 function extractMetaDataFromArticle () {
239 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
240 $this->mMetaData
= '' ;
241 if ( !$wgUseMetadataEdit ) return ;
242 if ( $wgMetadataWhitelist == '' ) return ;
244 $t = $this->getContent();
246 # MISSING : <nowiki> filtering
248 # Categories and language links
249 $t = explode ( "\n" , $t ) ;
250 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY
) ) ;
251 $cat = $ll = array() ;
252 foreach ( $t AS $key => $x )
254 $y = trim ( strtolower ( $x ) ) ;
255 while ( substr ( $y , 0 , 2 ) == '[[' )
257 $y = explode ( ']]' , trim ( $x ) ) ;
258 $first = array_shift ( $y ) ;
259 $first = explode ( ':' , $first ) ;
260 $ns = array_shift ( $first ) ;
261 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
262 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
264 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
265 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
267 $x = implode ( ']]' , $y ) ;
269 $y = trim ( strtolower ( $x ) ) ;
273 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
274 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
275 $t = implode ( "\n" , $t ) ;
278 $sat = array () ; # stand-alone-templates; must be lowercase
279 $wl_title = Title
::newFromText ( $wgMetadataWhitelist ) ;
280 $wl_article = new Article ( $wl_title ) ;
281 $wl = explode ( "\n" , $wl_article->getContent() ) ;
282 foreach ( $wl AS $x )
286 while ( substr ( $x , 0 , 1 ) == '*' )
289 $x = trim ( substr ( $x , 1 ) ) ;
293 $sat[] = strtolower ( $x ) ;
298 # Templates, but only some
299 $t = explode ( '{{' , $t ) ;
301 foreach ( $t AS $key => $x )
303 $y = explode ( '}}' , $x , 2 ) ;
304 if ( count ( $y ) == 2 )
307 $z = explode ( '|' , $z ) ;
308 $tn = array_shift ( $z ) ;
309 if ( in_array ( strtolower ( $tn ) , $sat ) )
311 $tl[] = '{{' . $y[0] . '}}' ;
313 $y = explode ( '}}' , $y[1] , 2 ) ;
315 else $t[$key] = '{{' . $x ;
317 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
320 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
321 $t = implode ( '' , $t ) ;
323 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
324 $this->mArticle
->mContent
= $t ;
325 $this->mMetaData
= $s ;
328 protected function wasDeletedSinceLastEdit() {
329 /* Note that we rely on the logging table, which hasn't been always there,
330 * but that doesn't matter, because this only applies to brand new
333 if ( $this->deletedSinceEdit
)
335 if ( $this->mTitle
->isDeleted() ) {
336 $this->lastDelete
= $this->getLastDelete();
337 if ( !is_null($this->lastDelete
) ) {
338 $deletetime = $this->lastDelete
->log_timestamp
;
339 if ( ($deletetime - $this->starttime
) > 0 ) {
340 $this->deletedSinceEdit
= true;
344 return $this->deletedSinceEdit
;
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.
363 global $wgOut, $wgUser, $wgRequest;
365 if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) )
368 wfProfileIn( __METHOD__
);
369 wfDebug( __METHOD__
.": enter\n" );
371 // this is not an article
372 $wgOut->setArticleFlag(false);
374 $this->importFormData( $wgRequest );
375 $this->firsttime
= false;
378 $this->livePreview();
379 wfProfileOut( __METHOD__
);
383 $wgOut->addScriptFile( 'edit.js' );
386 $this->readOnlyPage( $this->getContent() );
387 wfProfileOut( __METHOD__
);
391 $permErrors = $this->mTitle
->getUserPermissionsErrors('edit', $wgUser);
393 if( !$this->mTitle
->exists() ) {
394 $permErrors = array_merge( $permErrors,
395 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors('create', $wgUser), $permErrors ) );
398 # Ignore some permissions errors.
400 foreach( $permErrors as $error ) {
401 if ( ( $this->preview ||
$this->diff
) &&
402 ($error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext'))
404 // Don't worry about blocks when previewing/diffing
408 if ($error[0] == 'readonlytext')
411 $this->formtype
= 'preview';
412 } elseif ($this->save ||
$this->preview ||
$this->diff
) {
417 $permErrors = wfArrayDiff2( $permErrors, $remove );
420 wfDebug( __METHOD__
.": User can't edit\n" );
421 $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
422 wfProfileOut( __METHOD__
);
426 $this->formtype
= 'save';
427 } else if ( $this->preview
) {
428 $this->formtype
= 'preview';
429 } else if ( $this->diff
) {
430 $this->formtype
= 'diff';
431 } else { # First time through
432 $this->firsttime
= true;
433 if( $this->previewOnOpen() ) {
434 $this->formtype
= 'preview';
436 $this->extractMetaDataFromArticle () ;
437 $this->formtype
= 'initial';
442 wfProfileIn( __METHOD__
."-business-end" );
444 $this->isConflict
= false;
445 // css / js subpages of user pages get a special treatment
446 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
447 $this->isValidCssJsSubpage
= $this->mTitle
->isValidCssJsSubpage();
449 # Show applicable editing introductions
450 if( $this->formtype
== 'initial' ||
$this->firsttime
)
453 if( $this->mTitle
->isTalkPage() ) {
454 $wgOut->addWikiMsg( 'talkpagetext' );
457 # Attempt submission here. This will check for edit conflicts,
458 # and redundantly check for locked database, blocked IPs, etc.
459 # that edit() already checked just in case someone tries to sneak
460 # in the back door with a hand-edited submission URL.
462 if ( 'save' == $this->formtype
) {
463 if ( !$this->attemptSave() ) {
464 wfProfileOut( __METHOD__
."-business-end" );
465 wfProfileOut( __METHOD__
);
470 # First time through: get contents, set time for conflict
472 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
473 if ($this->initialiseForm() === false) {
474 $this->noSuchSectionPage();
475 wfProfileOut( __METHOD__
."-business-end" );
476 wfProfileOut( __METHOD__
);
479 if( !$this->mTitle
->getArticleId() )
480 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
483 $this->showEditForm();
484 wfProfileOut( __METHOD__
."-business-end" );
485 wfProfileOut( __METHOD__
);
489 * Show a read-only error
490 * Parameters are the same as OutputPage:readOnlyPage()
491 * Redirect to the article page if redlink=1
493 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
494 global $wgRequest, $wgOut;
495 if ( $wgRequest->getBool( 'redlink' ) ) {
496 // The edit page was reached via a red link.
497 // Redirect to the article page and let them click the edit tab if
498 // they really want a permission error.
499 $wgOut->redirect( $this->mTitle
->getFullUrl() );
501 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
506 * Should we show a preview when the edit form is first shown?
510 private function previewOnOpen() {
511 global $wgRequest, $wgUser;
512 if( $wgRequest->getVal( 'preview' ) == 'yes' ) {
513 // Explicit override from request
515 } elseif( $wgRequest->getVal( 'preview' ) == 'no' ) {
516 // Explicit override from request
518 } elseif( $this->section
== 'new' ) {
519 // Nothing *to* preview for new sections
521 } elseif( ( $wgRequest->getVal( 'preload' ) !== '' ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
522 // Standard preference behaviour
524 } elseif( !$this->mTitle
->exists() && $this->mTitle
->getNamespace() == NS_CATEGORY
) {
525 // Categories are special
536 function importFormData( &$request ) {
537 global $wgLang, $wgUser;
538 $fname = 'EditPage::importFormData';
539 wfProfileIn( $fname );
541 # Section edit can come from either the form or a link
542 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
544 if( $request->wasPosted() ) {
545 # These fields need to be checked for encoding.
546 # Also remove trailing whitespace, but don't remove _initial_
547 # whitespace from the text boxes. This may be significant formatting.
548 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
549 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
550 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
551 # Truncate for whole multibyte characters. +5 bytes for ellipsis
552 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
554 # Remove extra headings from summaries and new sections.
555 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
557 $this->edittime
= $request->getVal( 'wpEdittime' );
558 $this->starttime
= $request->getVal( 'wpStarttime' );
560 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
562 if( is_null( $this->edittime
) ) {
563 # If the form is incomplete, force to preview.
564 wfDebug( "$fname: Form data appears to be incomplete\n" );
565 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
566 $this->preview
= true;
568 /* Fallback for live preview */
569 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
570 $this->diff
= $request->getCheck( 'wpDiff' );
572 // Remember whether a save was requested, so we can indicate
573 // if we forced preview due to session failure.
574 $this->mTriedSave
= !$this->preview
;
576 if ( $this->tokenOk( $request ) ) {
577 # Some browsers will not report any submit button
578 # if the user hits enter in the comment box.
579 # The unmarked state will be assumed to be a save,
580 # if the form seems otherwise complete.
581 wfDebug( "$fname: Passed token check.\n" );
582 } else if ( $this->diff
) {
583 # Failed token check, but only requested "Show Changes".
584 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
586 # Page might be a hack attempt posted from
587 # an external site. Preview instead of saving.
588 wfDebug( "$fname: Failed token check; forcing preview\n" );
589 $this->preview
= true;
592 $this->save
= !$this->preview
&& !$this->diff
;
593 if( !preg_match( '/^\d{14}$/', $this->edittime
)) {
594 $this->edittime
= null;
597 if( !preg_match( '/^\d{14}$/', $this->starttime
)) {
598 $this->starttime
= null;
601 $this->recreate
= $request->getCheck( 'wpRecreate' );
603 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
604 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
606 # Don't force edit summaries when a user is editing their own user or talk page
607 if( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) && $this->mTitle
->getText() == $wgUser->getName() ) {
608 $this->allowBlankSummary
= true;
610 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' );
613 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
615 # Not a posted form? Start with nothing.
616 wfDebug( "$fname: Not a posted form.\n" );
617 $this->textbox1
= '';
618 $this->textbox2
= '';
619 $this->mMetaData
= '';
621 $this->edittime
= '';
622 $this->starttime
= wfTimestampNow();
624 $this->preview
= false;
627 $this->minoredit
= false;
628 $this->watchthis
= false;
629 $this->recreate
= false;
631 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
632 $this->summary
= $request->getVal( 'preloadtitle' );
636 $this->oldid
= $request->getInt( 'oldid' );
638 $this->live
= $request->getCheck( 'live' );
639 $this->editintro
= $request->getText( 'editintro' );
641 wfProfileOut( $fname );
645 * Make sure the form isn't faking a user's credentials.
647 * @param $request WebRequest
651 function tokenOk( &$request ) {
653 $token = $request->getVal( 'wpEditToken' );
654 $this->mTokenOk
= $wgUser->matchEditToken( $token );
655 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
656 return $this->mTokenOk
;
660 * Show all applicable editing introductions
662 private function showIntro() {
663 global $wgOut, $wgUser;
664 if( $this->suppressIntro
)
667 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
668 if( $this->mTitle
->getNamespace() == NS_USER ||
$this->mTitle
->getNamespace() == NS_USER_TALK
) {
669 $parts = explode( '/', $this->mTitle
->getText(), 2 );
670 $username = $parts[0];
671 $id = User
::idFromName( $username );
672 $ip = User
::isIP( $username );
674 if ( $id == 0 && !$ip ) {
675 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
676 array( 'userpage-userdoesnotexist', $username ) );
680 if( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
681 if( $wgUser->isLoggedIn() ) {
682 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
684 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
686 $this->showDeletionLog( $wgOut );
691 * Attempt to show a custom editing introduction, if supplied
695 private function showCustomIntro() {
696 if( $this->editintro
) {
697 $title = Title
::newFromText( $this->editintro
);
698 if( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
700 $revision = Revision
::newFromTitle( $title );
701 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle
);
712 * Attempt submission (no UI)
713 * @return one of the constants describing the result
715 function internalAttemptSave( &$result, $bot = false ) {
716 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser;
717 global $wgMaxArticleSize;
719 $fname = 'EditPage::attemptSave';
720 wfProfileIn( $fname );
721 wfProfileIn( "$fname-checks" );
723 if( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
725 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
726 return self
::AS_HOOK_ERROR
;
729 # Check image redirect
730 if ( $this->mTitle
->getNamespace() == NS_IMAGE
&&
731 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
732 !$wgUser->isAllowed( 'upload' ) ) {
733 if( $wgUser->isAnon() ) {
734 return self
::AS_IMAGE_REDIRECT_ANON
;
736 return self
::AS_IMAGE_REDIRECT_LOGGED
;
740 # Reintegrate metadata
741 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
742 $this->mMetaData
= '' ;
746 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
747 $result['spam'] = $matches[0];
748 wfProfileOut( "$fname-checks" );
749 wfProfileOut( $fname );
750 return self
::AS_SPAM_ERROR
;
752 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
753 # Error messages or other handling should be performed by the filter function
754 wfProfileOut( "$fname-checks" );
755 wfProfileOut( $fname );
756 return self
::AS_FILTERING
;
758 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
) ) ) {
759 # Error messages etc. could be handled within the hook...
760 wfProfileOut( "$fname-checks" );
761 wfProfileOut( $fname );
762 return self
::AS_HOOK_ERROR
;
763 } elseif( $this->hookError
!= '' ) {
764 # ...or the hook could be expecting us to produce an error
765 wfProfileOut( "$fname-checks" );
766 wfProfileOut( $fname );
767 return self
::AS_HOOK_ERROR_EXPECTED
;
769 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
770 # Check block state against master, thus 'false'.
771 wfProfileOut( "$fname-checks" );
772 wfProfileOut( $fname );
773 return self
::AS_BLOCKED_PAGE_FOR_USER
;
775 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
776 if ( $this->kblength
> $wgMaxArticleSize ) {
777 // Error will be displayed by showEditForm()
778 $this->tooBig
= true;
779 wfProfileOut( "$fname-checks" );
780 wfProfileOut( $fname );
781 return self
::AS_CONTENT_TOO_BIG
;
784 if ( !$wgUser->isAllowed('edit') ) {
785 if ( $wgUser->isAnon() ) {
786 wfProfileOut( "$fname-checks" );
787 wfProfileOut( $fname );
788 return self
::AS_READ_ONLY_PAGE_ANON
;
791 wfProfileOut( "$fname-checks" );
792 wfProfileOut( $fname );
793 return self
::AS_READ_ONLY_PAGE_LOGGED
;
797 if ( wfReadOnly() ) {
798 wfProfileOut( "$fname-checks" );
799 wfProfileOut( $fname );
800 return self
::AS_READ_ONLY_PAGE
;
802 if ( $wgUser->pingLimiter() ) {
803 wfProfileOut( "$fname-checks" );
804 wfProfileOut( $fname );
805 return self
::AS_RATE_LIMITED
;
808 # If the article has been deleted while editing, don't save it without
810 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
811 wfProfileOut( "$fname-checks" );
812 wfProfileOut( $fname );
813 return self
::AS_ARTICLE_WAS_DELETED
;
816 wfProfileOut( "$fname-checks" );
818 # If article is new, insert it.
819 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
822 // Late check for create permission, just in case *PARANOIA*
823 if ( !$this->mTitle
->userCan( 'create' ) ) {
824 wfDebug( "$fname: no create permission\n" );
825 wfProfileOut( $fname );
826 return self
::AS_NO_CREATE_PERMISSION
;
829 # Don't save a new article if it's blank.
830 if ( '' == $this->textbox1
) {
831 wfProfileOut( $fname );
832 return self
::AS_BLANK_ARTICLE
;
835 // Run post-section-merge edit filter
836 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
) ) ) {
837 # Error messages etc. could be handled within the hook...
838 wfProfileOut( $fname );
839 return self
::AS_HOOK_ERROR
;
842 $isComment = ( $this->section
== 'new' );
844 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
845 $this->minoredit
, $this->watchthis
, false, $isComment, $bot);
847 wfProfileOut( $fname );
848 return self
::AS_SUCCESS_NEW_ARTICLE
;
851 # Article exists. Check for edit conflict.
853 $this->mArticle
->clear(); # Force reload of dates, etc.
854 $this->mArticle
->forUpdate( true ); # Lock the article
856 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
858 if( $this->mArticle
->getTimestamp() != $this->edittime
) {
859 $this->isConflict
= true;
860 if( $this->section
== 'new' ) {
861 if( $this->mArticle
->getUserText() == $wgUser->getName() &&
862 $this->mArticle
->getComment() == $this->summary
) {
863 // Probably a duplicate submission of a new comment.
864 // This can happen when squid resends a request after
865 // a timeout but the first one actually went through.
866 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
868 // New comment; suppress conflict.
869 $this->isConflict
= false;
870 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
874 $userid = $wgUser->getId();
876 if ( $this->isConflict
) {
877 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
878 $this->mArticle
->getTimestamp() . "')\n" );
879 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
882 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
883 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
885 if( is_null( $text ) ) {
886 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
887 $this->isConflict
= true;
888 $text = $this->textbox1
;
891 # Suppress edit conflict with self, except for section edits where merging is required.
892 if ( ( $this->section
== '' ) && ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
893 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
894 $this->isConflict
= false;
896 # switch from section editing to normal editing in edit conflict
897 if($this->isConflict
) {
899 if( $this->mergeChangesInto( $text ) ){
900 // Successful merge! Maybe we should tell the user the good news?
901 $this->isConflict
= false;
902 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
905 $this->textbox1
= $text;
906 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
911 if ( $this->isConflict
) {
912 wfProfileOut( $fname );
913 return self
::AS_CONFLICT_DETECTED
;
916 $oldtext = $this->mArticle
->getContent();
918 // Run post-section-merge edit filter
919 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
) ) ) {
920 # Error messages etc. could be handled within the hook...
921 wfProfileOut( $fname );
922 return self
::AS_HOOK_ERROR
;
925 # Handle the user preference to force summaries here, but not for null edits
926 if( $this->section
!= 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary')
927 && 0 != strcmp($oldtext, $text) && !Article
::getRedirectAutosummary( $text )) {
928 if( md5( $this->summary
) == $this->autoSumm
) {
929 $this->missingSummary
= true;
930 wfProfileOut( $fname );
931 return self
::AS_SUMMARY_NEEDED
;
935 # And a similar thing for new sections
936 if( $this->section
== 'new' && !$this->allowBlankSummary
&& $wgUser->getOption( 'forceeditsummary' ) ) {
937 if (trim($this->summary
) == '') {
938 $this->missingSummary
= true;
939 wfProfileOut( $fname );
940 return self
::AS_SUMMARY_NEEDED
;
945 wfProfileIn( "$fname-sectionanchor" );
947 if( $this->section
== 'new' ) {
948 if ( $this->textbox1
== '' ) {
949 $this->missingComment
= true;
950 return self
::AS_TEXTBOX_EMPTY
;
952 if( $this->summary
!= '' ) {
953 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary
);
954 # This is a new section, so create a link to the new section
955 # in the revision summary.
956 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
957 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
959 } elseif( $this->section
!= '' ) {
960 # Try to get a section anchor from the section source, redirect to edited section if header found
961 # XXX: might be better to integrate this into Article::replaceSection
962 # for duplicate heading checking and maybe parsing
963 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
964 # we can't deal with anchors, includes, html etc in the header for now,
965 # headline would need to be parsed to improve this
966 if($hasmatch and strlen($matches[2]) > 0) {
967 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
970 wfProfileOut( "$fname-sectionanchor" );
972 // Save errors may fall down to the edit form, but we've now
973 // merged the section into full text. Clear the section field
974 // so that later submission of conflict forms won't try to
975 // replace that into a duplicated mess.
976 $this->textbox1
= $text;
979 // Check for length errors again now that the section is merged in
980 $this->kblength
= (int)(strlen( $text ) / 1024);
981 if ( $this->kblength
> $wgMaxArticleSize ) {
982 $this->tooBig
= true;
983 wfProfileOut( $fname );
984 return self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
;
987 # update the article here
988 if( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
989 $this->watchthis
, $bot, $sectionanchor ) ) {
990 wfProfileOut( $fname );
991 return self
::AS_SUCCESS_UPDATE
;
993 $this->isConflict
= true;
995 wfProfileOut( $fname );
1000 * Initialise form fields in the object
1001 * Called on the first invocation, e.g. when a user clicks an edit link
1003 function initialiseForm() {
1004 $this->edittime
= $this->mArticle
->getTimestamp();
1005 $this->textbox1
= $this->getContent(false);
1006 if ($this->textbox1
=== false) return false;
1008 if ( !$this->mArticle
->exists() && $this->mTitle
->getNamespace() == NS_MEDIAWIKI
)
1009 $this->textbox1
= wfMsgWeirdKey( $this->mTitle
->getText() );
1015 * Send the edit form and related headers to $wgOut
1016 * @param $formCallback Optional callable that takes an OutputPage
1017 * parameter; will be called during form output
1018 * near the top, for captchas and the like.
1020 function showEditForm( $formCallback=null ) {
1021 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle;
1023 # If $wgTitle is null, that means we're in API mode.
1024 # Some hook probably called this function without checking
1025 # for is_null($wgTitle) first. Bail out right here so we don't
1026 # do lots of work just to discard it right after.
1027 if(is_null($wgTitle))
1030 $fname = 'EditPage::showEditForm';
1031 wfProfileIn( $fname );
1033 $sk = $wgUser->getSkin();
1035 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
1037 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1039 # Enabled article-related sidebar, toplinks, etc.
1040 $wgOut->setArticleRelated( true );
1042 if ( $this->formtype
== 'preview' ) {
1043 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1046 if ( $this->isConflict
) {
1047 $s = wfMsg( 'editconflict', $wgTitle->getPrefixedText() );
1048 $wgOut->setPageTitle( $s );
1049 $wgOut->addWikiMsg( 'explainconflict' );
1051 $this->textbox2
= $this->textbox1
;
1052 $this->textbox1
= $this->getContent();
1053 $this->edittime
= $this->mArticle
->getTimestamp();
1055 if( $this->section
!= '' ) {
1056 if( $this->section
== 'new' ) {
1057 $s = wfMsg('editingcomment', $wgTitle->getPrefixedText() );
1059 $s = wfMsg('editingsection', $wgTitle->getPrefixedText() );
1061 if( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1062 preg_match( "/^(=+)(.+)\\1/mi",
1065 if( !empty( $matches[2] ) ) {
1067 $this->summary
= "/* " .
1068 $wgParser->stripSectionName(trim($matches[2])) .
1074 $s = wfMsg( 'editing', $wgTitle->getPrefixedText() );
1076 $wgOut->setPageTitle( $s );
1078 if ( $this->missingComment
) {
1079 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1082 if( $this->missingSummary
&& $this->section
!= 'new' ) {
1083 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1086 if( $this->missingSummary
&& $this->section
== 'new' ) {
1087 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1090 if( $this->hookError
!== '' ) {
1091 $wgOut->addWikiText( $this->hookError
);
1094 if ( !$this->checkUnicodeCompliantBrowser() ) {
1095 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1097 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1098 // Let sysop know that this will make private content public if saved
1100 if( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1101 $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
1102 } else if( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1103 $wgOut->addWikiMsg( 'rev-deleted-text-view' );
1106 if( !$this->mArticle
->mRevision
->isCurrent() ) {
1107 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1108 $wgOut->addWikiMsg( 'editingold' );
1113 if( wfReadOnly() ) {
1114 $wgOut->addHTML( '<div id="mw-read-only-warning">'.wfMsgWikiHTML( 'readonlywarning' ).'</div>' );
1115 } elseif( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
1116 $wgOut->addHTML( '<div id="mw-anon-edit-warning">'.wfMsgWikiHTML( 'anoneditwarning' ).'</div>' );
1118 if( $this->isCssJsSubpage
&& $this->formtype
!= 'preview' ) {
1119 # Check the skin exists
1120 if( $this->isValidCssJsSubpage
) {
1121 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
1123 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1128 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1129 # Show a warning if editing an interface message
1130 $wgOut->addWikiMsg( 'editinginterface' );
1131 } elseif( $this->mTitle
->isProtected( 'edit' ) ) {
1132 # Is the title semi-protected?
1133 if( $this->mTitle
->isSemiProtected() ) {
1134 $noticeMsg = 'semiprotectedpagewarning';
1136 # Then it must be protected based on static groups (regular)
1137 $noticeMsg = 'protectedpagewarning';
1139 $wgOut->addWikiMsg( $noticeMsg );
1141 if ( $this->mTitle
->isCascadeProtected() ) {
1142 # Is this page under cascading protection from some source pages?
1143 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1145 if ( count($cascadeSources) > 0 ) {
1146 # Explain, and list the titles responsible
1147 foreach( $cascadeSources as $page ) {
1148 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1151 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', count($cascadeSources) ) );
1153 if( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) != array() ){
1154 $wgOut->addWikiMsg( 'titleprotectedwarning' );
1157 if ( $this->kblength
=== false ) {
1158 $this->kblength
= (int)(strlen( $this->textbox1
) / 1024);
1160 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1161 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgMaxArticleSize );
1162 } elseif( $this->kblength
> 29 ) {
1163 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) );
1166 #need to parse the preview early so that we know which templates are used,
1167 #otherwise users with "show preview after edit box" will get a blank list
1168 if ( $this->formtype
== 'preview' ) {
1169 $previewOutput = $this->getPreviewText();
1172 $rows = $wgUser->getIntOption( 'rows' );
1173 $cols = $wgUser->getIntOption( 'cols' );
1175 $ew = $wgUser->getOption( 'editwidth' );
1176 if ( $ew ) $ew = " style=\"width:100%\"";
1179 $q = 'action=submit';
1180 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1181 $action = $wgTitle->escapeLocalURL( $q );
1183 $summary = wfMsg('summary');
1184 $subject = wfMsg('subject');
1186 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
1187 wfMsgExt('cancel', array('parseinline')) );
1188 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1189 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1190 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1191 htmlspecialchars( wfMsg( 'newwindow' ) );
1193 global $wgRightsText;
1194 if ( $wgRightsText ) {
1195 $copywarnMsg = array( 'copyrightwarning',
1196 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1199 $copywarnMsg = array( 'copyrightwarning2',
1200 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1203 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage
) {
1204 # prepare toolbar for edit buttons
1205 $toolbar = $this->getEditToolbar();
1210 // activate checkboxes if user wants them to be always active
1211 if( !$this->preview
&& !$this->diff
) {
1212 # Sort out the "watch" checkbox
1213 if( $wgUser->getOption( 'watchdefault' ) ) {
1215 $this->watchthis
= true;
1216 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1218 $this->watchthis
= true;
1219 } elseif( $this->mTitle
->userIsWatching() ) {
1221 $this->watchthis
= true;
1224 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
1227 $wgOut->addHTML( $this->editFormPageTop
);
1229 if ( $wgUser->getOption( 'previewontop' ) ) {
1231 if ( 'preview' == $this->formtype
) {
1232 $this->showPreview( $previewOutput );
1234 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1237 if ( 'diff' == $this->formtype
) {
1243 $wgOut->addHTML( $this->editFormTextTop
);
1245 # if this is a comment, show a subject line at the top, which is also the edit summary.
1246 # Otherwise, show a summary field at the bottom
1247 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
1249 # If a blank edit summary was previously provided, and the appropriate
1250 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1251 # user being bounced back more than once in the event that a summary
1254 # For a bit more sophisticated detection of blank summaries, hash the
1255 # automatic one and pass that in the hidden field wpAutoSummary.
1256 $summaryhiddens = '';
1257 if( $this->missingSummary
) $summaryhiddens .= Xml
::hidden( 'wpIgnoreBlankSummary', true );
1258 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1259 $summaryhiddens .= Xml
::hidden( 'wpAutoSummary', $autosumm );
1260 if( $this->section
== 'new' ) {
1261 $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' />{$summaryhiddens}<br />";
1264 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary
) );
1265 $subjectpreview = $summarytext && $this->preview ?
"<div class=\"mw-summary-preview\">".wfMsg('subject-preview').':'.$sk->commentBlock( $formattedSummary, $this->mTitle
, true )."</div>\n" : '';
1266 $summarypreview = '';
1268 $commentsubject = '';
1269 $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' />{$summaryhiddens}<br />";
1270 $summarypreview = $summarytext && $this->preview ?
"<div class=\"mw-summary-preview\">".wfMsg('summary-preview').':'.$sk->commentBlock( $this->summary
, $this->mTitle
)."</div>\n" : '';
1271 $subjectpreview = '';
1274 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1275 if( !$this->preview
&& !$this->diff
) {
1276 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1278 $templates = ($this->preview ||
$this->section
!= '') ?
$this->mPreviewTemplates
: $this->mArticle
->getUsedTemplates();
1279 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview
, $this->section
!= '');
1281 $hiddencats = $this->mArticle
->getHiddenCategories();
1282 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1284 global $wgUseMetadataEdit ;
1285 if ( $wgUseMetadataEdit ) {
1286 $metadata = $this->mMetaData
;
1287 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1288 $top = wfMsgWikiHtml( 'metadata_help' );
1289 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1291 else $metadata = "" ;
1295 if ($this->wasDeletedSinceLastEdit()) {
1296 if ( 'save' != $this->formtype
) {
1297 $wgOut->addWikiMsg('deletedwhileediting');
1299 // Hide the toolbar and edit area, use can click preview to get it back
1300 // Add an confirmation checkbox and explanation.
1302 $hidden = 'type="hidden" style="display:none;"';
1303 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
));
1305 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1306 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1312 $checkboxes = self
::getCheckboxes( $tabindex, $sk,
1313 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1315 $checkboxhtml = implode( $checkboxes, "\n" );
1317 $buttons = $this->getEditButtons( $tabindex );
1318 $buttonshtml = implode( $buttons, "\n" );
1320 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1321 ?
'' : Xml
::hidden( 'safemode', '1' );
1323 $wgOut->addHTML( <<<END
1325 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1329 if( is_callable( $formCallback ) ) {
1330 call_user_func_array( $formCallback, array( &$wgOut ) );
1333 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1335 // Put these up at the top to ensure they aren't lost on early form submission
1337 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1338 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1339 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1340 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1342 $encodedtext = htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1
) );
1343 if( $encodedtext !== '' ) {
1344 // Ensure there's a newline at the end, otherwise adding lines
1346 // But don't add a newline if the ext is empty, or Firefox in XHTML
1347 // mode will show an extra newline. A bit annoying.
1348 $encodedtext .= "\n";
1351 $wgOut->addHTML( <<<END
1355 {$this->editFormTextBeforeContent}
1356 <textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'
1357 cols='{$cols}'{$ew} $hidden>{$encodedtext}</textarea>
1361 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1362 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1372 "<div class='editButtons'>
1374 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1375 </div><!-- editButtons -->
1376 </div><!-- editOptions -->");
1379 * To make it harder for someone to slip a user a page
1380 * which submits an edit form to the wiki without their
1381 * knowledge, a random token is associated with the login
1382 * session. If it's not passed back with the submission,
1383 * we won't save the page, or render user JavaScript and
1386 * For anon editors, who may not have a session, we just
1387 * include the constant suffix to prevent editing from
1388 * broken text-mangling proxies.
1390 $token = htmlspecialchars( $wgUser->editToken() );
1391 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1393 $wgOut->addHtml( '<div class="mw-editTools">' );
1394 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1395 $wgOut->addHtml( '</div>' );
1397 $wgOut->addHTML( $this->editFormTextAfterTools
);
1400 <div class='templatesUsed'>
1401 {$formattedtemplates}
1403 <div class='hiddencats'>
1404 {$formattedhiddencats}
1408 if ( $this->isConflict
&& wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1409 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1411 $de = new DifferenceEngine( $this->mTitle
);
1412 $de->setText( $this->textbox2
, $this->textbox1
);
1413 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1415 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1416 $wgOut->addHTML( "<textarea tabindex='6' id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}'>"
1417 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2
) ) . "\n</textarea>" );
1419 $wgOut->addHTML( $this->editFormTextBottom
);
1420 $wgOut->addHTML( "</form>\n" );
1421 if ( !$wgUser->getOption( 'previewontop' ) ) {
1423 if ( $this->formtype
== 'preview') {
1424 $this->showPreview( $previewOutput );
1426 $wgOut->addHTML( '<div id="wikiPreview"></div>' );
1429 if ( $this->formtype
== 'diff') {
1435 wfProfileOut( $fname );
1439 * Append preview output to $wgOut.
1440 * Includes category rendering if this is a category page.
1442 * @param string $text The HTML to be output for the preview.
1444 private function showPreview( $text ) {
1447 $wgOut->addHTML( '<div id="wikiPreview">' );
1448 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1449 $this->mArticle
->openShowCategory();
1451 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1452 $wgOut->addHTML( $text );
1453 if($this->mTitle
->getNamespace() == NS_CATEGORY
) {
1454 $this->mArticle
->closeShowCategory();
1456 $wgOut->addHTML( '</div>' );
1460 * Live Preview lets us fetch rendered preview page content and
1461 * add it to the page without refreshing the whole page.
1462 * If not supported by the browser it will fall through to the normal form
1463 * submission method.
1465 * This function outputs a script tag to support live preview, and
1466 * returns an onclick handler which should be added to the attributes
1467 * of the preview button
1469 function doLivePreviewScript() {
1470 global $wgOut, $wgTitle;
1471 $wgOut->addScriptFile( 'preview.js' );
1472 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
1473 return "return !lpDoPreview(" .
1474 "editform.wpTextbox1.value," .
1475 '"' . $liveAction . '"' . ")";
1478 function getLastDelete() {
1479 $dbr = wfGetDB( DB_SLAVE
);
1480 $fname = 'EditPage::getLastDelete';
1481 $res = $dbr->select(
1482 array( 'logging', 'user' ),
1492 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1493 'log_title' => $this->mTitle
->getDBkey(),
1494 'log_type' => 'delete',
1495 'log_action' => 'delete',
1496 'user_id=log_user' ),
1498 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1500 if($dbr->numRows($res) == 1) {
1501 while ( $x = $dbr->fetchObject ( $res ) )
1503 $dbr->freeResult ( $res ) ;
1513 function getPreviewText() {
1514 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
1516 $fname = 'EditPage::getPreviewText';
1517 wfProfileIn( $fname );
1519 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1520 if ( $this->mTokenOkExceptSuffix
) {
1521 $note = wfMsg( 'token_suffix_mismatch' );
1523 $note = wfMsg( 'session_fail_preview' );
1526 $note = wfMsg( 'previewnote' );
1529 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1530 $parserOptions->setEditSection( false );
1533 if( $wgRawHtml && !$this->mTokenOk
) {
1534 // Could be an offsite preview attempt. This is very unsafe if
1535 // HTML is enabled, as it could be an attack.
1536 return $wgOut->parse( "<div class='previewnote'>" .
1537 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1540 # don't parse user css/js, show message about preview
1541 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1543 if ( $this->isCssJsSubpage
) {
1544 if(preg_match("/\\.css$/", $this->mTitle
->getText() ) ) {
1545 $previewtext = wfMsg('usercsspreview');
1546 } else if(preg_match("/\\.js$/", $this->mTitle
->getText() ) ) {
1547 $previewtext = wfMsg('userjspreview');
1549 $parserOptions->setTidy(true);
1550 $parserOutput = $wgParser->parse( $previewtext , $this->mTitle
, $parserOptions );
1551 $wgOut->addHTML( $parserOutput->mText
);
1554 $toparse = $this->textbox1
;
1556 # If we're adding a comment, we need to show the
1557 # summary as the headline
1558 if($this->section
=="new" && $this->summary
!="") {
1559 $toparse="== {$this->summary} ==\n\n".$toparse;
1562 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1564 // Parse mediawiki messages with correct target language
1565 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1566 $pos = strrpos( $this->mTitle
->getText(), '/' );
1567 if ( $pos !== false ) {
1568 $code = substr( $this->mTitle
->getText(), $pos+
1 );
1570 case $wgLang->getCode():
1571 $obj = $wgLang; break;
1572 case $wgContLang->getCode():
1573 $obj = $wgContLang; break;
1575 $obj = Language
::factory( $code );
1577 $parserOptions->setTargetLanguage( $obj );
1582 $parserOptions->setTidy(true);
1583 $parserOptions->enableLimitReport();
1584 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
1585 $this->mTitle
, $parserOptions );
1587 $previewHTML = $parserOutput->getText();
1588 $wgOut->addParserOutputNoText( $parserOutput );
1590 # ParserOutput might have altered the page title, so reset it
1591 # Also, use the title defined by DISPLAYTITLE magic word when present
1592 if( ( $dt = $parserOutput->getDisplayTitle() ) !== false ) {
1593 $wgOut->setPageTitle( wfMsg( 'editing', $dt ) );
1595 $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) );
1598 foreach ( $parserOutput->getTemplates() as $ns => $template)
1599 foreach ( array_keys( $template ) as $dbk)
1600 $this->mPreviewTemplates
[] = Title
::makeTitle($ns, $dbk);
1602 if ( count( $parserOutput->getWarnings() ) ) {
1603 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1607 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1608 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
1609 if ( $this->isConflict
) {
1610 $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1613 if( $wgUser->getOption( 'previewontop' ) ) {
1614 // Spacer for the edit toolbar
1615 $previewfoot = '<p><br /></p>';
1620 wfProfileOut( $fname );
1621 return $previewhead . $previewHTML . $previewfoot;
1625 * Call the stock "user is blocked" page
1627 function blockedPage() {
1628 global $wgOut, $wgUser;
1629 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1631 # If the user made changes, preserve them when showing the markup
1632 # (This happens when a user is blocked during edit, for instance)
1633 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1635 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1637 $source = $this->textbox1
;
1640 # Spit out the source or the user's modified version
1641 if( $source !== false ) {
1642 $rows = $wgUser->getOption( 'rows' );
1643 $cols = $wgUser->getOption( 'cols' );
1644 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1645 $wgOut->addHtml( '<hr />' );
1646 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
1647 # Why we don't use Xml::element here?
1648 # Is it because if $source is '', it returns <textarea />?
1649 $wgOut->addHtml( Xml
::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml
::closeElement( 'textarea' ) );
1654 * Produce the stock "please login to edit pages" page
1656 function userNotLoggedInPage() {
1657 global $wgUser, $wgOut, $wgTitle;
1658 $skin = $wgUser->getSkin();
1660 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1661 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1663 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1664 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1665 $wgOut->setArticleRelated( false );
1667 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1668 $wgOut->returnToMain( false, $wgTitle );
1672 * Creates a basic error page which informs the user that
1673 * they have attempted to edit a nonexistant section.
1675 function noSuchSectionPage() {
1676 global $wgOut, $wgTitle;
1678 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1679 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1680 $wgOut->setArticleRelated( false );
1682 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section
);
1683 $wgOut->returnToMain( false, $wgTitle );
1687 * Produce the stock "your edit contains spam" page
1689 * @param $match Text which triggered one or more filters
1691 function spamPage( $match = false ) {
1692 global $wgOut, $wgTitle;
1694 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1695 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1696 $wgOut->setArticleRelated( false );
1698 $wgOut->addHtml( '<div id="spamprotected">' );
1699 $wgOut->addWikiMsg( 'spamprotectiontext' );
1701 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1702 $wgOut->addHtml( '</div>' );
1704 $wgOut->returnToMain( false, $wgTitle );
1711 function mergeChangesInto( &$editText ){
1712 $fname = 'EditPage::mergeChangesInto';
1713 wfProfileIn( $fname );
1715 $db = wfGetDB( DB_MASTER
);
1717 // This is the revision the editor started from
1718 $baseRevision = Revision
::loadFromTimestamp(
1719 $db, $this->mTitle
, $this->edittime
);
1720 if( is_null( $baseRevision ) ) {
1721 wfProfileOut( $fname );
1724 $baseText = $baseRevision->getText();
1726 // The current state, we want to merge updates into it
1727 $currentRevision = Revision
::loadFromTitle(
1728 $db, $this->mTitle
);
1729 if( is_null( $currentRevision ) ) {
1730 wfProfileOut( $fname );
1733 $currentText = $currentRevision->getText();
1736 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1737 $editText = $result;
1738 wfProfileOut( $fname );
1741 wfProfileOut( $fname );
1747 * Check if the browser is on a blacklist of user-agents known to
1748 * mangle UTF-8 data on form submission. Returns true if Unicode
1749 * should make it through, false if it's known to be a problem.
1753 function checkUnicodeCompliantBrowser() {
1754 global $wgBrowserBlackList;
1755 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1756 // No User-Agent header sent? Trust it by default...
1759 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1760 foreach ( $wgBrowserBlackList as $browser ) {
1761 if ( preg_match($browser, $currentbrowser) ) {
1769 * @deprecated use $wgParser->stripSectionName()
1771 function pseudoParseSectionAnchor( $text ) {
1773 return $wgParser->stripSectionName( $text );
1777 * Format an anchor fragment as it would appear for a given section name
1778 * @param string $text
1782 function sectionAnchor( $text ) {
1784 return $wgParser->guessSectionNameFromWikiText( $text );
1788 * Shows a bulletin board style toolbar for common editing functions.
1789 * It can be disabled in the user preferences.
1790 * The necessary JavaScript code can be found in style/wikibits.js.
1792 function getEditToolbar() {
1793 global $wgStylePath, $wgContLang, $wgJsMimeType;
1796 * toolarray an array of arrays which each include the filename of
1797 * the button image (without path), the opening tag, the closing tag,
1798 * and optionally a sample text that is inserted between the two when no
1799 * selection is highlighted.
1800 * The tip text is shown when the user moves the mouse over the button.
1802 * Already here are accesskeys (key), which are not used yet until someone
1803 * can figure out a way to make them work in IE. However, we should make
1804 * sure these keys are not defined on the edit page.
1807 array( 'image' => 'button_bold.png',
1808 'id' => 'mw-editbutton-bold',
1810 'close' => '\'\'\'',
1811 'sample'=> wfMsg('bold_sample'),
1812 'tip' => wfMsg('bold_tip'),
1815 array( 'image' => 'button_italic.png',
1816 'id' => 'mw-editbutton-italic',
1819 'sample'=> wfMsg('italic_sample'),
1820 'tip' => wfMsg('italic_tip'),
1823 array( 'image' => 'button_link.png',
1824 'id' => 'mw-editbutton-link',
1827 'sample'=> wfMsg('link_sample'),
1828 'tip' => wfMsg('link_tip'),
1831 array( 'image' => 'button_extlink.png',
1832 'id' => 'mw-editbutton-extlink',
1835 'sample'=> wfMsg('extlink_sample'),
1836 'tip' => wfMsg('extlink_tip'),
1839 array( 'image' => 'button_headline.png',
1840 'id' => 'mw-editbutton-headline',
1843 'sample'=> wfMsg('headline_sample'),
1844 'tip' => wfMsg('headline_tip'),
1847 array( 'image' => 'button_image.png',
1848 'id' => 'mw-editbutton-image',
1849 'open' => '[['.$wgContLang->getNsText(NS_IMAGE
).":",
1851 'sample'=> wfMsg('image_sample'),
1852 'tip' => wfMsg('image_tip'),
1855 array( 'image' => 'button_media.png',
1856 'id' => 'mw-editbutton-media',
1857 'open' => '[['.$wgContLang->getNsText(NS_MEDIA
).':',
1859 'sample'=> wfMsg('media_sample'),
1860 'tip' => wfMsg('media_tip'),
1863 array( 'image' => 'button_math.png',
1864 'id' => 'mw-editbutton-math',
1866 'close' => "</math>",
1867 'sample'=> wfMsg('math_sample'),
1868 'tip' => wfMsg('math_tip'),
1871 array( 'image' => 'button_nowiki.png',
1872 'id' => 'mw-editbutton-nowiki',
1873 'open' => "<nowiki>",
1874 'close' => "</nowiki>",
1875 'sample'=> wfMsg('nowiki_sample'),
1876 'tip' => wfMsg('nowiki_tip'),
1879 array( 'image' => 'button_sig.png',
1880 'id' => 'mw-editbutton-signature',
1884 'tip' => wfMsg('sig_tip'),
1887 array( 'image' => 'button_hr.png',
1888 'id' => 'mw-editbutton-hr',
1889 'open' => "\n----\n",
1892 'tip' => wfMsg('hr_tip'),
1896 $toolbar = "<div id='toolbar'>\n";
1897 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
1899 foreach($toolarray as $tool) {
1901 $image = $wgStylePath.'/common/images/'.$tool['image'],
1902 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
1903 // Older browsers show a "speedtip" type message only for ALT.
1904 // Ideally these should be different, realistically they
1905 // probably don't need to be.
1906 $tip = $tool['tip'],
1907 $open = $tool['open'],
1908 $close = $tool['close'],
1909 $sample = $tool['sample'],
1910 $cssId = $tool['id'],
1913 $paramList = implode( ',',
1914 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
1915 $toolbar.="addButton($paramList);\n";
1918 $toolbar.="/*]]>*/\n</script>";
1919 $toolbar.="\n</div>";
1924 * Returns an array of html code of the following checkboxes:
1927 * @param $tabindex Current tabindex
1928 * @param $skin Skin object
1929 * @param $checked Array of checkbox => bool, where bool indicates the checked
1930 * status of the checkbox
1934 public static function getCheckboxes( &$tabindex, $skin, $checked ) {
1937 $checkboxes = array();
1939 $checkboxes['minor'] = '';
1940 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
1941 if ( $wgUser->isAllowed('minoredit') ) {
1943 'tabindex' => ++
$tabindex,
1944 'accesskey' => wfMsg( 'accesskey-minoredit' ),
1945 'id' => 'wpMinoredit',
1947 $checkboxes['minor'] =
1948 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
1949 " <label for='wpMinoredit'".$skin->tooltipAndAccesskey('minoredit').">{$minorLabel}</label>";
1952 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
1953 $checkboxes['watch'] = '';
1954 if ( $wgUser->isLoggedIn() ) {
1956 'tabindex' => ++
$tabindex,
1957 'accesskey' => wfMsg( 'accesskey-watch' ),
1958 'id' => 'wpWatchthis',
1960 $checkboxes['watch'] =
1961 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
1962 " <label for='wpWatchthis'".$skin->tooltipAndAccesskey('watch').">{$watchLabel}</label>";
1968 * Returns an array of html code of the following buttons:
1969 * save, diff, preview and live
1971 * @param $tabindex Current tabindex
1975 public function getEditButtons(&$tabindex) {
1976 global $wgLivePreview, $wgUser;
1984 'tabindex' => ++
$tabindex,
1985 'value' => wfMsg('savearticle'),
1986 'accesskey' => wfMsg('accesskey-save'),
1987 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
1989 $buttons['save'] = Xml
::element('input', $temp, '');
1991 ++
$tabindex; // use the same for preview and live preview
1992 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
1994 'id' => 'wpPreview',
1995 'name' => 'wpPreview',
1997 'tabindex' => $tabindex,
1998 'value' => wfMsg('showpreview'),
2000 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2001 'style' => 'display: none;',
2003 $buttons['preview'] = Xml
::element('input', $temp, '');
2006 'id' => 'wpLivePreview',
2007 'name' => 'wpLivePreview',
2009 'tabindex' => $tabindex,
2010 'value' => wfMsg('showlivepreview'),
2011 'accesskey' => wfMsg('accesskey-preview'),
2013 'onclick' => $this->doLivePreviewScript(),
2015 $buttons['live'] = Xml
::element('input', $temp, '');
2018 'id' => 'wpPreview',
2019 'name' => 'wpPreview',
2021 'tabindex' => $tabindex,
2022 'value' => wfMsg('showpreview'),
2023 'accesskey' => wfMsg('accesskey-preview'),
2024 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2026 $buttons['preview'] = Xml
::element('input', $temp, '');
2027 $buttons['live'] = '';
2034 'tabindex' => ++
$tabindex,
2035 'value' => wfMsg('showdiff'),
2036 'accesskey' => wfMsg('accesskey-diff'),
2037 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2039 $buttons['diff'] = Xml
::element('input', $temp, '');
2041 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons ) );
2046 * Output preview text only. This can be sucked into the edit page
2047 * via JavaScript, and saves the server time rendering the skin as
2048 * well as theoretically being more robust on the client (doesn't
2049 * disturb the edit box's undo history, won't eat your text on
2052 * @todo This doesn't include category or interlanguage links.
2053 * Would need to enhance it a bit, <s>maybe wrap them in XML
2054 * or something...</s> that might also require more skin
2055 * initialization, so check whether that's a problem.
2057 function livePreview() {
2060 header( 'Content-type: text/xml; charset=utf-8' );
2061 header( 'Cache-control: no-cache' );
2063 $previewText = $this->getPreviewText();
2064 #$categories = $skin->getCategoryLinks();
2067 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2068 Xml
::tags( 'livepreview', null,
2069 Xml
::element( 'preview', null, $previewText )
2070 #. Xml::element( 'category', null, $categories )
2077 * Get a diff between the current contents of the edit box and the
2078 * version of the page we're editing from.
2080 * If this is a section edit, we'll replace the section as for final
2081 * save and then make a comparison.
2083 function showDiff() {
2084 $oldtext = $this->mArticle
->fetchContent();
2085 $newtext = $this->mArticle
->replaceSection(
2086 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2087 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2088 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2089 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2090 if ( $oldtext !== false ||
$newtext != '' ) {
2091 $de = new DifferenceEngine( $this->mTitle
);
2092 $de->setText( $oldtext, $newtext );
2093 $difftext = $de->getDiff( $oldtitle, $newtitle );
2094 $de->showDiffStyle();
2100 $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
2104 * Filter an input field through a Unicode de-armoring process if it
2105 * came from an old browser with known broken Unicode editing issues.
2107 * @param WebRequest $request
2108 * @param string $field
2112 function safeUnicodeInput( $request, $field ) {
2113 $text = rtrim( $request->getText( $field ) );
2114 return $request->getBool( 'safemode' )
2115 ?
$this->unmakesafe( $text )
2120 * Filter an output field through a Unicode armoring process if it is
2121 * going to an old browser with known broken Unicode editing issues.
2123 * @param string $text
2127 function safeUnicodeOutput( $text ) {
2129 $codedText = $wgContLang->recodeForEdit( $text );
2130 return $this->checkUnicodeCompliantBrowser()
2132 : $this->makesafe( $codedText );
2136 * A number of web browsers are known to corrupt non-ASCII characters
2137 * in a UTF-8 text editing environment. To protect against this,
2138 * detected browsers will be served an armored version of the text,
2139 * with non-ASCII chars converted to numeric HTML character references.
2141 * Preexisting such character references will have a 0 added to them
2142 * to ensure that round-trips do not alter the original data.
2144 * @param string $invalue
2148 function makesafe( $invalue ) {
2149 // Armor existing references for reversability.
2150 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2155 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2156 $bytevalue = ord( $invalue{$i} );
2157 if( $bytevalue <= 0x7F ) { //0xxx xxxx
2158 $result .= chr( $bytevalue );
2160 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
2161 $working = $working << 6;
2162 $working +
= ($bytevalue & 0x3F);
2164 if( $bytesleft <= 0 ) {
2165 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2167 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
2168 $working = $bytevalue & 0x1F;
2170 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
2171 $working = $bytevalue & 0x0F;
2173 } else { //1111 0xxx
2174 $working = $bytevalue & 0x07;
2182 * Reverse the previously applied transliteration of non-ASCII characters
2183 * back to UTF-8. Used to protect data from corruption by broken web browsers
2184 * as listed in $wgBrowserBlackList.
2186 * @param string $invalue
2190 function unmakesafe( $invalue ) {
2192 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2193 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
2197 $hexstring .= $invalue{$i};
2199 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2201 // Do some sanity checks. These aren't needed for reversability,
2202 // but should help keep the breakage down if the editor
2203 // breaks one of the entities whilst editing.
2204 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
2205 $codepoint = hexdec($hexstring);
2206 $result .= codepointToUtf8( $codepoint );
2208 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2211 $result .= substr( $invalue, $i, 1 );
2214 // reverse the transform that we made for reversability reasons.
2215 return strtr( $result, array( "�" => "&#x" ) );
2218 function noCreatePermission() {
2220 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2221 $wgOut->addWikiMsg( 'nocreatetext' );
2225 * If there are rows in the deletion log for this page, show them,
2226 * along with a nice little note for the user
2228 * @param OutputPage $out
2230 private function showDeletionLog( $out ) {
2232 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2233 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle
->getPrefixedText() );
2234 if( $pager->getNumRows() > 0 ) {
2235 $out->addHtml( '<div id="mw-recreate-deleted-warn">' );
2236 $out->addWikiMsg( 'recreate-deleted-warn' );
2238 $loglist->beginLogEventsList() .
2240 $loglist->endLogEventsList()
2242 $out->addHtml( '</div>' );
2247 * Attempt submission
2248 * @return bool false if output is done, true if the rest of the form should be displayed
2250 function attemptSave() {
2251 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2253 $resultDetails = false;
2254 $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
2256 if( $value == self
::AS_SUCCESS_UPDATE ||
$value == self
::AS_SUCCESS_NEW_ARTICLE
) {
2257 $this->didSave
= true;
2261 case self
::AS_HOOK_ERROR_EXPECTED
:
2262 case self
::AS_CONTENT_TOO_BIG
:
2263 case self
::AS_ARTICLE_WAS_DELETED
:
2264 case self
::AS_CONFLICT_DETECTED
:
2265 case self
::AS_SUMMARY_NEEDED
:
2266 case self
::AS_TEXTBOX_EMPTY
:
2267 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2271 case self
::AS_HOOK_ERROR
:
2272 case self
::AS_FILTERING
:
2273 case self
::AS_SUCCESS_NEW_ARTICLE
:
2274 case self
::AS_SUCCESS_UPDATE
:
2277 case self
::AS_SPAM_ERROR
:
2278 $this->spamPage ( $resultDetails['spam'] );
2281 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2282 $this->blockedPage();
2285 case self
::AS_IMAGE_REDIRECT_ANON
:
2286 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2289 case self
::AS_READ_ONLY_PAGE_ANON
:
2290 $this->userNotLoggedInPage();
2293 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2294 case self
::AS_READ_ONLY_PAGE
:
2295 $wgOut->readOnlyPage();
2298 case self
::AS_RATE_LIMITED
:
2299 $wgOut->rateLimited();
2302 case self
::AS_NO_CREATE_PERMISSION
;
2303 $this->noCreatePermission();
2306 case self
::AS_BLANK_ARTICLE
:
2307 $wgOut->redirect( $wgTitle->getFullURL() );
2310 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2311 $wgOut->permissionRequired( 'upload' );