3 * Contain the EditPage class
8 * Splitting edit page/HTML interface from Article...
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
21 var $save = false, $preview = false;
22 var $minoredit = false, $watchthis = false;
23 var $textbox1 = '', $textbox2 = '', $summary = '';
24 var $edittime = '', $section = '';
31 function EditPage( $article ) {
32 $this->mArticle
=& $article;
34 $this->mTitle
=& $wgTitle;
38 * This is the function that gets called for "action=edit".
41 global $wgOut, $wgUser, $wgWhitelistEdit, $wgRequest;
42 // this is not an article
43 $wgOut->setArticleFlag(false);
45 $this->importFormData( $wgRequest );
52 if ( ! $this->mTitle
->userCanEdit() ) {
53 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ), true );
56 if ( $wgUser->isBlocked() ) {
57 $this->blockedIPpage();
60 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
61 $this->userNotLoggedInPage();
65 if( $this->save ||
$this->preview
) {
66 $this->editForm( 'preview' );
68 $wgOut->readOnlyPage( $this->mArticle
->getContent( true ) );
73 $this->editForm( 'save' );
74 } else if ( $this->preview
) {
75 $this->editForm( 'preview' );
76 } else { # First time through
78 if( $wgUser->getOption('previewonfirst') ) {
79 $this->editForm( 'preview' );
81 $this->editForm( 'initial' );
89 function importFormData( &$request ) {
90 # These fields need to be checked for encoding.
91 # Also remove trailing whitespace, but don't remove _initial_
92 # whitespace from the text boxes. This may be significant formatting.
93 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
94 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
95 $this->summary
= trim( $request->getText( 'wpSummary' ) );
97 $this->edittime
= $request->getVal( 'wpEdittime' );
98 if( !preg_match( '/^\d{14}$/', $this->edittime
)) $this->edittime
= '';
100 $this->preview
= $request->getCheck( 'wpPreview' );
101 $this->save
= $request->wasPosted() && !$this->preview
;
102 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
103 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
105 $this->oldid
= $request->getInt( 'oldid' );
107 # Section edit can come from either the form or a link
108 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
110 $this->live
= $request->getCheck( 'live' );
114 * Since there is only one text field on the edit form,
115 * pressing <enter> will cause the form to be submitted, but
116 * the submit button value won't appear in the query, so we
117 * Fake it here before going back to edit(). This is kind of
118 * ugly, but it helps some old URLs to still work.
121 if( !$this->preview
) $this->save
= true;
127 * The edit form is self-submitting, so that when things like
128 * preview and edit conflicts occur, we get the same form back
129 * with the extra stuff added. Only when the final submission
130 * is made and all is well do we actually save and redirect to
131 * the newly-edited page.
133 * @param string $formtype Type of form either : save, initial or preview
135 function editForm( $formtype ) {
136 global $wgOut, $wgUser;
137 global $wgLang, $wgContLang, $wgParser, $wgTitle;
138 global $wgAllowAnonymousMinor;
139 global $wgWhitelistEdit;
140 global $wgSpamRegex, $wgFilterCallback;
143 $sk = $wgUser->getSkin();
145 // css / js subpages of user pages get a special treatment
146 $isCssJsSubpage = (Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() ));
148 if(!$this->mTitle
->getArticleID()) { # new article
149 $wgOut->addWikiText(wfmsg('newarticletext'));
152 if( Namespace::isTalk( $this->mTitle
->getNamespace() ) ) {
153 $wgOut->addWikiText(wfmsg('talkpagetext'));
156 # Attempt submission here. This will check for edit conflicts,
157 # and redundantly check for locked database, blocked IPs, etc.
158 # that edit() already checked just in case someone tries to sneak
159 # in the back door with a hand-edited submission URL.
161 if ( 'save' == $formtype ) {
163 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
164 $this->spamPage ( $matches[0] );
167 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
168 # Error messages or other handling should be performed by the filter function
171 if ( $wgUser->isBlocked() ) {
172 $this->blockedIPpage();
175 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
176 $this->userNotLoggedInPage();
179 if ( wfReadOnly() ) {
180 $wgOut->readOnlyPage();
184 # If article is new, insert it.
185 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
187 # Don't save a new article if it's blank.
188 if ( ( '' == $this->textbox1
) ||
189 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
190 $wgOut->redirect( $this->mTitle
->getFullURL() );
193 if (wfRunHooks('ArticleSave', $this->mArticle
, $wgUser, $this->textbox1
,
194 $this->summary
, $this->minoredit
, $this->watchthis
, NULL))
196 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
197 $this->minoredit
, $this->watchthis
);
198 wfRunHooks('ArticleSaveComplete', $this->mArticle
, $wgUser, $this->textbox1
,
199 $this->summary
, $this->minoredit
, $this->watchthis
, NULL);
204 # Article exists. Check for edit conflict.
206 $this->mArticle
->clear(); # Force reload of dates, etc.
207 $this->mArticle
->forUpdate( true ); # Lock the article
209 if( ( $this->section
!= 'new' ) &&
210 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
213 $userid = $wgUser->getID();
216 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
217 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
220 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
221 $this->section
, $this->textbox1
, $this->summary
);
223 # Suppress edit conflict with self
225 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
228 # switch from section editing to normal editing in edit conflict
231 if( $this->mergeChangesInto( $text ) ){
232 // Successful merge! Maybe we should tell the user the good news?
236 $this->textbox1
= $text;
240 if ( ! $isConflict ) {
243 if( $this->section
== 'new' ) {
244 if( $this->summary
!= '' ) {
245 $sectionanchor = $this->sectionAnchor( $this->summary
);
247 } elseif( $this->section
!= '' ) {
248 # Try to get a section anchor from the section source, redirect to edited section if header found
249 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
250 # for duplicate heading checking and maybe parsing
251 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
252 # we can't deal with anchors, includes, html etc in the header for now,
253 # headline would need to be parsed to improve this
254 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
255 if($hasmatch and strlen($matches[2]) > 0) {
256 $sectionanchor = $this->sectionAnchor( $matches[2] );
260 if (wfRunHooks('ArticleSave', $this, $wgUser, $text, $this->summary
,
261 $this->minoredit
, $this->watchthis
, $sectionanchor))
263 # update the article here
264 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
265 $this->watchthis
, '', $sectionanchor ))
267 wfRunHooks('ArticleSaveComplete', $this, $wgUser, $text, $this->summary
,
268 $this->minoredit
, $this->watchthis
, $sectionanchor);
276 # First time through: get contents, set time for conflict
279 if ( 'initial' == $formtype ) {
282 $wgOut->setRobotpolicy( 'noindex,nofollow' );
284 # Enabled article-related sidebar, toplinks, etc.
285 $wgOut->setArticleRelated( true );
288 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
289 $wgOut->setPageTitle( $s );
290 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
292 $this->textbox2
= $this->textbox1
;
293 $this->textbox1
= $this->mArticle
->getContent( true );
294 $this->edittime
= $this->mArticle
->getTimestamp();
297 if( $this->section
!= '' ) {
298 if( $this->section
== 'new' ) {
299 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
301 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
303 if(!$this->preview
) {
304 preg_match( "/^(=+)(.+)\\1/mi",
307 if( !empty( $matches[2] ) ) {
308 $this->summary
= "/* ". trim($matches[2])." */ ";
312 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
314 $wgOut->setPageTitle( $s );
315 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
316 $this->mArticle
->setOldSubtitle();
317 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
319 if ( $this->oldid
) {
320 $this->mArticle
->setOldSubtitle();
321 $wgOut->addHTML( wfMsg( 'editingold' ) );
326 $wgOut->addHTML( '<strong>' .
327 wfMsg( 'readonlywarning' ) .
329 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
330 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
332 if( $this->mTitle
->isProtected('edit') ) {
333 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
334 "</strong><br />\n" );
337 $kblength = (int)(strlen( $this->textbox1
) / 1024);
338 if( $kblength > 29 ) {
339 $wgOut->addHTML( '<strong>' .
340 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
344 $rows = $wgUser->getOption( 'rows' );
345 $cols = $wgUser->getOption( 'cols' );
347 $ew = $wgUser->getOption( 'editwidth' );
348 if ( $ew ) $ew = " style=\"width:100%\"";
351 $q = 'action=submit';
352 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
353 $action = $this->mTitle
->escapeLocalURL( $q );
355 $summary = wfMsg('summary');
356 $subject = wfMsg('subject');
357 $minor = wfMsg('minoredit');
358 $watchthis = wfMsg ('watchthis');
359 $save = wfMsg('savearticle');
360 $prev = wfMsg('showpreview');
362 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
364 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
365 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
366 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
367 htmlspecialchars( wfMsg( 'newwindow' ) );
369 global $wgRightsText;
370 $copywarn = "<div id=\"editpage-copywarn\">\n" .
371 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
372 '[[' . wfMsg( 'copyrightpage' ) . ']]',
373 $wgRightsText ) . "\n</div>";
375 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
376 # prepare toolbar for edit buttons
377 $toolbar = $this->getEditToolbar();
382 // activate checkboxes if user wants them to be always active
383 if( !$this->preview
) {
384 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
385 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
387 // activate checkbox also if user is already watching the page,
388 // require wpWatchthis to be unset so that second condition is not
389 // checked unnecessarily
390 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
395 if ( 0 != $wgUser->getID() ||
$wgAllowAnonymousMinor ) {
397 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
398 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
399 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
404 if ( 0 != $wgUser->getID() ) {
405 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
406 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
407 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
410 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
412 $wgOut->addHTML( '<div id="wikiPreview">' );
413 if ( 'preview' == $formtype) {
414 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
415 if( $wgUser->getOption('previewontop' ) ) {
416 $wgOut->addHTML( $previewOutput );
417 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
420 $wgOut->addHTML( '</div>' );
422 # if this is a comment, show a subject line at the top, which is also the edit summary.
423 # Otherwise, show a summary field at the bottom
424 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
425 if( $this->section
== 'new' ) {
426 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
429 $commentsubject = '';
430 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
433 if( !$this->preview
) {
434 # Don't select the edit box on preview; this interferes with seeing what's going on.
435 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
437 # Prepare a list of templates used by this page
438 $db =& wfGetDB( DB_SLAVE
);
439 $page = $db->tableName( 'page' );
440 $links = $db->tableName( 'links' );
441 $id = $this->mTitle
->getArticleID();
442 $sql = "SELECT page_namespace,page_title,page_id ".
443 "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE
;
444 $res = $db->query( $sql, "EditPage::editform" );
446 if ( $db->numRows( $res ) ) {
447 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
448 while ( $row = $db->fetchObject( $res ) ) {
449 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
450 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
453 $templates .= '</ul>';
458 global $wgLivePreview, $wgStylePath;
460 * Live Preview lets us fetch rendered preview page content and
461 * add it to the page without refreshing the whole page.
462 * Set up the button for it; if not supported by the browser
463 * it will fall through to the normal form submission method.
465 if( $wgLivePreview ) {
466 $wgOut->addHTML( '<script type="text/javascript" src="' .
467 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
468 '"></script>' . "\n" );
469 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
470 $liveOnclick = 'onclick="return !livePreview('.
471 'getElementById(\'wikiPreview\'),' .
472 'editform.wpTextbox1.value,' .
473 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
478 $wgOut->addHTML( <<<END
480 <form id="editform" name="editform" method="post" action="$action"
481 enctype="multipart/form-data">
483 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
486 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
491 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
492 " title=\"".wfMsg('tooltip-save')."\"/>
493 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
494 " title=\"".wfMsg('tooltip-preview')."\"/>
495 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
496 $wgOut->addWikiText( $copywarn );
498 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
499 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
502 require_once( "DifferenceEngine.php" );
503 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
504 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
505 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
507 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
508 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
509 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
513 $wgOut->addHTML( "</form>\n" );
514 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
515 $wgOut->addHTML('<div id="wikiPreview">' . $previewOutput . '</div>');
522 function initForm() {
523 $this->edittime
= $this->mArticle
->getTimestamp();
524 $this->textbox1
= $this->mArticle
->getContent( true );
529 function getPreviewText( $isConflict, $isCssJsSubpage ) {
530 global $wgOut, $wgUser, $wgTitle, $wgParser;
531 $previewhead='<h2>' . wfMsg( 'preview' ) . "</h2>\n<p><center><font color=\"#cc0000\">" .
532 wfMsg( 'note' ) . wfMsg( 'previewnote' ) . "</font></center></p>\n";
534 $previewhead.='<h2>' . wfMsg( 'previewconflict' ) .
538 $parserOptions = ParserOptions
::newFromUser( $wgUser );
539 $parserOptions->setEditSection( false );
540 $parserOptions->setEditSectionOnRightClick( false );
542 # don't parse user css/js, show message about preview
543 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
545 if ( $isCssJsSubpage ) {
546 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
547 $previewtext = wfMsg('usercsspreview');
548 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
549 $previewtext = wfMsg('userjspreview');
551 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
552 $wgOut->addHTML( $parserOutput->mText
);
554 # if user want to see preview when he edit an article
555 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
556 $this->textbox1
= $this->mArticle
->getContent(true);
559 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $this->textbox1
) ."\n\n",
560 $wgTitle, $parserOptions );
562 $previewHTML = $parserOutput->mText
;
563 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
564 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
566 return $previewhead . $previewHTML;
572 function blockedIPpage() {
573 global $wgOut, $wgUser, $wgContLang, $wgIP;
575 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
576 $wgOut->setRobotpolicy( 'noindex,nofollow' );
577 $wgOut->setArticleRelated( false );
579 $id = $wgUser->blockedBy();
580 $reason = $wgUser->blockedFor();
583 if ( is_numeric( $id ) ) {
584 $name = User
::whoIs( $id );
588 $link = '[[' . $wgContLang->getNsText( Namespace::getUser() ) .
589 ":{$name}|{$name}]]";
591 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
592 $wgOut->returnToMain( false );
598 function userNotLoggedInPage() {
599 global $wgOut, $wgUser;
601 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
602 $wgOut->setRobotpolicy( 'noindex,nofollow' );
603 $wgOut->setArticleRelated( false );
605 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
606 $wgOut->returnToMain( false );
612 function spamPage ( $match = false )
615 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
616 $wgOut->setRobotpolicy( 'noindex,nofollow' );
617 $wgOut->setArticleRelated( false );
619 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
621 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
623 $wgOut->returnToMain( false );
627 * Forks processes to scan the originating IP for an open proxy server
628 * MemCached can be used to skip IPs that have already been scanned
630 function proxyCheck() {
631 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
632 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
634 if ( !$wgBlockOpenProxies ) {
640 if ( $wgUseMemCached ) {
641 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
642 $mcValue = $wgMemc->get( $mcKey );
650 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
651 $iphash = md5( $wgIP . $wgProxyKey );
652 $url = $title->getFullURL( 'ip='.$iphash );
654 foreach ( $wgProxyPorts as $port ) {
655 $params = implode( ' ', array(
656 escapeshellarg( $wgProxyScriptPath ),
657 escapeshellarg( $wgIP ),
658 escapeshellarg( $port ),
659 escapeshellarg( $url )
661 exec( "php $params &>/dev/null &" );
664 if ( $wgUseMemCached ) {
665 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
674 function mergeChangesInto( &$text ){
675 $yourtext = $this->mArticle
->fetchRevisionText();
677 $db =& wfGetDB( DB_SLAVE
);
678 $oldText = $this->mArticle
->fetchRevisionText(
679 $db->timestamp( $this->edittime
),
682 if(wfMerge($oldText, $text, $yourtext, $result)){
691 function checkUnicodeCompliantBrowser() {
692 global $wgBrowserBlackList;
693 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
694 foreach ( $wgBrowserBlackList as $browser ) {
695 if ( preg_match($browser, $currentbrowser) ) {
703 * Format an anchor fragment as it would appear for a given section name
704 * @param string $text
708 function sectionAnchor( $text ) {
709 global $wgInputEncoding;
710 $headline = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
712 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
713 $headline = trim( $headline );
714 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
715 $replacearray = array(
720 array_keys( $replacearray ),
721 array_values( $replacearray ),
726 * Shows a bulletin board style toolbar for common editing functions.
727 * It can be disabled in the user preferences.
728 * The necessary JavaScript code can be found in style/wikibits.js.
730 function getEditToolbar() {
731 global $wgStylePath, $wgLang, $wgMimeType;
734 * toolarray an array of arrays which each include the filename of
735 * the button image (without path), the opening tag, the closing tag,
736 * and optionally a sample text that is inserted between the two when no
737 * selection is highlighted.
738 * The tip text is shown when the user moves the mouse over the button.
740 * Already here are accesskeys (key), which are not used yet until someone
741 * can figure out a way to make them work in IE. However, we should make
742 * sure these keys are not defined on the edit page.
745 array( 'image'=>'button_bold.png',
748 'sample'=> wfMsg('bold_sample'),
749 'tip' => wfMsg('bold_tip'),
752 array( 'image'=>'button_italic.png',
755 'sample'=> wfMsg('italic_sample'),
756 'tip' => wfMsg('italic_tip'),
759 array( 'image'=>'button_link.png',
762 'sample'=> wfMsg('link_sample'),
763 'tip' => wfMsg('link_tip'),
766 array( 'image'=>'button_extlink.png',
769 'sample'=> wfMsg('extlink_sample'),
770 'tip' => wfMsg('extlink_tip'),
773 array( 'image'=>'button_headline.png',
776 'sample'=> wfMsg('headline_sample'),
777 'tip' => wfMsg('headline_tip'),
780 array( 'image'=>'button_image.png',
781 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
783 'sample'=> wfMsg('image_sample'),
784 'tip' => wfMsg('image_tip'),
787 array( 'image' => 'button_media.png',
788 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
790 'sample'=> wfMsg('media_sample'),
791 'tip' => wfMsg('media_tip'),
794 array( 'image' => 'button_math.png',
795 'open' => "\\<math\\>",
796 'close' => "\\</math\\>",
797 'sample'=> wfMsg('math_sample'),
798 'tip' => wfMsg('math_tip'),
801 array( 'image' => 'button_nowiki.png',
802 'open' => "\\<nowiki\\>",
803 'close' => "\\</nowiki\\>",
804 'sample'=> wfMsg('nowiki_sample'),
805 'tip' => wfMsg('nowiki_tip'),
808 array( 'image' => 'button_sig.png',
812 'tip' => wfMsg('sig_tip'),
815 array( 'image' => 'button_hr.png',
816 'open' => "\\n----\\n",
819 'tip' => wfMsg('hr_tip'),
823 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
825 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
826 foreach($toolarray as $tool) {
828 $image=$wgStylePath.'/common/images/'.$tool['image'];
830 $close=$tool['close'];
831 $sample = addslashes( $tool['sample'] );
833 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
834 // Older browsers show a "speedtip" type message only for ALT.
835 // Ideally these should be different, realistically they
836 // probably don't need to be.
837 $tip = addslashes( $tool['tip'] );
839 #$key = $tool["key"];
841 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
844 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
845 $toolbar.="document.writeln(\"</div>\");\n";
847 $toolbar.="/*]]>*/\n</script>";
852 * Output preview text only. This can be sucked into the edit page
853 * via JavaScript, and saves the server time rendering the skin as
854 * well as theoretically being more robust on the client (doesn't
855 * disturb the edit box's undo history, won't eat your text on
858 * @todo This doesn't include category or interlanguage links.
859 * Would need to enhance it a bit, maybe wrap them in XML
860 * or something... that might also require more skin
861 * initialization, so check whether that's a problem.
863 function livePreview() {
866 header( 'Content-type: text/xml' );
867 header( 'Cache-control: no-cache' );
869 echo $this->getPreviewText( false, false );