editpage.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,865 行 · 第 1/4 页
PHP
1,865 行
#if ( "no" == $redirect ) { $q .= "&redirect=no"; } $action = $this->mTitle->escapeLocalURL( $q ); $summary = wfMsg('summary'); $subject = wfMsg('subject'); $minor = wfMsgExt('minoredit', array('parseinline')); $watchthis = wfMsgExt('watchthis', array('parseinline')); $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(), wfMsgExt('cancel', array('parseinline')) ); $edithelpurl = $sk->makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' )); $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'. htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '. htmlspecialchars( wfMsg( 'newwindow' ) ); global $wgRightsText; $copywarn = "<div id=\"editpage-copywarn\">\n" . wfMsg( $wgRightsText ? 'copyrightwarning' : 'copyrightwarning2', '[[' . wfMsgForContent( 'copyrightpage' ) . ']]', $wgRightsText ) . "\n</div>"; if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) { # prepare toolbar for edit buttons $toolbar = $this->getEditToolbar(); } else { $toolbar = ''; } // activate checkboxes if user wants them to be always active if( !$this->preview && !$this->diff ) { # Sort out the "watch" checkbox if( $wgUser->getOption( 'watchdefault' ) ) { # Watch all edits $this->watchthis = true; } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) { # Watch creations $this->watchthis = true; } elseif( $this->mTitle->userIsWatching() ) { # Already watched $this->watchthis = true; } if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true; } $minoredithtml = ''; if ( $wgUser->isAllowed('minoredit') ) { $minoredithtml = "<input tabindex='3' type='checkbox' value='1' name='wpMinoredit'".($this->minoredit?" checked='checked'":""). " accesskey='".wfMsg('accesskey-minoredit')."' id='wpMinoredit' />\n". "<label for='wpMinoredit' title='".wfMsg('tooltip-minoredit')."'>{$minor}</label>\n"; } $watchhtml = ''; if ( $wgUser->isLoggedIn() ) { $watchhtml = "<input tabindex='4' type='checkbox' name='wpWatchthis'". ($this->watchthis?" checked='checked'":""). " accesskey=\"".htmlspecialchars(wfMsg('accesskey-watch'))."\" id='wpWatchthis' />\n". "<label for='wpWatchthis' title=\"" . htmlspecialchars(wfMsg('tooltip-watch'))."\">{$watchthis}</label>\n"; } $checkboxhtml = $minoredithtml . $watchhtml; if ( $wgUser->getOption( 'previewontop' ) ) { if ( 'preview' == $this->formtype ) { $this->showPreview(); } else { $wgOut->addHTML( '<div id="wikiPreview"></div>' ); } if ( 'diff' == $this->formtype ) { $wgOut->addHTML( $this->getDiff() ); } } # if this is a comment, show a subject line at the top, which is also the edit summary. # Otherwise, show a summary field at the bottom $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME if( $this->section == 'new' ) { $commentsubject="<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}:</label></span>\n<div class='editOptions'>\n<input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />"; $editsummary = ''; } else { $commentsubject = ''; $editsummary="<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}:</label></span>\n<div class='editOptions'>\n<input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' /><br />"; } # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display if( !$this->preview && !$this->diff ) { $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' ); } $templates = $this->formatTemplates(); global $wgUseMetadataEdit ; if ( $wgUseMetadataEdit ) { $metadata = $this->mMetaData ; $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ; $top = wfMsgWikiHtml( 'metadata_help' ); $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ; } else $metadata = "" ; $hidden = ''; $recreate = ''; if ($this->deletedSinceEdit) { if ( 'save' != $this->formtype ) { $wgOut->addWikiText( wfMsg('deletedwhileediting')); } else { // Hide the toolbar and edit area, use can click preview to get it back // Add an confirmation checkbox and explanation. $toolbar = ''; $hidden = 'type="hidden" style="display:none;"'; $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment )); $recreate .= "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />". "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>"; } } $temp = array( 'id' => 'wpSave', 'name' => 'wpSave', 'type' => 'submit', 'tabindex' => '5', 'value' => wfMsg('savearticle'), 'accesskey' => wfMsg('accesskey-save'), 'title' => wfMsg('tooltip-save'), ); $buttons['save'] = wfElement('input', $temp, ''); $temp = array( 'id' => 'wpDiff', 'name' => 'wpDiff', 'type' => 'submit', 'tabindex' => '7', 'value' => wfMsg('showdiff'), 'accesskey' => wfMsg('accesskey-diff'), 'title' => wfMsg('tooltip-diff'), ); $buttons['diff'] = wfElement('input', $temp, ''); global $wgLivePreview; if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) { $temp = array( 'id' => 'wpPreview', 'name' => 'wpPreview', 'type' => 'submit', 'tabindex' => '6', 'value' => wfMsg('showpreview'), 'accesskey' => '', 'title' => wfMsg('tooltip-preview'), 'style' => 'display: none;', ); $buttons['preview'] = wfElement('input', $temp, ''); $temp = array( 'id' => 'wpLivePreview', 'name' => 'wpLivePreview', 'type' => 'submit', 'tabindex' => '6', 'value' => wfMsg('showlivepreview'), 'accesskey' => wfMsg('accesskey-preview'), 'title' => '', 'onclick' => $this->doLivePreviewScript(), ); $buttons['live'] = wfElement('input', $temp, ''); } else { $temp = array( 'id' => 'wpPreview', 'name' => 'wpPreview', 'type' => 'submit', 'tabindex' => '6', 'value' => wfMsg('showpreview'), 'accesskey' => wfMsg('accesskey-preview'), 'title' => wfMsg('tooltip-preview'), ); $buttons['preview'] = wfElement('input', $temp, ''); $buttons['live'] = ''; } $safemodehtml = $this->checkUnicodeCompliantBrowser() ? "" : "<input type='hidden' name=\"safemode\" value='1' />\n"; $wgOut->addHTML( <<<END{$toolbar}<form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">END); if( is_callable( $formCallback ) ) { call_user_func_array( $formCallback, array( &$wgOut ) ); } // Put these up at the top to ensure they aren't lost on early form submission $wgOut->addHTML( "<input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" /><input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n<input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" ); $wgOut->addHTML( <<<END$recreate{$commentsubject}<textarea tabindex='1' accesskey="," name="wpTextbox1" id="wpTextbox1" rows='{$rows}'cols='{$cols}'{$ew} $hidden>END. htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) ."</textarea> " ); $wgOut->addWikiText( $copywarn ); $wgOut->addHTML( "{$metadata}{$editsummary}{$checkboxhtml}{$safemodehtml}"); $wgOut->addHTML("<div class='editButtons'> {$buttons['save']} {$buttons['preview']} {$buttons['live']} {$buttons['diff']} <span class='editHelp'>{$cancel} | {$edithelp}</span></div><!-- editButtons --></div><!-- editOptions -->"); $wgOut->addWikiText( wfMsgForContent( 'edittools' ) ); $wgOut->addHTML( "<div class='templatesUsed'>{$templates}</div>" ); if ( $wgUser->isLoggedIn() ) { /** * To make it harder for someone to slip a user a page * which submits an edit form to the wiki without their * knowledge, a random token is associated with the login * session. If it's not passed back with the submission, * we won't save the page, or render user JavaScript and * CSS previews. */ $token = htmlspecialchars( $wgUser->editToken() ); $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" ); } # If a blank edit summary was previously provided, and the appropriate # user preference is active, pass a hidden tag here. This will stop the # user being bounced back more than once in the event that a summary # is not required. if( $this->missingSummary ) { $wgOut->addHTML( "<input type=\"hidden\" name=\"wpIgnoreBlankSummary\" value=\"1\" />\n" ); } # For a bit more sophisticated detection of blank summaries, hash the # automatic one and pass that in a hidden field. $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary ); $wgOut->addHtml( wfHidden( 'wpAutoSummary', $autosumm ) ); if ( $this->isConflict ) { require_once( "DifferenceEngine.php" ); $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' ); $de = new DifferenceEngine( $this->mTitle ); $de->setText( $this->textbox2, $this->textbox1 ); $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) ); $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' ); $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>" . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox2 ) ) . "\n</textarea>" ); } $wgOut->addHTML( "</form>\n" ); if ( !$wgUser->getOption( 'previewontop' ) ) { if ( $this->formtype == 'preview') { $this->showPreview(); } else { $wgOut->addHTML( '<div id="wikiPreview"></div>' ); } if ( $this->formtype == 'diff') { $wgOut->addHTML( $this->getDiff() ); } } wfProfileOut( $fname ); } /** * Append preview output to $wgOut. * Includes category rendering if this is a category page. * @private */ function showPreview() { global $wgOut; $wgOut->addHTML( '<div id="wikiPreview">' ); if($this->mTitle->getNamespace() == NS_CATEGORY) { $this->mArticle->openShowCategory(); } $previewOutput = $this->getPreviewText(); $wgOut->addHTML( $previewOutput ); if($this->mTitle->getNamespace() == NS_CATEGORY) { $this->mArticle->closeShowCategory(); } $wgOut->addHTML( "<br style=\"clear:both;\" />\n" ); $wgOut->addHTML( '</div>' ); } /** * Prepare a list of templates used by this page. Returns HTML. */ function formatTemplates() { global $wgUser; $fname = 'EditPage::formatTemplates'; wfProfileIn( $fname ); $sk =& $wgUser->getSkin(); $outText = ''; $templates = $this->mArticle->getUsedTemplates(); if ( count( $templates ) > 0 ) { # Do a batch existence check $batch = new LinkBatch; foreach( $templates as $title ) { $batch->addObj( $title ); } $batch->execute(); # Construct the HTML $outText = '<br />'. wfMsgExt( 'templatesused', array( 'parseinline' ) ) . '<ul>'; foreach ( $templates as $titleObj ) { $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>'; } $outText .= '</ul>'; } wfProfileOut( $fname ); return $outText; } /** * Live Preview lets us fetch rendered preview page content and * add it to the page without refreshing the whole page. * If not supported by the browser it will fall through to the normal form * submission method. * * This function outputs a script tag to support live preview, and * returns an onclick handler which should be added to the attributes * of the preview button */ function doLivePreviewScript() { global $wgStylePath, $wgJsMimeType, $wgOut, $wgTitle; $wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' . htmlspecialchars( $wgStylePath . '/common/preview.js' ) . '"></script>' . "\n" ); $liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' ); return "return !livePreview(" . "getElementById('wikiPreview')," . "editform.wpTextbox1.value," . '"' . $liveAction . '"' . ")"; } function getLastDelete() { $dbr =& wfGetDB( DB_SLAVE ); $fname = 'EditPage::getLastDelete'; $res = $dbr->select( array( 'logging', 'user' ), array( 'log_type', 'log_action', 'log_timestamp', 'log_user', 'log_namespace', 'log_title', 'log_comment', 'log_params', 'user_name', ), array( 'log_namespace' => $this->mTitle->getNamespace(), 'log_title' => $this->mTitle->getDBkey(), 'log_type' => 'delete', 'log_action' => 'delete', 'user_id=log_user' ), $fname, array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) ); if($dbr->numRows($res) == 1) { while ( $x = $dbr->fetchObject ( $res ) ) $data = $x; $dbr->freeResult ( $res ) ; } else { $data = null; } return $data; } /** * @todo document */ function getPreviewText() { global $wgOut, $wgUser, $wgTitle, $wgParser; $fname = 'EditPage::getPreviewText'; wfProfileIn( $fname ); if ( $this->mTriedSave && !$this->mTokenOk ) { $msg = 'session_fail_preview'; } else { $msg = 'previewnote'; } $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" . "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n"; if ( $this->isConflict ) { $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n"; } $parserOptions = ParserOptions::newFromUser( $wgUser ); $parserOptions->setEditSection( false ); global $wgRawHtml; if( $wgRawHtml && !$this->mTokenOk ) { // Could be an offsite preview attempt. This is very unsafe if // HTML is enabled, as it could be an attack. return $wgOut->parse( "<div class='previewnote'>" . wfMsg( 'session_fail_preview_html' ) . "</div>" ); } # don't parse user css/js, show message about preview # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here if ( $this->isCssJsSubpage ) { if(preg_match("/\\.css$/", $wgTitle->getText() ) ) { $previewtext = wfMsg('usercsspreview'); } else if(preg_match("/\\.js$/", $wgTitle->getText() ) ) { $previewtext = wfMsg('userjspreview'); } $parserOptions->setTidy(true); $parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions ); $wgOut->addHTML( $parserOutput->mText ); wfProfileOut( $fname ); return $previewhead; } else { # if user want to see preview when he edit an article if( $wgUser->getOption('previewonfirst') and ($this->textbox1 == '')) { $this->textbox1 = $this->getContent(); } $toparse = $this->textbox1; # If we're adding a comment, we need to show the # summary as the headline if($this->section=="new" && $this->summary!="") { $toparse="== {$this->summary} ==\n\n".$toparse; } if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ; $parserOptions->setTidy(true); $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n", $wgTitle, $parserOptions ); $previewHTML = $parserOutput->getText();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?