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 $isCssSubpage = false;
51 var $isJsSubpage = false;
52 var $deletedSinceEdit = false;
56 var $mTokenOk = false;
57 var $mTokenOkExceptSuffix = false;
58 var $mTriedSave = false;
60 var $kblength = false;
61 var $missingComment = false;
62 var $missingSummary = false;
63 var $allowBlankSummary = false;
66 #var $mPreviewTemplates;
68 var $mBaseRevision = false;
69 var $mShowSummaryField = true;
72 var $save = false, $preview = false, $diff = false;
73 var $minoredit = false, $watchthis = false, $recreate = false;
74 var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false;
75 var $edittime = '', $section = '', $starttime = '';
76 var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true;
78 # Placeholders for text injection by hooks (must be HTML)
79 # extensions should take care to _append_ to the present value
80 public $editFormPageTop; // Before even the preview
81 public $editFormTextTop;
82 public $editFormTextBeforeContent;
83 public $editFormTextAfterWarn;
84 public $editFormTextAfterTools;
85 public $editFormTextBottom;
86 public $editFormTextAfterContent;
87 public $previewTextAfterContent;
89 /* $didSave should be set to true whenever an article was succesfully altered. */
90 public $didSave = false;
93 public $suppressIntro = false;
99 function EditPage( $article ) {
100 $this->mArticle
=& $article;
101 $this->mTitle
= $article->getTitle();
102 $this->action
= 'submit';
104 # Placeholders for text injection by hooks (empty per default)
105 $this->editFormPageTop
=
106 $this->editFormTextTop
=
107 $this->editFormTextBeforeContent
=
108 $this->editFormTextAfterWarn
=
109 $this->editFormTextAfterTools
=
110 $this->editFormTextBottom
=
111 $this->editFormTextAfterContent
=
112 $this->previewTextAfterContent
=
113 $this->mPreloadText
= "";
116 function getArticle() {
117 return $this->mArticle
;
122 * Fetch initial editing page content.
123 * @returns mixed string on success, $def_text for invalid sections
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' );
133 $preload = $wgRequest->getVal( 'preload',
134 // Custom preload text for new sections
135 $section === 'new' ?
'MediaWiki:addsection-preload' : '' );
136 $undoafter = $wgRequest->getVal( 'undoafter' );
137 $undo = $wgRequest->getVal( 'undo' );
140 // For message page not locally set, use the i18n message.
141 // For other non-existent articles, use preload text if any.
142 if ( !$this->mTitle
->exists() ) {
143 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
144 # If this is a system message, get the default text.
145 list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle
->getText() ) );
146 $wgMessageCache->loadAllMessages( $lang );
147 $text = wfMsgGetKey( $message, false, $lang, false );
148 if( wfEmptyMsg( $message, $text ) )
149 $text = $this->getPreloadedText( $preload );
151 # If requested, preload some text.
152 $text = $this->getPreloadedText( $preload );
154 // For existing pages, get text based on "undo" or section parameters.
156 $text = $this->mArticle
->getContent();
157 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
158 # If they got undoafter and undo round the wrong way, switch them
159 list( $undo, $undoafter ) = array( $undoafter, $undo );
161 if ( $undo > 0 && $undo > $undoafter ) {
162 # Undoing a specific edit overrides section editing; section-editing
163 # doesn't work with undoing.
165 $undorev = Revision
::newFromId( $undo );
166 $oldrev = Revision
::newFromId( $undoafter );
168 $undorev = Revision
::newFromId( $undo );
169 $oldrev = $undorev ?
$undorev->getPrevious() : null;
172 # Sanity check, make sure it's the right page,
173 # the revisions exist and they were not deleted.
174 # Otherwise, $text will be left as-is.
175 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
176 $undorev->getPage() == $oldrev->getPage() &&
177 $undorev->getPage() == $this->mArticle
->getID() &&
178 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
179 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
181 $undotext = $this->mArticle
->getUndoText( $undorev, $oldrev );
182 if ( $undotext === false ) {
183 # Warn the user that something went wrong
184 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
187 # Inform the user of our success and set an automatic edit summary
188 $this->editFormPageTop
.= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
189 $firstrev = $oldrev->getNext();
190 # If we just undid one rev, use an autosummary
191 if ( $firstrev->mId
== $undo ) {
192 $this->summary
= wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
193 $this->undidRev
= $undo;
195 $this->formtype
= 'diff';
198 // Failed basic sanity checks.
199 // Older revisions may have been removed since the link
200 // was created, or we may simply have got bogus input.
201 $this->editFormPageTop
.= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
203 } else if ( $section != '' ) {
204 if ( $section == 'new' ) {
205 $text = $this->getPreloadedText( $preload );
207 // Get section edit text (returns $def_text for invalid sections)
208 $text = $wgParser->getSection( $text, $section, $def_text );
213 wfProfileOut( __METHOD__
);
217 /** Use this method before edit() to preload some text into the edit box */
218 public function setPreloadedText( $text ) {
219 $this->mPreloadText
= $text;
223 * Get the contents to be preloaded into the box, either set by
224 * an earlier setPreloadText() or by loading the given page.
226 * @param $preload String: representing the title to preload from.
229 protected function getPreloadedText( $preload ) {
230 global $wgUser, $wgParser;
231 if ( !empty( $this->mPreloadText
) ) {
232 return $this->mPreloadText
;
233 } elseif ( $preload !== '' ) {
234 $title = Title
::newFromText( $preload );
235 # Check for existence to avoid getting MediaWiki:Noarticletext
236 if ( isset( $title ) && $title->exists() && $title->userCanRead() ) {
237 $article = new Article( $title );
239 if ( $article->isRedirect() ) {
240 $title = Title
::newFromRedirectRecurse( $article->getContent() );
241 # Redirects to missing titles are displayed, to hidden pages are followed
242 # Copying observed behaviour from ?action=view
243 if ( $title->exists() ) {
244 if ($title->userCanRead() ) {
245 $article = new Article( $title );
251 $parserOptions = ParserOptions
::newFromUser( $wgUser );
252 return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions );
259 * Check if a page was deleted while the user was editing it, before submit.
260 * Note that we rely on the logging table, which hasn't been always there,
261 * but that doesn't matter, because this only applies to brand new
264 protected function wasDeletedSinceLastEdit() {
265 if ( $this->deletedSinceEdit
)
267 if ( $this->mTitle
->isDeletedQuick() ) {
268 $this->lastDelete
= $this->getLastDelete();
269 if ( $this->lastDelete
) {
270 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
271 if ( $deleteTime > $this->starttime
) {
272 $this->deletedSinceEdit
= true;
276 return $this->deletedSinceEdit
;
284 * This is the function that gets called for "action=edit". It
285 * sets up various member variables, then passes execution to
286 * another function, usually showEditForm()
288 * The edit form is self-submitting, so that when things like
289 * preview and edit conflicts occur, we get the same form back
290 * with the extra stuff added. Only when the final submission
291 * is made and all is well do we actually save and redirect to
292 * the newly-edited page.
295 global $wgOut, $wgRequest, $wgUser;
296 // Allow extensions to modify/prevent this form or submission
297 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
301 wfProfileIn( __METHOD__
);
302 wfDebug( __METHOD__
.": enter\n" );
304 // This is not an article
305 $wgOut->setArticleFlag( false );
307 $this->importFormData( $wgRequest );
308 $this->firsttime
= false;
311 $this->livePreview();
312 wfProfileOut( __METHOD__
);
316 if ( wfReadOnly() && $this->save
) {
319 $this->preview
= true;
322 $wgOut->addScriptFile( 'edit.js' );
324 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
325 $wgOut->includeJQuery();
326 $wgOut->addScriptFile( 'preview.js' );
328 // Bug #19334: textarea jumps when editing articles in IE8
329 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
331 $permErrors = $this->getEditPermissionErrors();
333 wfDebug( __METHOD__
. ": User can't edit\n" );
334 $this->readOnlyPage( $this->getContent( false ), true, $permErrors, 'edit' );
335 wfProfileOut( __METHOD__
);
339 $this->formtype
= 'save';
340 } else if ( $this->preview
) {
341 $this->formtype
= 'preview';
342 } else if ( $this->diff
) {
343 $this->formtype
= 'diff';
344 } else { # First time through
345 $this->firsttime
= true;
346 if ( $this->previewOnOpen() ) {
347 $this->formtype
= 'preview';
349 $this->formtype
= 'initial';
354 // If they used redlink=1 and the page exists, redirect to the main article
355 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
356 $wgOut->redirect( $this->mTitle
->getFullURL() );
359 wfProfileIn( __METHOD__
."-business-end" );
361 $this->isConflict
= false;
362 // css / js subpages of user pages get a special treatment
363 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
364 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
365 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
366 $this->isValidCssJsSubpage
= $this->mTitle
->isValidCssJsSubpage();
368 # Show applicable editing introductions
369 if ( $this->formtype
== 'initial' ||
$this->firsttime
)
372 if ( $this->mTitle
->isTalkPage() ) {
373 $wgOut->addWikiMsg( 'talkpagetext' );
376 # Optional notices on a per-namespace and per-page basis
377 $editnotice_ns = 'editnotice-'.$this->mTitle
->getNamespace();
378 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
379 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
381 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
382 $parts = explode( '/', $this->mTitle
->getDBkey() );
383 $editnotice_base = $editnotice_ns;
384 while ( count( $parts ) > 0 ) {
385 $editnotice_base .= '-'.array_shift( $parts );
386 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
387 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
392 # Attempt submission here. This will check for edit conflicts,
393 # and redundantly check for locked database, blocked IPs, etc.
394 # that edit() already checked just in case someone tries to sneak
395 # in the back door with a hand-edited submission URL.
397 if ( 'save' == $this->formtype
) {
398 if ( !$this->attemptSave() ) {
399 wfProfileOut( __METHOD__
."-business-end" );
400 wfProfileOut( __METHOD__
);
405 # First time through: get contents, set time for conflict
407 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
408 if ( $this->initialiseForm() === false ) {
409 $this->noSuchSectionPage();
410 wfProfileOut( __METHOD__
."-business-end" );
411 wfProfileOut( __METHOD__
);
414 if ( !$this->mTitle
->getArticleId() )
415 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
417 wfRunHooks( 'EditFormInitialText', array( $this ) );
420 $this->showEditForm();
421 wfProfileOut( __METHOD__
."-business-end" );
422 wfProfileOut( __METHOD__
);
425 protected function getEditPermissionErrors() {
427 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
428 # Can this title be created?
429 if ( !$this->mTitle
->exists() ) {
430 $permErrors = array_merge( $permErrors,
431 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
433 # Ignore some permissions errors when a user is just previewing/viewing diffs
435 foreach( $permErrors as $error ) {
436 if ( ( $this->preview ||
$this->diff
) &&
437 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
442 $permErrors = wfArrayDiff2( $permErrors, $remove );
447 * Show a read-only error
448 * Parameters are the same as OutputPage:readOnlyPage()
449 * Redirect to the article page if redlink=1
451 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
452 global $wgRequest, $wgOut;
453 if ( $wgRequest->getBool( 'redlink' ) ) {
454 // The edit page was reached via a red link.
455 // Redirect to the article page and let them click the edit tab if
456 // they really want a permission error.
457 $wgOut->redirect( $this->mTitle
->getFullUrl() );
459 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
464 * Should we show a preview when the edit form is first shown?
468 protected function previewOnOpen() {
469 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
470 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
471 // Explicit override from request
473 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
474 // Explicit override from request
476 } elseif ( $this->section
== 'new' ) {
477 // Nothing *to* preview for new sections
479 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
480 // Standard preference behaviour
482 } elseif ( !$this->mTitle
->exists() &&
483 isset($wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()]) &&
484 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
486 // Categories are special
494 * Does this EditPage class support section editing?
495 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
499 protected function isSectionEditSupported() {
504 * Returns the URL to use in the form's action attribute.
505 * This is used by EditPage subclasses when simply customizing the action
506 * variable in the constructor is not enough. This can be used when the
507 * EditPage lives inside of a Special page rather than a custom page action.
509 * @param $title Title object for which is being edited (where we go to for &action= links)
512 protected function getActionURL( Title
$title ) {
513 return $title->getLocalURL( array( 'action' => $this->action
) );
520 function importFormData( &$request ) {
521 global $wgLang, $wgUser;
523 wfProfileIn( __METHOD__
);
525 # Section edit can come from either the form or a link
526 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
528 if ( $request->wasPosted() ) {
529 # These fields need to be checked for encoding.
530 # Also remove trailing whitespace, but don't remove _initial_
531 # whitespace from the text boxes. This may be significant formatting.
532 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
533 if ( !$request->getCheck('wpTextbox2') ) {
534 // Skip this if wpTextbox2 has input, it indicates that we came
535 // from a conflict page with raw page text, not a custom form
536 // modified by subclasses
537 wfProfileIn( get_class($this)."::importContentFormData" );
538 $textbox1 = $this->importContentFormData( $request );
539 if ( isset($textbox1) )
540 $this->textbox1
= $textbox1;
541 wfProfileOut( get_class($this)."::importContentFormData" );
544 # Truncate for whole multibyte characters. +5 bytes for ellipsis
545 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
547 # Remove extra headings from summaries and new sections.
548 $this->summary
= preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
550 $this->edittime
= $request->getVal( 'wpEdittime' );
551 $this->starttime
= $request->getVal( 'wpStarttime' );
553 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
555 if ( is_null( $this->edittime
) ) {
556 # If the form is incomplete, force to preview.
557 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
558 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
559 $this->preview
= true;
561 /* Fallback for live preview */
562 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
563 $this->diff
= $request->getCheck( 'wpDiff' );
565 // Remember whether a save was requested, so we can indicate
566 // if we forced preview due to session failure.
567 $this->mTriedSave
= !$this->preview
;
569 if ( $this->tokenOk( $request ) ) {
570 # Some browsers will not report any submit button
571 # if the user hits enter in the comment box.
572 # The unmarked state will be assumed to be a save,
573 # if the form seems otherwise complete.
574 wfDebug( __METHOD__
. ": Passed token check.\n" );
575 } else if ( $this->diff
) {
576 # Failed token check, but only requested "Show Changes".
577 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
579 # Page might be a hack attempt posted from
580 # an external site. Preview instead of saving.
581 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
582 $this->preview
= true;
585 $this->save
= !$this->preview
&& !$this->diff
;
586 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
587 $this->edittime
= null;
590 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
591 $this->starttime
= null;
594 $this->recreate
= $request->getCheck( 'wpRecreate' );
596 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
597 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
599 # Don't force edit summaries when a user is editing their own user or talk page
600 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
601 $this->mTitle
->getText() == $wgUser->getName() )
603 $this->allowBlankSummary
= true;
605 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary');
608 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
610 # Not a posted form? Start with nothing.
611 wfDebug( __METHOD__
. ": Not a posted form.\n" );
612 $this->textbox1
= '';
614 $this->edittime
= '';
615 $this->starttime
= wfTimestampNow();
617 $this->preview
= false;
620 $this->minoredit
= false;
621 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
622 $this->recreate
= false;
624 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
625 $this->summary
= $request->getVal( 'preloadtitle' );
627 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
628 $this->summary
= $request->getText( 'summary' );
631 if ( $request->getVal( 'minor' ) ) {
632 $this->minoredit
= true;
636 $this->bot
= $request->getBool( 'bot', true );
637 $this->nosummary
= $request->getBool( 'nosummary' );
639 // FIXME: unused variable?
640 $this->oldid
= $request->getInt( 'oldid' );
642 $this->live
= $request->getCheck( 'live' );
643 $this->editintro
= $request->getText( 'editintro',
644 // Custom edit intro for new sections
645 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
647 wfProfileOut( __METHOD__
);
649 // Allow extensions to modify form data
650 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
654 * Subpage overridable method for extracting the page content data from the
655 * posted form to be placed in $this->textbox1, if using customized input
656 * this method should be overrided and return the page text that will be used
657 * for saving, preview parsing and so on...
659 * @param $request WebRequest
661 protected function importContentFormData( &$request ) {
662 return; // Don't do anything, EditPage already extracted wpTextbox1
666 * Make sure the form isn't faking a user's credentials.
668 * @param $request WebRequest
672 function tokenOk( &$request ) {
674 $token = $request->getVal( 'wpEditToken' );
675 $this->mTokenOk
= $wgUser->matchEditToken( $token );
676 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
677 return $this->mTokenOk
;
681 * Show all applicable editing introductions
683 protected function showIntro() {
684 global $wgOut, $wgUser;
685 if ( $this->suppressIntro
) {
689 $namespace = $this->mTitle
->getNamespace();
691 if ( $namespace == NS_MEDIAWIKI
) {
692 # Show a warning if editing an interface message
693 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
696 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
697 # Show log extract when the user is currently blocked
698 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
699 $parts = explode( '/', $this->mTitle
->getText(), 2 );
700 $username = $parts[0];
701 $user = User
::newFromName( $username, false /* allow IP users*/ );
702 $ip = User
::isIP( $username );
703 if ( !$user->isLoggedIn() && !$ip ) { # User does not exist
704 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1</div>",
705 array( 'userpage-userdoesnotexist', $username ) );
706 } else if ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
707 LogEventsList
::showLogExtract(
710 $user->getUserPage()->getPrefixedText(),
714 'showIfEmpty' => false,
716 'blocked-notice-logextract',
717 $user->getName() # Support GENDER in notice
723 # Try to add a custom edit intro, or use the standard one if this is not possible.
724 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
725 if ( $wgUser->isLoggedIn() ) {
726 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1</div>", 'newarticletext' );
728 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1</div>", 'newarticletextanon' );
731 # Give a notice if the user is editing a deleted/moved page...
732 if ( !$this->mTitle
->exists() ) {
733 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
->getPrefixedText(),
734 '', array( 'lim' => 10,
735 'conds' => array( "log_action != 'revision'" ),
736 'showIfEmpty' => false,
737 'msgKey' => array( 'recreate-moveddeleted-warn') )
743 * Attempt to show a custom editing introduction, if supplied
747 protected function showCustomIntro() {
748 if ( $this->editintro
) {
749 $title = Title
::newFromText( $this->editintro
);
750 if ( $title instanceof Title
&& $title->exists() && $title->userCanRead() ) {
752 $revision = Revision
::newFromTitle( $title );
753 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle
);
764 * Attempt submission (no UI)
765 * @return one of the constants describing the result
767 function internalAttemptSave( &$result, $bot = false ) {
768 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
769 global $wgMaxArticleSize;
771 wfProfileIn( __METHOD__
);
772 wfProfileIn( __METHOD__
. '-checks' );
774 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
775 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
776 return self
::AS_HOOK_ERROR
;
779 # Check image redirect
780 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
781 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&&
782 !$wgUser->isAllowed( 'upload' ) ) {
783 if ( $wgUser->isAnon() ) {
784 return self
::AS_IMAGE_REDIRECT_ANON
;
786 return self
::AS_IMAGE_REDIRECT_LOGGED
;
791 $match = self
::matchSummarySpamRegex( $this->summary
);
792 if ( $match === false ) {
793 $match = self
::matchSpamRegex( $this->textbox1
);
795 if ( $match !== false ) {
796 $result['spam'] = $match;
798 $pdbk = $this->mTitle
->getPrefixedDBkey();
799 $match = str_replace( "\n", '', $match );
800 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
801 wfProfileOut( __METHOD__
. '-checks' );
802 wfProfileOut( __METHOD__
);
803 return self
::AS_SPAM_ERROR
;
805 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
, $this->hookError
, $this->summary
) ) {
806 # Error messages or other handling should be performed by the filter function
807 wfProfileOut( __METHOD__
. '-checks' );
808 wfProfileOut( __METHOD__
);
809 return self
::AS_FILTERING
;
811 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
812 # Error messages etc. could be handled within the hook...
813 wfProfileOut( __METHOD__
. '-checks' );
814 wfProfileOut( __METHOD__
);
815 return self
::AS_HOOK_ERROR
;
816 } elseif ( $this->hookError
!= '' ) {
817 # ...or the hook could be expecting us to produce an error
818 wfProfileOut( __METHOD__
. '-checks' );
819 wfProfileOut( __METHOD__
);
820 return self
::AS_HOOK_ERROR_EXPECTED
;
822 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
823 # Check block state against master, thus 'false'.
824 wfProfileOut( __METHOD__
. '-checks' );
825 wfProfileOut( __METHOD__
);
826 return self
::AS_BLOCKED_PAGE_FOR_USER
;
828 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
829 if ( $this->kblength
> $wgMaxArticleSize ) {
830 // Error will be displayed by showEditForm()
831 $this->tooBig
= true;
832 wfProfileOut( __METHOD__
. '-checks' );
833 wfProfileOut( __METHOD__
);
834 return self
::AS_CONTENT_TOO_BIG
;
837 if ( !$wgUser->isAllowed( 'edit' ) ) {
838 if ( $wgUser->isAnon() ) {
839 wfProfileOut( __METHOD__
. '-checks' );
840 wfProfileOut( __METHOD__
);
841 return self
::AS_READ_ONLY_PAGE_ANON
;
843 wfProfileOut( __METHOD__
. '-checks' );
844 wfProfileOut( __METHOD__
);
845 return self
::AS_READ_ONLY_PAGE_LOGGED
;
849 if ( wfReadOnly() ) {
850 wfProfileOut( __METHOD__
. '-checks' );
851 wfProfileOut( __METHOD__
);
852 return self
::AS_READ_ONLY_PAGE
;
854 if ( $wgUser->pingLimiter() ) {
855 wfProfileOut( __METHOD__
. '-checks' );
856 wfProfileOut( __METHOD__
);
857 return self
::AS_RATE_LIMITED
;
860 # If the article has been deleted while editing, don't save it without
862 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
863 wfProfileOut( __METHOD__
. '-checks' );
864 wfProfileOut( __METHOD__
);
865 return self
::AS_ARTICLE_WAS_DELETED
;
868 wfProfileOut( __METHOD__
. '-checks' );
870 # If article is new, insert it.
871 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
873 // Late check for create permission, just in case *PARANOIA*
874 if ( !$this->mTitle
->userCan( 'create' ) ) {
875 wfDebug( __METHOD__
. ": no create permission\n" );
876 wfProfileOut( __METHOD__
);
877 return self
::AS_NO_CREATE_PERMISSION
;
880 # Don't save a new article if it's blank.
881 if ( $this->textbox1
== '' ) {
882 wfProfileOut( __METHOD__
);
883 return self
::AS_BLANK_ARTICLE
;
886 // Run post-section-merge edit filter
887 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
888 # Error messages etc. could be handled within the hook...
889 wfProfileOut( __METHOD__
);
890 return self
::AS_HOOK_ERROR
;
891 } elseif ( $this->hookError
!= '' ) {
892 # ...or the hook could be expecting us to produce an error
893 wfProfileOut( __METHOD__
);
894 return self
::AS_HOOK_ERROR_EXPECTED
;
897 # Handle the user preference to force summaries here. Check if it's not a redirect.
898 if ( !$this->allowBlankSummary
&& !Title
::newFromRedirect( $this->textbox1
) ) {
899 if ( md5( $this->summary
) == $this->autoSumm
) {
900 $this->missingSummary
= true;
901 wfProfileOut( __METHOD__
);
902 return self
::AS_SUMMARY_NEEDED
;
906 $isComment = ( $this->section
== 'new' );
908 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
909 $this->minoredit
, $this->watchthis
, false, $isComment, $bot );
911 wfProfileOut( __METHOD__
);
912 return self
::AS_SUCCESS_NEW_ARTICLE
;
915 # Article exists. Check for edit conflict.
917 $this->mArticle
->clear(); # Force reload of dates, etc.
918 $this->mArticle
->forUpdate( true ); # Lock the article
920 wfDebug( "timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n" );
922 if ( $this->mArticle
->getTimestamp() != $this->edittime
) {
923 $this->isConflict
= true;
924 if ( $this->section
== 'new' ) {
925 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
926 $this->mArticle
->getComment() == $this->summary
) {
927 // Probably a duplicate submission of a new comment.
928 // This can happen when squid resends a request after
929 // a timeout but the first one actually went through.
930 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
932 // New comment; suppress conflict.
933 $this->isConflict
= false;
934 wfDebug( __METHOD__
.": conflict suppressed; new section\n" );
938 $userid = $wgUser->getId();
940 # Suppress edit conflict with self, except for section edits where merging is required.
941 if ( $this->isConflict
&& $this->section
== '' && $this->userWasLastToEdit( $userid, $this->edittime
) ) {
942 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
943 $this->isConflict
= false;
946 if ( $this->isConflict
) {
947 wfDebug( __METHOD__
. ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
948 $this->mArticle
->getTimestamp() . "')\n" );
949 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
951 wfDebug( __METHOD__
. ": getting section '$this->section'\n" );
952 $text = $this->mArticle
->replaceSection( $this->section
, $this->textbox1
, $this->summary
);
954 if ( is_null( $text ) ) {
955 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
956 $this->isConflict
= true;
957 $text = $this->textbox1
; // do not try to merge here!
958 } else if ( $this->isConflict
) {
960 if ( $this->mergeChangesInto( $text ) ) {
961 // Successful merge! Maybe we should tell the user the good news?
962 $this->isConflict
= false;
963 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
966 $this->textbox1
= $text;
967 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
971 if ( $this->isConflict
) {
972 wfProfileOut( __METHOD__
);
973 return self
::AS_CONFLICT_DETECTED
;
976 $oldtext = $this->mArticle
->getContent();
978 // Run post-section-merge edit filter
979 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError
, $this->summary
) ) ) {
980 # Error messages etc. could be handled within the hook...
981 wfProfileOut( __METHOD__
);
982 return self
::AS_HOOK_ERROR
;
983 } elseif ( $this->hookError
!= '' ) {
984 # ...or the hook could be expecting us to produce an error
985 wfProfileOut( __METHOD__
);
986 return self
::AS_HOOK_ERROR_EXPECTED
;
989 # Handle the user preference to force summaries here, but not for null edits
990 if ( $this->section
!= 'new' && !$this->allowBlankSummary
&& 0 != strcmp( $oldtext, $text )
991 && !Title
::newFromRedirect( $text ) ) # check if it's not a redirect
993 if ( md5( $this->summary
) == $this->autoSumm
) {
994 $this->missingSummary
= true;
995 wfProfileOut( __METHOD__
);
996 return self
::AS_SUMMARY_NEEDED
;
1000 # And a similar thing for new sections
1001 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1002 if ( trim( $this->summary
) == '' ) {
1003 $this->missingSummary
= true;
1004 wfProfileOut( __METHOD__
);
1005 return self
::AS_SUMMARY_NEEDED
;
1010 wfProfileIn( __METHOD__
. '-sectionanchor' );
1011 $sectionanchor = '';
1012 if ( $this->section
== 'new' ) {
1013 if ( $this->textbox1
== '' ) {
1014 $this->missingComment
= true;
1015 wfProfileOut( __METHOD__
. '-sectionanchor' );
1016 wfProfileOut( __METHOD__
);
1017 return self
::AS_TEXTBOX_EMPTY
;
1019 if ( $this->summary
!= '' ) {
1020 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary
);
1021 # This is a new section, so create a link to the new section
1022 # in the revision summary.
1023 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1024 $this->summary
= wfMsgForContent( 'newsectionsummary', $cleanSummary );
1026 } elseif ( $this->section
!= '' ) {
1027 # Try to get a section anchor from the section source, redirect to edited section if header found
1028 # XXX: might be better to integrate this into Article::replaceSection
1029 # for duplicate heading checking and maybe parsing
1030 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1031 # we can't deal with anchors, includes, html etc in the header for now,
1032 # headline would need to be parsed to improve this
1033 if ( $hasmatch and strlen( $matches[2] ) > 0 ) {
1034 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
1037 wfProfileOut( __METHOD__
. '-sectionanchor' );
1039 // Save errors may fall down to the edit form, but we've now
1040 // merged the section into full text. Clear the section field
1041 // so that later submission of conflict forms won't try to
1042 // replace that into a duplicated mess.
1043 $this->textbox1
= $text;
1044 $this->section
= '';
1046 // Check for length errors again now that the section is merged in
1047 $this->kblength
= (int)( strlen( $text ) / 1024 );
1048 if ( $this->kblength
> $wgMaxArticleSize ) {
1049 $this->tooBig
= true;
1050 wfProfileOut( __METHOD__
);
1051 return self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
;
1054 # update the article here
1055 if ( $this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
1056 $this->watchthis
, $bot, $sectionanchor ) )
1058 wfProfileOut( __METHOD__
);
1059 return self
::AS_SUCCESS_UPDATE
;
1061 $this->isConflict
= true;
1063 wfProfileOut( __METHOD__
);
1064 return self
::AS_END
;
1068 * Check if no edits were made by other users since
1069 * the time a user started editing the page. Limit to
1070 * 50 revisions for the sake of performance.
1072 protected function userWasLastToEdit( $id, $edittime ) {
1073 if( !$id ) return false;
1074 $dbw = wfGetDB( DB_MASTER
);
1075 $res = $dbw->select( 'revision',
1078 'rev_page' => $this->mArticle
->getId(),
1079 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
1082 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1083 while( $row = $res->fetchObject() ) {
1084 if( $row->rev_user
!= $id ) {
1092 * Check given input text against $wgSpamRegex, and return the text of the first match.
1093 * @return mixed -- matching string or false
1095 public static function matchSpamRegex( $text ) {
1096 global $wgSpamRegex;
1097 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1098 $regexes = (array)$wgSpamRegex;
1099 return self
::matchSpamRegexInternal( $text, $regexes );
1103 * Check given input text against $wgSpamRegex, and return the text of the first match.
1104 * @return mixed -- matching string or false
1106 public static function matchSummarySpamRegex( $text ) {
1107 global $wgSummarySpamRegex;
1108 $regexes = (array)$wgSummarySpamRegex;
1109 return self
::matchSpamRegexInternal( $text, $regexes );
1112 protected static function matchSpamRegexInternal( $text, $regexes ) {
1113 foreach( $regexes as $regex ) {
1115 if( preg_match( $regex, $text, $matches ) ) {
1123 * Initialise form fields in the object
1124 * Called on the first invocation, e.g. when a user clicks an edit link
1125 * @returns bool -- if the requested section is valid
1127 function initialiseForm() {
1129 $this->edittime
= $this->mArticle
->getTimestamp();
1130 $this->textbox1
= $this->getContent( false );
1131 // activate checkboxes if user wants them to be always active
1132 # Sort out the "watch" checkbox
1133 if ( $wgUser->getOption( 'watchdefault' ) ) {
1135 $this->watchthis
= true;
1136 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
1138 $this->watchthis
= true;
1139 } elseif ( $this->mTitle
->userIsWatching() ) {
1141 $this->watchthis
= true;
1143 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
1144 if ( $this->textbox1
=== false ) return false;
1149 function setHeaders() {
1150 global $wgOut, $wgTitle;
1151 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1152 if ( $this->formtype
== 'preview' ) {
1153 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1155 if ( $this->isConflict
) {
1156 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1157 } elseif ( $this->section
!= '' ) {
1158 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1159 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1161 # Use the title defined by DISPLAYTITLE magic word when present
1162 if ( isset( $this->mParserOutput
)
1163 && ( $dt = $this->mParserOutput
->getDisplayTitle() ) !== false ) {
1166 $title = $wgTitle->getPrefixedText();
1168 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1173 * Send the edit form and related headers to $wgOut
1174 * @param $formCallback Optional callable that takes an OutputPage
1175 * parameter; will be called during form output
1176 * near the top, for captchas and the like.
1178 function showEditForm( $formCallback=null ) {
1179 global $wgOut, $wgUser, $wgTitle;
1181 # If $wgTitle is null, that means we're in API mode.
1182 # Some hook probably called this function without checking
1183 # for is_null($wgTitle) first. Bail out right here so we don't
1184 # do lots of work just to discard it right after.
1185 if ( is_null( $wgTitle ) )
1188 wfProfileIn( __METHOD__
);
1190 $sk = $wgUser->getSkin();
1192 #need to parse the preview early so that we know which templates are used,
1193 #otherwise users with "show preview after edit box" will get a blank list
1194 #we parse this near the beginning so that setHeaders can do the title
1195 #setting work instead of leaving it in getPreviewText
1196 $previewOutput = '';
1197 if ( $this->formtype
== 'preview' ) {
1198 $previewOutput = $this->getPreviewText();
1201 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) );
1203 $this->setHeaders();
1205 # Enabled article-related sidebar, toplinks, etc.
1206 $wgOut->setArticleRelated( true );
1208 if ( $this->showHeader() === false )
1211 $action = htmlspecialchars($this->getActionURL($wgTitle));
1213 if ( $wgUser->getOption( 'showtoolbar' ) and !$this->isCssJsSubpage
) {
1214 # prepare toolbar for edit buttons
1215 $toolbar = EditPage
::getEditToolbar();
1221 $wgOut->addHTML( $this->editFormPageTop
);
1223 if ( $wgUser->getOption( 'previewontop' ) ) {
1224 $this->displayPreviewArea( $previewOutput, true );
1227 $wgOut->addHTML( $this->editFormTextTop
);
1229 $templates = $this->getTemplates();
1230 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview
, $this->section
!= '');
1232 $hiddencats = $this->mArticle
->getHiddenCategories();
1233 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1235 if ( $this->wasDeletedSinceLastEdit() && 'save' != $this->formtype
) {
1236 $wgOut->wrapWikiMsg(
1237 "<div class='error mw-deleted-while-editing'>\n$1</div>",
1238 'deletedwhileediting' );
1239 } elseif ( $this->wasDeletedSinceLastEdit() ) {
1240 // Hide the toolbar and edit area, user can click preview to get it back
1241 // Add an confirmation checkbox and explanation.
1243 // @todo move this to a cleaner conditional instead of blanking a variable
1245 $wgOut->addHTML( <<<HTML
1247 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1251 if ( is_callable( $formCallback ) ) {
1252 call_user_func_array( $formCallback, array( &$wgOut ) );
1255 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1257 // Put these up at the top to ensure they aren't lost on early form submission
1258 $this->showFormBeforeText();
1260 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1262 '<div class="mw-confirm-recreate">' .
1263 $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete
->user_name
, $this->lastDelete
->log_comment
) ) .
1264 Xml
::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
1265 array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1271 # If a blank edit summary was previously provided, and the appropriate
1272 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1273 # user being bounced back more than once in the event that a summary
1276 # For a bit more sophisticated detection of blank summaries, hash the
1277 # automatic one and pass that in the hidden field wpAutoSummary.
1278 if ( $this->missingSummary ||
1279 ( $this->section
== 'new' && $this->nosummary
) )
1280 $wgOut->addHTML( Xml
::hidden( 'wpIgnoreBlankSummary', true ) );
1281 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
1282 $wgOut->addHTML( Xml
::hidden( 'wpAutoSummary', $autosumm ) );
1284 $wgOut->addHTML( Xml
::hidden( 'oldid', $this->mArticle
->getOldID() ) );
1286 if ( $this->section
== 'new' ) {
1287 $this->showSummaryInput( true, $this->summary
);
1288 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
1291 $wgOut->addHTML( $this->editFormTextBeforeContent
);
1293 if ( $this->isConflict
) {
1294 // In an edit conflict bypass the overrideable content form method
1295 // and fallback to the raw wpTextbox1 since editconflicts can't be
1296 // resolved between page source edits and custom ui edits using the
1298 $this->showTextbox1( null, $this->getContent() );
1300 $this->showContentForm();
1303 $wgOut->addHTML( $this->editFormTextAfterContent
);
1305 $wgOut->addWikiText( $this->getCopywarn() );
1306 if ( isset($this->editFormTextAfterWarn
) && $this->editFormTextAfterWarn
!== '' )
1307 $wgOut->addHTML( $this->editFormTextAfterWarn
);
1309 $this->showStandardInputs();
1311 $this->showFormAfterText();
1313 $this->showTosSummary();
1314 $this->showEditTools();
1316 $wgOut->addHTML( <<<HTML
1317 {$this->editFormTextAfterTools}
1318 <div class='templatesUsed'>
1319 {$formattedtemplates}
1321 <div class='hiddencats'>
1322 {$formattedhiddencats}
1327 if ( $this->isConflict
)
1328 $this->showConflict();
1330 $wgOut->addHTML( $this->editFormTextBottom
);
1331 $wgOut->addHTML( "</form>\n" );
1332 if ( !$wgUser->getOption( 'previewontop' ) ) {
1333 $this->displayPreviewArea( $previewOutput, false );
1336 wfProfileOut( __METHOD__
);
1339 protected function showHeader() {
1340 global $wgOut, $wgUser, $wgTitle, $wgMaxArticleSize, $wgLang;
1341 if ( $this->isConflict
) {
1342 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
1343 $this->edittime
= $this->mArticle
->getTimestamp();
1345 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
1346 // We use $this->section to much before this and getVal('wgSection') directly in other places
1347 // at this point we can't reset $this->section to '' to fallback to non-section editing.
1348 // Someone is welcome to try refactoring though
1349 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
1353 if ( $this->section
!= '' && $this->section
!= 'new' ) {
1355 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
1356 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1
, $matches );
1357 if ( !empty( $matches[2] ) ) {
1359 $this->summary
= "/* " .
1360 $wgParser->stripSectionName(trim($matches[2])) .
1366 if ( $this->missingComment
) {
1367 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1</div>", 'missingcommenttext' );
1370 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
1371 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1</div>", 'missingsummary' );
1374 if ( $this->missingSummary
&& $this->section
== 'new' ) {
1375 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1</div>", 'missingcommentheader' );
1378 if ( $this->hookError
!== '' ) {
1379 $wgOut->addWikiText( $this->hookError
);
1382 if ( !$this->checkUnicodeCompliantBrowser() ) {
1383 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1386 if ( isset( $this->mArticle
) && isset( $this->mArticle
->mRevision
) ) {
1387 // Let sysop know that this will make private content public if saved
1389 if ( !$this->mArticle
->mRevision
->userCan( Revision
::DELETED_TEXT
) ) {
1390 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
1391 } else if ( $this->mArticle
->mRevision
->isDeleted( Revision
::DELETED_TEXT
) ) {
1392 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
1395 if ( !$this->mArticle
->mRevision
->isCurrent() ) {
1396 $this->mArticle
->setOldSubtitle( $this->mArticle
->mRevision
->getId() );
1397 $wgOut->addWikiMsg( 'editingold' );
1402 if ( wfReadOnly() ) {
1403 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1404 } elseif ( $wgUser->isAnon() ) {
1405 if ( $this->formtype
!= 'preview' ) {
1406 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
1408 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\">\n$1</div>", 'anonpreviewwarning' );
1411 if ( $this->isCssJsSubpage
) {
1412 # Check the skin exists
1413 if ( !$this->isValidCssJsSubpage
) {
1414 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1416 if ( $this->formtype
!== 'preview' ) {
1417 if ( $this->isCssSubpage
)
1418 $wgOut->addWikiMsg( 'usercssyoucanpreview' );
1419 if ( $this->isJsSubpage
)
1420 $wgOut->addWikiMsg( 'userjsyoucanpreview' );
1425 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1426 # Is the title semi-protected?
1427 if ( $this->mTitle
->isSemiProtected() ) {
1428 $noticeMsg = 'semiprotectedpagewarning';
1430 # Then it must be protected based on static groups (regular)
1431 $noticeMsg = 'protectedpagewarning';
1433 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1434 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
1436 if ( $this->mTitle
->isCascadeProtected() ) {
1437 # Is this page under cascading protection from some source pages?
1438 list($cascadeSources, /* $restrictions */) = $this->mTitle
->getCascadeProtectionSources();
1439 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
1440 $cascadeSourcesCount = count( $cascadeSources );
1441 if ( $cascadeSourcesCount > 0 ) {
1442 # Explain, and list the titles responsible
1443 foreach( $cascadeSources as $page ) {
1444 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1447 $notice .= '</div>';
1448 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
1450 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
1451 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
->getPrefixedText(), '',
1453 'showIfEmpty' => false,
1454 'msgKey' => array( 'titleprotectedwarning' ),
1455 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
1458 if ( $this->kblength
=== false ) {
1459 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1462 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
1463 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
1464 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) );
1465 $wgOut->addHTML( "</div>\n" );
1466 } elseif ( $this->kblength
> 29 ) {
1467 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1468 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength
) );
1469 $wgOut->addHTML( "</div>\n" );
1474 * Standard summary input and label (wgSummary), abstracted so EditPage
1475 * subclasses may reorganize the form.
1476 * Note that you do not need to worry about the label's for=, it will be
1477 * inferred by the id given to the input. You can remove them both by
1478 * passing array( 'id' => false ) to $userInputAttrs.
1480 * @param $summary The value of the summary input
1481 * @param $labelText The html to place inside the label
1482 * @param $inputAttrs An array of attrs to use on the input
1483 * @param $spanLabelAttrs An array of attrs to use on the span inside the label
1485 * @return array An array in the format array( $label, $input )
1487 function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
1489 $inputAttrs = ( is_array($inputAttrs) ?
$inputAttrs : array() ) +
array(
1490 'id' => 'wpSummary',
1491 'maxlength' => '200',
1494 'spellcheck' => 'true',
1495 ) +
$wgUser->getSkin()->tooltipAndAccessKeyAttribs( 'summary' );
1497 $spanLabelAttrs = ( is_array($spanLabelAttrs) ?
$spanLabelAttrs : array() ) +
array(
1498 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
1499 'id' => "wpSummaryLabel"
1504 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
1505 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
1508 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
1510 return array( $label, $input );
1514 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1515 * up top, or false if this is the comment summary
1516 * down below the textarea
1517 * @param $summary String: The text of the summary to display
1520 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
1521 global $wgOut, $wgContLang;
1522 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
1523 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
1524 if ( $isSubjectPreview ) {
1525 if ( $this->nosummary
)
1528 if ( !$this->mShowSummaryField
)
1531 $summary = $wgContLang->recodeForEdit( $summary );
1532 $labelText = wfMsgExt( $isSubjectPreview ?
'subject' : 'summary', 'parseinline' );
1533 list($label, $input) = $this->getSummaryInput($summary, $labelText, array( 'class' => $summaryClass ), array());
1534 $wgOut->addHTML("{$label} {$input}");
1538 * @param $isSubjectPreview Boolean: true if this is the section subject/title
1539 * up top, or false if this is the comment summary
1540 * down below the textarea
1541 * @param $summary String: the text of the summary to display
1544 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
1545 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
1548 global $wgParser, $wgUser;
1549 $sk = $wgUser->getSkin();
1551 if ( $isSubjectPreview )
1552 $summary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $summary ) );
1554 $summary = wfMsgExt( 'subject-preview', 'parseinline' ) . $sk->commentBlock( $summary, $this->mTitle
, !!$isSubjectPreview );
1555 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
1558 protected function showFormBeforeText() {
1560 $section = htmlspecialchars( $this->section
);
1561 $wgOut->addHTML( <<<INPUTS
1562 <input type='hidden' value="{$section}" name="wpSection" />
1563 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
1564 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
1565 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
1569 if ( !$this->checkUnicodeCompliantBrowser() )
1570 $wgOut->addHTML(Xml
::hidden( 'safemode', '1' ));
1573 protected function showFormAfterText() {
1574 global $wgOut, $wgUser;
1576 * To make it harder for someone to slip a user a page
1577 * which submits an edit form to the wiki without their
1578 * knowledge, a random token is associated with the login
1579 * session. If it's not passed back with the submission,
1580 * we won't save the page, or render user JavaScript and
1583 * For anon editors, who may not have a session, we just
1584 * include the constant suffix to prevent editing from
1585 * broken text-mangling proxies.
1587 $wgOut->addHTML( "\n" . Xml
::hidden( "wpEditToken", $wgUser->editToken() ) . "\n" );
1591 * Subpage overridable method for printing the form for page content editing
1592 * By default this simply outputs wpTextbox1
1593 * Subclasses can override this to provide a custom UI for editing;
1594 * be it a form, or simply wpTextbox1 with a modified content that will be
1595 * reverse modified when extracted from the post data.
1596 * Note that this is basically the inverse for importContentFormData
1598 * @param $request WebRequest
1600 protected function showContentForm() {
1601 $this->showTextbox1();
1605 * Method to output wpTextbox1
1606 * The $textoverride method can be used by subclasses overriding showContentForm
1607 * to pass back to this method.
1609 * @param $customAttribs An array of html attributes to use in the textarea
1610 * @param $textoverride String: optional text to override $this->textarea1 with
1612 protected function showTextbox1($customAttribs = null, $textoverride = null) {
1613 $classes = array(); // Textarea CSS
1614 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
1615 # Is the title semi-protected?
1616 if ( $this->mTitle
->isSemiProtected() ) {
1617 $classes[] = 'mw-textarea-sprotected';
1619 # Then it must be protected based on static groups (regular)
1620 $classes[] = 'mw-textarea-protected';
1623 $attribs = array( 'tabindex' => 1 );
1624 if ( is_array($customAttribs) )
1625 $attribs +
= $customAttribs;
1627 if ( $this->wasDeletedSinceLastEdit() )
1628 $attribs['type'] = 'hidden';
1629 if ( !empty( $classes ) ) {
1630 if ( isset($attribs['class']) )
1631 $classes[] = $attribs['class'];
1632 $attribs['class'] = implode( ' ', $classes );
1635 $this->showTextbox( isset($textoverride) ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
1638 protected function showTextbox2() {
1639 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6 ) );
1642 protected function showTextbox( $content, $name, $customAttribs = array() ) {
1643 global $wgOut, $wgUser;
1645 $wikitext = $this->safeUnicodeOutput( $content );
1646 if ( $wikitext !== '' ) {
1647 // Ensure there's a newline at the end, otherwise adding lines
1649 // But don't add a newline if the ext is empty, or Firefox in XHTML
1650 // mode will show an extra newline. A bit annoying.
1654 $attribs = $customAttribs +
array(
1657 'cols' => $wgUser->getIntOption( 'cols' ),
1658 'rows' => $wgUser->getIntOption( 'rows' ),
1659 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
1662 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
1665 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1669 $classes[] = 'ontop';
1671 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1673 if ( $this->formtype
!= 'preview' )
1674 $attribs['style'] = 'display: none;';
1676 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
1678 if ( $this->formtype
== 'preview' ) {
1679 $this->showPreview( $previewOutput );
1682 $wgOut->addHTML( '</div>' );
1684 if ( $this->formtype
== 'diff') {
1690 * Append preview output to $wgOut.
1691 * Includes category rendering if this is a category page.
1693 * @param $text String: the HTML to be output for the preview.
1695 protected function showPreview( $text ) {
1697 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1698 $this->mArticle
->openShowCategory();
1700 # This hook seems slightly odd here, but makes things more
1701 # consistent for extensions.
1702 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1703 $wgOut->addHTML( $text );
1704 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
1705 $this->mArticle
->closeShowCategory();
1710 * Give a chance for site and per-namespace customizations of
1711 * terms of service summary link that might exist separately
1712 * from the copyright notice.
1714 * This will display between the save button and the edit tools,
1715 * so should remain short!
1717 protected function showTosSummary() {
1718 $msg = 'editpage-tos-summary';
1719 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
1720 $text = wfMsg( $msg );
1721 if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
1723 $wgOut->addHTML( '<div class="mw-tos-summary">' );
1724 $wgOut->addWikiMsgArray( $msg, array() );
1725 $wgOut->addHTML( '</div>' );
1729 protected function showEditTools() {
1731 $wgOut->addHTML( '<div class="mw-editTools">' );
1732 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1733 $wgOut->addHTML( '</div>' );
1736 protected function getCopywarn() {
1737 global $wgRightsText;
1738 if ( $wgRightsText ) {
1739 $copywarnMsg = array( 'copyrightwarning',
1740 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1743 $copywarnMsg = array( 'copyrightwarning2',
1744 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1746 // Allow for site and per-namespace customization of contribution/copyright notice.
1747 wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle
, &$copywarnMsg ) );
1749 return "<div id=\"editpage-copywarn\">\n" . call_user_func_array("wfMsgNoTrans", $copywarnMsg) . "\n</div>";
1752 protected function showStandardInputs( &$tabindex = 2 ) {
1753 global $wgOut, $wgUser;
1754 $wgOut->addHTML( "<div class='editOptions'>\n" );
1756 if ( $this->section
!= 'new' ) {
1757 $this->showSummaryInput( false, $this->summary
);
1758 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
1761 $checkboxes = $this->getCheckboxes( $tabindex, $wgUser->getSkin(),
1762 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
1763 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
1764 $wgOut->addHTML( "<div class='editButtons'>\n" );
1765 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
1767 $cancel = $this->getCancelLink();
1768 $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1769 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ) );
1770 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1771 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1772 htmlspecialchars( wfMsg( 'newwindow' ) );
1773 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>\n" );
1774 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
1778 * Show an edit conflict. textbox1 is already shown in showEditForm().
1779 * If you want to use another entry point to this function, be careful.
1781 protected function showConflict() {
1783 $this->textbox2
= $this->textbox1
;
1784 $this->textbox1
= $this->getContent();
1785 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1786 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
1788 $de = new DifferenceEngine( $this->mTitle
);
1789 $de->setText( $this->textbox2
, $this->textbox1
);
1790 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1792 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
1793 $this->showTextbox2();
1797 protected function getLastDelete() {
1798 $dbr = wfGetDB( DB_SLAVE
);
1799 $data = $dbr->selectRow(
1800 array( 'logging', 'user' ),
1811 array( 'log_namespace' => $this->mTitle
->getNamespace(),
1812 'log_title' => $this->mTitle
->getDBkey(),
1813 'log_type' => 'delete',
1814 'log_action' => 'delete',
1815 'user_id=log_user' ),
1817 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
1819 // Quick paranoid permission checks...
1820 if( is_object( $data ) ) {
1821 if( $data->log_deleted
& LogPage
::DELETED_USER
)
1822 $data->user_name
= wfMsgHtml( 'rev-deleted-user' );
1823 if( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
1824 $data->log_comment
= wfMsgHtml( 'rev-deleted-comment' );
1830 * Get the rendered text for previewing.
1833 function getPreviewText() {
1834 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
1836 wfProfileIn( __METHOD__
);
1838 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
1839 if ( $this->mTokenOkExceptSuffix
) {
1840 $note = wfMsg( 'token_suffix_mismatch' );
1842 $note = wfMsg( 'session_fail_preview' );
1845 $note = wfMsg( 'previewnote' );
1848 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1849 $parserOptions->setEditSection( false );
1850 $parserOptions->setIsPreview( true );
1851 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
1854 if ( $wgRawHtml && !$this->mTokenOk
) {
1855 // Could be an offsite preview attempt. This is very unsafe if
1856 // HTML is enabled, as it could be an attack.
1857 return $wgOut->parse( "<div class='previewnote'>" .
1858 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1861 # don't parse user css/js, show message about preview
1862 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1864 if ( $this->isCssJsSubpage
) {
1865 if (preg_match( "/\\.css$/", $this->mTitle
->getText() ) ) {
1866 $previewtext = wfMsg( 'usercsspreview' );
1867 } else if (preg_match( "/\\.js$/", $this->mTitle
->getText() ) ) {
1868 $previewtext = wfMsg( 'userjspreview' );
1870 $parserOptions->setTidy( true );
1871 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle
, $parserOptions );
1872 $previewHTML = $parserOutput->mText
;
1873 } elseif ( $rt = Title
::newFromRedirectArray( $this->textbox1
) ) {
1874 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
1876 $toparse = $this->textbox1
;
1878 # If we're adding a comment, we need to show the
1879 # summary as the headline
1880 if ( $this->section
== "new" && $this->summary
!= "" ) {
1881 $toparse = "== {$this->summary} ==\n\n" . $toparse;
1884 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
1886 // Parse mediawiki messages with correct target language
1887 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1888 list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle
->getText() );
1889 $obj = wfGetLangObj( $lang );
1890 $parserOptions->setTargetLanguage( $obj );
1894 $parserOptions->setTidy( true );
1895 $parserOptions->enableLimitReport();
1896 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $toparse ),
1897 $this->mTitle
, $parserOptions );
1899 $previewHTML = $parserOutput->getText();
1900 $this->mParserOutput
= $parserOutput;
1901 $wgOut->addParserOutputNoText( $parserOutput );
1903 if ( count( $parserOutput->getWarnings() ) ) {
1904 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1908 if( $this->isConflict
) {
1909 $conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1911 $conflict = '<hr />';
1914 $previewhead = "<div class='previewnote'>\n" .
1915 '<h2 id="mw-previewheader">' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>" .
1916 $wgOut->parse( $note ) . $conflict . "</div>\n";
1918 wfProfileOut( __METHOD__
);
1919 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
1922 function getTemplates() {
1923 if ( $this->preview ||
$this->section
!= '' ) {
1924 $templates = array();
1925 if ( !isset( $this->mParserOutput
) ) return $templates;
1926 foreach( $this->mParserOutput
->getTemplates() as $ns => $template) {
1927 foreach( array_keys( $template ) as $dbk ) {
1928 $templates[] = Title
::makeTitle($ns, $dbk);
1933 return $this->mArticle
->getUsedTemplates();
1938 * Call the stock "user is blocked" page
1940 function blockedPage() {
1942 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1944 # If the user made changes, preserve them when showing the markup
1945 # (This happens when a user is blocked during edit, for instance)
1946 $first = $this->firsttime ||
( !$this->save
&& $this->textbox1
== '' );
1948 $source = $this->mTitle
->exists() ?
$this->getContent() : false;
1950 $source = $this->textbox1
;
1953 # Spit out the source or the user's modified version
1954 if ( $source !== false ) {
1955 $wgOut->addHTML( '<hr />' );
1956 $wgOut->addWikiMsg( $first ?
'blockedoriginalsource' : 'blockededitsource', $this->mTitle
->getPrefixedText() );
1957 $this->showTextbox1( array( 'readonly' ), $source );
1962 * Produce the stock "please login to edit pages" page
1964 function userNotLoggedInPage() {
1965 global $wgUser, $wgOut, $wgTitle;
1966 $skin = $wgUser->getSkin();
1968 $loginTitle = SpecialPage
::getTitleFor( 'Userlogin' );
1969 $loginLink = $skin->link(
1971 wfMsgHtml( 'loginreqlink' ),
1973 array( 'returnto' => $wgTitle->getPrefixedText() ),
1974 array( 'known', 'noclasses' )
1977 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1978 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1979 $wgOut->setArticleRelated( false );
1981 $wgOut->addHTML( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1982 $wgOut->returnToMain( false, $wgTitle );
1986 * Creates a basic error page which informs the user that
1987 * they have attempted to edit a nonexistent section.
1989 function noSuchSectionPage() {
1992 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1993 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1994 $wgOut->setArticleRelated( false );
1996 $res = wfMsgExt( 'nosuchsectiontext', 'parse', $this->section
);
1997 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
1998 $wgOut->addHTML( $res );
2000 $wgOut->returnToMain( false, $this->mTitle
);
2004 * Produce the stock "your edit contains spam" page
2006 * @param $match Text which triggered one or more filters
2008 function spamPage( $match = false ) {
2009 global $wgOut, $wgTitle;
2011 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
2012 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2013 $wgOut->setArticleRelated( false );
2015 $wgOut->addHTML( '<div id="spamprotected">' );
2016 $wgOut->addWikiMsg( 'spamprotectiontext' );
2018 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
2019 $wgOut->addHTML( '</div>' );
2021 $wgOut->returnToMain( false, $wgTitle );
2028 function mergeChangesInto( &$editText ){
2029 wfProfileIn( __METHOD__
);
2031 $db = wfGetDB( DB_MASTER
);
2033 // This is the revision the editor started from
2034 $baseRevision = $this->getBaseRevision();
2035 if ( is_null( $baseRevision ) ) {
2036 wfProfileOut( __METHOD__
);
2039 $baseText = $baseRevision->getText();
2041 // The current state, we want to merge updates into it
2042 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
2043 if ( is_null( $currentRevision ) ) {
2044 wfProfileOut( __METHOD__
);
2047 $currentText = $currentRevision->getText();
2050 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
2051 $editText = $result;
2052 wfProfileOut( __METHOD__
);
2055 wfProfileOut( __METHOD__
);
2061 * Check if the browser is on a blacklist of user-agents known to
2062 * mangle UTF-8 data on form submission. Returns true if Unicode
2063 * should make it through, false if it's known to be a problem.
2067 function checkUnicodeCompliantBrowser() {
2068 global $wgBrowserBlackList;
2069 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
2070 // No User-Agent header sent? Trust it by default...
2073 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
2074 foreach ( $wgBrowserBlackList as $browser ) {
2075 if ( preg_match($browser, $currentbrowser) ) {
2083 * @deprecated use $wgParser->stripSectionName()
2085 function pseudoParseSectionAnchor( $text ) {
2087 return $wgParser->stripSectionName( $text );
2091 * Format an anchor fragment as it would appear for a given section name
2092 * @param $text String
2096 function sectionAnchor( $text ) {
2098 return $wgParser->guessSectionNameFromWikiText( $text );
2102 * Shows a bulletin board style toolbar for common editing functions.
2103 * It can be disabled in the user preferences.
2104 * The necessary JavaScript code can be found in skins/common/edit.js.
2108 static function getEditToolbar() {
2109 global $wgStylePath, $wgContLang, $wgLang;
2113 * toolarray an array of arrays which each include the filename of
2114 * the button image (without path), the opening tag, the closing tag,
2115 * and optionally a sample text that is inserted between the two when no
2116 * selection is highlighted.
2117 * The tip text is shown when the user moves the mouse over the button.
2119 * Already here are accesskeys (key), which are not used yet until someone
2120 * can figure out a way to make them work in IE. However, we should make
2121 * sure these keys are not defined on the edit page.
2125 'image' => $wgLang->getImageFile( 'button-bold' ),
2126 'id' => 'mw-editbutton-bold',
2128 'close' => '\'\'\'',
2129 'sample' => wfMsg( 'bold_sample' ),
2130 'tip' => wfMsg( 'bold_tip' ),
2134 'image' => $wgLang->getImageFile( 'button-italic' ),
2135 'id' => 'mw-editbutton-italic',
2138 'sample' => wfMsg( 'italic_sample' ),
2139 'tip' => wfMsg( 'italic_tip' ),
2143 'image' => $wgLang->getImageFile( 'button-link' ),
2144 'id' => 'mw-editbutton-link',
2147 'sample' => wfMsg( 'link_sample' ),
2148 'tip' => wfMsg( 'link_tip' ),
2152 'image' => $wgLang->getImageFile( 'button-extlink' ),
2153 'id' => 'mw-editbutton-extlink',
2156 'sample' => wfMsg( 'extlink_sample' ),
2157 'tip' => wfMsg( 'extlink_tip' ),
2161 'image' => $wgLang->getImageFile( 'button-headline' ),
2162 'id' => 'mw-editbutton-headline',
2165 'sample' => wfMsg( 'headline_sample' ),
2166 'tip' => wfMsg( 'headline_tip' ),
2170 'image' => $wgLang->getImageFile( 'button-image' ),
2171 'id' => 'mw-editbutton-image',
2172 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
2174 'sample' => wfMsg( 'image_sample' ),
2175 'tip' => wfMsg( 'image_tip' ),
2179 'image' => $wgLang->getImageFile( 'button-media' ),
2180 'id' => 'mw-editbutton-media',
2181 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
2183 'sample' => wfMsg( 'media_sample' ),
2184 'tip' => wfMsg( 'media_tip' ),
2188 'image' => $wgLang->getImageFile( 'button-math' ),
2189 'id' => 'mw-editbutton-math',
2191 'close' => "</math>",
2192 'sample' => wfMsg( 'math_sample' ),
2193 'tip' => wfMsg( 'math_tip' ),
2197 'image' => $wgLang->getImageFile( 'button-nowiki' ),
2198 'id' => 'mw-editbutton-nowiki',
2199 'open' => "<nowiki>",
2200 'close' => "</nowiki>",
2201 'sample' => wfMsg( 'nowiki_sample' ),
2202 'tip' => wfMsg( 'nowiki_tip' ),
2206 'image' => $wgLang->getImageFile( 'button-sig' ),
2207 'id' => 'mw-editbutton-signature',
2211 'tip' => wfMsg( 'sig_tip' ),
2215 'image' => $wgLang->getImageFile( 'button-hr' ),
2216 'id' => 'mw-editbutton-hr',
2217 'open' => "\n----\n",
2220 'tip' => wfMsg( 'hr_tip' ),
2224 $toolbar = "<div id='toolbar'>\n";
2227 foreach ( $toolarray as $tool ) {
2229 $image = $wgStylePath . '/common/images/' . $tool['image'],
2230 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2231 // Older browsers show a "speedtip" type message only for ALT.
2232 // Ideally these should be different, realistically they
2233 // probably don't need to be.
2234 $tip = $tool['tip'],
2235 $open = $tool['open'],
2236 $close = $tool['close'],
2237 $sample = $tool['sample'],
2238 $cssId = $tool['id'],
2241 $paramList = implode( ',',
2242 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2243 $script .= "addButton($paramList);\n";
2245 $toolbar .= Html
::inlineScript( "\n$script\n" );
2247 $toolbar .= "\n</div>";
2249 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
2255 * Returns an array of html code of the following checkboxes:
2258 * @param $tabindex Current tabindex
2259 * @param $skin Skin object
2260 * @param $checked Array of checkbox => bool, where bool indicates the checked
2261 * status of the checkbox
2265 public function getCheckboxes( &$tabindex, $skin, $checked ) {
2268 $checkboxes = array();
2270 $checkboxes['minor'] = '';
2271 $minorLabel = wfMsgExt( 'minoredit', array( 'parseinline' ) );
2272 if ( $wgUser->isAllowed( 'minoredit' ) ) {
2274 'tabindex' => ++
$tabindex,
2275 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2276 'id' => 'wpMinoredit',
2278 $checkboxes['minor'] =
2279 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2280 " <label for='wpMinoredit'" . $skin->tooltip( 'minoredit', 'withaccess' ) . ">{$minorLabel}</label>";
2283 $watchLabel = wfMsgExt( 'watchthis', array( 'parseinline' ) );
2284 $checkboxes['watch'] = '';
2285 if ( $wgUser->isLoggedIn() ) {
2287 'tabindex' => ++
$tabindex,
2288 'accesskey' => wfMsg( 'accesskey-watch' ),
2289 'id' => 'wpWatchthis',
2291 $checkboxes['watch'] =
2292 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2293 " <label for='wpWatchthis'" . $skin->tooltip( 'watch', 'withaccess' ) . ">{$watchLabel}</label>";
2295 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
2300 * Returns an array of html code of the following buttons:
2301 * save, diff, preview and live
2303 * @param $tabindex Current tabindex
2307 public function getEditButtons(&$tabindex) {
2314 'tabindex' => ++
$tabindex,
2315 'value' => wfMsg( 'savearticle' ),
2316 'accesskey' => wfMsg( 'accesskey-save' ),
2317 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2319 $buttons['save'] = Xml
::element('input', $temp, '');
2321 ++
$tabindex; // use the same for preview and live preview
2323 'id' => 'wpPreview',
2324 'name' => 'wpPreview',
2326 'tabindex' => $tabindex,
2327 'value' => wfMsg( 'showpreview' ),
2328 'accesskey' => wfMsg( 'accesskey-preview' ),
2329 'title' => wfMsg( 'tooltip-preview' ) . ' [' . wfMsg( 'accesskey-preview' ) . ']',
2331 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
2332 $buttons['live'] = '';
2338 'tabindex' => ++
$tabindex,
2339 'value' => wfMsg( 'showdiff' ),
2340 'accesskey' => wfMsg( 'accesskey-diff' ),
2341 'title' => wfMsg( 'tooltip-diff' ) . ' [' . wfMsg( 'accesskey-diff' ) . ']',
2343 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
2345 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
2350 * Output preview text only. This can be sucked into the edit page
2351 * via JavaScript, and saves the server time rendering the skin as
2352 * well as theoretically being more robust on the client (doesn't
2353 * disturb the edit box's undo history, won't eat your text on
2356 * @todo This doesn't include category or interlanguage links.
2357 * Would need to enhance it a bit, <s>maybe wrap them in XML
2358 * or something...</s> that might also require more skin
2359 * initialization, so check whether that's a problem.
2361 function livePreview() {
2364 header( 'Content-type: text/xml; charset=utf-8' );
2365 header( 'Cache-control: no-cache' );
2367 $previewText = $this->getPreviewText();
2368 #$categories = $skin->getCategoryLinks();
2371 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2372 Xml
::tags( 'livepreview', null,
2373 Xml
::element( 'preview', null, $previewText )
2374 #. Xml::element( 'category', null, $categories )
2380 public function getCancelLink() {
2381 global $wgUser, $wgTitle;
2383 $cancelParams = array();
2384 if ( !$this->isConflict
&& $this->mArticle
->getOldID() > 0 ) {
2385 $cancelParams['oldid'] = $this->mArticle
->getOldID();
2388 return $wgUser->getSkin()->link(
2390 wfMsgExt( 'cancel', array( 'parseinline' ) ),
2391 array( 'id' => 'mw-editform-cancel' ),
2393 array( 'known', 'noclasses' )
2398 * Get a diff between the current contents of the edit box and the
2399 * version of the page we're editing from.
2401 * If this is a section edit, we'll replace the section as for final
2402 * save and then make a comparison.
2404 function showDiff() {
2405 $oldtext = $this->mArticle
->fetchContent();
2406 $newtext = $this->mArticle
->replaceSection(
2407 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
2409 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2411 $newtext = $this->mArticle
->preSaveTransform( $newtext );
2412 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
2413 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
2414 if ( $oldtext !== false ||
$newtext != '' ) {
2415 $de = new DifferenceEngine( $this->mTitle
);
2416 $de->setText( $oldtext, $newtext );
2417 $difftext = $de->getDiff( $oldtitle, $newtitle );
2418 $de->showDiffStyle();
2424 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2428 * Filter an input field through a Unicode de-armoring process if it
2429 * came from an old browser with known broken Unicode editing issues.
2431 * @param $request WebRequest
2432 * @param $field String
2436 function safeUnicodeInput( $request, $field ) {
2437 $text = rtrim( $request->getText( $field ) );
2438 return $request->getBool( 'safemode' )
2439 ?
$this->unmakesafe( $text )
2443 function safeUnicodeText( $request, $text ) {
2444 $text = rtrim( $text );
2445 return $request->getBool( 'safemode' )
2446 ?
$this->unmakesafe( $text )
2451 * Filter an output field through a Unicode armoring process if it is
2452 * going to an old browser with known broken Unicode editing issues.
2454 * @param $text String
2458 function safeUnicodeOutput( $text ) {
2460 $codedText = $wgContLang->recodeForEdit( $text );
2461 return $this->checkUnicodeCompliantBrowser()
2463 : $this->makesafe( $codedText );
2467 * A number of web browsers are known to corrupt non-ASCII characters
2468 * in a UTF-8 text editing environment. To protect against this,
2469 * detected browsers will be served an armored version of the text,
2470 * with non-ASCII chars converted to numeric HTML character references.
2472 * Preexisting such character references will have a 0 added to them
2473 * to ensure that round-trips do not alter the original data.
2475 * @param $invalue String
2479 function makesafe( $invalue ) {
2480 // Armor existing references for reversability.
2481 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
2486 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2487 $bytevalue = ord( $invalue{$i} );
2488 if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2489 $result .= chr( $bytevalue );
2491 } elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2492 $working = $working << 6;
2493 $working +
= ($bytevalue & 0x3F);
2495 if ( $bytesleft <= 0 ) {
2496 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2498 } elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2499 $working = $bytevalue & 0x1F;
2501 } elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2502 $working = $bytevalue & 0x0F;
2504 } else { //1111 0xxx
2505 $working = $bytevalue & 0x07;
2513 * Reverse the previously applied transliteration of non-ASCII characters
2514 * back to UTF-8. Used to protect data from corruption by broken web browsers
2515 * as listed in $wgBrowserBlackList.
2517 * @param $invalue String
2521 function unmakesafe( $invalue ) {
2523 for( $i = 0; $i < strlen( $invalue ); $i++
) {
2524 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+
3} != '0' ) ) {
2528 $hexstring .= $invalue{$i};
2530 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2532 // Do some sanity checks. These aren't needed for reversability,
2533 // but should help keep the breakage down if the editor
2534 // breaks one of the entities whilst editing.
2535 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
2536 $codepoint = hexdec($hexstring);
2537 $result .= codepointToUtf8( $codepoint );
2539 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2542 $result .= substr( $invalue, $i, 1 );
2545 // reverse the transform that we made for reversability reasons.
2546 return strtr( $result, array( "�" => "&#x" ) );
2549 function noCreatePermission() {
2551 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2552 $wgOut->addWikiMsg( 'nocreatetext' );
2556 * Attempt submission
2557 * @return bool false if output is done, true if the rest of the form should be displayed
2559 function attemptSave() {
2560 global $wgUser, $wgOut, $wgTitle;
2562 $resultDetails = false;
2563 # Allow bots to exempt some edits from bot flagging
2564 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
2565 $value = $this->internalAttemptSave( $resultDetails, $bot );
2567 if ( $value == self
::AS_SUCCESS_UPDATE ||
$value == self
::AS_SUCCESS_NEW_ARTICLE
) {
2568 $this->didSave
= true;
2572 case self
::AS_HOOK_ERROR_EXPECTED
:
2573 case self
::AS_CONTENT_TOO_BIG
:
2574 case self
::AS_ARTICLE_WAS_DELETED
:
2575 case self
::AS_CONFLICT_DETECTED
:
2576 case self
::AS_SUMMARY_NEEDED
:
2577 case self
::AS_TEXTBOX_EMPTY
:
2578 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
2582 case self
::AS_HOOK_ERROR
:
2583 case self
::AS_FILTERING
:
2584 case self
::AS_SUCCESS_NEW_ARTICLE
:
2585 case self
::AS_SUCCESS_UPDATE
:
2588 case self
::AS_SPAM_ERROR
:
2589 $this->spamPage( $resultDetails['spam'] );
2592 case self
::AS_BLOCKED_PAGE_FOR_USER
:
2593 $this->blockedPage();
2596 case self
::AS_IMAGE_REDIRECT_ANON
:
2597 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2600 case self
::AS_READ_ONLY_PAGE_ANON
:
2601 $this->userNotLoggedInPage();
2604 case self
::AS_READ_ONLY_PAGE_LOGGED
:
2605 case self
::AS_READ_ONLY_PAGE
:
2606 $wgOut->readOnlyPage();
2609 case self
::AS_RATE_LIMITED
:
2610 $wgOut->rateLimited();
2613 case self
::AS_NO_CREATE_PERMISSION
:
2614 $this->noCreatePermission();
2617 case self
::AS_BLANK_ARTICLE
:
2618 $wgOut->redirect( $wgTitle->getFullURL() );
2621 case self
::AS_IMAGE_REDIRECT_LOGGED
:
2622 $wgOut->permissionRequired( 'upload' );
2627 function getBaseRevision() {
2628 if ( $this->mBaseRevision
== false ) {
2629 $db = wfGetDB( DB_MASTER
);
2630 $baseRevision = Revision
::loadFromTimestamp(
2631 $db, $this->mTitle
, $this->edittime
);
2632 return $this->mBaseRevision
= $baseRevision;
2634 return $this->mBaseRevision
;