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;
49 var $isConflict = false;
50 var $isCssJsSubpage = false;
51 var $isCssSubpage = false;
52 var $isJsSubpage = false;
53 var $deletedSinceEdit = false;
57 var $mTokenOk = false;
58 var $mTokenOkExceptSuffix = false;
59 var $mTriedSave = false;
61 var $kblength = false;
62 var $missingComment = false;
63 var $missingSummary = false;
64 var $allowBlankSummary = false;
67 #var $mPreviewTemplates;
69 var $mBaseRevision = false;
70 var $mShowSummaryField = true;
73 var $save = false, $preview = false, $diff = false;
74 var $minoredit = false, $watchthis = false, $recreate = false;
75 var $textbox1 = '', $textbox2 = '', $summary = '';
76 var $edittime = '', $section = '', $starttime = '';
77 var $oldid = 0, $editintro = '', $scrolltop = null;
79 # Placeholders for text injection by hooks (must be HTML)
80 # extensions should take care to _append_ to the present value
81 public $editFormPageTop; // Before even the preview
82 public $editFormTextTop;
83 public $editFormTextBeforeContent;
84 public $editFormTextAfterWarn;
85 public $editFormTextAfterTools;
86 public $editFormTextBottom;
87 public $editFormTextAfterContent;
88 public $previewTextAfterContent;
90 /* $didSave should be set to true whenever an article was succesfully altered. */
91 public $didSave = false;
94 public $suppressIntro = false;
100 function EditPage( $article ) {
101 $this->mArticle
=& $article;
102 $this->mTitle
= $article->getTitle();
103 $this->action
= 'submit';
105 # Placeholders for text injection by hooks (empty per default)
106 $this->editFormPageTop
=
107 $this->editFormTextTop
=
108 $this->editFormTextBeforeContent
=
109 $this->editFormTextAfterWarn
=
110 $this->editFormTextAfterTools
=
111 $this->editFormTextBottom
=
112 $this->editFormTextAfterContent
=
113 $this->previewTextAfterContent
=
114 $this->mPreloadText
= "";
117 function getArticle() {
118 return $this->mArticle
;
123 * Fetch initial editing page content.
126 function getContent( $def_text = '' ) {
127 global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
129 wfProfileIn( __METHOD__
);
130 # Get variables from query string :P
131 $section = $wgRequest->getVal( 'section' );
132 $preload = $wgRequest->getVal( 'preload' );
133 $undoafter = $wgRequest->getVal( 'undoafter' );
134 $undo = $wgRequest->getVal( 'undo' );
137 // For message page not locally set, use the i18n message.
138 // For other non-existent articles, use preload text if any.
139 if ( !$this->mTitle
->exists() ) {
140 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
141 # If this is a system message, get the default text.
142 list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle
->getText() ) );
143 $wgMessageCache->loadAllMessages( $lang );
144 $text = wfMsgGetKey( $message, false, $lang, false );
145 if( wfEmptyMsg( $message, $text ) )
146 $text = $this->getPreloadedText( $preload );
148 # If requested, preload some text.
149 $text = $this->getPreloadedText( $preload );
151 // For existing pages, get text based on "undo" or section parameters.
153 $text = $this->mArticle
->getContent();
154 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
155 # If they got undoafter and undo round the wrong way, switch them
156 list( $undo, $undoafter ) = array( $undoafter, $undo );
158 if ( $undo > 0 && $undo > $undoafter ) {
159 # Undoing a specific edit overrides section editing; section-editing
160 # doesn't work with undoing.
162 $undorev = Revision
::newFromId( $undo );
163 $oldrev = Revision
::newFromId( $undoafter );
165 $undorev = Revision
::newFromId( $undo );
166 $oldrev = $undorev ?
$undorev->getPrevious() : null;
169 # Sanity check, make sure it's the right page,
170 # the revisions exist and they were not deleted.
171 # Otherwise, $text will be left as-is.
172 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
173 $undorev->getPage() == $oldrev->getPage() &&
174 $undorev->getPage() == $this->mArticle
->getID() &&
175 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
176 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
178 $undotext = $this->mArticle
->getUndoText( $undorev, $oldrev );
179 if ( $undotext === false ) {
180 # Warn the user that something went wrong
181 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
184 # Inform the user of our success and set an automatic edit summary
185 $this->editFormPageTop
.= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
186 $firstrev = $oldrev->getNext();
187 # If we just undid one rev, use an autosummary
188 if ( $firstrev->mId
== $undo ) {
189 $this->summary
= wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
190 $this->undidRev
= $undo;
192 $this->formtype
= 'diff';
195 // Failed basic sanity checks.
196 // Older revisions may have been removed since the link
197 // was created, or we may simply have got bogus input.
198 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
200 } else if ( $section != '' ) {
201 if ( $section == 'new' ) {
202 $text = $this->getPreloadedText( $preload );
204 $text = $wgParser->getSection( $text, $section, $def_text );
209 wfProfileOut( __METHOD__
);
213 /** Use this method before edit() to preload some text into the edit box */
214 public function setPreloadedText( $text ) {
215 $this->mPreloadText
= $text;
219 * Get the contents of a page from its title and remove includeonly tags
221 * @param $preload String: the title of the page.
222 * @return string The contents of the page.
224 protected function getPreloadedText( $preload ) {
225 if ( !empty( $this->mPreloadText
) ) {
226 return $this->mPreloadText
;
227 } elseif ( $preload === '' ) {
230 $preloadTitle = Title
::newFromText( $preload );
231 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
232 $rev = Revision
::newFromTitle( $preloadTitle );
233 if ( is_object( $rev ) ) {
234 $text = $rev->getText();
235 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
236 // its own mini-parser! -ævar
237 $text = preg_replace( '~</?includeonly>~', '', $text );
246 * This is the function that extracts metadata from the article body on the first view.
247 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
248 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
250 function extractMetaDataFromArticle () {
251 global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
252 $this->mMetaData
= '';
253 if ( !$wgUseMetadataEdit ) return;
254 if ( $wgMetadataWhitelist == '' ) return;
256 $t = $this->getContent();
258 # MISSING : <nowiki> filtering
260 # Categories and language links
261 $t = explode( "\n" , $t );
262 $catlow = strtolower( $wgContLang->getNsText( NS_CATEGORY
) );
263 $cat = $ll = array();
264 foreach ( $t as $key => $x ) {
265 $y = trim( strtolower ( $x ) );
266 while ( substr( $y , 0 , 2 ) == '[[' ) {
267 $y = explode( ']]' , trim ( $x ) );
268 $first = array_shift( $y );
269 $first = explode( ':' , $first );
270 $ns = array_shift( $first );
271 $ns = trim( str_replace( '[' , '' , $ns ) );
272 if ( $wgContLang->getLanguageName( $ns ) ||
strtolower( $ns ) == $catlow ) {
273 $add = '[[' . $ns . ':' . implode( ':' , $first ) . ']]';
274 if ( strtolower( $ns ) == $catlow ) $cat[] = $add;
276 $x = implode( ']]', $y );
278 $y = trim( strtolower( $x ) );
280 $x = implode( ']]' , $y );
281 $y = trim( strtolower( $x ) );
285 if ( count( $cat ) ) $s .= implode( ' ' , $cat ) . "\n";
286 if ( count( $ll ) ) $s .= implode( ' ' , $ll ) . "\n";
287 $t = implode( "\n" , $t );
290 $sat = array () ; # stand-alone-templates; must be lowercase
291 $wl_title = Title
::newFromText( $wgMetadataWhitelist );
292 $wl_article = new Article ( $wl_title );
293 $wl = explode ( "\n" , $wl_article->getContent() );
294 foreach ( $wl AS $x ) {
297 while ( substr ( $x , 0 , 1 ) == '*' ) {
299 $x = trim ( substr ( $x , 1 ) );
302 $sat[] = strtolower ( $x );
307 # Templates, but only some
308 $t = explode( '{{' , $t );
310 foreach ( $t as $key => $x ) {
311 $y = explode( '}}' , $x , 2 );
312 if ( count( $y ) == 2 ) {
314 $z = explode( '|' , $z );
315 $tn = array_shift( $z );
316 if ( in_array( strtolower( $tn ) , $sat ) ) {
317 $tl[] = '{{' . $y[0] . '}}';
319 $y = explode( '}}' , $y[1] , 2 );
321 else $t[$key] = '{{' . $x;
323 else if ( $key != 0 ) $t[$key] = '{{' . $x;
326 if ( count( $tl ) ) $s .= implode( ' ' , $tl );
327 $t = implode( '' , $t );
329 $t = str_replace( "\n\n\n", "\n", $t );
330 $this->mArticle
->mContent
= $t;
331 $this->mMetaData
= $s;
335 * Check if a page was deleted while the user was editing it, before submit.
336 * Note that we rely on the logging table, which hasn't been always there,
337 * but that doesn't matter, because this only applies to brand new
340 protected function wasDeletedSinceLastEdit() {
341 if ( $this->deletedSinceEdit
)
343 if ( $this->mTitle
->isDeletedQuick() ) {
344 $this->lastDelete
= $this->getLastDelete();
345 if ( $this->lastDelete
) {
346 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
347 if ( $deleteTime > $this->starttime
) {
348 $this->deletedSinceEdit
= true;
352 return $this->deletedSinceEdit
;
360 * This is the function that gets called for "action=edit". It
361 * sets up various member variables, then passes execution to
362 * another function, usually showEditForm()
364 * The edit form is self-submitting, so that when things like
365 * preview and edit conflicts occur, we get the same form back
366 * with the extra stuff added. Only when the final submission
367 * is made and all is well do we actually save and redirect to
368 * the newly-edited page.
371 global $wgOut, $wgRequest;
372 // Allow extensions to modify/prevent this form or submission
373 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
377 wfProfileIn( __METHOD__
);
378 wfDebug( __METHOD__
.": enter\n" );
380 // This is not an article
381 $wgOut->setArticleFlag( false );
383 $this->importFormData( $wgRequest );
384 $this->firsttime
= false;
387 $this->livePreview();
388 wfProfileOut( __METHOD__
);
392 if ( wfReadOnly() && $this->save
) {
395 $this->preview
= true;
398 $wgOut->addScriptFile( 'edit.js' );
400 $permErrors = $this->getEditPermissionErrors();
402 wfDebug( __METHOD__
. ": User can't edit\n" );
403 $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
404 wfProfileOut( __METHOD__
);
408 $this->formtype
= 'save';
409 } else if ( $this->preview
) {
410 $this->formtype
= 'preview';
411 } else if ( $this->diff
) {
412 $this->formtype
= 'diff';
413 } else { # First time through
414 $this->firsttime
= true;
415 if ( $this->previewOnOpen() ) {
416 $this->formtype
= 'preview';
418 $this->extractMetaDataFromArticle () ;
419 $this->formtype
= 'initial';
424 // If they used redlink=1 and the page exists, redirect to the main article
425 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
426 $wgOut->redirect( $this->mTitle
->getFullURL() );
429 wfProfileIn( __METHOD__
."-business-end" );
431 $this->isConflict
= false;
432 // css / js subpages of user pages get a special treatment
433 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
434 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
435 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
436 $this->isValidCssJsSubpage
= $this->mTitle
->isValidCssJsSubpage();
438 # Show applicable editing introductions
439 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
442 if ( $this->mTitle
->isTalkPage() ) {
443 $wgOut->addWikiMsg( 'talkpagetext' );
446 # Optional notices on a per-namespace and per-page basis
447 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
448 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
449 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
451 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
452 $parts = explode( '/', $this->mTitle
->getDBkey() );
453 $editnotice_base = $editnotice_ns;
454 while ( count( $parts ) > 0 ) {
455 $editnotice_base .= '-'.array_shift( $parts );
456 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
457 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
462 # Attempt submission here. This will check for edit conflicts,
463 # and redundantly check for locked database, blocked IPs, etc.
464 # that edit() already checked just in case someone tries to sneak
465 # in the back door with a hand-edited submission URL.
467 if ( 'save' == $this->formtype
) {
468 if ( !$this->attemptSave() ) {
469 wfProfileOut( __METHOD__
."-business-end" );
470 wfProfileOut( __METHOD__
);
475 # First time through: get contents, set time for conflict
477 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
478 if ( $this->initialiseForm() === false ) {
479 $this->noSuchSectionPage();
480 wfProfileOut( __METHOD__
."-business-end" );
481 wfProfileOut( __METHOD__
);
484 if ( !$this->mTitle
->getArticleId() )
485 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
488 $this->showEditForm();
489 wfProfileOut( __METHOD__
."-business-end" );
490 wfProfileOut( __METHOD__
);
493 protected function getEditPermissionErrors() {
495 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
496 # Can this title be created?
497 if ( !$this->mTitle
->exists() ) {
498 $permErrors = array_merge( $permErrors,
499 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
501 # Ignore some permissions errors when a user is just previewing/viewing diffs
503 foreach( $permErrors as $error ) {
504 if ( ( $this->preview ||
$this->diff
) &&
505 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
510 $permErrors = wfArrayDiff2( $permErrors, $remove );
515 * Show a read-only error
516 * Parameters are the same as OutputPage:readOnlyPage()
517 * Redirect to the article page if redlink=1
519 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
520 global $wgRequest, $wgOut;
521 if ( $wgRequest->getBool( 'redlink' ) ) {
522 // The edit page was reached via a red link.
523 // Redirect to the article page and let them click the edit tab if
524 // they really want a permission error.
525 $wgOut->redirect( $this->mTitle
->getFullUrl() );
527 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
532 * Should we show a preview when the edit form is first shown?
536 protected function previewOnOpen() {
537 global $wgRequest, $wgUser;
538 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
539 // Explicit override from request
541 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
542 // Explicit override from request
544 } elseif ( $this->section
== 'new' ) {
545 // Nothing *to* preview for new sections
547 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
548 // Standard preference behaviour
550 } elseif ( !$this->mTitle
->exists() && $this->mTitle
->getNamespace() == NS_CATEGORY
) {
551 // Categories are special
562 function importFormData( &$request ) {
563 global $wgLang, $wgUser;
565 wfProfileIn( __METHOD__
);
567 # Section edit can come from either the form or a link
568 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
570 if ( $request->wasPosted() ) {
571 # These fields need to be checked for encoding.
572 # Also remove trailing whitespace, but don't remove _initial_
573 # whitespace from the text boxes. This may be significant formatting.
574 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
575 $this->textbox2
= $this->safeUnicodeInput( $request, 'wpTextbox2' );
576 $this->mMetaData
= rtrim( $request->getText( 'metadata' ) );
577 # Truncate for whole multibyte characters. +5 bytes for ellipsis
578 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
580 # Remove extra headings from summaries and new sections.
581 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
583 $this->edittime
= $request->getVal( 'wpEdittime' );
584 $this->starttime
= $request->getVal( 'wpStarttime' );
586 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
588 if ( is_null( $this->edittime
) ) {
589 # If the form is incomplete, force to preview.
590 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
591 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
592 $this->preview
= true;
594 /* Fallback for live preview */
595 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
596 $this->diff
= $request->getCheck( 'wpDiff' );
598 // Remember whether a save was requested, so we can indicate
599 // if we forced preview due to session failure.
600 $this->mTriedSave
= !$this->preview
;
602 if ( $this->tokenOk( $request ) ) {
603 # Some browsers will not report any submit button
604 # if the user hits enter in the comment box.
605 # The unmarked state will be assumed to be a save,
606 # if the form seems otherwise complete.
607 wfDebug( __METHOD__
. ": Passed token check.\n" );
608 } else if ( $this->diff
) {
609 # Failed token check, but only requested "Show Changes".
610 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
612 # Page might be a hack attempt posted from
613 # an external site. Preview instead of saving.
614 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
615 $this->preview
= true;
618 $this->save
= !$this->preview
&& !$this->diff
;
619 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
620 $this->edittime
= null;
623 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
624 $this->starttime
= null;
627 $this->recreate
= $request->getCheck( 'wpRecreate' );
629 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
630 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
632 # Don't force edit summaries when a user is editing their own user or talk page
633 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
634 $this->mTitle
->getText() == $wgUser->getName() )
636 $this->allowBlankSummary
= true;
638 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
641 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
643 # Not a posted form? Start with nothing.
644 wfDebug( __METHOD__
. ": Not a posted form.\n" );
645 $this->textbox1
= '';
646 $this->textbox2
= '';
647 $this->mMetaData
= '';
649 $this->edittime
= '';
650 $this->starttime
= wfTimestampNow();
652 $this->preview
= false;
655 $this->minoredit
= false;
656 $this->watchthis
= false;
657 $this->recreate
= false;
659 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
660 $this->summary
= $request->getVal( 'preloadtitle' );
662 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
663 $this->summary
= $request->getText( 'summary' );
666 if ( $request->getVal( 'minor' ) ) {
667 $this->minoredit
= true;
671 // FIXME: unused variable?
672 $this->oldid
= $request->getInt( 'oldid' );
674 $this->live
= $request->getCheck( 'live' );
675 $this->editintro
= $request->getText( 'editintro' );
677 wfProfileOut( __METHOD__
);
679 // Allow extensions to modify form data
680 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
684 * Make sure the form isn't faking a user's credentials.
686 * @param $request WebRequest
690 function tokenOk( &$request ) {
692 $token = $request->getVal( 'wpEditToken' );
693 $this->mTokenOk
= $wgUser->matchEditToken( $token );
694 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
695 return $this->mTokenOk
;
699 * Show all applicable editing introductions
701 protected function showIntro() {
702 global $wgOut, $wgUser;
703 if ( $this->suppressIntro
) {
707 $namespace = $this->mTitle
->getNamespace();
709 if ( $namespace == NS_MEDIAWIKI
) {
710 # Show a warning if editing an interface message
711 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
714 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
715 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
716 $parts = explode( '/', $this->mTitle
->getText(), 2 );
717 $username = $parts[0];
718 $id = User
::idFromName( $username );
719 $ip = User
::isIP( $username );
720 if ( $id == 0 && !$ip ) {
721 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
722 array( 'userpage-userdoesnotexist', $username ) );
725 # Try to add a custom edit intro, or use the standard one if this is not possible.
726 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
727 if ( $wgUser->isLoggedIn() ) {
728 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
730 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
733 # Give a notice if the user is editing a deleted/moved page...
734 if ( !$this->mTitle
->exists() ) {
735 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
->getPrefixedText(),
736 '', array( 'lim' => 10,
737 'conds' => array( "log_action != 'revision'" ),
738 'showIfEmpty' => false,
739 'msgKey' => array( 'recreate-moveddeleted-warn') )
745 * Attempt to show a custom editing introduction, if supplied
749 protected function showCustomIntro() {
750 if ( $this->editintro
) {
751 $title = Title
::newFromText( $this->editintro
);
752 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
754 $revision = Revision
::newFromTitle( $title );
755 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle
);
766 * Attempt submission (no UI)
767 * @return one of the constants describing the result
769 function internalAttemptSave( &$result, $bot = false ) {
770 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
771 global $wgMaxArticleSize;
773 wfProfileIn( __METHOD__
);
774 wfProfileIn( __METHOD__
. '-checks' );
776 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) )
778 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
779 return self
::AS_HOOK_ERROR
;
782 # Check image redirect
783 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
784 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
785 !$wgUser->isAllowed( 'upload' ) ) {
786 if ( $wgUser->isAnon() ) {
787 return self
::AS_IMAGE_REDIRECT_ANON
;
789 return self
::AS_IMAGE_REDIRECT_LOGGED
;
793 # Reintegrate metadata
794 if ( $this->mMetaData
!= '' ) $this->textbox1
.= "\n" . $this->mMetaData
;
795 $this->mMetaData
= '' ;
798 $match = self
::matchSummarySpamRegex( $this->summary
);
799 if ( $match === false ) {
800 $match = self
::matchSpamRegex( $this->textbox1
);
802 if ( $match !== false ) {
803 $result['spam'] = $match;
805 $pdbk = $this->mTitle
->getPrefixedDBkey();
806 $match = str_replace( "\n", '', $match );
807 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
808 wfProfileOut( __METHOD__
. '-checks' );
809 wfProfileOut( __METHOD__
);
810 return self
::AS_SPAM_ERROR
;
812 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
813 # Error messages or other handling should be performed by the filter function
814 wfProfileOut( __METHOD__
. '-checks' );
815 wfProfileOut( __METHOD__
);
816 return self
::AS_FILTERING
;
818 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
819 # Error messages etc. could be handled within the hook...
820 wfProfileOut( __METHOD__
. '-checks' );
821 wfProfileOut( __METHOD__
);
822 return self
::AS_HOOK_ERROR
;
823 } elseif ( $this->hookError
!= '' ) {
824 # ...or the hook could be expecting us to produce an error
825 wfProfileOut( __METHOD__
. '-checks' );
826 wfProfileOut( __METHOD__
);
827 return self
::AS_HOOK_ERROR_EXPECTED
;
829 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
830 # Check block state against master, thus 'false'.
831 wfProfileOut( __METHOD__
. '-checks' );
832 wfProfileOut( __METHOD__
);
833 return self
::AS_BLOCKED_PAGE_FOR_USER
;
835 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
836 if ( $this->kblength
> $wgMaxArticleSize ) {
837 // Error will be displayed by showEditForm()
838 $this->tooBig
= true;
839 wfProfileOut( __METHOD__
. '-checks' );
840 wfProfileOut( __METHOD__
);
841 return self
::AS_CONTENT_TOO_BIG
;
844 if ( !$wgUser->isAllowed( 'edit' ) ) {
845 if ( $wgUser->isAnon() ) {
846 wfProfileOut( __METHOD__
. '-checks' );
847 wfProfileOut( __METHOD__
);
848 return self
::AS_READ_ONLY_PAGE_ANON
;
850 wfProfileOut( __METHOD__
. '-checks' );
851 wfProfileOut( __METHOD__
);
852 return self
::AS_READ_ONLY_PAGE_LOGGED
;
856 if ( wfReadOnly() ) {
857 wfProfileOut( __METHOD__
. '-checks' );
858 wfProfileOut( __METHOD__
);
859 return self
::AS_READ_ONLY_PAGE
;
861 if ( $wgUser->pingLimiter() ) {
862 wfProfileOut( __METHOD__
. '-checks' );
863 wfProfileOut( __METHOD__
);
864 return self
::AS_RATE_LIMITED
;
867 # If the article has been deleted while editing, don't save it without
869 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
870 wfProfileOut( __METHOD__
. '-checks' );
871 wfProfileOut( __METHOD__
);
872 return self
::AS_ARTICLE_WAS_DELETED
;
875 wfProfileOut( __METHOD__
. '-checks' );
877 # If article is new, insert it.
878 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
880 // Late check for create permission, just in case *PARANOIA*
881 if ( !$this->mTitle
->userCan( 'create' ) ) {
882 wfDebug( __METHOD__
. ": no create permission\n" );
883 wfProfileOut( __METHOD__
);
884 return self
::AS_NO_CREATE_PERMISSION
;
887 # Don't save a new article if it's blank.
888 if ( '' == $this->textbox1
) {
889 wfProfileOut( __METHOD__
);
890 return self
::AS_BLANK_ARTICLE
;
893 // Run post-section-merge edit filter
894 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
895 # Error messages etc. could be handled within the hook...
896 wfProfileOut( __METHOD__
);
897 return self
::AS_HOOK_ERROR
;
898 } elseif ( $this->hookError
!= '' ) {
899 # ...or the hook could be expecting us to produce an error
900 wfProfileOut( __METHOD__
);
901 return self
::AS_HOOK_ERROR_EXPECTED
;
904 # Handle the user preference to force summaries here. Check if it's not a redirect.
905 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
906 if ( md5( $this->summary
) == $this->autoSumm
) {
907 $this->missingSummary
= true;
908 wfProfileOut( __METHOD__
);
909 return self
::AS_SUMMARY_NEEDED
;
913 $isComment = ( $this->section
== 'new' );
915 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
916 $this->minoredit
, $this->watchthis
, false, $isComment, $bot );
918 wfProfileOut( __METHOD__
);
919 return self
::AS_SUCCESS_NEW_ARTICLE
;
922 # Article exists. Check for edit conflict.
924 $this->mArticle
->clear(); # Force reload of dates, etc.
925 $this->mArticle
->forUpdate( true ); # Lock the article
927 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
929 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
930 $this->isConflict
= true;
931 if ( $this->section
== 'new' ) {
932 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
933 $this->mArticle
->getComment() == $this->summary
) {
934 // Probably a duplicate submission of a new comment.
935 // This can happen when squid resends a request after
936 // a timeout but the first one actually went through.
937 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
939 // New comment; suppress conflict.
940 $this->isConflict
= false;
941 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
945 $userid = $wgUser->getId();
947 # Suppress edit conflict with self, except for section edits where merging is required.
948 if ( $this->isConflict
&& $this->section
== '' && $this->userWasLastToEdit( $userid, $this->edittime
) ) {
949 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
950 $this->isConflict
= false;
953 if ( $this->isConflict
) {
954 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
955 $this->mArticle
->getTimestamp() . "')\n" );
956 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
958 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
959 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
961 if ( is_null( $text ) ) {
962 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
963 $this->isConflict
= true;
964 $text = $this->textbox1
; // do not try to merge here!
965 } else if ( $this->isConflict
) {
967 if ( $this->mergeChangesInto( $text ) ) {
968 // Successful merge! Maybe we should tell the user the good news?
969 $this->isConflict
= false;
970 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
973 $this->textbox1
= $text;
974 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
978 if ( $this->isConflict
) {
979 wfProfileOut( __METHOD__
);
980 return self
::AS_CONFLICT_DETECTED
;
983 $oldtext = $this->mArticle
->getContent();
985 // Run post-section-merge edit filter
986 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
987 # Error messages etc. could be handled within the hook...
988 wfProfileOut( __METHOD__
);
989 return self
::AS_HOOK_ERROR
;
990 } elseif ( $this->hookError
!= '' ) {
991 # ...or the hook could be expecting us to produce an error
992 wfProfileOut( __METHOD__
);
993 return self
::AS_HOOK_ERROR_EXPECTED
;
996 # Handle the user preference to force summaries here, but not for null edits
997 if ( $this->section
!= 'new' && !$this->allowBlankSummary
&& 0 != strcmp( $oldtext, $text )
998 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
1000 if ( md5( $this->summary
) == $this->autoSumm
) {
1001 $this->missingSummary
= true;
1002 wfProfileOut( __METHOD__
);
1003 return self
::AS_SUMMARY_NEEDED
;
1007 # And a similar thing for new sections
1008 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1009 if ( trim( $this->summary
) == '' ) {
1010 $this->missingSummary
= true;
1011 wfProfileOut( __METHOD__
);
1012 return self
::AS_SUMMARY_NEEDED
;
1017 wfProfileIn( __METHOD__
. '-sectionanchor' );
1018 $sectionanchor = '';
1019 if ( $this->section
== 'new' ) {
1020 if ( $this->textbox1
== '' ) {
1021 $this->missingComment
= true;
1022 wfProfileOut( __METHOD__
. '-sectionanchor' );
1023 wfProfileOut( __METHOD__
);
1024 return self
::AS_TEXTBOX_EMPTY
;
1026 if ( $this->summary
!= '' ) {
1027 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary
);
1028 # This is a new section, so create a link to the new section
1029 # in the revision summary.
1030 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1031 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1033 } elseif ( $this->section
!= '' ) {
1034 # Try to get a section anchor from the section source, redirect to edited section if header found
1035 # XXX: might be better to integrate this into Article::replaceSection
1036 # for duplicate heading checking and maybe parsing
1037 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1038 # we can't deal with anchors, includes, html etc in the header for now,
1039 # headline would need to be parsed to improve this
1040 if ( $hasmatch and strlen( $matches[2] ) > 0 ) {
1041 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
1044 wfProfileOut( __METHOD__
. '-sectionanchor' );
1046 // Save errors may fall down to the edit form, but we've now
1047 // merged the section into full text. Clear the section field
1048 // so that later submission of conflict forms won't try to
1049 // replace that into a duplicated mess.
1050 $this->textbox1
= $text;
1051 $this->section
= '';
1053 // Check for length errors again now that the section is merged in
1054 $this->kblength
= (int)( strlen( $text ) / 1024 );
1055 if ( $this->kblength
> $wgMaxArticleSize ) {
1056 $this->tooBig
= true;
1057 wfProfileOut( __METHOD__
);
1058 return self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
;
1061 # update the article here
1062 if ( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
1063 $this->watchthis
, $bot, $sectionanchor ) )
1065 wfProfileOut( __METHOD__
);
1066 return self
::AS_SUCCESS_UPDATE
;
1068 $this->isConflict
= true;
1070 wfProfileOut( __METHOD__
);
1071 return self
::AS_END
;
1075 * Check if no edits were made by other users since
1076 * the time a user started editing the page. Limit to
1077 * 50 revisions for the sake of performance.
1079 protected function userWasLastToEdit( $id, $edittime ) {
1080 if( !$id ) return false;
1081 $dbw = wfGetDB( DB_MASTER
);
1082 $res = $dbw->select( 'revision',
1085 'rev_page' => $this->mArticle
->getId(),
1086 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1089 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1090 while( $row = $res->fetchObject() ) {
1091 if( $row->rev_user
!= $id ) {
1099 * Check given input text against $wgSpamRegex, and return the text of the first match.
1100 * @return mixed -- matching string or false
1102 public static function matchSpamRegex( $text ) {
1103 global $wgSpamRegex;
1104 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1105 $regexes = (array)$wgSpamRegex;
1106 return self
::matchSpamRegexInternal( $text, $regexes );
1110 * Check given input text against $wgSpamRegex, and return the text of the first match.
1111 * @return mixed -- matching string or false
1113 public static function matchSummarySpamRegex( $text ) {
1114 global $wgSummarySpamRegex;
1115 $regexes = (array)$wgSummarySpamRegex;
1116 return self
::matchSpamRegexInternal( $text, $regexes );
1119 protected static function matchSpamRegexInternal( $text, $regexes ) {
1120 foreach( $regexes as $regex ) {
1122 if( preg_match( $regex, $text, $matches ) ) {
1130 * Initialise form fields in the object
1131 * Called on the first invocation, e.g. when a user clicks an edit link
1133 function initialiseForm() {
1134 $this->edittime
= $this->mArticle
->getTimestamp();
1135 $this->textbox1
= $this->getContent( false );
1136 if ( $this->textbox1
=== false ) return false;
1141 function setHeaders() {
1142 global $wgOut, $wgTitle;
1143 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1144 if ( $this->formtype
== 'preview' ) {
1145 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1147 if ( $this->isConflict
) {
1148 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1149 } elseif ( $this->section
!= '' ) {
1150 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1151 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1153 # Use the title defined by DISPLAYTITLE magic word when present
1154 if ( isset( $this->mParserOutput
)
1155 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1158 $title = $wgTitle->getPrefixedText();
1160 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1165 * Send the edit form and related headers to $wgOut
1166 * @param $formCallback Optional callable that takes an OutputPage
1167 * parameter; will be called during form output
1168 * near the top, for captchas and the like.
1170 function showEditForm( $formCallback=null ) {
1171 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle, $wgRequest;
1173 # If $wgTitle is null, that means we're in API mode.
1174 # Some hook probably called this function without checking
1175 # for is_null($wgTitle) first. Bail out right here so we don't
1176 # do lots of work just to discard it right after.
1177 if ( is_null( $wgTitle ) )
1180 wfProfileIn( __METHOD__
);
1182 $sk = $wgUser->getSkin();
1184 #need to parse the preview early so that we know which templates are used,
1185 #otherwise users with "show preview after edit box" will get a blank list
1186 #we parse this near the beginning so that setHeaders can do the title
1187 #setting work instead of leaving it in getPreviewText
1188 $previewOutput = '';
1189 if ( $this->formtype
== 'preview' ) {
1190 $previewOutput = $this->getPreviewText();
1193 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1195 $this->setHeaders();
1197 # Enabled article-related sidebar, toplinks, etc.
1198 $wgOut->setArticleRelated( true );
1200 $cancelParams = array();
1202 if ( $this->isConflict
) {
1203 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
1205 $this->textbox2
= $this->textbox1
;
1206 $this->textbox1
= $this->getContent();
1207 $this->edittime
= $this->mArticle
->getTimestamp();
1209 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1211 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1212 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1213 if ( !empty( $matches[2] ) ) {
1215 $this->summary
= "/* " .
1216 $wgParser->stripSectionName(trim($matches[2])) .
1222 if ( $this->missingComment
) {
1223 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1226 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1227 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1230 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1231 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1234 if ( $this->hookError
!== '' ) {
1235 $wgOut->addWikiText( $this->hookError
);
1238 if ( !$this->checkUnicodeCompliantBrowser() ) {
1239 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1241 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1242 // Let sysop know that this will make private content public if saved
1244 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1245 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
1246 } else if ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1247 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
1250 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1251 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1252 $cancelParams['oldid'] = $this->mArticle
->mRevision
->getId();
1253 $wgOut->addWikiMsg( 'editingold' );
1258 if ( wfReadOnly() ) {
1259 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1260 } elseif ( $wgUser->isAnon() && $this->formtype
!= 'preview' ) {
1261 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
1263 if ( $this->isCssJsSubpage
) {
1264 # Check the skin exists
1265 if ( !$this->isValidCssJsSubpage
) {
1266 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1268 if ( $this->formtype
!== 'preview' ) {
1269 if ( $this->isCssSubpage
)
1270 $wgOut->addWikiMsg( 'usercssyoucanpreview' );
1271 if ( $this->isJsSubpage
)
1272 $wgOut->addWikiMsg( 'userjsyoucanpreview' );
1277 $classes = array(); // Textarea CSS
1278 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1279 } elseif ( $this->mTitle
->isProtected( 'edit' ) ) {
1280 # Is the title semi-protected?
1281 if ( $this->mTitle
->isSemiProtected() ) {
1282 $noticeMsg = 'semiprotectedpagewarning';
1283 $classes[] = 'mw-textarea-sprotected';
1285 # Then it must be protected based on static groups (regular)
1286 $noticeMsg = 'protectedpagewarning';
1287 $classes[] = 'mw-textarea-protected';
1289 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1290 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1292 if ( $this->mTitle
->isCascadeProtected() ) {
1293 # Is this page under cascading protection from some source pages?
1294 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1295 $notice = "<div class='mw-cascadeprotectedwarning'>$1\n";
1296 $cascadeSourcesCount = count( $cascadeSources );
1297 if ( $cascadeSourcesCount > 0 ) {
1298 # Explain, and list the titles responsible
1299 foreach( $cascadeSources as $page ) {
1300 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1303 $notice .= '</div>';
1304 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1306 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1307 $wgOut->wrapWikiMsg( '<div class="mw-titleprotectedwarning">$1</div>', 'titleprotectedwarning' );
1310 if ( $this->kblength
=== false ) {
1311 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1313 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1314 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
1315 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) );
1316 $wgOut->addHTML( "</div>\n" );
1317 } elseif ( $this->kblength
> 29 ) {
1318 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1319 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) );
1320 $wgOut->addHTML( "</div>\n" );
1323 $action = $wgTitle->escapeLocalURL( array( 'action' => $this->action
) );
1325 $summary = wfMsgExt( 'summary', 'parseinline' );
1326 $subject = wfMsgExt( 'subject', 'parseinline' );
1328 $cancel = $sk->link(
1330 wfMsgExt( 'cancel', array( 'parseinline' ) ),
1331 array( 'id' => 'mw-editform-cancel' ),
1333 array( 'known', 'noclasses' )
1335 $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1336 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1337 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1338 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1339 htmlspecialchars( wfMsg( 'newwindow' ) );
1341 global $wgRightsText;
1342 if ( $wgRightsText ) {
1343 $copywarnMsg = array( 'copyrightwarning',
1344 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1347 $copywarnMsg = array( 'copyrightwarning2',
1348 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1350 // Allow for site and per-namespace customization of contribution/copyright notice.
1351 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1353 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1354 # prepare toolbar for edit buttons
1355 $toolbar = EditPage
::getEditToolbar();
1361 // activate checkboxes if user wants them to be always active
1362 if ( !$this->preview
&& !$this->diff
) {
1363 # Sort out the "watch" checkbox
1364 if ( $wgUser->getOption( 'watchdefault' ) ) {
1366 $this->watchthis
= true;
1367 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1369 $this->watchthis
= true;
1370 } elseif ( $this->mTitle
->userIsWatching() ) {
1372 $this->watchthis
= true;
1375 # May be overriden by request parameters
1376 if( $wgRequest->getBool( 'watchthis' ) ) {
1377 $this->watchthis
= true;
1380 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
1383 $wgOut->addHTML( $this->editFormPageTop
);
1385 if ( $wgUser->getOption( 'previewontop' ) ) {
1386 $this->displayPreviewArea( $previewOutput, true );
1390 $wgOut->addHTML( $this->editFormTextTop
);
1392 # if this is a comment, show a subject line at the top, which is also the edit summary.
1393 # Otherwise, show a summary field at the bottom
1394 $summarytext = $wgContLang->recodeForEdit( $this->summary
);
1396 # If a blank edit summary was previously provided, and the appropriate
1397 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1398 # user being bounced back more than once in the event that a summary
1401 # For a bit more sophisticated detection of blank summaries, hash the
1402 # automatic one and pass that in the hidden field wpAutoSummary.
1403 $summaryhiddens = '';
1404 if ( $this->missingSummary
) $summaryhiddens .= Xml
::hidden( 'wpIgnoreBlankSummary', true );
1405 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1406 $summaryhiddens .= Xml
::hidden( 'wpAutoSummary', $autosumm );
1407 if ( $this->section
== 'new' ) {
1408 $commentsubject = '';
1409 if ( !$wgRequest->getBool( 'nosummary' ) ) {
1410 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1411 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1414 Xml
::tags( 'label', array( 'for' => 'wpSummary' ), $subject );
1416 Xml
::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
1418 $commentsubject .= ' ';
1419 $commentsubject .= Html
::input( 'wpSummary',
1423 'id' => 'wpSummary',
1424 'maxlength' => '200',
1427 'spellcheck' => 'true'
1430 $summaryhiddens .= Xml
::hidden( 'wpIgnoreBlankSummary', true ); # bug 18699
1432 $editsummary = "<div class='editOptions'>\n";
1434 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary
) );
1435 $subjectpreview = $summarytext && ( $this->preview ||
$this->diff
) ?
1436 "<div class=\"mw-summary-preview\">". wfMsgExt( 'subject-preview', 'parseinline' ) . $sk->commentBlock( $formattedSummary, $this->mTitle
, true )."</div>\n" : '';
1437 $summarypreview = '';
1439 $commentsubject = '';
1441 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1442 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1444 $editsummary = Xml
::tags( 'label', array( 'for' => 'wpSummary' ), $summary );
1445 $editsummary = Xml
::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
1446 $editsummary ) . ' ';
1448 $editsummary .= Html
::input( 'wpSummary',
1452 'id' => 'wpSummary',
1453 'maxlength' => '200',
1456 'spellcheck' => 'true'
1459 // No idea where this is closed.
1460 $editsummary .= '<br/>';
1461 $editsummary = Xml
::openElement( 'div', array( 'class' => 'editOptions' ) )
1462 . ($this->mShowSummaryField ?
$editsummary : '');
1464 $summarypreview = '';
1465 if ( $summarytext && ( $this->preview ||
$this->diff
) ) {
1468 array( 'class' => 'mw-summary-preview' ),
1469 wfMsgExt( 'summary-preview', 'parseinline' ) .
1470 $sk->commentBlock( $this->summary
, $this->mTitle
)
1473 $subjectpreview = '';
1475 $commentsubject .= $summaryhiddens;
1477 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1478 if ( !$this->preview
&& !$this->diff
) {
1479 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1481 $templates = $this->getTemplates();
1482 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview
, $this->section
!= '');
1484 $hiddencats = $this->mArticle
->getHiddenCategories();
1485 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1487 global $wgUseMetadataEdit ;
1488 if ( $wgUseMetadataEdit ) {
1489 $metadata = $this->mMetaData
;
1490 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1491 $top = wfMsgWikiHtml( 'metadata_help' );
1492 /* ToDo: Replace with clean code */
1493 $ew = $wgUser->getOption( 'editwidth' );
1494 if ( $ew ) $ew = " style=\"width:100%\"";
1496 $cols = $wgUser->getIntOption( 'cols' );
1498 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1500 else $metadata = "" ;
1503 if ( $this->wasDeletedSinceLastEdit() ) {
1504 if ( 'save' != $this->formtype
) {
1505 $wgOut->wrapWikiMsg(
1506 "<div class='error mw-deleted-while-editing'>\n$1</div>",
1507 'deletedwhileediting' );
1509 // Hide the toolbar and edit area, user can click preview to get it back
1510 // Add an confirmation checkbox and explanation.
1512 $recreate = '<div class="mw-confirm-recreate">' .
1513 $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
) ) .
1514 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1515 array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1522 $checkboxes = $this->getCheckboxes( $tabindex, $sk,
1523 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1525 $checkboxhtml = implode( $checkboxes, "\n" );
1527 $buttons = $this->getEditButtons( $tabindex );
1528 $buttonshtml = implode( $buttons, "\n" );
1530 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1531 ?
'' : Xml
::hidden( 'safemode', '1' );
1533 $wgOut->addHTML( <<<END
1535 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1539 if ( is_callable( $formCallback ) ) {
1540 call_user_func_array( $formCallback, array( &$wgOut ) );
1543 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1545 // Put these up at the top to ensure they aren't lost on early form submission
1546 $this->showFormBeforeText();
1548 $wgOut->addHTML( <<<END
1552 {$this->editFormTextBeforeContent}
1555 $this->showTextbox1( $classes );
1557 $wgOut->addHTML( $this->editFormTextAfterContent
);
1559 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1560 $wgOut->addHTML( <<<END
1561 {$this->editFormTextAfterWarn}
1571 "<div class='editButtons'>
1573 <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>
1574 </div><!-- editButtons -->
1575 </div><!-- editOptions -->");
1578 * To make it harder for someone to slip a user a page
1579 * which submits an edit form to the wiki without their
1580 * knowledge, a random token is associated with the login
1581 * session. If it's not passed back with the submission,
1582 * we won't save the page, or render user JavaScript and
1585 * For anon editors, who may not have a session, we just
1586 * include the constant suffix to prevent editing from
1587 * broken text-mangling proxies.
1589 $token = htmlspecialchars( $wgUser->editToken() );
1590 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1592 $this->showTosSummary();
1593 $this->showEditTools();
1595 $wgOut->addHTML( <<<END
1596 {$this->editFormTextAfterTools}
1597 <div class='templatesUsed'>
1598 {$formattedtemplates}
1600 <div class='hiddencats'>
1601 {$formattedhiddencats}
1606 if ( $this->isConflict
&& wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1607 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
1609 $de = new DifferenceEngine( $this->mTitle
);
1610 $de->setText( $this->textbox2
, $this->textbox1
);
1611 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1613 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
1614 $this->showTextbox2();
1616 $wgOut->addHTML( $this->editFormTextBottom
);
1617 $wgOut->addHTML( "</form>\n" );
1618 if ( !$wgUser->getOption( 'previewontop' ) ) {
1619 $this->displayPreviewArea( $previewOutput, false );
1622 wfProfileOut( __METHOD__
);
1625 protected function showFormBeforeText() {
1628 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
1629 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1630 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1631 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1634 protected function showTextbox1( $classes ) {
1635 $attribs = array( 'tabindex' => 1 );
1637 if ( $this->wasDeletedSinceLastEdit() )
1638 $attribs['type'] = 'hidden';
1639 if ( !empty( $classes ) )
1640 $attribs['class'] = implode( ' ', $classes );
1642 $this->showTextbox( $this->textbox1
, 'wpTextbox1', $attribs );
1645 protected function showTextbox2() {
1646 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6 ) );
1649 protected function showTextbox( $content, $name, $attribs = array() ) {
1650 global $wgOut, $wgUser;
1652 $wikitext = $this->safeUnicodeOutput( $content );
1653 if ( $wikitext !== '' ) {
1654 // Ensure there's a newline at the end, otherwise adding lines
1656 // But don't add a newline if the ext is empty, or Firefox in XHTML
1657 // mode will show an extra newline. A bit annoying.
1661 $attribs['accesskey'] = ',';
1662 $attribs['id'] = $name;
1664 if ( $wgUser->getOption( 'editwidth' ) )
1665 $attribs['style'] = 'width: 100%';
1667 $wgOut->addHTML( Xml
::textarea(
1670 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1674 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1678 $classes[] = 'ontop';
1680 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1682 if ( $this->formtype
!= 'preview' )
1683 $attribs['style'] = 'display: none;';
1685 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1687 if ( $this->formtype
== 'preview' ) {
1688 $this->showPreview( $previewOutput );
1691 $wgOut->addHTML( '</div>' );
1693 if ( $this->formtype
== 'diff') {
1699 * Append preview output to $wgOut.
1700 * Includes category rendering if this is a category page.
1702 * @param string $text The HTML to be output for the preview.
1704 protected function showPreview( $text ) {
1706 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1707 $this->mArticle
->openShowCategory();
1709 # This hook seems slightly odd here, but makes things more
1710 # consistent for extensions.
1711 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1712 $wgOut->addHTML( $text );
1713 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1714 $this->mArticle
->closeShowCategory();
1718 protected function showTosSummary() {
1719 $msg = 'editpage-tos-summary';
1720 // Give a chance for site and per-namespace customizations of
1721 // terms of service summary link that might exist separately
1722 // from the copyright notice.
1724 // This will display between the save button and the edit tools,
1725 // so should remain short!
1726 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1727 $text = wfMsg( $msg );
1728 if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
1730 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1731 $wgOut->addWikiMsgArray( $msg, array() );
1732 $wgOut->addHTML( '</div>' );
1736 protected function showEditTools() {
1738 $wgOut->addHTML( '<div class="mw-editTools">' );
1739 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1740 $wgOut->addHTML( '</div>' );
1743 protected function getLastDelete() {
1744 $dbr = wfGetDB( DB_SLAVE
);
1745 $data = $dbr->selectRow(
1746 array( 'logging', 'user' ),
1757 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1758 'log_title' => $this->mTitle
->getDBkey(),
1759 'log_type' => 'delete',
1760 'log_action' => 'delete',
1761 'user_id=log_user' ),
1763 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
1765 // Quick paranoid permission checks...
1766 if( is_object( $data ) ) {
1767 if( $data->log_deleted
& LogPage
::DELETED_USER
)
1768 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
1769 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
1770 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
1776 * Get the rendered text for previewing.
1779 function getPreviewText() {
1780 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
1782 wfProfileIn( __METHOD__
);
1784 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1785 if ( $this->mTokenOkExceptSuffix
) {
1786 $note = wfMsg( 'token_suffix_mismatch' );
1788 $note = wfMsg( 'session_fail_preview' );
1791 $note = wfMsg( 'previewnote' );
1794 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1795 $parserOptions->setEditSection( false );
1796 $parserOptions->setIsPreview( true );
1797 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
1800 if ( $wgRawHtml && !$this->mTokenOk
) {
1801 // Could be an offsite preview attempt. This is very unsafe if
1802 // HTML is enabled, as it could be an attack.
1803 return $wgOut->parse( "<div class='previewnote'>" .
1804 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1807 # don't parse user css/js, show message about preview
1808 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1810 if ( $this->isCssJsSubpage
) {
1811 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
1812 $previewtext = wfMsg( 'usercsspreview' );
1813 } else if (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
1814 $previewtext = wfMsg( 'userjspreview' );
1816 $parserOptions->setTidy( true );
1817 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
1818 $previewHTML = $parserOutput->mText
;
1819 } elseif ( $rt = Title
::newFromRedirectArray( $this->textbox1
) ) {
1820 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
1822 $toparse = $this->textbox1
;
1824 # If we're adding a comment, we need to show the
1825 # summary as the headline
1826 if ( $this->section
== "new" && $this->summary
!= "" ) {
1827 $toparse="== {$this->summary} ==\n\n" . $toparse;
1830 if ( $this->mMetaData
!= "" ) $toparse .= "\n" . $this->mMetaData
;
1832 // Parse mediawiki messages with correct target language
1833 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1834 list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle
->getText() );
1835 $obj = wfGetLangObj( $lang );
1836 $parserOptions->setTargetLanguage( $obj );
1840 $parserOptions->setTidy( true );
1841 $parserOptions->enableLimitReport();
1842 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
1843 $this->mTitle
, $parserOptions );
1845 $previewHTML = $parserOutput->getText();
1846 $this->mParserOutput
= $parserOutput;
1847 $wgOut->addParserOutputNoText( $parserOutput );
1849 if ( count( $parserOutput->getWarnings() ) ) {
1850 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1854 if( $this->isConflict
) {
1855 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1857 $conflict = '<hr />';
1860 $previewhead = "<div class='previewnote'>\n" .
1861 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
1862 $wgOut->parse( $note ) . $conflict . "</div>\n";
1864 wfProfileOut( __METHOD__
);
1865 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
1868 function getTemplates() {
1869 if ( $this->preview ||
$this->section
!= '' ) {
1870 $templates = array();
1871 if ( !isset( $this->mParserOutput
) ) return $templates;
1872 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
1873 foreach( array_keys( $template ) as $dbk ) {
1874 $templates[] = Title
::makeTitle($ns, $dbk);
1879 return $this->mArticle
->getUsedTemplates();
1884 * Call the stock "user is blocked" page
1886 function blockedPage() {
1887 global $wgOut, $wgUser;
1888 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1890 # If the user made changes, preserve them when showing the markup
1891 # (This happens when a user is blocked during edit, for instance)
1892 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1894 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1896 $source = $this->textbox1
;
1899 # Spit out the source or the user's modified version
1900 if ( $source !== false ) {
1901 $rows = $wgUser->getIntOption( 'rows' );
1902 $cols = $wgUser->getIntOption( 'cols' );
1903 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1904 $wgOut->addHTML( '<hr />' );
1905 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
1906 # Why we don't use Xml::element here?
1907 # Is it because if $source is '', it returns <textarea />?
1908 $wgOut->addHTML( Xml
::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml
::closeElement( 'textarea' ) );
1913 * Produce the stock "please login to edit pages" page
1915 function userNotLoggedInPage() {
1916 global $wgUser, $wgOut, $wgTitle;
1917 $skin = $wgUser->getSkin();
1919 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1920 $loginLink = $skin->link(
1922 wfMsgHtml( 'loginreqlink' ),
1924 array( 'returnto' => $wgTitle->getPrefixedText() ),
1925 array( 'known', 'noclasses' )
1928 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1929 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1930 $wgOut->setArticleRelated( false );
1932 $wgOut->addHTML( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1933 $wgOut->returnToMain( false, $wgTitle );
1937 * Creates a basic error page which informs the user that
1938 * they have attempted to edit a nonexistent section.
1940 function noSuchSectionPage() {
1941 global $wgOut, $wgTitle;
1943 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1944 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1945 $wgOut->setArticleRelated( false );
1947 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section
);
1948 $wgOut->returnToMain( false, $wgTitle );
1952 * Produce the stock "your edit contains spam" page
1954 * @param $match Text which triggered one or more filters
1956 function spamPage( $match = false ) {
1957 global $wgOut, $wgTitle;
1959 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1960 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1961 $wgOut->setArticleRelated( false );
1963 $wgOut->addHTML( '<div id="spamprotected">' );
1964 $wgOut->addWikiMsg( 'spamprotectiontext' );
1966 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1967 $wgOut->addHTML( '</div>' );
1969 $wgOut->returnToMain( false, $wgTitle );
1976 function mergeChangesInto( &$editText ){
1977 wfProfileIn( __METHOD__
);
1979 $db = wfGetDB( DB_MASTER
);
1981 // This is the revision the editor started from
1982 $baseRevision = $this->getBaseRevision();
1983 if ( is_null( $baseRevision ) ) {
1984 wfProfileOut( __METHOD__
);
1987 $baseText = $baseRevision->getText();
1989 // The current state, we want to merge updates into it
1990 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
1991 if ( is_null( $currentRevision ) ) {
1992 wfProfileOut( __METHOD__
);
1995 $currentText = $currentRevision->getText();
1998 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
1999 $editText = $result;
2000 wfProfileOut( __METHOD__
);
2003 wfProfileOut( __METHOD__
);
2009 * Check if the browser is on a blacklist of user-agents known to
2010 * mangle UTF-8 data on form submission. Returns true if Unicode
2011 * should make it through, false if it's known to be a problem.
2015 function checkUnicodeCompliantBrowser() {
2016 global $wgBrowserBlackList;
2017 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2018 // No User-Agent header sent? Trust it by default...
2021 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2022 foreach ( $wgBrowserBlackList as $browser ) {
2023 if ( preg_match($browser, $currentbrowser) ) {
2031 * @deprecated use $wgParser->stripSectionName()
2033 function pseudoParseSectionAnchor( $text ) {
2035 return $wgParser->stripSectionName( $text );
2039 * Format an anchor fragment as it would appear for a given section name
2040 * @param string $text
2044 function sectionAnchor( $text ) {
2046 return $wgParser->guessSectionNameFromWikiText( $text );
2050 * Shows a bulletin board style toolbar for common editing functions.
2051 * It can be disabled in the user preferences.
2052 * The necessary JavaScript code can be found in skins/common/edit.js.
2056 static function getEditToolbar() {
2057 global $wgStylePath, $wgContLang, $wgLang;
2060 * toolarray an array of arrays which each include the filename of
2061 * the button image (without path), the opening tag, the closing tag,
2062 * and optionally a sample text that is inserted between the two when no
2063 * selection is highlighted.
2064 * The tip text is shown when the user moves the mouse over the button.
2066 * Already here are accesskeys (key), which are not used yet until someone
2067 * can figure out a way to make them work in IE. However, we should make
2068 * sure these keys are not defined on the edit page.
2072 'image' => $wgLang->getImageFile( 'button-bold' ),
2073 'id' => 'mw-editbutton-bold',
2075 'close' => '\'\'\'',
2076 'sample' => wfMsg( 'bold_sample' ),
2077 'tip' => wfMsg( 'bold_tip' ),
2081 'image' => $wgLang->getImageFile( 'button-italic' ),
2082 'id' => 'mw-editbutton-italic',
2085 'sample' => wfMsg( 'italic_sample' ),
2086 'tip' => wfMsg( 'italic_tip' ),
2090 'image' => $wgLang->getImageFile( 'button-link' ),
2091 'id' => 'mw-editbutton-link',
2094 'sample' => wfMsg( 'link_sample' ),
2095 'tip' => wfMsg( 'link_tip' ),
2099 'image' => $wgLang->getImageFile( 'button-extlink' ),
2100 'id' => 'mw-editbutton-extlink',
2103 'sample' => wfMsg( 'extlink_sample' ),
2104 'tip' => wfMsg( 'extlink_tip' ),
2108 'image' => $wgLang->getImageFile( 'button-headline' ),
2109 'id' => 'mw-editbutton-headline',
2112 'sample' => wfMsg( 'headline_sample' ),
2113 'tip' => wfMsg( 'headline_tip' ),
2117 'image' => $wgLang->getImageFile( 'button-image' ),
2118 'id' => 'mw-editbutton-image',
2119 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2121 'sample' => wfMsg( 'image_sample' ),
2122 'tip' => wfMsg( 'image_tip' ),
2126 'image' => $wgLang->getImageFile( 'button-media' ),
2127 'id' => 'mw-editbutton-media',
2128 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2130 'sample' => wfMsg( 'media_sample' ),
2131 'tip' => wfMsg( 'media_tip' ),
2135 'image' => $wgLang->getImageFile( 'button-math' ),
2136 'id' => 'mw-editbutton-math',
2138 'close' => "</math>",
2139 'sample' => wfMsg( 'math_sample' ),
2140 'tip' => wfMsg( 'math_tip' ),
2144 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2145 'id' => 'mw-editbutton-nowiki',
2146 'open' => "<nowiki>",
2147 'close' => "</nowiki>",
2148 'sample' => wfMsg( 'nowiki_sample' ),
2149 'tip' => wfMsg( 'nowiki_tip' ),
2153 'image' => $wgLang->getImageFile( 'button-sig' ),
2154 'id' => 'mw-editbutton-signature',
2158 'tip' => wfMsg( 'sig_tip' ),
2162 'image' => $wgLang->getImageFile( 'button-hr' ),
2163 'id' => 'mw-editbutton-hr',
2164 'open' => "\n----\n",
2167 'tip' => wfMsg( 'hr_tip' ),
2171 $toolbar = "<div id='toolbar'>\n";
2174 foreach ( $toolarray as $tool ) {
2176 $image = $wgStylePath . '/common/images/' . $tool['image'],
2177 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2178 // Older browsers show a "speedtip" type message only for ALT.
2179 // Ideally these should be different, realistically they
2180 // probably don't need to be.
2181 $tip = $tool['tip'],
2182 $open = $tool['open'],
2183 $close = $tool['close'],
2184 $sample = $tool['sample'],
2185 $cssId = $tool['id'],
2188 $paramList = implode( ',',
2189 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2190 $script .= "addButton($paramList);\n";
2192 $toolbar .= Html
::inlineScript( "\n$script\n" );
2194 $toolbar .= "\n</div>";
2196 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2202 * Returns an array of html code of the following checkboxes:
2205 * @param $tabindex Current tabindex
2206 * @param $skin Skin object
2207 * @param $checked Array of checkbox => bool, where bool indicates the checked
2208 * status of the checkbox
2212 public function getCheckboxes( &$tabindex, $skin, $checked ) {
2215 $checkboxes = array();
2217 $checkboxes['minor'] = '';
2218 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2219 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2221 'tabindex' => ++
$tabindex,
2222 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2223 'id' => 'wpMinoredit',
2225 $checkboxes['minor'] =
2226 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2227 " <label for='wpMinoredit'" . $skin->tooltip( 'minoredit', 'withaccess' ) . ">{$minorLabel}</label>";
2230 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2231 $checkboxes['watch'] = '';
2232 if ( $wgUser->isLoggedIn() ) {
2234 'tabindex' => ++
$tabindex,
2235 'accesskey' => wfMsg( 'accesskey-watch' ),
2236 'id' => 'wpWatchthis',
2238 $checkboxes['watch'] =
2239 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2240 " <label for='wpWatchthis'" . $skin->tooltip( 'watch', 'withaccess' ) . ">{$watchLabel}</label>";
2242 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2247 * Returns an array of html code of the following buttons:
2248 * save, diff, preview and live
2250 * @param $tabindex Current tabindex
2254 public function getEditButtons(&$tabindex) {
2261 'tabindex' => ++
$tabindex,
2262 'value' => wfMsg( 'savearticle' ),
2263 'accesskey' => wfMsg( 'accesskey-save' ),
2264 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2266 $buttons['save'] = Xml
::element('input', $temp, '');
2268 ++
$tabindex; // use the same for preview and live preview
2270 'id' => 'wpPreview',
2271 'name' => 'wpPreview',
2273 'tabindex' => $tabindex,
2274 'value' => wfMsg( 'showpreview' ),
2275 'accesskey' => wfMsg( 'accesskey-preview' ),
2276 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2278 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2279 $buttons['live'] = '';
2285 'tabindex' => ++
$tabindex,
2286 'value' => wfMsg( 'showdiff' ),
2287 'accesskey' => wfMsg( 'accesskey-diff' ),
2288 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2290 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2292 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2297 * Output preview text only. This can be sucked into the edit page
2298 * via JavaScript, and saves the server time rendering the skin as
2299 * well as theoretically being more robust on the client (doesn't
2300 * disturb the edit box's undo history, won't eat your text on
2303 * @todo This doesn't include category or interlanguage links.
2304 * Would need to enhance it a bit, <s>maybe wrap them in XML
2305 * or something...</s> that might also require more skin
2306 * initialization, so check whether that's a problem.
2308 function livePreview() {
2311 header( 'Content-type: text/xml; charset=utf-8' );
2312 header( 'Cache-control: no-cache' );
2314 $previewText = $this->getPreviewText();
2315 #$categories = $skin->getCategoryLinks();
2318 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2319 Xml
::tags( 'livepreview', null,
2320 Xml
::element( 'preview', null, $previewText )
2321 #. Xml::element( 'category', null, $categories )
2328 * Get a diff between the current contents of the edit box and the
2329 * version of the page we're editing from.
2331 * If this is a section edit, we'll replace the section as for final
2332 * save and then make a comparison.
2334 function showDiff() {
2335 $oldtext = $this->mArticle
->fetchContent();
2336 $newtext = $this->mArticle
->replaceSection(
2337 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2338 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2339 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2340 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2341 if ( $oldtext !== false ||
$newtext != '' ) {
2342 $de = new DifferenceEngine( $this->mTitle
);
2343 $de->setText( $oldtext, $newtext );
2344 $difftext = $de->getDiff( $oldtitle, $newtitle );
2345 $de->showDiffStyle();
2351 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2355 * Filter an input field through a Unicode de-armoring process if it
2356 * came from an old browser with known broken Unicode editing issues.
2358 * @param WebRequest $request
2359 * @param string $field
2363 function safeUnicodeInput( $request, $field ) {
2364 $text = rtrim( $request->getText( $field ) );
2365 return $request->getBool( 'safemode' )
2366 ?
$this->unmakesafe( $text )
2371 * Filter an output field through a Unicode armoring process if it is
2372 * going to an old browser with known broken Unicode editing issues.
2374 * @param string $text
2378 function safeUnicodeOutput( $text ) {
2380 $codedText = $wgContLang->recodeForEdit( $text );
2381 return $this->checkUnicodeCompliantBrowser()
2383 : $this->makesafe( $codedText );
2387 * A number of web browsers are known to corrupt non-ASCII characters
2388 * in a UTF-8 text editing environment. To protect against this,
2389 * detected browsers will be served an armored version of the text,
2390 * with non-ASCII chars converted to numeric HTML character references.
2392 * Preexisting such character references will have a 0 added to them
2393 * to ensure that round-trips do not alter the original data.
2395 * @param string $invalue
2399 function makesafe( $invalue ) {
2400 // Armor existing references for reversability.
2401 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2406 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2407 $bytevalue = ord( $invalue{$i} );
2408 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2409 $result .= chr( $bytevalue );
2411 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2412 $working = $working << 6;
2413 $working +
= ($bytevalue & 0x3F);
2415 if ( $bytesleft <= 0 ) {
2416 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2418 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2419 $working = $bytevalue & 0x1F;
2421 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2422 $working = $bytevalue & 0x0F;
2424 } else { //1111 0xxx
2425 $working = $bytevalue & 0x07;
2433 * Reverse the previously applied transliteration of non-ASCII characters
2434 * back to UTF-8. Used to protect data from corruption by broken web browsers
2435 * as listed in $wgBrowserBlackList.
2437 * @param string $invalue
2441 function unmakesafe( $invalue ) {
2443 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2444 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
2448 $hexstring .= $invalue{$i};
2450 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2452 // Do some sanity checks. These aren't needed for reversability,
2453 // but should help keep the breakage down if the editor
2454 // breaks one of the entities whilst editing.
2455 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2456 $codepoint = hexdec($hexstring);
2457 $result .= codepointToUtf8( $codepoint );
2459 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2462 $result .= substr( $invalue, $i, 1 );
2465 // reverse the transform that we made for reversability reasons.
2466 return strtr( $result, array( "�" => "&#x" ) );
2469 function noCreatePermission() {
2471 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2472 $wgOut->addWikiMsg( 'nocreatetext' );
2476 * Attempt submission
2477 * @return bool false if output is done, true if the rest of the form should be displayed
2479 function attemptSave() {
2480 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2482 $resultDetails = false;
2483 # Allow bots to exempt some edits from bot flagging
2484 $bot = $wgUser->isAllowed( 'bot' ) && $wgRequest->getBool( 'bot', true );
2485 $value = $this->internalAttemptSave( $resultDetails, $bot );
2487 if ( $value == self
::AS_SUCCESS_UPDATE ||
$value == self
::AS_SUCCESS_NEW_ARTICLE
) {
2488 $this->didSave
= true;
2492 case self
::AS_HOOK_ERROR_EXPECTED
:
2493 case self
::AS_CONTENT_TOO_BIG
:
2494 case self
::AS_ARTICLE_WAS_DELETED
:
2495 case self
::AS_CONFLICT_DETECTED
:
2496 case self
::AS_SUMMARY_NEEDED
:
2497 case self
::AS_TEXTBOX_EMPTY
:
2498 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2502 case self
::AS_HOOK_ERROR
:
2503 case self
::AS_FILTERING
:
2504 case self
::AS_SUCCESS_NEW_ARTICLE
:
2505 case self
::AS_SUCCESS_UPDATE
:
2508 case self
::AS_SPAM_ERROR
:
2509 $this->spamPage( $resultDetails['spam'] );
2512 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2513 $this->blockedPage();
2516 case self
::AS_IMAGE_REDIRECT_ANON
:
2517 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2520 case self
::AS_READ_ONLY_PAGE_ANON
:
2521 $this->userNotLoggedInPage();
2524 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2525 case self
::AS_READ_ONLY_PAGE
:
2526 $wgOut->readOnlyPage();
2529 case self
::AS_RATE_LIMITED
:
2530 $wgOut->rateLimited();
2533 case self
::AS_NO_CREATE_PERMISSION
:
2534 $this->noCreatePermission();
2537 case self
::AS_BLANK_ARTICLE
:
2538 $wgOut->redirect( $wgTitle->getFullURL() );
2541 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2542 $wgOut->permissionRequired( 'upload' );
2547 function getBaseRevision() {
2548 if ( $this->mBaseRevision
== false ) {
2549 $db = wfGetDB( DB_MASTER
);
2550 $baseRevision = Revision
::loadFromTimestamp(
2551 $db, $this->mTitle
, $this->edittime
);
2552 return $this->mBaseRevision
= $baseRevision;
2554 return $this->mBaseRevision
;