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
or $wgUser->getOption('previewonfirst')) {
75 $this->editForm( 'preview' );
76 } else { # First time through
77 $this->editForm( 'initial' );
84 function importFormData( &$request ) {
85 # These fields need to be checked for encoding.
86 # Also remove trailing whitespace, but don't remove _initial_
87 # whitespace from the text boxes. This may be significant formatting.
88 $this->textbox1
= rtrim( $request->getText( 'wpTextbox1' ) );
89 $this->textbox2
= rtrim( $request->getText( 'wpTextbox2' ) );
90 $this->summary
= trim( $request->getText( 'wpSummary' ) );
92 $this->edittime
= $request->getVal( 'wpEdittime' );
93 if( !preg_match( '/^\d{14}$/', $this->edittime
)) $this->edittime
= '';
95 $this->preview
= $request->getCheck( 'wpPreview' );
96 $this->save
= $request->wasPosted() && !$this->preview
;
97 $this->minoredit
= $request->getCheck( 'wpMinoredit' );
98 $this->watchthis
= $request->getCheck( 'wpWatchthis' );
100 $this->oldid
= $request->getInt( 'oldid' );
102 # Section edit can come from either the form or a link
103 $this->section
= $request->getVal( 'wpSection', $request->getVal( 'section' ) );
105 $this->live
= $request->getCheck( 'live' );
109 * Since there is only one text field on the edit form,
110 * pressing <enter> will cause the form to be submitted, but
111 * the submit button value won't appear in the query, so we
112 * Fake it here before going back to edit(). This is kind of
113 * ugly, but it helps some old URLs to still work.
116 if( !$this->preview
) $this->save
= true;
122 * The edit form is self-submitting, so that when things like
123 * preview and edit conflicts occur, we get the same form back
124 * with the extra stuff added. Only when the final submission
125 * is made and all is well do we actually save and redirect to
126 * the newly-edited page.
128 * @param string $formtype Type of form either : save, initial or preview
130 function editForm( $formtype ) {
131 global $wgOut, $wgUser;
132 global $wgLang, $wgContLang, $wgParser, $wgTitle;
133 global $wgAllowAnonymousMinor;
134 global $wgWhitelistEdit;
135 global $wgSpamRegex, $wgFilterCallback;
138 $sk = $wgUser->getSkin();
140 // css / js subpages of user pages get a special treatment
141 $isCssJsSubpage = (Namespace::getUser() == $wgTitle->getNamespace() and preg_match("/\\.(css|js)$/", $wgTitle->getText() ));
143 if(!$this->mTitle
->getArticleID()) { # new article
144 $wgOut->addWikiText(wfmsg('newarticletext'));
147 if( Namespace::isTalk( $this->mTitle
->getNamespace() ) ) {
148 $wgOut->addWikiText(wfmsg('talkpagetext'));
151 # Attempt submission here. This will check for edit conflicts,
152 # and redundantly check for locked database, blocked IPs, etc.
153 # that edit() already checked just in case someone tries to sneak
154 # in the back door with a hand-edited submission URL.
156 if ( 'save' == $formtype ) {
158 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1
, $matches ) ) {
159 $this->spamPage ( $matches[0] );
162 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle
, $this->textbox1
, $this->section
) ) {
163 # Error messages or other handling should be performed by the filter function
166 if ( $wgUser->isBlocked() ) {
167 $this->blockedIPpage();
170 if ( !$wgUser->getID() && $wgWhitelistEdit ) {
171 $this->userNotLoggedInPage();
174 if ( wfReadOnly() ) {
175 $wgOut->readOnlyPage();
179 # If article is new, insert it.
180 $aid = $this->mTitle
->getArticleID( GAID_FOR_UPDATE
);
182 # Don't save a new article if it's blank.
183 if ( ( '' == $this->textbox1
) ||
184 ( wfMsg( 'newarticletext' ) == $this->textbox1
) ) {
185 $wgOut->redirect( $this->mTitle
->getFullURL() );
188 if (wfRunHooks('ArticleSave', $this->mArticle
, $wgUser, $this->textbox1
,
189 $this->summary
, $this->minoredit
, $this->watchthis
, NULL))
191 $this->mArticle
->insertNewArticle( $this->textbox1
, $this->summary
,
192 $this->minoredit
, $this->watchthis
);
193 wfRunHooks('ArticleSaveComplete', $this->mArticle
, $wgUser, $this->textbox1
,
194 $this->summary
, $this->minoredit
, $this->watchthis
, NULL);
199 # Article exists. Check for edit conflict.
201 $this->mArticle
->clear(); # Force reload of dates, etc.
202 $this->mArticle
->forUpdate( true ); # Lock the article
204 if( ( $this->section
!= 'new' ) &&
205 ($this->mArticle
->getTimestamp() != $this->edittime
) ) {
208 $userid = $wgUser->getID();
211 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
212 $this->section
, $this->textbox1
, $this->summary
, $this->edittime
);
215 $text = $this->mArticle
->getTextOfLastEditWithSectionReplacedOrAdded(
216 $this->section
, $this->textbox1
, $this->summary
);
218 # Suppress edit conflict with self
220 if ( ( 0 != $userid ) && ( $this->mArticle
->getUser() == $userid ) ) {
223 # switch from section editing to normal editing in edit conflict
226 if( $this->mergeChangesInto( $text ) ){
227 // Successful merge! Maybe we should tell the user the good news?
231 $this->textbox1
= $text;
235 if ( ! $isConflict ) {
238 if( $this->section
== 'new' ) {
239 if( $this->summary
!= '' ) {
240 $sectionanchor = $this->sectionAnchor( $this->summary
);
242 } elseif( $this->section
!= '' ) {
243 # Try to get a section anchor from the section source, redirect to edited section if header found
244 # XXX: might be better to integrate this into Article::getTextOfLastEditWithSectionReplacedOrAdded
245 # for duplicate heading checking and maybe parsing
246 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1
, $matches );
247 # we can't deal with anchors, includes, html etc in the header for now,
248 # headline would need to be parsed to improve this
249 #if($hasmatch and strlen($matches[2]) > 0 and !preg_match( "/[\\['{<>]/", $matches[2])) {
250 if($hasmatch and strlen($matches[2]) > 0) {
251 $sectionanchor = $this->sectionAnchor( $matches[2] );
255 if (wfRunHooks('ArticleSave', $this, $wgUser, $text, $this->summary
,
256 $this->minoredit
, $this->watchthis
, $sectionanchor))
258 # update the article here
259 if($this->mArticle
->updateArticle( $text, $this->summary
, $this->minoredit
,
260 $this->watchthis
, '', $sectionanchor ))
262 wfRunHooks('ArticleSaveComplete', $this, $wgUser, $text, $this->summary
,
263 $this->minoredit
, $this->watchthis
, $sectionanchor);
271 # First time through: get contents, set time for conflict
274 if ( 'initial' == $formtype ) {
275 $this->edittime
= $this->mArticle
->getTimestamp();
276 $this->textbox1
= $this->mArticle
->getContent( true );
280 $wgOut->setRobotpolicy( 'noindex,nofollow' );
282 # Enabled article-related sidebar, toplinks, etc.
283 $wgOut->setArticleRelated( true );
286 $s = wfMsg( 'editconflict', $this->mTitle
->getPrefixedText() );
287 $wgOut->setPageTitle( $s );
288 $wgOut->addHTML( wfMsg( 'explainconflict' ) );
290 $this->textbox2
= $this->textbox1
;
291 $this->textbox1
= $this->mArticle
->getContent( true );
292 $this->edittime
= $this->mArticle
->getTimestamp();
295 if( $this->section
!= '' ) {
296 if( $this->section
== 'new' ) {
297 $s = wfMsg('editingcomment', $this->mTitle
->getPrefixedText() );
299 $s = wfMsg('editingsection', $this->mTitle
->getPrefixedText() );
301 if(!$this->preview
) {
302 preg_match( "/^(=+)(.+)\\1/mi",
305 if( !empty( $matches[2] ) ) {
306 $this->summary
= "/* ". trim($matches[2])." */ ";
310 $s = wfMsg( 'editing', $this->mTitle
->getPrefixedText() );
312 $wgOut->setPageTitle( $s );
313 if ( !$wgUseLatin1 && !$this->checkUnicodeCompliantBrowser() ) {
314 $this->mArticle
->setOldSubtitle();
315 $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
317 if ( $this->oldid
) {
318 $this->mArticle
->setOldSubtitle();
319 $wgOut->addHTML( wfMsg( 'editingold' ) );
324 $wgOut->addHTML( '<strong>' .
325 wfMsg( 'readonlywarning' ) .
327 } else if ( $isCssJsSubpage and 'preview' != $formtype) {
328 $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
330 if( $this->mTitle
->isProtected('edit') ) {
331 $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
332 "</strong><br />\n" );
335 $kblength = (int)(strlen( $this->textbox1
) / 1024);
336 if( $kblength > 29 ) {
337 $wgOut->addHTML( '<strong>' .
338 wfMsg( 'longpagewarning', $wgLang->formatNum( $kblength ) )
342 $rows = $wgUser->getOption( 'rows' );
343 $cols = $wgUser->getOption( 'cols' );
345 $ew = $wgUser->getOption( 'editwidth' );
346 if ( $ew ) $ew = " style=\"width:100%\"";
349 $q = 'action=submit';
350 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
351 $action = $this->mTitle
->escapeLocalURL( $q );
353 $summary = wfMsg('summary');
354 $subject = wfMsg('subject');
355 $minor = wfMsg('minoredit');
356 $watchthis = wfMsg ('watchthis');
357 $save = wfMsg('savearticle');
358 $prev = wfMsg('showpreview');
360 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedText(),
362 $edithelpurl = $sk->makeUrl( wfMsg( 'edithelppage' ));
363 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
364 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
365 htmlspecialchars( wfMsg( 'newwindow' ) );
367 global $wgRightsText;
368 $copywarn = "<div id=\"editpage-copywarn\">\n" .
369 wfMsg( $wgRightsText ?
'copyrightwarning' : 'copyrightwarning2',
370 '[[' . wfMsg( 'copyrightpage' ) . ']]',
371 $wgRightsText ) . "\n</div>";
373 if( $wgUser->getOption('showtoolbar') and !$isCssJsSubpage ) {
374 # prepare toolbar for edit buttons
375 $toolbar = $this->getEditToolbar();
380 // activate checkboxes if user wants them to be always active
381 if( !$this->preview
) {
382 if( $wgUser->getOption( 'watchdefault' ) ) $this->watchthis
= true;
383 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit
= true;
385 // activate checkbox also if user is already watching the page,
386 // require wpWatchthis to be unset so that second condition is not
387 // checked unnecessarily
388 if( !$this->watchthis
&& $this->mTitle
->userIsWatching() ) $this->watchthis
= true;
393 if ( 0 != $wgUser->getID() ||
$wgAllowAnonymousMinor ) {
395 "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?
" checked='checked'":"").
396 " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />".
397 "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>";
402 if ( 0 != $wgUser->getID() ) {
403 $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'".($this->watchthis?
" checked='checked'":"").
404 " accesskey='".wfMsg('accesskey-watch')."' id='wpWatchthis' />".
405 "<label for='wpWatchthis' title='".wfMsg('tooltip-watch')."'>{$watchthis}</label>";
408 $checkboxhtml = $minoredithtml . $watchhtml . '<br />';
410 $wgOut->addHTML( '<div id="wikiPreview">' );
411 if ( 'preview' == $formtype) {
412 $previewOutput = $this->getPreviewText( $isConflict, $isCssJsSubpage );
413 if( $wgUser->getOption('previewontop' ) ) {
414 $wgOut->addHTML( $previewOutput );
415 $wgOut->addHTML( "<br style=\"clear:both;\" />\n" );
418 $wgOut->addHTML( '</div>' );
420 # if this is a comment, show a subject line at the top, which is also the edit summary.
421 # Otherwise, show a summary field at the bottom
422 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary
) ); # FIXME
423 if( $this->section
== 'new' ) {
424 $commentsubject="{$subject}: <input tabindex='1' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
427 $commentsubject = '';
428 $editsummary="{$summary}: <input tabindex='3' type='text' value=\"$summarytext\" name=\"wpSummary\" maxlength='200' size='60' /><br />";
431 if( !$this->preview
) {
432 # Don't select the edit box on preview; this interferes with seeing what's going on.
433 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
435 # Prepare a list of templates used by this page
436 $db =& wfGetDB( DB_SLAVE
);
437 $page = $db->tableName( 'page' );
438 $links = $db->tableName( 'links' );
439 $id = $this->mTitle
->getArticleID();
440 $sql = "SELECT page_namespace,page_title,page_id ".
441 "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE
;
442 $res = $db->query( $sql, "EditPage::editform" );
444 if ( $db->numRows( $res ) ) {
445 $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
446 while ( $row = $db->fetchObject( $res ) ) {
447 if ( $titleObj = Title
::makeTitle( $row->page_namespace
, $row->page_title
) ) {
448 $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
451 $templates .= '</ul>';
456 global $wgLivePreview, $wgStylePath;
458 * Live Preview lets us fetch rendered preview page content and
459 * add it to the page without refreshing the whole page.
460 * Set up the button for it; if not supported by the browser
461 * it will fall through to the normal form submission method.
463 if( $wgLivePreview ) {
464 $wgOut->addHTML( '<script type="text/javascript" src="' .
465 htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
466 '"></script>' . "\n" );
467 $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
468 $liveOnclick = 'onclick="return !livePreview('.
469 'getElementById(\'wikiPreview\'),' .
470 'editform.wpTextbox1.value,' .
471 htmlspecialchars( '"' . $liveAction . '"' ) . ')"';
476 $wgOut->addHTML( <<<END
478 <form id="editform" name="editform" method="post" action="$action"
479 enctype="multipart/form-data">
481 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
484 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1
) ) .
489 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
490 " title=\"".wfMsg('tooltip-save')."\"/>
491 <input tabindex='6' id='wpPreview' type='submit' $liveOnclick value=\"{$prev}\" name=\"wpPreview\" accesskey=\"".wfMsg('accesskey-preview')."\"".
492 " title=\"".wfMsg('tooltip-preview')."\"/>
493 <em>{$cancel}</em> | <em>{$edithelp}</em>{$templates}" );
494 $wgOut->addWikiText( $copywarn );
496 <input type='hidden' value=\"" . htmlspecialchars( $this->section
) . "\" name=\"wpSection\" />
497 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n" );
500 require_once( "DifferenceEngine.php" );
501 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
502 DifferenceEngine
::showDiff( $this->textbox2
, $this->textbox1
,
503 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
505 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
506 <textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
507 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox2
) ) .
511 $wgOut->addHTML( "</form>\n" );
512 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
513 $wgOut->addHTML('<div id="wikiPreview">' . $previewOutput . '</div>');
517 function getPreviewText( $isConflict, $isCssJsSubpage ) {
518 global $wgOut, $wgUser, $wgTitle, $wgParser;
519 $previewhead='<h2>' . wfMsg( 'preview' ) . "</h2>\n<p><center><font color=\"#cc0000\">" .
520 wfMsg( 'note' ) . wfMsg( 'previewnote' ) . "</font></center></p>\n";
522 $previewhead.='<h2>' . wfMsg( 'previewconflict' ) .
526 $parserOptions = ParserOptions
::newFromUser( $wgUser );
527 $parserOptions->setEditSection( false );
528 $parserOptions->setEditSectionOnRightClick( false );
530 # don't parse user css/js, show message about preview
531 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
533 if ( $isCssJsSubpage ) {
534 if(preg_match("/\\.css$/", $wgTitle->getText() ) ) {
535 $previewtext = wfMsg('usercsspreview');
536 } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) {
537 $previewtext = wfMsg('userjspreview');
539 $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
540 $wgOut->addHTML( $parserOutput->mText
);
542 # if user want to see preview when he edit an article
543 if( $wgUser->getOption('previewonfirst') and ($this->textbox1
== '')) {
544 $this->textbox1
= $this->mArticle
->getContent(true);
547 $parserOutput = $wgParser->parse( $this->mArticle
->preSaveTransform( $this->textbox1
) ."\n\n",
548 $wgTitle, $parserOptions );
550 $previewHTML = $parserOutput->mText
;
551 $wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
552 $wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
554 return $previewhead . $previewHTML;
560 function blockedIPpage() {
561 global $wgOut, $wgUser, $wgContLang, $wgIP;
563 $wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
564 $wgOut->setRobotpolicy( 'noindex,nofollow' );
565 $wgOut->setArticleRelated( false );
567 $id = $wgUser->blockedBy();
568 $reason = $wgUser->blockedFor();
571 if ( is_numeric( $id ) ) {
572 $name = User
::whoIs( $id );
576 $link = '[[' . $wgContLang->getNsText( Namespace::getUser() ) .
577 ":{$name}|{$name}]]";
579 $wgOut->addWikiText( wfMsg( 'blockedtext', $link, $reason, $ip, $name ) );
580 $wgOut->returnToMain( false );
586 function userNotLoggedInPage() {
587 global $wgOut, $wgUser;
589 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
590 $wgOut->setRobotpolicy( 'noindex,nofollow' );
591 $wgOut->setArticleRelated( false );
593 $wgOut->addWikiText( wfMsg( 'whitelistedittext' ) );
594 $wgOut->returnToMain( false );
600 function spamPage ( $match = false )
603 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
604 $wgOut->setRobotpolicy( 'noindex,nofollow' );
605 $wgOut->setArticleRelated( false );
607 $wgOut->addWikiText( wfMsg( 'spamprotectiontext' ) );
609 $wgOut->addWikiText( wfMsg( 'spamprotectionmatch', "<nowiki>{$match}</nowiki>" ) );
611 $wgOut->returnToMain( false );
615 * Forks processes to scan the originating IP for an open proxy server
616 * MemCached can be used to skip IPs that have already been scanned
618 function proxyCheck() {
619 global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
620 global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
622 if ( !$wgBlockOpenProxies ) {
628 if ( $wgUseMemCached ) {
629 $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
630 $mcValue = $wgMemc->get( $mcKey );
638 $title = Title
::makeTitle( NS_SPECIAL
, 'Blockme' );
639 $iphash = md5( $wgIP . $wgProxyKey );
640 $url = $title->getFullURL( 'ip='.$iphash );
642 foreach ( $wgProxyPorts as $port ) {
643 $params = implode( ' ', array(
644 escapeshellarg( $wgProxyScriptPath ),
645 escapeshellarg( $wgIP ),
646 escapeshellarg( $port ),
647 escapeshellarg( $url )
649 exec( "php $params &>/dev/null &" );
652 if ( $wgUseMemCached ) {
653 $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
662 function mergeChangesInto( &$text ){
663 $yourtext = $this->mArticle
->fetchRevisionText();
665 $db =& wfGetDB( DB_SLAVE
);
666 $oldText = $this->mArticle
->fetchRevisionText(
667 $db->timestamp( $this->edittime
),
670 if(wfMerge($oldText, $text, $yourtext, $result)){
679 function checkUnicodeCompliantBrowser() {
680 global $wgBrowserBlackList;
681 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
682 foreach ( $wgBrowserBlackList as $browser ) {
683 if ( preg_match($browser, $currentbrowser) ) {
691 * Format an anchor fragment as it would appear for a given section name
692 * @param string $text
696 function sectionAnchor( $text ) {
697 global $wgInputEncoding;
698 $headline = do_html_entity_decode( $text, ENT_COMPAT
, $wgInputEncoding );
700 $headline = preg_replace( '/<.*?' . '>/', '', $headline );
701 $headline = trim( $headline );
702 $sectionanchor = '#' . urlencode( str_replace( ' ', '_', $headline ) );
703 $replacearray = array(
708 array_keys( $replacearray ),
709 array_values( $replacearray ),
714 * Shows a bulletin board style toolbar for common editing functions.
715 * It can be disabled in the user preferences.
716 * The necessary JavaScript code can be found in style/wikibits.js.
718 function getEditToolbar() {
719 global $wgStylePath, $wgLang, $wgMimeType;
722 * toolarray an array of arrays which each include the filename of
723 * the button image (without path), the opening tag, the closing tag,
724 * and optionally a sample text that is inserted between the two when no
725 * selection is highlighted.
726 * The tip text is shown when the user moves the mouse over the button.
728 * Already here are accesskeys (key), which are not used yet until someone
729 * can figure out a way to make them work in IE. However, we should make
730 * sure these keys are not defined on the edit page.
733 array( 'image'=>'button_bold.png',
736 'sample'=> wfMsg('bold_sample'),
737 'tip' => wfMsg('bold_tip'),
740 array( 'image'=>'button_italic.png',
743 'sample'=> wfMsg('italic_sample'),
744 'tip' => wfMsg('italic_tip'),
747 array( 'image'=>'button_link.png',
750 'sample'=> wfMsg('link_sample'),
751 'tip' => wfMsg('link_tip'),
754 array( 'image'=>'button_extlink.png',
757 'sample'=> wfMsg('extlink_sample'),
758 'tip' => wfMsg('extlink_tip'),
761 array( 'image'=>'button_headline.png',
764 'sample'=> wfMsg('headline_sample'),
765 'tip' => wfMsg('headline_tip'),
768 array( 'image'=>'button_image.png',
769 'open' => '[['.$wgLang->getNsText(NS_IMAGE
).":",
771 'sample'=> wfMsg('image_sample'),
772 'tip' => wfMsg('image_tip'),
775 array( 'image' => 'button_media.png',
776 'open' => '[['.$wgLang->getNsText(NS_MEDIA
).':',
778 'sample'=> wfMsg('media_sample'),
779 'tip' => wfMsg('media_tip'),
782 array( 'image' => 'button_math.png',
783 'open' => "\\<math\\>",
784 'close' => "\\</math\\>",
785 'sample'=> wfMsg('math_sample'),
786 'tip' => wfMsg('math_tip'),
789 array( 'image' => 'button_nowiki.png',
790 'open' => "\\<nowiki\\>",
791 'close' => "\\</nowiki\\>",
792 'sample'=> wfMsg('nowiki_sample'),
793 'tip' => wfMsg('nowiki_tip'),
796 array( 'image' => 'button_sig.png',
800 'tip' => wfMsg('sig_tip'),
803 array( 'image' => 'button_hr.png',
804 'open' => "\\n----\\n",
807 'tip' => wfMsg('hr_tip'),
811 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
813 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
814 foreach($toolarray as $tool) {
816 $image=$wgStylePath.'/common/images/'.$tool['image'];
818 $close=$tool['close'];
819 $sample = addslashes( $tool['sample'] );
821 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
822 // Older browsers show a "speedtip" type message only for ALT.
823 // Ideally these should be different, realistically they
824 // probably don't need to be.
825 $tip = addslashes( $tool['tip'] );
827 #$key = $tool["key"];
829 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
832 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
833 $toolbar.="document.writeln(\"</div>\");\n";
835 $toolbar.="/*]]>*/\n</script>";
840 * Output preview text only. This can be sucked into the edit page
841 * via JavaScript, and saves the server time rendering the skin as
842 * well as theoretically being more robust on the client (doesn't
843 * disturb the edit box's undo history, won't eat your text on
846 * @todo This doesn't include category or interlanguage links.
847 * Would need to enhance it a bit, maybe wrap them in XML
848 * or something... that might also require more skin
849 * initialization, so check whether that's a problem.
851 function livePreview() {
854 header( 'Content-type: text/xml' );
855 header( 'Cache-control: no-cache' );
857 echo $this->getPreviewText( false, false );