X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=0b247f154c164de429c89f783990f579cdc0a782;hb=418e7767b4e6d27344bd81da8a8ddd319784f4b3;hp=4163a127a844d2072d857dcfc5da60d19e94fa0a;hpb=25a0b5503fbe17a34efc6970e2d70ab66efecfec;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index 4163a127a8..0b247f154c 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -103,13 +103,15 @@ class EditPage { $this->editFormTextBeforeContent = $this->editFormTextAfterWarn = $this->editFormTextAfterTools = - $this->editFormTextBottom = ""; + $this->editFormTextBottom = + $this->mPreloadText = ""; } function getArticle() { return $this->mArticle; } + /** * Fetch initial editing page content. * @private @@ -200,6 +202,11 @@ class EditPage { wfProfileOut( __METHOD__ ); return $text; } + + /** Use this method before edit() to preload some text into the edit box */ + public function setPreloadedText( $text ) { + $this->mPreloadText = $text; + } /** * Get the contents of a page from its title and remove includeonly tags @@ -208,7 +215,9 @@ class EditPage { * @return string The contents of the page. */ protected function getPreloadedText( $preload ) { - if ( $preload === '' ) { + if ( !empty($this->mPreloadText) ) { + return $this->mPreloadText; + } elseif ( $preload === '' ) { return ''; } else { $preloadTitle = Title::newFromText( $preload ); @@ -324,7 +333,7 @@ class EditPage { protected function wasDeletedSinceLastEdit() { if ( $this->deletedSinceEdit ) return true; - if ( $this->mTitle->isDeleted() ) { + if ( $this->mTitle->isDeletedQuick() ) { $this->lastDelete = $this->getLastDelete(); if ( $this->lastDelete ) { $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp ); @@ -352,7 +361,7 @@ class EditPage { * the newly-edited page. */ function edit() { - global $wgOut, $wgUser, $wgRequest; + global $wgOut, $wgRequest, $wgEnableJS2system; // Allow extensions to modify/prevent this form or submission if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) { return; @@ -380,6 +389,10 @@ class EditPage { } $wgOut->addScriptFile( 'edit.js' ); + + if($wgEnableJS2system) + $wgOut->addScriptClass( 'editPage' ); + $permErrors = $this->getEditPermissionErrors(); if ( $permErrors ) { wfDebug( __METHOD__.": User can't edit\n" ); @@ -403,6 +416,11 @@ class EditPage { } } } + + // If they used redlink=1 and the page exists, redirect to the main article + if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) { + $wgOut->redirect( $this->mTitle->getFullURL() ); + } wfProfileIn( __METHOD__."-business-end" ); @@ -421,7 +439,6 @@ class EditPage { # Optional notices on a per-namespace and per-page basis $editnotice_ns = 'editnotice-'.$this->mTitle->getNamespace(); - $editnotice_page = $editnotice_ns.'-'.$this->mTitle->getDBkey(); if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) { $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) ); } @@ -434,8 +451,6 @@ class EditPage { $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) ); } } - } else if ( !wfEmptyMsg( $editnotice_page, wfMsgForContent( $editnotice_page ) ) ) { - $wgOut->addWikiText( wfMsgForContent( $editnotice_page ) ); } # Attempt submission here. This will check for edit conflicts, @@ -647,12 +662,16 @@ class EditPage { } } + // FIXME: unused variable? $this->oldid = $request->getInt( 'oldid' ); $this->live = $request->getCheck( 'live' ); $this->editintro = $request->getText( 'editintro' ); wfProfileOut( $fname ); + + // Allow extensions to modify form data + wfRunHooks( 'EditPage::importFormData', array( &$this, $request ) ); } /** @@ -705,9 +724,9 @@ class EditPage { $wgOut->wrapWikiMsg( '
$1
', 'newarticletextanon' ); } } - # Give a notice if the user is editing a deleted page... + # Give a notice if the user is editing a deleted/moved page... if ( !$this->mTitle->exists() ) { - $this->showDeletionLog( $wgOut ); + $this->showLogs( $wgOut ); } } @@ -766,7 +785,7 @@ class EditPage { $this->mMetaData = '' ; # Check for spam - $match = self::matchSpamRegex( $this->summary ); + $match = self::matchSummarySpamRegex( $this->summary ); if ( $match === false ) { $match = self::matchSpamRegex( $this->textbox1 ); } @@ -863,7 +882,7 @@ class EditPage { } // Run post-section-merge edit filter - if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) { + if ( !wfRunHooks( 'EditFilterMerged', array( &$this, $this->textbox1, &$this->hookError, $this->summary ) ) ) { # Error messages etc. could be handled within the hook... wfProfileOut( $fname ); return self::AS_HOOK_ERROR; @@ -951,7 +970,7 @@ class EditPage { $oldtext = $this->mArticle->getContent(); // Run post-section-merge edit filter - if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) { + if ( !wfRunHooks( 'EditFilterMerged', array( &$this, $text, &$this->hookError, $this->summary ) ) ) { # Error messages etc. could be handled within the hook... wfProfileOut( $fname ); return self::AS_HOOK_ERROR; @@ -1056,21 +1075,33 @@ class EditPage { } return true; } - + /** * Check given input text against $wgSpamRegex, and return the text of the first match. * @return mixed -- matching string or false */ public static function matchSpamRegex( $text ) { global $wgSpamRegex; - if ( $wgSpamRegex ) { - // For back compatibility, $wgSpamRegex may be a single string or an array of regexes. - $regexes = (array)$wgSpamRegex; - foreach( $regexes as $regex ) { - $matches = array(); - if ( preg_match( $regex, $text, $matches ) ) { - return $matches[0]; - } + // For back compatibility, $wgSpamRegex may be a single string or an array of regexes. + $regexes = (array)$wgSpamRegex; + return self::matchSpamRegexInternal( $text, $regexes ); + } + + /** + * Check given input text against $wgSpamRegex, and return the text of the first match. + * @return mixed -- matching string or false + */ + public static function matchSummarySpamRegex( $text ) { + global $wgSummarySpamRegex; + $regexes = (array)$wgSummarySpamRegex; + return self::matchSpamRegexInternal( $text, $regexes ); + } + + protected static function matchSpamRegexInternal( $text, $regexes ) { + foreach( $regexes as $regex ) { + $matches = array(); + if( preg_match( $regex, $text, $matches ) ) { + return $matches[0]; } } return false; @@ -1132,8 +1163,6 @@ class EditPage { $sk = $wgUser->getSkin(); - wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ; - #need to parse the preview early so that we know which templates are used, #otherwise users with "show preview after edit box" will get a blank list #we parse this near the beginning so that setHeaders can do the title @@ -1142,6 +1171,8 @@ class EditPage { if ( $this->formtype == 'preview' ) { $previewOutput = $this->getPreviewText(); } + + wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ; $this->setHeaders(); @@ -1149,7 +1180,7 @@ class EditPage { $wgOut->setArticleRelated( true ); if ( $this->isConflict ) { - $wgOut->addWikiMsg( 'explainconflict' ); + $wgOut->wrapWikiMsg( "
\n$1
", 'explainconflict' ); $this->textbox2 = $this->textbox1; $this->textbox1 = $this->getContent(); @@ -1268,15 +1299,18 @@ class EditPage { $wgOut->addHTML( "\n" ); } - $q = 'action='.$this->action; - #if ( "no" == $redirect ) { $q .= "&redirect=no"; } - $action = $wgTitle->escapeLocalURL( $q ); + $action = $wgTitle->escapeLocalURL( array( 'action' => $this->action ) ); - $summary = wfMsg( 'summary' ); - $subject = wfMsg( 'subject' ); + $summary = wfMsgExt( 'summary', 'parseinline' ); + $subject = wfMsgExt( 'subject', 'parseinline' ); - $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(), - wfMsgExt('cancel', array('parseinline')) ); + $cancel = $sk->link( + $wgTitle, + wfMsgExt( 'cancel', array( 'parseinline' ) ), + array(), + array(), + array( 'known', 'noclasses' ) + ); $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' ); $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' )); $edithelp = ''. @@ -1292,6 +1326,8 @@ class EditPage { $copywarnMsg = array( 'copyrightwarning2', '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' ); } + // Allow for site and per-namespace customization of contribution/copyright notice. + wfRunHooks( 'EditPageCopyrightWarning', array( $this->mTitle, &$copywarnMsg ) ); if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) { # prepare toolbar for edit buttons @@ -1300,6 +1336,7 @@ class EditPage { $toolbar = ''; } + // activate checkboxes if user wants them to be always active if ( !$this->preview && !$this->diff ) { # Sort out the "watch" checkbox @@ -1313,7 +1350,7 @@ class EditPage { # Already watched $this->watchthis = true; } - + # May be overriden by request parameters if( $wgRequest->getBool( 'watchthis' ) ) { $this->watchthis = true; @@ -1349,13 +1386,14 @@ class EditPage { if ( $this->section == 'new' ) { $commentsubject = ''; if ( !$wgRequest->getBool( 'nosummary' ) ) { - # Add an ID if 'missingsummary' is triggered to allow styling of the summary line - $summaryMissedID = $this->missingSummary ? ' mw-summarymissed' : ''; + # Add a class if 'missingsummary' is triggered to allow styling of the summary line + $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary'; $commentsubject = Xml::tags( 'label', array( 'for' => 'wpSummary' ), $subject ); $commentsubject = - Xml::tags( 'span', array( 'id' => "wpSummaryLabel$summaryMissedID" ), $commentsubject ); + Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ), + $commentsubject ); $commentsubject .= ' '; $commentsubject .= Xml::input( 'wpSummary', 60, @@ -1369,16 +1407,18 @@ class EditPage { $editsummary = "
\n"; global $wgParser; $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) ); - $subjectpreview = $summarytext && $this->preview ? "
". wfMsg('subject-preview') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."
\n" : ''; + $subjectpreview = $summarytext && $this->preview ? + "
". wfMsgExt('subject-preview', 'parseinline') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."
\n" : ''; $summarypreview = ''; } else { $commentsubject = ''; - # Add an ID if 'missingsummary' is triggered to allow styling of the summary line - $summaryMissedID = $this->missingSummary ? ' mw-summarymissed' : ''; + # Add a class if 'missingsummary' is triggered to allow styling of the summary line + $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary'; $editsummary = Xml::tags( 'label', array( 'for' => 'wpSummary' ), $summary ); - $editsummary = Xml::tags( 'span', array( 'id' => "wpSummaryLabel$summaryMissedID" ), $editsummary ) . ' '; + $editsummary = Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ), + $editsummary ) . ' '; $editsummary .= Xml::input( 'wpSummary', 60, @@ -1398,7 +1438,7 @@ class EditPage { $summarypreview = Xml::tags( 'div', array( 'class' => 'mw-summary-preview' ), - wfMsg( 'summary-preview' ) . + wfMsgExt( 'summary-preview', 'parseinline' ) . $sk->commentBlock( $this->summary, $this->mTitle ) ); } @@ -1435,7 +1475,7 @@ class EditPage { if ( $this->wasDeletedSinceLastEdit() ) { if ( 'save' != $this->formtype ) { $wgOut->wrapWikiMsg( - '
$1
', + "
\n$1
", 'deletedwhileediting' ); } else { // Hide the toolbar and edit area, user can click preview to get it back @@ -1519,6 +1559,7 @@ END $token = htmlspecialchars( $wgUser->editToken() ); $wgOut->addHTML( "\n\n" ); + $this->showTosSummary(); $this->showEditTools(); $wgOut->addHTML( <<addScriptFile( 'preview.js' ); - $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" ); + $liveAction = $wgTitle->getLocalUrl( array( + 'action' => $this->action, + 'wpPreview' => 'true', + 'live' => 'true' + ) ); return "return !lpDoPreview(" . "editform.wpTextbox1.value," . '"' . $liveAction . '"' . ")"; } + protected function showTosSummary() { + $msg = 'editpage-tos-summary'; + // Give a chance for site and per-namespace customizations of + // terms of service summary link that might exist separately + // from the copyright notice. + // + // This will display between the save button and the edit tools, + // so should remain short! + wfRunHooks( 'EditPageTosSummary', array( $this->mTitle, &$msg ) ); + $text = wfMsg( $msg ); + if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) { + global $wgOut; + $wgOut->addHTML( '
' ); + $wgOut->addWikiMsgArray( $msg, array() ); + $wgOut->addHTML( '
' ); + } + } + protected function showEditTools() { global $wgOut; $wgOut->addHTML( '
' ); @@ -1670,7 +1733,7 @@ END $wgOut->addHTML( '
' ); } - function getLastDelete() { + protected function getLastDelete() { $dbr = wfGetDB( DB_SLAVE ); $data = $dbr->selectRow( array( 'logging', 'user' ), @@ -1682,15 +1745,23 @@ END 'log_title', 'log_comment', 'log_params', - 'user_name', ), + 'log_deleted', + 'user_name' ), array( 'log_namespace' => $this->mTitle->getNamespace(), 'log_title' => $this->mTitle->getDBkey(), 'log_type' => 'delete', 'log_action' => 'delete', 'user_id=log_user' ), __METHOD__, - array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) ); - + array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) + ); + // Quick paranoid permission checks... + if( is_object($data) ) { + if( $data->log_deleted & LogPage::DELETED_USER ) + $data->user_name = wfMsgHtml('rev-deleted-user'); + if( $data->log_deleted & LogPage::DELETED_COMMENT ) + $data->log_comment = wfMsgHtml('rev-deleted-comment'); + } return $data; } @@ -1773,12 +1844,16 @@ END } } - $previewhead = '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

\n" . - "
" . $wgOut->parse( $note ) . "
\n"; - if ( $this->isConflict ) { - $previewhead .='

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; + if( $this->isConflict ) { + $conflict = '

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; + } else { + $conflict = '
'; } + $previewhead = "
\n" . + '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

" . + $wgOut->parse( $note ) . $conflict . "
\n"; + wfProfileOut( __METHOD__ ); return $previewhead . $previewHTML; } @@ -1835,7 +1910,13 @@ END $skin = $wgUser->getSkin(); $loginTitle = SpecialPage::getTitleFor( 'Userlogin' ); - $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() ); + $loginLink = $skin->link( + $loginTitle, + wfMsgHtml( 'loginreqlink' ), + array(), + array( 'returnto' => $wgTitle->getPrefixedText() ), + array( 'known', 'noclasses' ) + ); $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); @@ -2105,6 +2186,9 @@ END $toolbar.="/*]]>*/\n"; $toolbar.="\n
"; + + wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) ); + return $toolbar; } @@ -2411,20 +2495,22 @@ END } /** - * If there are rows in the deletion log for this page, show them, + * If there are rows in the deletion/move log for this page, show them, * along with a nice little note for the user * * @param OutputPage $out */ - protected function showDeletionLog( $out ) { + protected function showLogs( $out ) { global $wgUser; $loglist = new LogEventsList( $wgUser->getSkin(), $out ); - $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() ); + $pager = new LogPager( $loglist, array('move', 'delete'), false, + $this->mTitle->getPrefixedText(), '', array( "log_action != 'revision'" ) ); + $count = $pager->getNumRows(); if ( $count > 0 ) { $pager->mLimit = 10; $out->addHTML( '
' ); - $out->addWikiMsg( 'recreate-deleted-warn' ); + $out->addWikiMsg( 'recreate-moveddeleted-warn' ); $out->addHTML( $loglist->beginLogEventsList() . $pager->getBody() . @@ -2433,11 +2519,9 @@ END if($count > 10){ $out->addHTML( $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'Log' ), - wfMsgHtml( 'deletelog-fulllog' ), + wfMsgHtml( 'log-fulllog' ), array(), - array( - 'type' => 'delete', - 'page' => $this->mTitle->getPrefixedText() ) ) ); + array( 'page' => $this->mTitle->getPrefixedText() ) ) ); } $out->addHTML( '
' ); return true;