3 * Page edition user interface.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * The edit page/HTML interface (split from Article)
25 * The actual database and text munging is still in Article,
26 * but it should get easier to call those from alternate
29 * EditPage cares about two distinct titles:
30 * $this->mContextTitle is the page that forms submit to, links point to,
31 * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
32 * page in the database that is actually being edited. These are
33 * usually the same, but they are now allowed to be different.
35 * Surgeon General's Warning: prolonged exposure to this class is known to cause
36 * headaches, which may be fatal.
41 * Status: Article successfully updated
43 const AS_SUCCESS_UPDATE
= 200;
46 * Status: Article successfully created
48 const AS_SUCCESS_NEW_ARTICLE
= 201;
51 * Status: Article update aborted by a hook function
53 const AS_HOOK_ERROR
= 210;
56 * Status: A hook function returned an error
58 const AS_HOOK_ERROR_EXPECTED
= 212;
61 * Status: User is blocked from editting this page
63 const AS_BLOCKED_PAGE_FOR_USER
= 215;
66 * Status: Content too big (> $wgMaxArticleSize)
68 const AS_CONTENT_TOO_BIG
= 216;
71 * Status: User cannot edit? (not used)
73 const AS_USER_CANNOT_EDIT
= 217;
76 * Status: this anonymous user is not allowed to edit this page
78 const AS_READ_ONLY_PAGE_ANON
= 218;
81 * Status: this logged in user is not allowed to edit this page
83 const AS_READ_ONLY_PAGE_LOGGED
= 219;
86 * Status: wiki is in readonly mode (wfReadOnly() == true)
88 const AS_READ_ONLY_PAGE
= 220;
91 * Status: rate limiter for action 'edit' was tripped
93 const AS_RATE_LIMITED
= 221;
96 * Status: article was deleted while editting and param wpRecreate == false or form
99 const AS_ARTICLE_WAS_DELETED
= 222;
102 * Status: user tried to create this page, but is not allowed to do that
103 * ( Title->usercan('create') == false )
105 const AS_NO_CREATE_PERMISSION
= 223;
108 * Status: user tried to create a blank page
110 const AS_BLANK_ARTICLE
= 224;
113 * Status: (non-resolvable) edit conflict
115 const AS_CONFLICT_DETECTED
= 225;
118 * Status: no edit summary given and the user has forceeditsummary set and the user is not
119 * editting in his own userspace or talkspace and wpIgnoreBlankSummary == false
121 const AS_SUMMARY_NEEDED
= 226;
124 * Status: user tried to create a new section without content
126 const AS_TEXTBOX_EMPTY
= 228;
129 * Status: article is too big (> $wgMaxArticleSize), after merging in the new section
131 const AS_MAX_ARTICLE_SIZE_EXCEEDED
= 229;
139 * Status: WikiPage::doEdit() was unsuccessfull
144 * Status: summary contained spam according to one of the regexes in $wgSummarySpamRegex
146 const AS_SPAM_ERROR
= 232;
149 * Status: anonymous user is not allowed to upload (User::isAllowed('upload') == false)
151 const AS_IMAGE_REDIRECT_ANON
= 233;
154 * Status: logged in user is not allowed to upload (User::isAllowed('upload') == false)
156 const AS_IMAGE_REDIRECT_LOGGED
= 234;
159 * Status: can't parse content
161 const AS_PARSE_ERROR
= 240;
164 * HTML id and name for the beginning of the edit form.
166 const EDITFORM_ID
= 'editform';
177 private $mContextTitle = null;
178 var $action = 'submit';
179 var $isConflict = false;
180 var $isCssJsSubpage = false;
181 var $isCssSubpage = false;
182 var $isJsSubpage = false;
183 var $isWrongCaseCssJsPage = false;
184 var $isNew = false; // new page or new section
185 var $deletedSinceEdit;
189 var $mTokenOk = false;
190 var $mTokenOkExceptSuffix = false;
191 var $mTriedSave = false;
192 var $incompleteForm = false;
194 var $kblength = false;
195 var $missingComment = false;
196 var $missingSummary = false;
197 var $allowBlankSummary = false;
200 #var $mPreviewTemplates;
208 * Has a summary been preset using GET parameter &summary= ?
211 var $hasPresetSummary = false;
213 var $mBaseRevision = false;
214 var $mShowSummaryField = true;
217 var $save = false, $preview = false, $diff = false;
218 var $minoredit = false, $watchthis = false, $recreate = false;
219 var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false;
220 var $edittime = '', $section = '', $sectiontitle = '', $starttime = '';
221 var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true;
222 var $content_model = null, $content_format = null;
224 # Placeholders for text injection by hooks (must be HTML)
225 # extensions should take care to _append_ to the present value
226 public $editFormPageTop = ''; // Before even the preview
227 public $editFormTextTop = '';
228 public $editFormTextBeforeContent = '';
229 public $editFormTextAfterWarn = '';
230 public $editFormTextAfterTools = '';
231 public $editFormTextBottom = '';
232 public $editFormTextAfterContent = '';
233 public $previewTextAfterContent = '';
234 public $mPreloadContent = null;
236 /* $didSave should be set to true whenever an article was succesfully altered. */
237 public $didSave = false;
238 public $undidRev = 0;
240 public $suppressIntro = false;
243 * @param $article Article
245 public function __construct( Article
$article ) {
246 $this->mArticle
= $article;
247 $this->mTitle
= $article->getTitle();
249 $this->content_model
= $this->mTitle
->getContentModel();
251 $handler = ContentHandler
::getForModelID( $this->content_model
);
252 $this->content_format
= $handler->getDefaultFormat(); #NOTE: should be overridden by format of actual revision
258 public function getArticle() {
259 return $this->mArticle
;
266 public function getTitle() {
267 return $this->mTitle
;
271 * Set the context Title object
273 * @param $title Title object or null
275 public function setContextTitle( $title ) {
276 $this->mContextTitle
= $title;
280 * Get the context title object.
281 * If not set, $wgTitle will be returned. This behavior might changed in
282 * the future to return $this->mTitle instead.
284 * @return Title object
286 public function getContextTitle() {
287 if ( is_null( $this->mContextTitle
) ) {
291 return $this->mContextTitle
;
300 * This is the function that gets called for "action=edit". It
301 * sets up various member variables, then passes execution to
302 * another function, usually showEditForm()
304 * The edit form is self-submitting, so that when things like
305 * preview and edit conflicts occur, we get the same form back
306 * with the extra stuff added. Only when the final submission
307 * is made and all is well do we actually save and redirect to
308 * the newly-edited page.
311 global $wgOut, $wgRequest, $wgUser;
312 // Allow extensions to modify/prevent this form or submission
313 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
317 wfProfileIn( __METHOD__
);
318 wfDebug( __METHOD__
. ": enter\n" );
320 // If they used redlink=1 and the page exists, redirect to the main article
321 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle
->exists() ) {
322 $wgOut->redirect( $this->mTitle
->getFullURL() );
323 wfProfileOut( __METHOD__
);
327 $this->importFormData( $wgRequest );
328 $this->firsttime
= false;
331 $this->livePreview();
332 wfProfileOut( __METHOD__
);
336 if ( wfReadOnly() && $this->save
) {
339 $this->preview
= true;
343 $this->formtype
= 'save';
344 } elseif ( $this->preview
) {
345 $this->formtype
= 'preview';
346 } elseif ( $this->diff
) {
347 $this->formtype
= 'diff';
348 } else { # First time through
349 $this->firsttime
= true;
350 if ( $this->previewOnOpen() ) {
351 $this->formtype
= 'preview';
353 $this->formtype
= 'initial';
357 $permErrors = $this->getEditPermissionErrors();
359 wfDebug( __METHOD__
. ": User can't edit\n" );
360 // Auto-block user's IP if the account was "hard" blocked
361 $wgUser->spreadAnyEditBlock();
363 $this->displayPermissionsError( $permErrors );
365 wfProfileOut( __METHOD__
);
369 wfProfileIn( __METHOD__
. "-business-end" );
371 $this->isConflict
= false;
372 // css / js subpages of user pages get a special treatment
373 $this->isCssJsSubpage
= $this->mTitle
->isCssJsSubpage();
374 $this->isCssSubpage
= $this->mTitle
->isCssSubpage();
375 $this->isJsSubpage
= $this->mTitle
->isJsSubpage();
376 $this->isWrongCaseCssJsPage
= $this->isWrongCaseCssJsPage();
377 $this->isNew
= !$this->mTitle
->exists() ||
$this->section
== 'new';
379 # Show applicable editing introductions
380 if ( $this->formtype
== 'initial' ||
$this->firsttime
) {
384 # Attempt submission here. This will check for edit conflicts,
385 # and redundantly check for locked database, blocked IPs, etc.
386 # that edit() already checked just in case someone tries to sneak
387 # in the back door with a hand-edited submission URL.
389 if ( 'save' == $this->formtype
) {
390 if ( !$this->attemptSave() ) {
391 wfProfileOut( __METHOD__
. "-business-end" );
392 wfProfileOut( __METHOD__
);
397 # First time through: get contents, set time for conflict
399 if ( 'initial' == $this->formtype ||
$this->firsttime
) {
400 if ( $this->initialiseForm() === false ) {
401 $this->noSuchSectionPage();
402 wfProfileOut( __METHOD__
. "-business-end" );
403 wfProfileOut( __METHOD__
);
406 if ( !$this->mTitle
->getArticleID() )
407 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1
, &$this->mTitle
) );
409 wfRunHooks( 'EditFormInitialText', array( $this ) );
412 $this->showEditForm();
413 wfProfileOut( __METHOD__
. "-business-end" );
414 wfProfileOut( __METHOD__
);
420 protected function getEditPermissionErrors() {
422 $permErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $wgUser );
423 # Can this title be created?
424 if ( !$this->mTitle
->exists() ) {
425 $permErrors = array_merge( $permErrors,
426 wfArrayDiff2( $this->mTitle
->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
428 # Ignore some permissions errors when a user is just previewing/viewing diffs
430 foreach ( $permErrors as $error ) {
431 if ( ( $this->preview ||
$this->diff
) &&
432 ( $error[0] == 'blockedtext' ||
$error[0] == 'autoblockedtext' ) )
437 $permErrors = wfArrayDiff2( $permErrors, $remove );
442 * Display a permissions error page, like OutputPage::showPermissionsErrorPage(),
443 * but with the following differences:
444 * - If redlink=1, the user will be redirected to the page
445 * - If there is content to display or the error occurs while either saving,
446 * previewing or showing the difference, it will be a
447 * "View source for ..." page displaying the source code after the error message.
450 * @param $permErrors Array of permissions errors, as returned by
451 * Title::getUserPermissionsErrors().
453 protected function displayPermissionsError( array $permErrors ) {
454 global $wgRequest, $wgOut;
456 if ( $wgRequest->getBool( 'redlink' ) ) {
457 // The edit page was reached via a red link.
458 // Redirect to the article page and let them click the edit tab if
459 // they really want a permission error.
460 $wgOut->redirect( $this->mTitle
->getFullUrl() );
464 $content = $this->getContentObject();
466 # Use the normal message if there's nothing to display
467 if ( $this->firsttime
&& $content->isEmpty() ) {
468 $action = $this->mTitle
->exists() ?
'edit' :
469 ( $this->mTitle
->isTalkPage() ?
'createtalk' : 'createpage' );
470 throw new PermissionsError( $action, $permErrors );
473 $wgOut->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) );
474 $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
475 $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) );
476 $wgOut->addHTML( "<hr />\n" );
478 # If the user made changes, preserve them when showing the markup
479 # (This happens when a user is blocked during edit, for instance)
480 if ( !$this->firsttime
) {
481 $text = $this->textbox1
;
482 $wgOut->addWikiMsg( 'viewyourtext' );
484 $text = $content->serialize( $this->content_format
);
485 $wgOut->addWikiMsg( 'viewsourcetext' );
488 $this->showTextbox( $text, 'wpTextbox1', array( 'readonly' ) );
490 $wgOut->addHTML( Html
::rawElement( 'div', array( 'class' => 'templatesUsed' ),
491 Linker
::formatTemplates( $this->getTemplates() ) ) );
493 if ( $this->mTitle
->exists() ) {
494 $wgOut->returnToMain( null, $this->mTitle
);
499 * Show a read-only error
500 * Parameters are the same as OutputPage:readOnlyPage()
501 * Redirect to the article page if redlink=1
502 * @deprecated in 1.19; use displayPermissionsError() instead
504 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
505 wfDeprecated( __METHOD__
, '1.19' );
507 global $wgRequest, $wgOut;
508 if ( $wgRequest->getBool( 'redlink' ) ) {
509 // The edit page was reached via a red link.
510 // Redirect to the article page and let them click the edit tab if
511 // they really want a permission error.
512 $wgOut->redirect( $this->mTitle
->getFullUrl() );
514 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
519 * Should we show a preview when the edit form is first shown?
523 protected function previewOnOpen() {
524 global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces;
525 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
526 // Explicit override from request
528 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
529 // Explicit override from request
531 } elseif ( $this->section
== 'new' ) {
532 // Nothing *to* preview for new sections
534 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null ||
$this->mTitle
->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
535 // Standard preference behaviour
537 } elseif ( !$this->mTitle
->exists() &&
538 isset( $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] ) &&
539 $wgPreviewOnOpenNamespaces[$this->mTitle
->getNamespace()] )
541 // Categories are special
549 * Checks whether the user entered a skin name in uppercase,
550 * e.g. "User:Example/Monobook.css" instead of "monobook.css"
554 protected function isWrongCaseCssJsPage() {
555 if ( $this->mTitle
->isCssJsSubpage() ) {
556 $name = $this->mTitle
->getSkinFromCssJsSubpage();
557 $skins = array_merge(
558 array_keys( Skin
::getSkinNames() ),
561 return !in_array( $name, $skins )
562 && in_array( strtolower( $name ), $skins );
569 * Does this EditPage class support section editing?
570 * This is used by EditPage subclasses to indicate their ui cannot handle section edits
574 protected function isSectionEditSupported() {
579 * This function collects the form data and uses it to populate various member variables.
580 * @param $request WebRequest
582 function importFormData( &$request ) {
583 global $wgLang, $wgUser;
585 wfProfileIn( __METHOD__
);
587 # Section edit can come from either the form or a link
588 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
590 if ( $request->wasPosted() ) {
591 # These fields need to be checked for encoding.
592 # Also remove trailing whitespace, but don't remove _initial_
593 # whitespace from the text boxes. This may be significant formatting.
594 $this->textbox1
= $this->safeUnicodeInput( $request, 'wpTextbox1' );
595 if ( !$request->getCheck( 'wpTextbox2' ) ) {
596 // Skip this if wpTextbox2 has input, it indicates that we came
597 // from a conflict page with raw page text, not a custom form
598 // modified by subclasses
599 wfProfileIn( get_class( $this ) . "::importContentFormData" );
600 $textbox1 = $this->importContentFormData( $request );
601 if ( isset( $textbox1 ) )
602 $this->textbox1
= $textbox1;
603 wfProfileOut( get_class( $this ) . "::importContentFormData" );
606 # Truncate for whole multibyte characters
607 $this->summary
= $wgLang->truncate( $request->getText( 'wpSummary' ), 255 );
609 # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
610 # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for
612 $this->summary
= preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary
);
614 # Treat sectiontitle the same way as summary.
615 # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is
616 # currently doing double duty as both edit summary and section title. Right now this
617 # is just to allow API edits to work around this limitation, but this should be
618 # incorporated into the actual edit form when EditPage is rewritten (Bugs 18654, 26312).
619 $this->sectiontitle
= $wgLang->truncate( $request->getText( 'wpSectionTitle' ), 255 );
620 $this->sectiontitle
= preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle
);
622 $this->edittime
= $request->getVal( 'wpEdittime' );
623 $this->starttime
= $request->getVal( 'wpStarttime' );
625 $this->scrolltop
= $request->getIntOrNull( 'wpScrolltop' );
627 if ( $this->textbox1
=== '' && $request->getVal( 'wpTextbox1' ) === null ) {
628 // wpTextbox1 field is missing, possibly due to being "too big"
629 // according to some filter rules such as Suhosin's setting for
630 // suhosin.request.max_value_length (d'oh)
631 $this->incompleteForm
= true;
633 // edittime should be one of our last fields; if it's missing,
634 // the submission probably broke somewhere in the middle.
635 $this->incompleteForm
= is_null( $this->edittime
);
637 if ( $this->incompleteForm
) {
638 # If the form is incomplete, force to preview.
639 wfDebug( __METHOD__
. ": Form data appears to be incomplete\n" );
640 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
641 $this->preview
= true;
643 /* Fallback for live preview */
644 $this->preview
= $request->getCheck( 'wpPreview' ) ||
$request->getCheck( 'wpLivePreview' );
645 $this->diff
= $request->getCheck( 'wpDiff' );
647 // Remember whether a save was requested, so we can indicate
648 // if we forced preview due to session failure.
649 $this->mTriedSave
= !$this->preview
;
651 if ( $this->tokenOk( $request ) ) {
652 # Some browsers will not report any submit button
653 # if the user hits enter in the comment box.
654 # The unmarked state will be assumed to be a save,
655 # if the form seems otherwise complete.
656 wfDebug( __METHOD__
. ": Passed token check.\n" );
657 } elseif ( $this->diff
) {
658 # Failed token check, but only requested "Show Changes".
659 wfDebug( __METHOD__
. ": Failed token check; Show Changes requested.\n" );
661 # Page might be a hack attempt posted from
662 # an external site. Preview instead of saving.
663 wfDebug( __METHOD__
. ": Failed token check; forcing preview\n" );
664 $this->preview
= true;
667 $this->save
= !$this->preview
&& !$this->diff
;
668 if ( !preg_match( '/^\d{14}$/', $this->edittime
) ) {
669 $this->edittime
= null;
672 if ( !preg_match( '/^\d{14}$/', $this->starttime
) ) {
673 $this->starttime
= null;
676 $this->recreate
= $request->getCheck( 'wpRecreate' );
678 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
679 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
681 # Don't force edit summaries when a user is editing their own user or talk page
682 if ( ( $this->mTitle
->mNamespace
== NS_USER ||
$this->mTitle
->mNamespace
== NS_USER_TALK
) &&
683 $this->mTitle
->getText() == $wgUser->getName() )
685 $this->allowBlankSummary
= true;
687 $this->allowBlankSummary
= $request->getBool( 'wpIgnoreBlankSummary' ) ||
!$wgUser->getOption( 'forceeditsummary' );
690 $this->autoSumm
= $request->getText( 'wpAutoSummary' );
692 # Not a posted form? Start with nothing.
693 wfDebug( __METHOD__
. ": Not a posted form.\n" );
694 $this->textbox1
= ''; #FIXME: track content object
696 $this->sectiontitle
= '';
697 $this->edittime
= '';
698 $this->starttime
= wfTimestampNow();
700 $this->preview
= false;
703 $this->minoredit
= false;
704 $this->watchthis
= $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters
705 $this->recreate
= false;
707 // When creating a new section, we can preload a section title by passing it as the
708 // preloadtitle parameter in the URL (Bug 13100)
709 if ( $this->section
== 'new' && $request->getVal( 'preloadtitle' ) ) {
710 $this->sectiontitle
= $request->getVal( 'preloadtitle' );
711 // Once wpSummary isn't being use for setting section titles, we should delete this.
712 $this->summary
= $request->getVal( 'preloadtitle' );
714 elseif ( $this->section
!= 'new' && $request->getVal( 'summary' ) ) {
715 $this->summary
= $request->getText( 'summary' );
716 if ( $this->summary
!== '' ) {
717 $this->hasPresetSummary
= true;
721 if ( $request->getVal( 'minor' ) ) {
722 $this->minoredit
= true;
726 $this->oldid
= $request->getInt( 'oldid' );
728 $this->bot
= $request->getBool( 'bot', true );
729 $this->nosummary
= $request->getBool( 'nosummary' );
731 $content_handler = ContentHandler
::getForTitle( $this->mTitle
);
732 $this->content_model
= $request->getText( 'model', $content_handler->getModelID() ); #may be overridden by revision
733 $this->content_format
= $request->getText( 'format', $content_handler->getDefaultFormat() ); #may be overridden by revision
735 #TODO: check if the desired model is allowed in this namespace, and if a transition from the page's current model to the new model is allowed
736 #TODO: check if the desired content model supports the given content format!
738 $this->live
= $request->getCheck( 'live' );
739 $this->editintro
= $request->getText( 'editintro',
740 // Custom edit intro for new sections
741 $this->section
=== 'new' ?
'MediaWiki:addsection-editintro' : '' );
743 // Allow extensions to modify form data
744 wfRunHooks( 'EditPage::importFormData', array( $this, $request ) );
746 wfProfileOut( __METHOD__
);
750 * Subpage overridable method for extracting the page content data from the
751 * posted form to be placed in $this->textbox1, if using customized input
752 * this method should be overrided and return the page text that will be used
753 * for saving, preview parsing and so on...
755 * @param $request WebRequest
757 protected function importContentFormData( &$request ) {
758 return; // Don't do anything, EditPage already extracted wpTextbox1
762 * Initialise form fields in the object
763 * Called on the first invocation, e.g. when a user clicks an edit link
764 * @return bool -- if the requested section is valid
766 function initialiseForm() {
768 $this->edittime
= $this->mArticle
->getTimestamp();
770 $content = $this->getContentObject( false ); #TODO: track content object?!
771 $this->textbox1
= $content->serialize( $this->content_format
);
773 // activate checkboxes if user wants them to be always active
774 # Sort out the "watch" checkbox
775 if ( $wgUser->getOption( 'watchdefault' ) ) {
777 $this->watchthis
= true;
778 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle
->exists() ) {
780 $this->watchthis
= true;
781 } elseif ( $wgUser->isWatched( $this->mTitle
) ) {
783 $this->watchthis
= true;
785 if ( $wgUser->getOption( 'minordefault' ) && !$this->isNew
) {
786 $this->minoredit
= true;
788 if ( $this->textbox1
=== false ) {
796 * Fetch initial editing page content.
798 * @param $def_text string
799 * @return mixed string on success, $def_text for invalid sections
801 * @deprecated since 1.WD
803 function getContent( $def_text = false ) { #FIXME: deprecated, replace usage!
804 wfDeprecated( __METHOD__
, '1.WD' );
806 if ( $def_text !== null && $def_text !== false && $def_text !== '' ) {
807 $def_content = ContentHandler
::makeContent( $def_text, $this->getTitle() );
809 $def_content = false;
812 $content = $this->getContentObject( $def_content );
814 return $content->serialize( $this->content_format
); #XXX: really use serialized form? use ContentHandler::getContentText() instead?
817 private function getContentObject( $def_content = null ) { #FIXME: use this!
818 global $wgOut, $wgRequest;
820 wfProfileIn( __METHOD__
);
824 // For message page not locally set, use the i18n message.
825 // For other non-existent articles, use preload text if any.
826 if ( !$this->mTitle
->exists() ||
$this->section
== 'new' ) {
827 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
&& $this->section
!= 'new' ) {
828 # If this is a system message, get the default text.
829 $msg = $this->mTitle
->getDefaultMessageText();
831 $content = ContentHandler
::makeContent( $msg, $this->mTitle
);
833 if ( $content === false ) {
834 # If requested, preload some text.
835 $preload = $wgRequest->getVal( 'preload',
836 // Custom preload text for new sections
837 $this->section
=== 'new' ?
'MediaWiki:addsection-preload' : '' );
839 $content = $this->getPreloadedContent( $preload );
841 // For existing pages, get text based on "undo" or section parameters.
843 if ( $this->section
!= '' ) {
844 // Get section edit text (returns $def_text for invalid sections)
845 $orig = $this->getOriginalContent();
846 $content = $orig ?
$orig->getSection( $this->section
) : null;
848 if ( !$content ) $content = $def_content;
850 $undoafter = $wgRequest->getInt( 'undoafter' );
851 $undo = $wgRequest->getInt( 'undo' );
853 if ( $undo > 0 && $undoafter > 0 ) {
854 if ( $undo < $undoafter ) {
855 # If they got undoafter and undo round the wrong way, switch them
856 list( $undo, $undoafter ) = array( $undoafter, $undo );
859 $undorev = Revision
::newFromId( $undo );
860 $oldrev = Revision
::newFromId( $undoafter );
862 # Sanity check, make sure it's the right page,
863 # the revisions exist and they were not deleted.
864 # Otherwise, $content will be left as-is.
865 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
866 $undorev->getPage() == $oldrev->getPage() &&
867 $undorev->getPage() == $this->mTitle
->getArticleID() &&
868 !$undorev->isDeleted( Revision
::DELETED_TEXT
) &&
869 !$oldrev->isDeleted( Revision
::DELETED_TEXT
) ) {
871 $content = $this->mArticle
->getUndoContent( $undorev, $oldrev );
873 if ( $content === false ) {
874 # Warn the user that something went wrong
875 $undoMsg = 'failure';
877 # Inform the user of our success and set an automatic edit summary
878 $undoMsg = 'success';
880 # If we just undid one rev, use an autosummary
881 $firstrev = $oldrev->getNext();
882 if ( $firstrev && $firstrev->getId() == $undo ) {
883 $undoSummary = wfMessage( 'undo-summary', $undo, $undorev->getUserText() )->inContentLanguage()->text() ;
884 if ( $this->summary
=== '' ) {
885 $this->summary
= $undoSummary;
887 $this->summary
= $undoSummary . wfMessage( 'colon-separator' )->inContentLanguage()->text() . $this->summary
;
889 $this->undidRev
= $undo;
891 $this->formtype
= 'diff';
894 // Failed basic sanity checks.
895 // Older revisions may have been removed since the link
896 // was created, or we may simply have got bogus input.
900 $class = ( $undoMsg == 'success' ?
'' : 'error ' ) . "mw-undo-{$undoMsg}";
901 $this->editFormPageTop
.= $wgOut->parse( "<div class=\"{$class}\">" .
902 wfMessage( 'undo-' . $undoMsg )->plain() . '</div>', true, /* interface */true );
905 if ( $content === false ) {
906 $content = $this->getOriginalContent();
911 wfProfileOut( __METHOD__
);
916 * Get the content of the wanted revision, without section extraction.
918 * The result of this function can be used to compare user's input with
919 * section replaced in its context (using WikiPage::replaceSection())
920 * to the original text of the edit.
922 * This difers from Article::getContent() that when a missing revision is
923 * encountered the result will be an empty string and not the
924 * 'missing-revision' message.
929 private function getOriginalContent() {
930 if ( $this->section
== 'new' ) {
931 return $this->getCurrentContent();
933 $revision = $this->mArticle
->getRevisionFetched();
934 if ( $revision === null ) {
935 if ( !$this->content_model
) $this->content_model
= $this->getTitle()->getContentModel();
936 $handler = ContentHandler
::getForModelID( $this->content_model
);
938 return $handler->makeEmptyContent();
940 $content = $revision->getContent();
945 * Get the current content of the page. This is basically similar to
946 * WikiPage::getContent( Revision::RAW ) except that when the page doesn't exist an empty
947 * content object is returned instead of null.
952 private function getCurrentContent() {
953 $rev = $this->mArticle
->getRevision();
954 $content = $rev ?
$rev->getContent( Revision
::RAW
) : null;
956 if ( $content === false ||
$content === null ) {
957 if ( !$this->content_model
) $this->content_model
= $this->getTitle()->getContentModel();
958 $handler = ContentHandler
::getForModelID( $this->content_model
);
960 return $handler->makeEmptyContent();
962 #FIXME: nasty side-effect!
963 $this->content_model
= $rev->getContentModel();
964 $this->content_format
= $rev->getContentFormat();
972 * Use this method before edit() to preload some text into the edit box
974 * @param $text string
975 * @deprecated since 1.WD
977 public function setPreloadedText( $text ) {
978 wfDeprecated( __METHOD__
, "1.WD" );
980 $content = ContentHandler
::makeContent( $text, $this->getTitle() );
982 $this->setPreloadedContent( $content );
986 * Use this method before edit() to preload some content into the edit box
988 * @param $content Content
992 public function setPreloadedContent( Content
$content ) {
993 $this->mPreloadedContent
= $content;
997 * Get the contents to be preloaded into the box, either set by
998 * an earlier setPreloadText() or by loading the given page.
1000 * @param $preload String: representing the title to preload from.
1004 * @deprecated since 1.WD, use getPreloadedContent() instead
1006 protected function getPreloadedText( $preload ) { #NOTE: B/C only, replace usage!
1007 wfDeprecated( __METHOD__
, "1.WD" );
1009 $content = $this->getPreloadedContent( $preload );
1010 $text = $content->serialize( $this->content_format
);
1011 #XXX: really use serialized form? use ContentHandler::getContentText() instead?!
1017 * Get the contents to be preloaded into the box, either set by
1018 * an earlier setPreloadText() or by loading the given page.
1020 * @param $preload String: representing the title to preload from.
1026 protected function getPreloadedContent( $preload ) { #@todo: use this!
1029 if ( !empty( $this->mPreloadContent
) ) {
1030 return $this->mPreloadContent
;
1033 $handler = ContentHandler
::getForTitle( $this->getTitle() );
1035 if ( $preload === '' ) {
1036 return $handler->makeEmptyContent();
1039 $title = Title
::newFromText( $preload );
1040 # Check for existence to avoid getting MediaWiki:Noarticletext
1041 if ( $title === null ||
!$title->exists() ||
!$title->userCan( 'read' ) ) {
1042 return $handler->makeEmptyContent();
1045 $page = WikiPage
::factory( $title );
1046 if ( $page->isRedirect() ) {
1047 $title = $page->getRedirectTarget();
1049 if ( $title === null ||
!$title->exists() ||
!$title->userCan( 'read' ) ) {
1050 return $handler->makeEmptyContent();
1052 $page = WikiPage
::factory( $title );
1055 $parserOptions = ParserOptions
::newFromUser( $wgUser );
1056 $content = $page->getContent( Revision
::RAW
);
1058 return $content->preloadTransform( $title, $parserOptions );
1062 * Make sure the form isn't faking a user's credentials.
1064 * @param $request WebRequest
1068 function tokenOk( &$request ) {
1070 $token = $request->getVal( 'wpEditToken' );
1071 $this->mTokenOk
= $wgUser->matchEditToken( $token );
1072 $this->mTokenOkExceptSuffix
= $wgUser->matchEditTokenNoSuffix( $token );
1073 return $this->mTokenOk
;
1077 * Attempt submission
1078 * @return bool false if output is done, true if the rest of the form should be displayed
1080 function attemptSave() {
1081 global $wgUser, $wgOut;
1083 $resultDetails = false;
1084 # Allow bots to exempt some edits from bot flagging
1085 $bot = $wgUser->isAllowed( 'bot' ) && $this->bot
;
1086 $status = $this->internalAttemptSave( $resultDetails, $bot );
1087 // FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
1088 if ( $status->value
== self
::AS_SUCCESS_UPDATE ||
$status->value
== self
::AS_SUCCESS_NEW_ARTICLE
) {
1089 $this->didSave
= true;
1092 switch ( $status->value
) {
1093 case self
::AS_HOOK_ERROR_EXPECTED
:
1094 case self
::AS_CONTENT_TOO_BIG
:
1095 case self
::AS_ARTICLE_WAS_DELETED
:
1096 case self
::AS_CONFLICT_DETECTED
:
1097 case self
::AS_SUMMARY_NEEDED
:
1098 case self
::AS_TEXTBOX_EMPTY
:
1099 case self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
:
1103 case self
::AS_HOOK_ERROR
:
1106 case self
::AS_PARSE_ERROR
:
1107 $wgOut->addWikiText( '<div class="error">' . $status->getWikiText() . '</div>');
1108 #FIXME: cause editform to be shown again, not just an error!
1111 case self
::AS_SUCCESS_NEW_ARTICLE
:
1112 $query = $resultDetails['redirect'] ?
'redirect=no' : '';
1113 $anchor = isset ( $resultDetails['sectionanchor'] ) ?
$resultDetails['sectionanchor'] : '';
1114 $wgOut->redirect( $this->mTitle
->getFullURL( $query ) . $anchor );
1117 case self
::AS_SUCCESS_UPDATE
:
1119 $sectionanchor = $resultDetails['sectionanchor'];
1121 // Give extensions a chance to modify URL query on update
1122 wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this->mArticle
, &$sectionanchor, &$extraQuery ) );
1124 if ( $resultDetails['redirect'] ) {
1125 if ( $extraQuery == '' ) {
1126 $extraQuery = 'redirect=no';
1128 $extraQuery = 'redirect=no&' . $extraQuery;
1131 $wgOut->redirect( $this->mTitle
->getFullURL( $extraQuery ) . $sectionanchor );
1134 case self
::AS_BLANK_ARTICLE
:
1135 $wgOut->redirect( $this->getContextTitle()->getFullURL() );
1138 case self
::AS_SPAM_ERROR
:
1139 $this->spamPageWithContent( $resultDetails['spam'] );
1142 case self
::AS_BLOCKED_PAGE_FOR_USER
:
1143 throw new UserBlockedError( $wgUser->getBlock() );
1145 case self
::AS_IMAGE_REDIRECT_ANON
:
1146 case self
::AS_IMAGE_REDIRECT_LOGGED
:
1147 throw new PermissionsError( 'upload' );
1149 case self
::AS_READ_ONLY_PAGE_ANON
:
1150 case self
::AS_READ_ONLY_PAGE_LOGGED
:
1151 throw new PermissionsError( 'edit' );
1153 case self
::AS_READ_ONLY_PAGE
:
1154 throw new ReadOnlyError
;
1156 case self
::AS_RATE_LIMITED
:
1157 throw new ThrottledError();
1159 case self
::AS_NO_CREATE_PERMISSION
:
1160 $permission = $this->mTitle
->isTalkPage() ?
'createtalk' : 'createpage';
1161 throw new PermissionsError( $permission );
1164 // We don't recognize $status->value. The only way that can happen
1165 // is if an extension hook aborted from inside ArticleSave.
1166 // Render the status object into $this->hookError
1167 // FIXME this sucks, we should just use the Status object throughout
1168 $this->hookError
= '<div class="error">' . $status->getWikitext() .
1175 * Attempt submission (no UI)
1180 * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
1182 * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
1183 * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
1184 * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
1186 function internalAttemptSave( &$result, $bot = false ) {
1187 global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize;
1189 $status = Status
::newGood();
1191 wfProfileIn( __METHOD__
);
1192 wfProfileIn( __METHOD__
. '-checks' );
1194 if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
1195 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
1196 $status->fatal( 'hookaborted' );
1197 $status->value
= self
::AS_HOOK_ERROR
;
1198 wfProfileOut( __METHOD__
. '-checks' );
1199 wfProfileOut( __METHOD__
);
1203 # Check image redirect
1204 if ( $this->mTitle
->getNamespace() == NS_FILE
&&
1205 Title
::newFromRedirect( $this->textbox1
) instanceof Title
&& #FIXME: use content handler to check for redirect
1206 !$wgUser->isAllowed( 'upload' ) ) {
1207 $code = $wgUser->isAnon() ? self
::AS_IMAGE_REDIRECT_ANON
: self
::AS_IMAGE_REDIRECT_LOGGED
;
1208 $status->setResult( false, $code );
1210 wfProfileOut( __METHOD__
. '-checks' );
1211 wfProfileOut( __METHOD__
);
1217 $match = self
::matchSummarySpamRegex( $this->summary
);
1218 if ( $match === false ) {
1219 $match = self
::matchSpamRegex( $this->textbox1
);
1221 if ( $match !== false ) {
1222 $result['spam'] = $match;
1223 $ip = $wgRequest->getIP();
1224 $pdbk = $this->mTitle
->getPrefixedDBkey();
1225 $match = str_replace( "\n", '', $match );
1226 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
1227 $status->fatal( 'spamprotectionmatch', $match );
1228 $status->value
= self
::AS_SPAM_ERROR
;
1229 wfProfileOut( __METHOD__
. '-checks' );
1230 wfProfileOut( __METHOD__
);
1233 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1
, $this->section
, &$this->hookError
, $this->summary
) ) ) {
1234 # Error messages etc. could be handled within the hook...
1235 $status->fatal( 'hookaborted' );
1236 $status->value
= self
::AS_HOOK_ERROR
;
1237 wfProfileOut( __METHOD__
. '-checks' );
1238 wfProfileOut( __METHOD__
);
1240 } elseif ( $this->hookError
!= '' ) {
1241 # ...or the hook could be expecting us to produce an error
1242 $status->fatal( 'hookaborted' );
1243 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1244 wfProfileOut( __METHOD__
. '-checks' );
1245 wfProfileOut( __METHOD__
);
1249 if ( $wgUser->isBlockedFrom( $this->mTitle
, false ) ) {
1250 // Auto-block user's IP if the account was "hard" blocked
1251 $wgUser->spreadAnyEditBlock();
1252 # Check block state against master, thus 'false'.
1253 $status->setResult( false, self
::AS_BLOCKED_PAGE_FOR_USER
);
1254 wfProfileOut( __METHOD__
. '-checks' );
1255 wfProfileOut( __METHOD__
);
1259 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
1260 if ( $this->kblength
> $wgMaxArticleSize ) {
1261 // Error will be displayed by showEditForm()
1262 $this->tooBig
= true;
1263 $status->setResult( false, self
::AS_CONTENT_TOO_BIG
);
1264 wfProfileOut( __METHOD__
. '-checks' );
1265 wfProfileOut( __METHOD__
);
1269 if ( !$wgUser->isAllowed( 'edit' ) ) {
1270 if ( $wgUser->isAnon() ) {
1271 $status->setResult( false, self
::AS_READ_ONLY_PAGE_ANON
);
1272 wfProfileOut( __METHOD__
. '-checks' );
1273 wfProfileOut( __METHOD__
);
1276 $status->fatal( 'readonlytext' );
1277 $status->value
= self
::AS_READ_ONLY_PAGE_LOGGED
;
1278 wfProfileOut( __METHOD__
. '-checks' );
1279 wfProfileOut( __METHOD__
);
1284 if ( wfReadOnly() ) {
1285 $status->fatal( 'readonlytext' );
1286 $status->value
= self
::AS_READ_ONLY_PAGE
;
1287 wfProfileOut( __METHOD__
. '-checks' );
1288 wfProfileOut( __METHOD__
);
1291 if ( $wgUser->pingLimiter() ) {
1292 $status->fatal( 'actionthrottledtext' );
1293 $status->value
= self
::AS_RATE_LIMITED
;
1294 wfProfileOut( __METHOD__
. '-checks' );
1295 wfProfileOut( __METHOD__
);
1299 # If the article has been deleted while editing, don't save it without
1301 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate
) {
1302 $status->setResult( false, self
::AS_ARTICLE_WAS_DELETED
);
1303 wfProfileOut( __METHOD__
. '-checks' );
1304 wfProfileOut( __METHOD__
);
1308 wfProfileOut( __METHOD__
. '-checks' );
1310 # Load the page data from the master. If anything changes in the meantime,
1311 # we detect it by using page_latest like a token in a 1 try compare-and-swap.
1312 $this->mArticle
->loadPageData( 'fromdbmaster' );
1313 $new = !$this->mArticle
->exists();
1317 // Late check for create permission, just in case *PARANOIA*
1318 if ( !$this->mTitle
->userCan( 'create' ) ) {
1319 $status->fatal( 'nocreatetext' );
1320 $status->value
= self
::AS_NO_CREATE_PERMISSION
;
1321 wfDebug( __METHOD__
. ": no create permission\n" );
1322 wfProfileOut( __METHOD__
);
1326 # Don't save a new article if it's blank.
1327 if ( $this->textbox1
== '' ) {
1328 $status->setResult( false, self
::AS_BLANK_ARTICLE
);
1329 wfProfileOut( __METHOD__
);
1333 // Run post-section-merge edit filter
1334 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1
, &$this->hookError
, $this->summary
) ) ) {
1335 # Error messages etc. could be handled within the hook...
1336 $status->fatal( 'hookaborted' );
1337 $status->value
= self
::AS_HOOK_ERROR
;
1338 wfProfileOut( __METHOD__
);
1340 } elseif ( $this->hookError
!= '' ) {
1341 # ...or the hook could be expecting us to produce an error
1342 $status->fatal( 'hookaborted' );
1343 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1344 wfProfileOut( __METHOD__
);
1348 $content = ContentHandler
::makeContent( $this->textbox1
, $this->getTitle(),
1349 $this->content_model
, $this->content_format
);
1351 $result['sectionanchor'] = '';
1352 if ( $this->section
== 'new' ) {
1353 if ( $this->sectiontitle
!== '' ) {
1354 // Insert the section title above the content.
1355 $content = $content->addSectionHeader( $this->sectiontitle
);
1357 // Jump to the new section
1358 $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle
);
1360 // If no edit summary was specified, create one automatically from the section
1361 // title and have it link to the new section. Otherwise, respect the summary as
1363 if ( $this->summary
=== '' ) {
1364 $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle
);
1365 $this->summary
= wfMessage( 'newsectionsummary', $cleanSectionTitle )->inContentLanguage()->text() ;
1367 } elseif ( $this->summary
!== '' ) {
1368 // Insert the section title above the content.
1369 $content = $content->addSectionHeader( $this->sectiontitle
);
1371 // Jump to the new section
1372 $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary
);
1374 // Create a link to the new section from the edit summary.
1375 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1376 $this->summary
= wfMessage( 'newsectionsummary', $cleanSummary )->inContentLanguage()->text() ;
1380 $status->value
= self
::AS_SUCCESS_NEW_ARTICLE
;
1384 # Article exists. Check for edit conflict.
1386 $this->mArticle
->clear(); # Force reload of dates, etc.
1387 $timestamp = $this->mArticle
->getTimestamp();
1389 wfDebug( "timestamp: {$timestamp}, edittime: {$this->edittime}\n" );
1391 if ( $timestamp != $this->edittime
) {
1392 $this->isConflict
= true;
1393 if ( $this->section
== 'new' ) {
1394 if ( $this->mArticle
->getUserText() == $wgUser->getName() &&
1395 $this->mArticle
->getComment() == $this->summary
) {
1396 // Probably a duplicate submission of a new comment.
1397 // This can happen when squid resends a request after
1398 // a timeout but the first one actually went through.
1399 wfDebug( __METHOD__
. ": duplicate new section submission; trigger edit conflict!\n" );
1401 // New comment; suppress conflict.
1402 $this->isConflict
= false;
1403 wfDebug( __METHOD__
. ": conflict suppressed; new section\n" );
1405 } elseif ( $this->section
== '' && $this->userWasLastToEdit( $wgUser->getId(), $this->edittime
) ) {
1406 # Suppress edit conflict with self, except for section edits where merging is required.
1407 wfDebug( __METHOD__
. ": Suppressing edit conflict, same user.\n" );
1408 $this->isConflict
= false;
1412 // If sectiontitle is set, use it, otherwise use the summary as the section title (for
1413 // backwards compatibility with old forms/bots).
1414 if ( $this->sectiontitle
!== '' ) {
1415 $sectionTitle = $this->sectiontitle
;
1417 $sectionTitle = $this->summary
;
1420 $textbox_content = ContentHandler
::makeContent( $this->textbox1
, $this->getTitle(),
1421 $this->content_model
, $this->content_format
);
1424 if ( $this->isConflict
) {
1425 wfDebug( __METHOD__
. ": conflict! getting section '{$this->section}' for time '{$this->edittime}'"
1426 . " (article time '{$timestamp}')\n" );
1428 $content = $this->mArticle
->replaceSectionContent( $this->section
, $textbox_content,
1429 $sectionTitle, $this->edittime
);
1431 wfDebug( __METHOD__
. ": getting section '{$this->section}'\n" );
1432 $content = $this->mArticle
->replaceSectionContent( $this->section
, $textbox_content, $sectionTitle );
1435 if ( is_null( $content ) ) {
1436 wfDebug( __METHOD__
. ": activating conflict; section replace failed.\n" );
1437 $this->isConflict
= true;
1438 $content = $textbox_content; // do not try to merge here!
1439 } elseif ( $this->isConflict
) {
1441 if ( $this->mergeChangesIntoContent( $textbox_content ) ) {
1442 // Successful merge! Maybe we should tell the user the good news?
1443 $this->isConflict
= false;
1444 $content = $textbox_content;
1445 wfDebug( __METHOD__
. ": Suppressing edit conflict, successful merge.\n" );
1447 $this->section
= '';
1448 #$this->textbox1 = $text; #redundant, nothing to do here?
1449 wfDebug( __METHOD__
. ": Keeping edit conflict, failed merge.\n" );
1453 if ( $this->isConflict
) {
1454 $status->setResult( false, self
::AS_CONFLICT_DETECTED
);
1455 wfProfileOut( __METHOD__
);
1459 // Run post-section-merge edit filter
1460 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $content->serialize( $this->content_format
), &$this->hookError
, $this->summary
) )
1461 ||
!wfRunHooks( 'EditFilterMergedContent', array( $this, $content, &$this->hookError
, $this->summary
) ) ) {
1462 # Error messages etc. could be handled within the hook...
1463 $status->fatal( 'hookaborted' );
1464 $status->value
= self
::AS_HOOK_ERROR
;
1465 wfProfileOut( __METHOD__
);
1467 } elseif ( $this->hookError
!= '' ) {
1468 # ...or the hook could be expecting us to produce an error
1469 $status->fatal( 'hookaborted' );
1470 $status->value
= self
::AS_HOOK_ERROR_EXPECTED
;
1471 wfProfileOut( __METHOD__
);
1475 $content = ContentHandler
::makeContent( $this->textbox1
, $this->getTitle(),
1476 $this->content_model
, $this->content_format
);
1478 # Handle the user preference to force summaries here, but not for null edits
1479 if ( $this->section
!= 'new' && !$this->allowBlankSummary
1480 && !$content->equals( $this->getOriginalContent() )
1481 && !$content->isRedirect() ) # check if it's not a redirect
1483 if ( md5( $this->summary
) == $this->autoSumm
) {
1484 $this->missingSummary
= true;
1485 $status->fatal( 'missingsummary' );
1486 $status->value
= self
::AS_SUMMARY_NEEDED
;
1487 wfProfileOut( __METHOD__
);
1492 # And a similar thing for new sections
1493 if ( $this->section
== 'new' && !$this->allowBlankSummary
) {
1494 if ( trim( $this->summary
) == '' ) {
1495 $this->missingSummary
= true;
1496 $status->fatal( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
1497 $status->value
= self
::AS_SUMMARY_NEEDED
;
1498 wfProfileOut( __METHOD__
);
1504 wfProfileIn( __METHOD__
. '-sectionanchor' );
1505 $sectionanchor = '';
1506 if ( $this->section
== 'new' ) {
1507 if ( $this->textbox1
== '' ) {
1508 $this->missingComment
= true;
1509 $status->fatal( 'missingcommenttext' );
1510 $status->value
= self
::AS_TEXTBOX_EMPTY
;
1511 wfProfileOut( __METHOD__
. '-sectionanchor' );
1512 wfProfileOut( __METHOD__
);
1515 if ( $this->sectiontitle
!== '' ) {
1516 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle
);
1517 // If no edit summary was specified, create one automatically from the section
1518 // title and have it link to the new section. Otherwise, respect the summary as
1520 if ( $this->summary
=== '' ) {
1521 $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle
);
1522 $this->summary
= wfMessage( 'newsectionsummary', $cleanSectionTitle )->inContentLanguage()->text() ;
1524 } elseif ( $this->summary
!== '' ) {
1525 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary
);
1526 # This is a new section, so create a link to the new section
1527 # in the revision summary.
1528 $cleanSummary = $wgParser->stripSectionName( $this->summary
);
1529 $this->summary
= wfMessage( 'newsectionsummary', $cleanSummary )->inContentLanguage()->text() ;
1531 } elseif ( $this->section
!= '' ) {
1532 # Try to get a section anchor from the section source, redirect to edited section if header found
1533 # XXX: might be better to integrate this into Article::replaceSection
1534 # for duplicate heading checking and maybe parsing
1535 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
1536 # we can't deal with anchors, includes, html etc in the header for now,
1537 # headline would need to be parsed to improve this
1538 if ( $hasmatch && strlen( $matches[2] ) > 0 ) {
1539 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $matches[2] );
1542 $result['sectionanchor'] = $sectionanchor;
1543 wfProfileOut( __METHOD__
. '-sectionanchor' );
1545 // Save errors may fall down to the edit form, but we've now
1546 // merged the section into full text. Clear the section field
1547 // so that later submission of conflict forms won't try to
1548 // replace that into a duplicated mess.
1549 $this->textbox1
= $content->serialize( $this->content_format
);
1550 $this->section
= '';
1552 $status->value
= self
::AS_SUCCESS_UPDATE
;
1555 // Check for length errors again now that the section is merged in
1556 $this->kblength
= (int)( strlen( $content->serialize( $this->content_format
) ) / 1024 );
1557 if ( $this->kblength
> $wgMaxArticleSize ) {
1558 $this->tooBig
= true;
1559 $status->setResult( false, self
::AS_MAX_ARTICLE_SIZE_EXCEEDED
);
1560 wfProfileOut( __METHOD__
);
1564 $flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1565 ( $new ? EDIT_NEW
: EDIT_UPDATE
) |
1566 ( ( $this->minoredit
&& !$this->isNew
) ? EDIT_MINOR
: 0 ) |
1567 ( $bot ? EDIT_FORCE_BOT
: 0 );
1569 $doEditStatus = $this->mArticle
->doEditContent( $content, $this->summary
, $flags,
1570 false, null, $this->content_format
);
1572 if ( $doEditStatus->isOK() ) {
1573 $result['redirect'] = $content->isRedirect();
1574 $this->commitWatch();
1575 wfProfileOut( __METHOD__
);
1578 // Failure from doEdit()
1579 // Show the edit conflict page for certain recognized errors from doEdit(),
1580 // but don't show it for errors from extension hooks
1581 $errors = $doEditStatus->getErrorsArray();
1582 if ( in_array( $errors[0][0], array( 'edit-gone-missing', 'edit-conflict',
1583 'edit-already-exists' ) ) )
1585 $this->isConflict
= true;
1586 // Destroys data doEdit() put in $status->value but who cares
1587 $doEditStatus->value
= self
::AS_END
;
1589 wfProfileOut( __METHOD__
);
1590 return $doEditStatus;
1592 } catch (MWContentSerializationException
$ex) {
1593 $status->fatal( 'content-failed-to-parse', $this->content_model
, $this->content_format
, $ex->getMessage() );
1594 $status->value
= self
::AS_PARSE_ERROR
;
1595 wfProfileOut( __METHOD__
);
1601 * Commit the change of watch status
1603 protected function commitWatch() {
1605 if ( $wgUser->isLoggedIn() && $this->watchthis
!= $wgUser->isWatched( $this->mTitle
) ) {
1606 $dbw = wfGetDB( DB_MASTER
);
1607 $dbw->begin( __METHOD__
);
1608 if ( $this->watchthis
) {
1609 WatchAction
::doWatch( $this->mTitle
, $wgUser );
1611 WatchAction
::doUnwatch( $this->mTitle
, $wgUser );
1613 $dbw->commit( __METHOD__
);
1618 * Check if no edits were made by other users since
1619 * the time a user started editing the page. Limit to
1620 * 50 revisions for the sake of performance.
1623 * @param $edittime string
1627 protected function userWasLastToEdit( $id, $edittime ) {
1628 if ( !$id ) return false;
1629 $dbw = wfGetDB( DB_MASTER
);
1630 $res = $dbw->select( 'revision',
1633 'rev_page' => $this->mTitle
->getArticleID(),
1634 'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $edittime ) )
1637 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1638 foreach ( $res as $row ) {
1639 if ( $row->rev_user
!= $id ) {
1650 * @param $editText string
1653 * @deprecated since 1.WD, use mergeChangesIntoContent() instead
1655 function mergeChangesInto( &$editText ){
1656 wfDebug( __METHOD__
, "1.WD" );
1658 $editContent = ContentHandler
::makeContent( $editText, $this->getTitle(),
1659 $this->content_model
, $this->content_format
);
1661 $ok = $this->mergeChangesIntoContent( $editContent );
1664 $editText = $editContent->serialize( $this->content_format
); #XXX: really serialize?!
1675 * @parma $editText string
1680 private function mergeChangesIntoContent( &$editContent ){
1681 wfProfileIn( __METHOD__
);
1683 $db = wfGetDB( DB_MASTER
);
1685 // This is the revision the editor started from
1686 $baseRevision = $this->getBaseRevision();
1687 if ( is_null( $baseRevision ) ) {
1688 wfProfileOut( __METHOD__
);
1691 $baseContent = $baseRevision->getContent();
1693 // The current state, we want to merge updates into it
1694 $currentRevision = Revision
::loadFromTitle( $db, $this->mTitle
);
1695 if ( is_null( $currentRevision ) ) {
1696 wfProfileOut( __METHOD__
);
1699 $currentContent = $currentRevision->getContent();
1701 $handler = ContentHandler
::getForModelID( $baseContent->getModel() );
1703 $result = $handler->merge3( $baseContent, $editContent, $currentContent );
1706 $editContent = $result;
1707 wfProfileOut( __METHOD__
);
1710 wfProfileOut( __METHOD__
);
1718 function getBaseRevision() {
1719 if ( !$this->mBaseRevision
) {
1720 $db = wfGetDB( DB_MASTER
);
1721 $baseRevision = Revision
::loadFromTimestamp(
1722 $db, $this->mTitle
, $this->edittime
);
1723 return $this->mBaseRevision
= $baseRevision;
1725 return $this->mBaseRevision
;
1730 * Check given input text against $wgSpamRegex, and return the text of the first match.
1732 * @param $text string
1734 * @return string|bool matching string or false
1736 public static function matchSpamRegex( $text ) {
1737 global $wgSpamRegex;
1738 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1739 $regexes = (array)$wgSpamRegex;
1740 return self
::matchSpamRegexInternal( $text, $regexes );
1744 * Check given input text against $wgSpamRegex, and return the text of the first match.
1746 * @param $text string
1748 * @return string|bool matching string or false
1750 public static function matchSummarySpamRegex( $text ) {
1751 global $wgSummarySpamRegex;
1752 $regexes = (array)$wgSummarySpamRegex;
1753 return self
::matchSpamRegexInternal( $text, $regexes );
1757 * @param $text string
1758 * @param $regexes array
1759 * @return bool|string
1761 protected static function matchSpamRegexInternal( $text, $regexes ) {
1762 foreach ( $regexes as $regex ) {
1764 if ( preg_match( $regex, $text, $matches ) ) {
1771 function setHeaders() {
1772 global $wgOut, $wgUser;
1774 $wgOut->addModules( 'mediawiki.action.edit' );
1776 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
1777 $wgOut->addModules( 'mediawiki.legacy.preview' );
1779 // Bug #19334: textarea jumps when editing articles in IE8
1780 $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
1782 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1784 # Enabled article-related sidebar, toplinks, etc.
1785 $wgOut->setArticleRelated( true );
1787 $contextTitle = $this->getContextTitle();
1788 if ( $this->isConflict
) {
1789 $msg = 'editconflict';
1790 } elseif ( $contextTitle->exists() && $this->section
!= '' ) {
1791 $msg = $this->section
== 'new' ?
'editingcomment' : 'editingsection';
1793 $msg = $contextTitle->exists() ||
( $contextTitle->getNamespace() == NS_MEDIAWIKI
&& $contextTitle->getDefaultMessageText() !== false ) ?
1794 'editing' : 'creating';
1796 # Use the title defined by DISPLAYTITLE magic word when present
1797 $displayTitle = isset( $this->mParserOutput
) ?
$this->mParserOutput
->getDisplayTitle() : false;
1798 if ( $displayTitle === false ) {
1799 $displayTitle = $contextTitle->getPrefixedText();
1801 $wgOut->setPageTitle( wfMessage( $msg, $displayTitle ) );
1805 * Show all applicable editing introductions
1807 protected function showIntro() {
1808 global $wgOut, $wgUser;
1809 if ( $this->suppressIntro
) {
1813 $namespace = $this->mTitle
->getNamespace();
1815 if ( $namespace == NS_MEDIAWIKI
) {
1816 # Show a warning if editing an interface message
1817 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1\n</div>", 'editinginterface' );
1818 } else if( $namespace == NS_FILE
) {
1819 # Show a hint to shared repo
1820 $file = wfFindFile( $this->mTitle
);
1821 if( $file && !$file->isLocal() ) {
1822 $descUrl = $file->getDescriptionUrl();
1823 # there must be a description url to show a hint to shared repo
1825 if( !$this->mTitle
->exists() ) {
1826 $wgOut->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-create\">\n$1\n</div>", array (
1827 'sharedupload-desc-create', $file->getRepo()->getDisplayName(), $descUrl
1830 $wgOut->wrapWikiMsg( "<div class=\"mw-sharedupload-desc-edit\">\n$1\n</div>", array(
1831 'sharedupload-desc-edit', $file->getRepo()->getDisplayName(), $descUrl
1838 # Show a warning message when someone creates/edits a user (talk) page but the user does not exist
1839 # Show log extract when the user is currently blocked
1840 if ( $namespace == NS_USER ||
$namespace == NS_USER_TALK
) {
1841 $parts = explode( '/', $this->mTitle
->getText(), 2 );
1842 $username = $parts[0];
1843 $user = User
::newFromName( $username, false /* allow IP users*/ );
1844 $ip = User
::isIP( $username );
1845 if ( !( $user && $user->isLoggedIn() ) && !$ip ) { # User does not exist
1846 $wgOut->wrapWikiMsg( "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
1847 array( 'userpage-userdoesnotexist', wfEscapeWikiText( $username ) ) );
1848 } elseif ( $user->isBlocked() ) { # Show log extract if the user is currently blocked
1849 LogEventsList
::showLogExtract(
1852 $user->getUserPage(),
1856 'showIfEmpty' => false,
1858 'blocked-notice-logextract',
1859 $user->getName() # Support GENDER in notice
1865 # Try to add a custom edit intro, or use the standard one if this is not possible.
1866 if ( !$this->showCustomIntro() && !$this->mTitle
->exists() ) {
1867 if ( $wgUser->isLoggedIn() ) {
1868 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletext\">\n$1\n</div>", 'newarticletext' );
1870 $wgOut->wrapWikiMsg( "<div class=\"mw-newarticletextanon\">\n$1\n</div>", 'newarticletextanon' );
1873 # Give a notice if the user is editing a deleted/moved page...
1874 if ( !$this->mTitle
->exists() ) {
1875 LogEventsList
::showLogExtract( $wgOut, array( 'delete', 'move' ), $this->mTitle
,
1876 '', array( 'lim' => 10,
1877 'conds' => array( "log_action != 'revision'" ),
1878 'showIfEmpty' => false,
1879 'msgKey' => array( 'recreate-moveddeleted-warn' ) )
1885 * Attempt to show a custom editing introduction, if supplied
1889 protected function showCustomIntro() {
1890 if ( $this->editintro
) {
1891 $title = Title
::newFromText( $this->editintro
);
1892 if ( $title instanceof Title
&& $title->exists() && $title->userCan( 'read' ) ) {
1894 // Added using template syntax, to take <noinclude>'s into account.
1895 $wgOut->addWikiTextTitleTidy( '{{:' . $title->getFullText() . '}}', $this->mTitle
);
1906 * Send the edit form and related headers to $wgOut
1907 * @param $formCallback Callback that takes an OutputPage parameter; will be called
1908 * during form output near the top, for captchas and the like.
1910 function showEditForm( $formCallback = null ) {
1911 global $wgOut, $wgUser;
1913 wfProfileIn( __METHOD__
);
1915 # need to parse the preview early so that we know which templates are used,
1916 # otherwise users with "show preview after edit box" will get a blank list
1917 # we parse this near the beginning so that setHeaders can do the title
1918 # setting work instead of leaving it in getPreviewText
1919 $previewOutput = '';
1920 if ( $this->formtype
== 'preview' ) {
1921 $previewOutput = $this->getPreviewText();
1924 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this, &$wgOut ) );
1926 $this->setHeaders();
1928 if ( $this->showHeader() === false ) {
1929 wfProfileOut( __METHOD__
);
1933 $wgOut->addHTML( $this->editFormPageTop
);
1935 if ( $wgUser->getOption( 'previewontop' ) ) {
1936 $this->displayPreviewArea( $previewOutput, true );
1939 $wgOut->addHTML( $this->editFormTextTop
);
1941 $showToolbar = true;
1942 if ( $this->wasDeletedSinceLastEdit() ) {
1943 if ( $this->formtype
== 'save' ) {
1944 // Hide the toolbar and edit area, user can click preview to get it back
1945 // Add an confirmation checkbox and explanation.
1946 $showToolbar = false;
1948 $wgOut->wrapWikiMsg( "<div class='error mw-deleted-while-editing'>\n$1\n</div>",
1949 'deletedwhileediting' );
1953 #FIXME: add EditForm plugin interface and use it here! #FIXME: search for textarea1 and textares2, and allow EditForm to override all uses.
1954 $wgOut->addHTML( Html
::openElement( 'form', array( 'id' => self
::EDITFORM_ID
, 'name' => self
::EDITFORM_ID
,
1955 'method' => 'post', 'action' => $this->getActionURL( $this->getContextTitle() ),
1956 'enctype' => 'multipart/form-data' ) ) );
1958 if ( is_callable( $formCallback ) ) {
1959 call_user_func_array( $formCallback, array( &$wgOut ) );
1962 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1964 // Put these up at the top to ensure they aren't lost on early form submission
1965 $this->showFormBeforeText();
1967 if ( $this->wasDeletedSinceLastEdit() && 'save' == $this->formtype
) {
1968 $username = $this->lastDelete
->user_name
;
1969 $comment = $this->lastDelete
->log_comment
;
1971 // It is better to not parse the comment at all than to have templates expanded in the middle
1972 // TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
1973 $key = $comment === ''
1974 ?
'confirmrecreate-noreason'
1975 : 'confirmrecreate';
1977 '<div class="mw-confirm-recreate">' .
1978 wfMessage( $key, $username, "<nowiki>$comment</nowiki>" )->parse() .
1979 Xml
::checkLabel( wfMessage( 'recreate' )->text() , 'wpRecreate', 'wpRecreate', false,
1980 array( 'title' => Linker
::titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
1986 # When the summary is hidden, also hide them on preview/show changes
1987 if( $this->nosummary
) {
1988 $wgOut->addHTML( Html
::hidden( 'nosummary', true ) );
1991 # If a blank edit summary was previously provided, and the appropriate
1992 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1993 # user being bounced back more than once in the event that a summary
1996 # For a bit more sophisticated detection of blank summaries, hash the
1997 # automatic one and pass that in the hidden field wpAutoSummary.
1998 if ( $this->missingSummary ||
( $this->section
== 'new' && $this->nosummary
) ) {
1999 $wgOut->addHTML( Html
::hidden( 'wpIgnoreBlankSummary', true ) );
2002 if ( $this->undidRev
) {
2003 $wgOut->addHTML( Html
::hidden( 'wpUndidRevision', $this->undidRev
) );
2006 if ( $this->hasPresetSummary
) {
2007 // If a summary has been preset using &summary= we dont want to prompt for
2008 // a different summary. Only prompt for a summary if the summary is blanked.
2010 $this->autoSumm
= md5( '' );
2013 $autosumm = $this->autoSumm ?
$this->autoSumm
: md5( $this->summary
);
2014 $wgOut->addHTML( Html
::hidden( 'wpAutoSummary', $autosumm ) );
2016 $wgOut->addHTML( Html
::hidden( 'oldid', $this->oldid
) );
2018 $wgOut->addHTML( Html
::hidden( 'format', $this->content_format
) );
2019 $wgOut->addHTML( Html
::hidden( 'model', $this->content_model
) );
2021 if ( $this->section
== 'new' ) {
2022 $this->showSummaryInput( true, $this->summary
);
2023 $wgOut->addHTML( $this->getSummaryPreview( true, $this->summary
) );
2026 $wgOut->addHTML( $this->editFormTextBeforeContent
);
2028 if ( !$this->isCssJsSubpage
&& $showToolbar && $wgUser->getOption( 'showtoolbar' ) ) {
2029 $wgOut->addHTML( EditPage
::getEditToolbar() );
2032 if ( $this->isConflict
) {
2033 // In an edit conflict bypass the overrideable content form method
2034 // and fallback to the raw wpTextbox1 since editconflicts can't be
2035 // resolved between page source edits and custom ui edits using the
2037 $this->textbox2
= $this->textbox1
;
2039 $content = $this->getCurrentContent();
2040 $this->textbox1
= $content->serialize( $this->content_format
);
2042 $this->showTextbox1();
2044 $this->showContentForm();
2047 $wgOut->addHTML( $this->editFormTextAfterContent
);
2049 $wgOut->addWikiText( $this->getCopywarn() );
2051 $wgOut->addHTML( $this->editFormTextAfterWarn
);
2053 $this->showStandardInputs();
2055 $this->showFormAfterText();
2057 $this->showTosSummary();
2059 $this->showEditTools();
2061 $wgOut->addHTML( $this->editFormTextAfterTools
. "\n" );
2063 $wgOut->addHTML( Html
::rawElement( 'div', array( 'class' => 'templatesUsed' ),
2064 Linker
::formatTemplates( $this->getTemplates(), $this->preview
, $this->section
!= '' ) ) );
2066 $wgOut->addHTML( Html
::rawElement( 'div', array( 'class' => 'hiddencats' ),
2067 Linker
::formatHiddenCategories( $this->mArticle
->getHiddenCategories() ) ) );
2069 if ( $this->isConflict
) {
2070 $this->showConflict();
2073 $wgOut->addHTML( $this->editFormTextBottom
. "\n</form>\n" );
2075 if ( !$wgUser->getOption( 'previewontop' ) ) {
2076 $this->displayPreviewArea( $previewOutput, false );
2079 wfProfileOut( __METHOD__
);
2083 * Extract the section title from current section text, if any.
2085 * @param string $text
2086 * @return Mixed|string or false
2088 public static function extractSectionTitle( $text ) {
2089 preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
2090 if ( !empty( $matches[2] ) ) {
2092 return $wgParser->stripSectionName( trim( $matches[2] ) );
2098 protected function showHeader() {
2099 global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
2101 if ( $this->mTitle
->isTalkPage() ) {
2102 $wgOut->addWikiMsg( 'talkpagetext' );
2105 # Optional notices on a per-namespace and per-page basis
2106 $editnotice_ns = 'editnotice-' . $this->mTitle
->getNamespace();
2107 $editnotice_ns_message = wfMessage( $editnotice_ns );
2108 if ( $editnotice_ns_message->exists() ) {
2109 $wgOut->addWikiText( $editnotice_ns_message->plain() );
2111 if ( MWNamespace
::hasSubpages( $this->mTitle
->getNamespace() ) ) {
2112 $parts = explode( '/', $this->mTitle
->getDBkey() );
2113 $editnotice_base = $editnotice_ns;
2114 while ( count( $parts ) > 0 ) {
2115 $editnotice_base .= '-' . array_shift( $parts );
2116 $editnotice_base_msg = wfMessage( $editnotice_base );
2117 if ( $editnotice_base_msg->exists() ) {
2118 $wgOut->addWikiText( $editnotice_base_msg->plain() );
2122 # Even if there are no subpages in namespace, we still don't want / in MW ns.
2123 $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle
->getDBkey() );
2124 $editnoticeMsg = wfMessage( $editnoticeText );
2125 if ( $editnoticeMsg->exists() ) {
2126 $wgOut->addWikiText( $editnoticeMsg->plain() );
2130 if ( $this->isConflict
) {
2131 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1\n</div>", 'explainconflict' );
2132 $this->edittime
= $this->mArticle
->getTimestamp();
2134 if ( $this->section
!= '' && !$this->isSectionEditSupported() ) {
2135 // We use $this->section to much before this and getVal('wgSection') directly in other places
2136 // at this point we can't reset $this->section to '' to fallback to non-section editing.
2137 // Someone is welcome to try refactoring though
2138 $wgOut->showErrorPage( 'sectioneditnotsupported-title', 'sectioneditnotsupported-text' );
2142 if ( $this->section
!= '' && $this->section
!= 'new' ) {
2143 if ( !$this->summary
&& !$this->preview
&& !$this->diff
) {
2144 $sectionTitle = self
::extractSectionTitle( $this->textbox1
);
2145 if ( $sectionTitle !== false ) {
2146 $this->summary
= "/* $sectionTitle */ ";
2151 if ( $this->missingComment
) {
2152 $wgOut->wrapWikiMsg( "<div id='mw-missingcommenttext'>\n$1\n</div>", 'missingcommenttext' );
2155 if ( $this->missingSummary
&& $this->section
!= 'new' ) {
2156 $wgOut->wrapWikiMsg( "<div id='mw-missingsummary'>\n$1\n</div>", 'missingsummary' );
2159 if ( $this->missingSummary
&& $this->section
== 'new' ) {
2160 $wgOut->wrapWikiMsg( "<div id='mw-missingcommentheader'>\n$1\n</div>", 'missingcommentheader' );
2163 if ( $this->hookError
!== '' ) {
2164 $wgOut->addWikiText( $this->hookError
);
2167 if ( !$this->checkUnicodeCompliantBrowser() ) {
2168 $wgOut->addWikiMsg( 'nonunicodebrowser' );
2171 if ( $this->section
!= 'new' ) {
2172 $revision = $this->mArticle
->getRevisionFetched();
2174 // Let sysop know that this will make private content public if saved
2176 if ( !$revision->userCan( Revision
::DELETED_TEXT
) ) {
2177 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
2178 } elseif ( $revision->isDeleted( Revision
::DELETED_TEXT
) ) {
2179 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-view' );
2182 if ( !$revision->isCurrent() ) {
2183 $this->mArticle
->setOldSubtitle( $revision->getId() );
2184 $wgOut->addWikiMsg( 'editingold' );
2186 } elseif ( $this->mTitle
->exists() ) {
2187 // Something went wrong
2189 $wgOut->wrapWikiMsg( "<div class='errorbox'>\n$1\n</div>\n",
2190 array( 'missing-revision', $this->oldid
) );
2195 if ( wfReadOnly() ) {
2196 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
2197 } elseif ( $wgUser->isAnon() ) {
2198 if ( $this->formtype
!= 'preview' ) {
2199 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-edit-warning\">\n$1</div>", 'anoneditwarning' );
2201 $wgOut->wrapWikiMsg( "<div id=\"mw-anon-preview-warning\">\n$1</div>", 'anonpreviewwarning' );
2204 if ( $this->isCssJsSubpage
) {
2205 # Check the skin exists
2206 if ( $this->isWrongCaseCssJsPage
) {
2207 $wgOut->wrapWikiMsg( "<div class='error' id='mw-userinvalidcssjstitle'>\n$1\n</div>", array( 'userinvalidcssjstitle', $this->mTitle
->getSkinFromCssJsSubpage() ) );
2209 if ( $this->formtype
!== 'preview' ) {
2210 if ( $this->isCssSubpage
)
2211 $wgOut->wrapWikiMsg( "<div id='mw-usercssyoucanpreview'>\n$1\n</div>", array( 'usercssyoucanpreview' ) );
2212 if ( $this->isJsSubpage
)
2213 $wgOut->wrapWikiMsg( "<div id='mw-userjsyoucanpreview'>\n$1\n</div>", array( 'userjsyoucanpreview' ) );
2218 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
2219 # Is the title semi-protected?
2220 if ( $this->mTitle
->isSemiProtected() ) {
2221 $noticeMsg = 'semiprotectedpagewarning';
2223 # Then it must be protected based on static groups (regular)
2224 $noticeMsg = 'protectedpagewarning';
2226 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
, '',
2227 array( 'lim' => 1, 'msgKey' => array( $noticeMsg ) ) );
2229 if ( $this->mTitle
->isCascadeProtected() ) {
2230 # Is this page under cascading protection from some source pages?
2231 list( $cascadeSources, /* $restrictions */ ) = $this->mTitle
->getCascadeProtectionSources();
2232 $notice = "<div class='mw-cascadeprotectedwarning'>\n$1\n";
2233 $cascadeSourcesCount = count( $cascadeSources );
2234 if ( $cascadeSourcesCount > 0 ) {
2235 # Explain, and list the titles responsible
2236 foreach ( $cascadeSources as $page ) {
2237 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
2240 $notice .= '</div>';
2241 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
2243 if ( !$this->mTitle
->exists() && $this->mTitle
->getRestrictions( 'create' ) ) {
2244 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->mTitle
, '',
2246 'showIfEmpty' => false,
2247 'msgKey' => array( 'titleprotectedwarning' ),
2248 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n$1</div>" ) );
2251 if ( $this->kblength
=== false ) {
2252 $this->kblength
= (int)( strlen( $this->textbox1
) / 1024 );
2255 if ( $this->tooBig ||
$this->kblength
> $wgMaxArticleSize ) {
2256 $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
2257 array( 'longpageerror', $wgLang->formatNum( $this->kblength
), $wgLang->formatNum( $wgMaxArticleSize ) ) );
2259 if ( !wfMessage( 'longpage-hint' )->isDisabled() ) {
2260 $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
2261 array( 'longpage-hint', $wgLang->formatSize( strlen( $this->textbox1
) ), strlen( $this->textbox1
) )
2268 * Standard summary input and label (wgSummary), abstracted so EditPage
2269 * subclasses may reorganize the form.
2270 * Note that you do not need to worry about the label's for=, it will be
2271 * inferred by the id given to the input. You can remove them both by
2272 * passing array( 'id' => false ) to $userInputAttrs.
2274 * @param $summary string The value of the summary input
2275 * @param $labelText string The html to place inside the label
2276 * @param $inputAttrs array of attrs to use on the input
2277 * @param $spanLabelAttrs array of attrs to use on the span inside the label
2279 * @return array An array in the format array( $label, $input )
2281 function getSummaryInput( $summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null ) {
2282 // Note: the maxlength is overriden in JS to 255 and to make it use UTF-8 bytes, not characters.
2283 $inputAttrs = ( is_array( $inputAttrs ) ?
$inputAttrs : array() ) +
array(
2284 'id' => 'wpSummary',
2285 'maxlength' => '200',
2288 'spellcheck' => 'true',
2289 ) + Linker
::tooltipAndAccesskeyAttribs( 'summary' );
2291 $spanLabelAttrs = ( is_array( $spanLabelAttrs ) ?
$spanLabelAttrs : array() ) +
array(
2292 'class' => $this->missingSummary ?
'mw-summarymissed' : 'mw-summary',
2293 'id' => "wpSummaryLabel"
2298 $label = Xml
::tags( 'label', $inputAttrs['id'] ?
array( 'for' => $inputAttrs['id'] ) : null, $labelText );
2299 $label = Xml
::tags( 'span', $spanLabelAttrs, $label );
2302 $input = Html
::input( 'wpSummary', $summary, 'text', $inputAttrs );
2304 return array( $label, $input );
2308 * @param $isSubjectPreview Boolean: true if this is the section subject/title
2309 * up top, or false if this is the comment summary
2310 * down below the textarea
2311 * @param $summary String: The text of the summary to display
2314 protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
2315 global $wgOut, $wgContLang;
2316 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
2317 $summaryClass = $this->missingSummary ?
'mw-summarymissed' : 'mw-summary';
2318 if ( $isSubjectPreview ) {
2319 if ( $this->nosummary
) {
2323 if ( !$this->mShowSummaryField
) {
2327 $summary = $wgContLang->recodeForEdit( $summary );
2328 $labelText = wfMessage( $isSubjectPreview ?
'subject' : 'summary' )->parse();
2329 list( $label, $input ) = $this->getSummaryInput( $summary, $labelText, array( 'class' => $summaryClass ), array() );
2330 $wgOut->addHTML( "{$label} {$input}" );
2334 * @param $isSubjectPreview Boolean: true if this is the section subject/title
2335 * up top, or false if this is the comment summary
2336 * down below the textarea
2337 * @param $summary String: the text of the summary to display
2340 protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
2341 if ( !$summary ||
( !$this->preview
&& !$this->diff
) )
2346 if ( $isSubjectPreview )
2347 $summary = wfMessage( 'newsectionsummary', $wgParser->stripSectionName( $summary )->inContentLanguage()->text() );
2349 $message = $isSubjectPreview ?
'subject-preview' : 'summary-preview';
2351 $summary = wfMessage( $message )->parse() . Linker
::commentBlock( $summary, $this->mTitle
, $isSubjectPreview );
2352 return Xml
::tags( 'div', array( 'class' => 'mw-summary-preview' ), $summary );
2355 protected function showFormBeforeText() {
2357 $section = htmlspecialchars( $this->section
);
2358 $wgOut->addHTML( <<<HTML
2359 <input type='hidden' value="{$section}" name="wpSection" />
2360 <input type='hidden' value="{$this->starttime}" name="wpStarttime" />
2361 <input type='hidden' value="{$this->edittime}" name="wpEdittime" />
2362 <input type='hidden' value="{$this->scrolltop}" name="wpScrolltop" id="wpScrolltop" />
2366 if ( !$this->checkUnicodeCompliantBrowser() )
2367 $wgOut->addHTML( Html
::hidden( 'safemode', '1' ) );
2370 protected function showFormAfterText() {
2371 global $wgOut, $wgUser;
2373 * To make it harder for someone to slip a user a page
2374 * which submits an edit form to the wiki without their
2375 * knowledge, a random token is associated with the login
2376 * session. If it's not passed back with the submission,
2377 * we won't save the page, or render user JavaScript and
2380 * For anon editors, who may not have a session, we just
2381 * include the constant suffix to prevent editing from
2382 * broken text-mangling proxies.
2384 $wgOut->addHTML( "\n" . Html
::hidden( "wpEditToken", $wgUser->getEditToken() ) . "\n" );
2388 * Subpage overridable method for printing the form for page content editing
2389 * By default this simply outputs wpTextbox1
2390 * Subclasses can override this to provide a custom UI for editing;
2391 * be it a form, or simply wpTextbox1 with a modified content that will be
2392 * reverse modified when extracted from the post data.
2393 * Note that this is basically the inverse for importContentFormData
2395 protected function showContentForm() {
2396 $this->showTextbox1();
2400 * Method to output wpTextbox1
2401 * The $textoverride method can be used by subclasses overriding showContentForm
2402 * to pass back to this method.
2404 * @param $customAttribs array of html attributes to use in the textarea
2405 * @param $textoverride String: optional text to override $this->textarea1 with
2407 protected function showTextbox1( $customAttribs = null, $textoverride = null ) {
2408 if ( $this->wasDeletedSinceLastEdit() && $this->formtype
== 'save' ) {
2409 $attribs = array( 'style' => 'display:none;' );
2411 $classes = array(); // Textarea CSS
2412 if ( $this->mTitle
->getNamespace() != NS_MEDIAWIKI
&& $this->mTitle
->isProtected( 'edit' ) ) {
2413 # Is the title semi-protected?
2414 if ( $this->mTitle
->isSemiProtected() ) {
2415 $classes[] = 'mw-textarea-sprotected';
2417 # Then it must be protected based on static groups (regular)
2418 $classes[] = 'mw-textarea-protected';
2420 # Is the title cascade-protected?
2421 if ( $this->mTitle
->isCascadeProtected() ) {
2422 $classes[] = 'mw-textarea-cprotected';
2426 $attribs = array( 'tabindex' => 1 );
2428 if ( is_array( $customAttribs ) ) {
2429 $attribs +
= $customAttribs;
2432 if ( count( $classes ) ) {
2433 if ( isset( $attribs['class'] ) ) {
2434 $classes[] = $attribs['class'];
2436 $attribs['class'] = implode( ' ', $classes );
2440 $this->showTextbox( $textoverride !== null ?
$textoverride : $this->textbox1
, 'wpTextbox1', $attribs );
2443 protected function showTextbox2() {
2444 $this->showTextbox( $this->textbox2
, 'wpTextbox2', array( 'tabindex' => 6, 'readonly' ) );
2447 protected function showTextbox( $text, $name, $customAttribs = array() ) {
2448 global $wgOut, $wgUser;
2450 $wikitext = $this->safeUnicodeOutput( $text );
2451 if ( strval( $wikitext ) !== '' ) {
2452 // Ensure there's a newline at the end, otherwise adding lines
2454 // But don't add a newline if the ext is empty, or Firefox in XHTML
2455 // mode will show an extra newline. A bit annoying.
2459 $attribs = $customAttribs +
array(
2462 'cols' => $wgUser->getIntOption( 'cols' ),
2463 'rows' => $wgUser->getIntOption( 'rows' ),
2464 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
2467 $pageLang = $this->mTitle
->getPageLanguage();
2468 $attribs['lang'] = $pageLang->getCode();
2469 $attribs['dir'] = $pageLang->getDir();
2471 $wgOut->addHTML( Html
::textarea( $name, $wikitext, $attribs ) );
2474 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
2478 $classes[] = 'ontop';
2480 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
2482 if ( $this->formtype
!= 'preview' )
2483 $attribs['style'] = 'display: none;';
2485 $wgOut->addHTML( Xml
::openElement( 'div', $attribs ) );
2487 if ( $this->formtype
== 'preview' ) {
2488 $this->showPreview( $previewOutput );
2491 $wgOut->addHTML( '</div>' );
2493 if ( $this->formtype
== 'diff' ) {
2499 * Append preview output to $wgOut.
2500 * Includes category rendering if this is a category page.
2502 * @param $text String: the HTML to be output for the preview.
2504 protected function showPreview( $text ) {
2506 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
2507 $this->mArticle
->openShowCategory();
2509 # This hook seems slightly odd here, but makes things more
2510 # consistent for extensions.
2511 wfRunHooks( 'OutputPageBeforeHTML', array( &$wgOut, &$text ) );
2512 $wgOut->addHTML( $text );
2513 if ( $this->mTitle
->getNamespace() == NS_CATEGORY
) {
2514 $this->mArticle
->closeShowCategory();
2519 * Get a diff between the current contents of the edit box and the
2520 * version of the page we're editing from.
2522 * If this is a section edit, we'll replace the section as for final
2523 * save and then make a comparison.
2525 function showDiff() {
2526 global $wgUser, $wgContLang, $wgParser, $wgOut;
2528 $oldtitlemsg = 'currentrev';
2529 # if message does not exist, show diff against the preloaded default
2530 if( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
&& !$this->mTitle
->exists() ) {
2531 $oldtext = $this->mTitle
->getDefaultMessageText();
2532 if( $oldtext !== false ) {
2533 $oldtitlemsg = 'defaultmessagetext';
2534 $oldContent = ContentHandler
::makeContent( $oldtext, $this->mTitle
);
2539 $oldContent = $this->getOriginalContent();
2542 #XXX: handle parse errors ?
2543 $textboxContent = ContentHandler
::makeContent( $this->textbox1
, $this->getTitle(),
2544 $this->content_model
, $this->content_format
);
2546 $newContent = $this->mArticle
->replaceSectionContent(
2547 $this->section
, $textboxContent,
2548 $this->summary
, $this->edittime
);
2550 # hanlde legacy text-based hook
2551 $newtext_orig = $newContent->serialize( $this->content_format
);
2552 $newtext = $newtext_orig; #clone
2553 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
2555 if ( $newtext != $newtext_orig ) {
2556 #if the hook changed the text, create a new Content object accordingly.
2557 #XXX: handle parse errors ?
2558 $newContent = ContentHandler
::makeContent( $newtext, $this->getTitle(),
2559 $newContent->getModel() );
2562 wfRunHooks( 'EditPageGetDiffContent', array( $this, &$newContent ) );
2564 $popts = ParserOptions
::newFromUserAndLang( $wgUser, $wgContLang );
2565 $newContent = $newContent->preSaveTransform( $this->mTitle
, $wgUser, $popts );
2567 if ( ( $oldContent && !$oldContent->isEmpty() ) ||
( $newContent && !$newContent->isEmpty() ) ) {
2568 $oldtitle = wfMessage( $oldtitlemsg )->parse();
2569 $newtitle = wfMessage( 'yourtext' )->parse();
2571 $de = $oldContent->getContentHandler()->createDifferenceEngine( $this->mArticle
->getContext() );
2572 $de->setContent( $oldContent, $newContent );
2574 $difftext = $de->getDiff( $oldtitle, $newtitle );
2575 $de->showDiffStyle();
2580 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
2584 * Give a chance for site and per-namespace customizations of
2585 * terms of service summary link that might exist separately
2586 * from the copyright notice.
2588 * This will display between the save button and the edit tools,
2589 * so should remain short!
2591 protected function showTosSummary() {
2592 $msg = 'editpage-tos-summary';
2593 wfRunHooks( 'EditPageTosSummary', array( $this->mTitle
, &$msg ) );
2594 if ( !wfMessage( $msg )->isDisabled() ) {
2596 $wgOut->addHTML( '<div class="mw-tos-summary">' );
2597 $wgOut->addWikiMsg( $msg );
2598 $wgOut->addHTML( '</div>' );
2602 protected function showEditTools() {
2604 $wgOut->addHTML( '<div class="mw-editTools">' .
2605 wfMessage( 'edittools' )->inContentLanguage()->parse() .
2610 * Get the copyright warning
2612 * Renamed to getCopyrightWarning(), old name kept around for backwards compatibility
2614 protected function getCopywarn() {
2615 return self
::getCopyrightWarning( $this->mTitle
);
2618 public static function getCopyrightWarning( $title ) {
2619 global $wgRightsText;
2620 if ( $wgRightsText ) {
2621 $copywarnMsg = array( 'copyrightwarning',
2622 '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]',
2625 $copywarnMsg = array( 'copyrightwarning2',
2626 '[[' . wfMessage( 'copyrightpage' )->inContentLanguage()->text() . ']]' );
2628 // Allow for site and per-namespace customization of contribution/copyright notice.
2629 wfRunHooks( 'EditPageCopyrightWarning', array( $title, &$copywarnMsg ) );
2631 $msg = call_user_func_array( "wfMessage", $copywarnMsg );
2632 return "<div id=\"editpage-copywarn\">\n" .
2633 $msg->plain() . "\n</div>";
2636 protected function showStandardInputs( &$tabindex = 2 ) {
2638 $wgOut->addHTML( "<div class='editOptions'>\n" );
2640 if ( $this->section
!= 'new' ) {
2641 $this->showSummaryInput( false, $this->summary
);
2642 $wgOut->addHTML( $this->getSummaryPreview( false, $this->summary
) );
2645 $checkboxes = $this->getCheckboxes( $tabindex,
2646 array( 'minor' => $this->minoredit
, 'watch' => $this->watchthis
) );
2647 $wgOut->addHTML( "<div class='editCheckboxes'>" . implode( $checkboxes, "\n" ) . "</div>\n" );
2648 $wgOut->addHTML( "<div class='editButtons'>\n" );
2649 $wgOut->addHTML( implode( $this->getEditButtons( $tabindex ), "\n" ) . "\n" );
2651 $cancel = $this->getCancelLink();
2652 if ( $cancel !== '' ) {
2653 $cancel .= wfMessage( 'pipe-separator' )->text();
2655 $edithelpurl = Skin
::makeInternalOrExternalUrl( wfMessage( 'edithelppage' )->inContentLanguage()->text() );
2656 $edithelp = '<a target="helpwindow" href="' . $edithelpurl . '">' .
2657 wfMessage( 'edithelp' )->escaped() . '</a> ' .
2658 wfMessage( 'newwindow' )->escaped();
2659 $wgOut->addHTML( " <span class='editHelp'>{$cancel}{$edithelp}</span>\n" );
2660 $wgOut->addHTML( "</div><!-- editButtons -->\n</div><!-- editOptions -->\n" );
2664 * Show an edit conflict. textbox1 is already shown in showEditForm().
2665 * If you want to use another entry point to this function, be careful.
2667 protected function showConflict() {
2670 if ( wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
2671 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
2673 $content1 = ContentHandler
::makeContent( $this->textbox1
, $this->getTitle(), $this->content_model
, $this->content_format
); #XXX: handle parse errors?
2674 $content2 = ContentHandler
::makeContent( $this->textbox2
, $this->getTitle(), $this->content_model
, $this->content_format
); #XXX: handle parse errors?
2676 $handler = ContentHandler
::getForModelID( $this->content_model
);
2677 $de = $handler->createDifferenceEngine( $this->mArticle
->getContext() );
2678 $de->setContent( $content2, $content1 );
2679 $de->showDiff( wfMessage( 'yourtext' )->parse(), wfMessage( 'storedversion' )->text() );
2681 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
2682 $this->showTextbox2();
2689 public function getCancelLink() {
2690 $cancelParams = array();
2691 if ( !$this->isConflict
&& $this->oldid
> 0 ) {
2692 $cancelParams['oldid'] = $this->oldid
;
2695 return Linker
::linkKnown(
2696 $this->getContextTitle(),
2697 wfMessage( 'cancel' )->parse(),
2698 array( 'id' => 'mw-editform-cancel' ),
2704 * Returns the URL to use in the form's action attribute.
2705 * This is used by EditPage subclasses when simply customizing the action
2706 * variable in the constructor is not enough. This can be used when the
2707 * EditPage lives inside of a Special page rather than a custom page action.
2709 * @param $title Title object for which is being edited (where we go to for &action= links)
2712 protected function getActionURL( Title
$title ) {
2713 return $title->getLocalURL( array( 'action' => $this->action
) );
2717 * Check if a page was deleted while the user was editing it, before submit.
2718 * Note that we rely on the logging table, which hasn't been always there,
2719 * but that doesn't matter, because this only applies to brand new
2722 protected function wasDeletedSinceLastEdit() {
2723 if ( $this->deletedSinceEdit
!== null ) {
2724 return $this->deletedSinceEdit
;
2727 $this->deletedSinceEdit
= false;
2729 if ( $this->mTitle
->isDeletedQuick() ) {
2730 $this->lastDelete
= $this->getLastDelete();
2731 if ( $this->lastDelete
) {
2732 $deleteTime = wfTimestamp( TS_MW
, $this->lastDelete
->log_timestamp
);
2733 if ( $deleteTime > $this->starttime
) {
2734 $this->deletedSinceEdit
= true;
2739 return $this->deletedSinceEdit
;
2742 protected function getLastDelete() {
2743 $dbr = wfGetDB( DB_SLAVE
);
2744 $data = $dbr->selectRow(
2745 array( 'logging', 'user' ),
2756 array( 'log_namespace' => $this->mTitle
->getNamespace(),
2757 'log_title' => $this->mTitle
->getDBkey(),
2758 'log_type' => 'delete',
2759 'log_action' => 'delete',
2760 'user_id=log_user' ),
2762 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
2764 // Quick paranoid permission checks...
2765 if ( is_object( $data ) ) {
2766 if ( $data->log_deleted
& LogPage
::DELETED_USER
)
2767 $data->user_name
= wfMessage( 'rev-deleted-user' )->escaped();
2768 if ( $data->log_deleted
& LogPage
::DELETED_COMMENT
)
2769 $data->log_comment
= wfMessage( 'rev-deleted-comment' )->escaped();
2775 * Get the rendered text for previewing.
2778 function getPreviewText() {
2779 global $wgOut, $wgUser, $wgParser, $wgRawHtml, $wgLang;
2781 wfProfileIn( __METHOD__
);
2783 if ( $wgRawHtml && !$this->mTokenOk
) {
2784 // Could be an offsite preview attempt. This is very unsafe if
2785 // HTML is enabled, as it could be an attack.
2787 if ( $this->textbox1
!== '' ) {
2788 // Do not put big scary notice, if previewing the empty
2789 // string, which happens when you initially edit
2790 // a category page, due to automatic preview-on-open.
2791 $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
2792 wfMessage( 'session_fail_preview_html' )->text() . "</div>", true, /* interface */true );
2794 wfProfileOut( __METHOD__
);
2801 $content = ContentHandler
::makeContent( $this->textbox1
, $this->getTitle(),
2802 $this->content_model
, $this->content_format
);
2804 if ( $this->mTriedSave
&& !$this->mTokenOk
) {
2805 if ( $this->mTokenOkExceptSuffix
) {
2806 $note = wfMessage( 'token_suffix_mismatch' )->text() ;
2808 $note = wfMessage( 'session_fail_preview' )->text() ;
2810 } elseif ( $this->incompleteForm
) {
2811 $note = wfMessage( 'edit_form_incomplete' )->text() ;
2813 $note = wfMessage( 'previewnote' )->text() .
2814 ' [[#' . self
::EDITFORM_ID
. '|' . $wgLang->getArrow() . ' '
2815 . wfMessage( 'continue-editing' )->text() . ']]';
2818 $parserOptions = ParserOptions
::newFromUser( $wgUser );
2819 $parserOptions->setEditSection( false );
2820 $parserOptions->setTidy( true );
2821 $parserOptions->setIsPreview( true );
2822 $parserOptions->setIsSectionPreview( !is_null($this->section
) && $this->section
!== '' );
2824 if ( $this->mTitle
->isCssJsSubpage() ||
$this->mTitle
->isCssOrJsPage() ) {
2825 # don't parse non-wikitext pages, show message about preview
2826 if( $this->mTitle
->isCssJsSubpage() ) {
2828 } elseif( $this->mTitle
->isCssOrJsPage() ) {
2834 if ( $content->getModel() == CONTENT_MODEL_CSS
) {
2836 } elseif ( $content->getModel() == CONTENT_MODEL_JAVASCRIPT
) {
2842 # Used messages to make sure grep find them:
2843 # Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2844 if( $level && $format ) {
2845 $note = "<div id='mw-{$level}{$format}preview'>" . wfMessage( "{$level}{$format}preview" )->text() . "</div>";
2847 $note = wfMessage( 'previewnote' )->text() ;
2850 $note = wfMessage( 'previewnote' )->text() ;
2853 $rt = $content->getRedirectChain();
2856 $previewHTML = $this->mArticle
->viewRedirect( $rt, false );
2859 # If we're adding a comment, we need to show the
2860 # summary as the headline
2861 if ( $this->section
== "new" && $this->summary
!= "" ) {
2862 $content = $content->addSectionHeader( $this->summary
);
2865 $toparse_orig = $content->serialize( $this->content_format
);
2866 $toparse = $toparse_orig;
2867 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
2869 if ( $toparse !== $toparse_orig ) {
2870 #hook changed the text, create new Content object
2871 $content = ContentHandler
::makeContent( $toparse, $this->getTitle(),
2872 $this->content_model
, $this->content_format
);
2875 wfRunHooks( 'EditPageGetPreviewContent', array( $this, &$content ) );
2877 $parserOptions->enableLimitReport();
2879 #XXX: For CSS/JS pages, we should have called the ShowRawCssJs hook here.
2880 # But it's now deprecated, so never mind
2881 $content = $content->preSaveTransform( $this->mTitle
, $wgUser, $parserOptions );
2883 // TODO: might be a saner way to get a meaningfull context here?
2884 $parserOutput = $content->getParserOutput( $this->getArticle()->getTitle(), null, $parserOptions );
2886 $previewHTML = $parserOutput->getText();
2887 $this->mParserOutput
= $parserOutput;
2888 $wgOut->addParserOutputNoText( $parserOutput );
2890 if ( count( $parserOutput->getWarnings() ) ) {
2891 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
2894 } catch (MWContentSerializationException
$ex) {
2895 $m = wfMessage('content-failed-to-parse', $this->content_model
, $this->content_format
, $ex->getMessage() );
2896 $note .= "\n\n" . $m->parse();
2900 if ( $this->isConflict
) {
2901 $conflict = '<h2 id="mw-previewconflict">' . wfMessage( 'previewconflict' )->escaped() . "</h2>\n";
2903 $conflict = '<hr />';
2906 $previewhead = "<div class='previewnote'>\n" .
2907 '<h2 id="mw-previewheader">' . wfMessage( 'preview' )->escaped() . "</h2>" .
2908 $wgOut->parse( $note, true, /* interface */true ) . $conflict . "</div>\n";
2910 $pageLang = $this->mTitle
->getPageLanguage();
2911 $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
2912 'class' => 'mw-content-' . $pageLang->getDir() );
2913 $previewHTML = Html
::rawElement( 'div', $attribs, $previewHTML );
2915 wfProfileOut( __METHOD__
);
2916 return $previewhead . $previewHTML . $this->previewTextAfterContent
;
2922 function getTemplates() {
2923 if ( $this->preview ||
$this->section
!= '' ) {
2924 $templates = array();
2925 if ( !isset( $this->mParserOutput
) ) {
2928 foreach ( $this->mParserOutput
->getTemplates() as $ns => $template ) {
2929 foreach ( array_keys( $template ) as $dbk ) {
2930 $templates[] = Title
::makeTitle( $ns, $dbk );
2935 return $this->mTitle
->getTemplateLinksFrom();
2940 * Shows a bulletin board style toolbar for common editing functions.
2941 * It can be disabled in the user preferences.
2942 * The necessary JavaScript code can be found in skins/common/edit.js.
2946 static function getEditToolbar() {
2947 global $wgStylePath, $wgContLang, $wgLang, $wgOut;
2948 global $wgUseTeX, $wgEnableUploads, $wgForeignFileRepos;
2950 $imagesAvailable = $wgEnableUploads ||
count( $wgForeignFileRepos );
2953 * $toolarray is an array of arrays each of which includes the
2954 * filename of the button image (without path), the opening
2955 * tag, the closing tag, optionally a sample text that is
2956 * inserted between the two when no selection is highlighted
2957 * and. The tip text is shown when the user moves the mouse
2960 * Also here: accesskeys (key), which are not used yet until
2961 * someone can figure out a way to make them work in
2962 * IE. However, we should make sure these keys are not defined
2967 'image' => $wgLang->getImageFile( 'button-bold' ),
2968 'id' => 'mw-editbutton-bold',
2970 'close' => '\'\'\'',
2971 'sample' => wfMessage( 'bold_sample' )->text() ,
2972 'tip' => wfMessage( 'bold_tip' )->text() ,
2976 'image' => $wgLang->getImageFile( 'button-italic' ),
2977 'id' => 'mw-editbutton-italic',
2980 'sample' => wfMessage( 'italic_sample' )->text() ,
2981 'tip' => wfMessage( 'italic_tip' )->text() ,
2985 'image' => $wgLang->getImageFile( 'button-link' ),
2986 'id' => 'mw-editbutton-link',
2989 'sample' => wfMessage( 'link_sample' )->text() ,
2990 'tip' => wfMessage( 'link_tip' )->text() ,
2994 'image' => $wgLang->getImageFile( 'button-extlink' ),
2995 'id' => 'mw-editbutton-extlink',
2998 'sample' => wfMessage( 'extlink_sample' )->text() ,
2999 'tip' => wfMessage( 'extlink_tip' )->text() ,
3003 'image' => $wgLang->getImageFile( 'button-headline' ),
3004 'id' => 'mw-editbutton-headline',
3007 'sample' => wfMessage( 'headline_sample' )->text() ,
3008 'tip' => wfMessage( 'headline_tip' )->text() ,
3011 $imagesAvailable ?
array(
3012 'image' => $wgLang->getImageFile( 'button-image' ),
3013 'id' => 'mw-editbutton-image',
3014 'open' => '[[' . $wgContLang->getNsText( NS_FILE
) . ':',
3016 'sample' => wfMessage( 'image_sample' )->text() ,
3017 'tip' => wfMessage( 'image_tip' )->text() ,
3020 $imagesAvailable ?
array(
3021 'image' => $wgLang->getImageFile( 'button-media' ),
3022 'id' => 'mw-editbutton-media',
3023 'open' => '[[' . $wgContLang->getNsText( NS_MEDIA
) . ':',
3025 'sample' => wfMessage( 'media_sample' )->text() ,
3026 'tip' => wfMessage( 'media_tip' )->text() ,
3030 'image' => $wgLang->getImageFile( 'button-math' ),
3031 'id' => 'mw-editbutton-math',
3033 'close' => "</math>",
3034 'sample' => wfMessage( 'math_sample' )->text() ,
3035 'tip' => wfMessage( 'math_tip' )->text() ,
3039 'image' => $wgLang->getImageFile( 'button-nowiki' ),
3040 'id' => 'mw-editbutton-nowiki',
3041 'open' => "<nowiki>",
3042 'close' => "</nowiki>",
3043 'sample' => wfMessage( 'nowiki_sample' )->text() ,
3044 'tip' => wfMessage( 'nowiki_tip' )->text() ,
3048 'image' => $wgLang->getImageFile( 'button-sig' ),
3049 'id' => 'mw-editbutton-signature',
3053 'tip' => wfMessage( 'sig_tip' )->text() ,
3057 'image' => $wgLang->getImageFile( 'button-hr' ),
3058 'id' => 'mw-editbutton-hr',
3059 'open' => "\n----\n",
3062 'tip' => wfMessage( 'hr_tip' )->text() ,
3067 $script = 'mw.loader.using("mediawiki.action.edit", function() {';
3068 foreach ( $toolarray as $tool ) {
3074 $image = $wgStylePath . '/common/images/' . $tool['image'],
3075 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
3076 // Older browsers show a "speedtip" type message only for ALT.
3077 // Ideally these should be different, realistically they
3078 // probably don't need to be.
3079 $tip = $tool['tip'],
3080 $open = $tool['open'],
3081 $close = $tool['close'],
3082 $sample = $tool['sample'],
3083 $cssId = $tool['id'],
3086 $script .= Xml
::encodeJsCall( 'mw.toolbar.addButton', $params );
3089 // This used to be called on DOMReady from mediawiki.action.edit, which
3090 // ended up causing race conditions with the setup code above.
3092 "// Create button bar\n" .
3093 "$(function() { mw.toolbar.init(); } );\n";
3096 $wgOut->addScript( Html
::inlineScript( ResourceLoader
::makeLoaderConditionalScript( $script ) ) );
3098 $toolbar = '<div id="toolbar"></div>';
3100 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
3106 * Returns an array of html code of the following checkboxes:
3109 * @param $tabindex int Current tabindex
3110 * @param $checked Array of checkbox => bool, where bool indicates the checked
3111 * status of the checkbox
3115 public function getCheckboxes( &$tabindex, $checked ) {
3118 $checkboxes = array();
3120 // don't show the minor edit checkbox if it's a new page or section
3121 if ( !$this->isNew
) {
3122 $checkboxes['minor'] = '';
3123 $minorLabel = wfMessage( 'minoredit' )->parse();
3124 if ( $wgUser->isAllowed( 'minoredit' ) ) {
3126 'tabindex' => ++
$tabindex,
3127 'accesskey' => wfMessage( 'accesskey-minoredit' )->text() ,
3128 'id' => 'wpMinoredit',
3130 $checkboxes['minor'] =
3131 Xml
::check( 'wpMinoredit', $checked['minor'], $attribs ) .
3132 " <label for='wpMinoredit' id='mw-editpage-minoredit'" .
3133 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'minoredit', 'withaccess' ) ) ) .
3134 ">{$minorLabel}</label>";
3138 $watchLabel = wfMessage( 'watchthis' )->parse();
3139 $checkboxes['watch'] = '';
3140 if ( $wgUser->isLoggedIn() ) {
3142 'tabindex' => ++
$tabindex,
3143 'accesskey' => wfMessage( 'accesskey-watch' )->text() ,
3144 'id' => 'wpWatchthis',
3146 $checkboxes['watch'] =
3147 Xml
::check( 'wpWatchthis', $checked['watch'], $attribs ) .
3148 " <label for='wpWatchthis' id='mw-editpage-watch'" .
3149 Xml
::expandAttributes( array( 'title' => Linker
::titleAttrib( 'watch', 'withaccess' ) ) ) .
3150 ">{$watchLabel}</label>";
3152 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
3157 * Returns an array of html code of the following buttons:
3158 * save, diff, preview and live
3160 * @param $tabindex int Current tabindex
3164 public function getEditButtons( &$tabindex ) {
3171 'tabindex' => ++
$tabindex,
3172 'value' => wfMessage( 'savearticle' )->text() ,
3173 'accesskey' => wfMessage( 'accesskey-save' )->text() ,
3174 'title' => wfMessage( 'tooltip-save' )->text() . ' [' . wfMessage( 'accesskey-save' )->text() . ']',
3176 $buttons['save'] = Xml
::element( 'input', $temp, '' );
3178 ++
$tabindex; // use the same for preview and live preview
3180 'id' => 'wpPreview',
3181 'name' => 'wpPreview',
3183 'tabindex' => $tabindex,
3184 'value' => wfMessage( 'showpreview' )->text() ,
3185 'accesskey' => wfMessage( 'accesskey-preview' )->text() ,
3186 'title' => wfMessage( 'tooltip-preview' )->text() . ' [' . wfMessage( 'accesskey-preview' )->text() . ']',
3188 $buttons['preview'] = Xml
::element( 'input', $temp, '' );
3189 $buttons['live'] = '';
3195 'tabindex' => ++
$tabindex,
3196 'value' => wfMessage( 'showdiff' )->text() ,
3197 'accesskey' => wfMessage( 'accesskey-diff' )->text() ,
3198 'title' => wfMessage( 'tooltip-diff' )->text() . ' [' . wfMessage( 'accesskey-diff' )->text() . ']',
3200 $buttons['diff'] = Xml
::element( 'input', $temp, '' );
3202 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
3207 * Output preview text only. This can be sucked into the edit page
3208 * via JavaScript, and saves the server time rendering the skin as
3209 * well as theoretically being more robust on the client (doesn't
3210 * disturb the edit box's undo history, won't eat your text on
3213 * @todo This doesn't include category or interlanguage links.
3214 * Would need to enhance it a bit, "<s>maybe wrap them in XML
3215 * or something...</s>" that might also require more skin
3216 * initialization, so check whether that's a problem.
3218 function livePreview() {
3221 header( 'Content-type: text/xml; charset=utf-8' );
3222 header( 'Cache-control: no-cache' );
3224 $previewText = $this->getPreviewText();
3225 #$categories = $skin->getCategoryLinks();
3228 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
3229 Xml
::tags( 'livepreview', null,
3230 Xml
::element( 'preview', null, $previewText )
3231 #. Xml::element( 'category', null, $categories )
3237 * Call the stock "user is blocked" page
3239 * @deprecated in 1.19; throw an exception directly instead
3241 function blockedPage() {
3242 wfDeprecated( __METHOD__
, '1.19' );
3245 throw new UserBlockedError( $wgUser->getBlock() );
3249 * Produce the stock "please login to edit pages" page
3251 * @deprecated in 1.19; throw an exception directly instead
3253 function userNotLoggedInPage() {
3254 wfDeprecated( __METHOD__
, '1.19' );
3255 throw new PermissionsError( 'edit' );
3259 * Show an error page saying to the user that he has insufficient permissions
3260 * to create a new page
3262 * @deprecated in 1.19; throw an exception directly instead
3264 function noCreatePermission() {
3265 wfDeprecated( __METHOD__
, '1.19' );
3266 $permission = $this->mTitle
->isTalkPage() ?
'createtalk' : 'createpage';
3267 throw new PermissionsError( $permission );
3271 * Creates a basic error page which informs the user that
3272 * they have attempted to edit a nonexistent section.
3274 function noSuchSectionPage() {
3277 $wgOut->prepareErrorPage( wfMessage( 'nosuchsectiontitle' ) );
3279 $res = wfMessage( 'nosuchsectiontext', 'parse', $this->section
)->parseAsBlock();
3280 wfRunHooks( 'EditPageNoSuchSection', array( &$this, &$res ) );
3281 $wgOut->addHTML( $res );
3283 $wgOut->returnToMain( false, $this->mTitle
);
3287 * Produce the stock "your edit contains spam" page
3289 * @param $match string Text which triggered one or more filters
3290 * @deprecated since 1.17 Use method spamPageWithContent() instead
3292 static function spamPage( $match = false ) {
3293 wfDeprecated( __METHOD__
, '1.17' );
3295 global $wgOut, $wgTitle;
3297 $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );
3299 $wgOut->addHTML( '<div id="spamprotected">' );
3300 $wgOut->addWikiMsg( 'spamprotectiontext' );
3302 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
3304 $wgOut->addHTML( '</div>' );
3306 $wgOut->returnToMain( false, $wgTitle );
3310 * Show "your edit contains spam" page with your diff and text
3312 * @param $match string|Array|bool Text (or array of texts) which triggered one or more filters
3314 public function spamPageWithContent( $match = false ) {
3315 global $wgOut, $wgLang;
3316 $this->textbox2
= $this->textbox1
;
3318 if( is_array( $match ) ){
3319 $match = $wgLang->listToText( $match );
3321 $wgOut->prepareErrorPage( wfMessage( 'spamprotectiontitle' ) );
3323 $wgOut->addHTML( '<div id="spamprotected">' );
3324 $wgOut->addWikiMsg( 'spamprotectiontext' );
3326 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
3328 $wgOut->addHTML( '</div>' );
3330 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourdiff" );
3333 $wgOut->wrapWikiMsg( '<h2>$1</h2>', "yourtext" );
3334 $this->showTextbox2();
3336 $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
3340 * Format an anchor fragment as it would appear for a given section name
3341 * @param $text String
3345 function sectionAnchor( $text ) {
3347 return $wgParser->guessSectionNameFromWikiText( $text );
3351 * Check if the browser is on a blacklist of user-agents known to
3352 * mangle UTF-8 data on form submission. Returns true if Unicode
3353 * should make it through, false if it's known to be a problem.
3357 function checkUnicodeCompliantBrowser() {
3358 global $wgBrowserBlackList, $wgRequest;
3360 $currentbrowser = $wgRequest->getHeader( 'User-Agent' );
3361 if ( $currentbrowser === false ) {
3362 // No User-Agent header sent? Trust it by default...
3366 foreach ( $wgBrowserBlackList as $browser ) {
3367 if ( preg_match( $browser, $currentbrowser ) ) {
3375 * Filter an input field through a Unicode de-armoring process if it
3376 * came from an old browser with known broken Unicode editing issues.
3378 * @param $request WebRequest
3379 * @param $field String
3383 function safeUnicodeInput( $request, $field ) {
3384 $text = rtrim( $request->getText( $field ) );
3385 return $request->getBool( 'safemode' )
3386 ?
$this->unmakesafe( $text )
3391 * @param $request WebRequest
3392 * @param $text string
3395 function safeUnicodeText( $request, $text ) {
3396 $text = rtrim( $text );
3397 return $request->getBool( 'safemode' )
3398 ?
$this->unmakesafe( $text )
3403 * Filter an output field through a Unicode armoring process if it is
3404 * going to an old browser with known broken Unicode editing issues.
3406 * @param $text String
3410 function safeUnicodeOutput( $text ) {
3412 $codedText = $wgContLang->recodeForEdit( $text );
3413 return $this->checkUnicodeCompliantBrowser()
3415 : $this->makesafe( $codedText );
3419 * A number of web browsers are known to corrupt non-ASCII characters
3420 * in a UTF-8 text editing environment. To protect against this,
3421 * detected browsers will be served an armored version of the text,
3422 * with non-ASCII chars converted to numeric HTML character references.
3424 * Preexisting such character references will have a 0 added to them
3425 * to ensure that round-trips do not alter the original data.
3427 * @param $invalue String
3431 function makesafe( $invalue ) {
3432 // Armor existing references for reversability.
3433 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
3438 for ( $i = 0; $i < strlen( $invalue ); $i++
) {
3439 $bytevalue = ord( $invalue[$i] );
3440 if ( $bytevalue <= 0x7F ) { // 0xxx xxxx
3441 $result .= chr( $bytevalue );
3443 } elseif ( $bytevalue <= 0xBF ) { // 10xx xxxx
3444 $working = $working << 6;
3445 $working +
= ( $bytevalue & 0x3F );
3447 if ( $bytesleft <= 0 ) {
3448 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
3450 } elseif ( $bytevalue <= 0xDF ) { // 110x xxxx
3451 $working = $bytevalue & 0x1F;
3453 } elseif ( $bytevalue <= 0xEF ) { // 1110 xxxx
3454 $working = $bytevalue & 0x0F;
3456 } else { // 1111 0xxx
3457 $working = $bytevalue & 0x07;
3465 * Reverse the previously applied transliteration of non-ASCII characters
3466 * back to UTF-8. Used to protect data from corruption by broken web browsers
3467 * as listed in $wgBrowserBlackList.
3469 * @param $invalue String
3473 function unmakesafe( $invalue ) {
3475 for ( $i = 0; $i < strlen( $invalue ); $i++
) {
3476 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i +
3] != '0' ) ) {
3480 $hexstring .= $invalue[$i];
3482 } while ( ctype_xdigit( $invalue[$i] ) && ( $i < strlen( $invalue ) ) );
3484 // Do some sanity checks. These aren't needed for reversability,
3485 // but should help keep the breakage down if the editor
3486 // breaks one of the entities whilst editing.
3487 if ( ( substr( $invalue, $i, 1 ) == ";" ) and ( strlen( $hexstring ) <= 6 ) ) {
3488 $codepoint = hexdec( $hexstring );
3489 $result .= codepointToUtf8( $codepoint );
3491 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
3494 $result .= substr( $invalue, $i, 1 );
3497 // reverse the transform that we made for reversability reasons.
3498 return strtr( $result, array( "�" => "&#x" ) );