X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FEditPage.php;h=57d2590ce0ea9e04fca9c614e6548073f7153d2b;hb=a605c351092d8a2e37d49ea982e1d83f7fccb215;hp=e92b43bd6eedaadddf9fc8407970d3b80de2669d;hpb=d4c2f2796bd9103f7281ec912be991eb513cb74f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/EditPage.php b/includes/EditPage.php index e92b43bd6e..57d2590ce0 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -49,7 +49,7 @@ class EditPage { var $isCssJsSubpage = false; var $isCssSubpage = false; var $isJsSubpage = false; - var $deletedSinceEdit = false; + var $deletedSinceEdit; var $formtype; var $firsttime; var $lastDelete; @@ -96,7 +96,7 @@ class EditPage { * @todo document * @param $article */ - function EditPage( $article ) { + function __construct( $article ) { $this->mArticle =& $article; $this->mTitle = $article->getTitle(); $this->action = 'submit'; @@ -124,29 +124,27 @@ class EditPage { * @private */ function getContent( $def_text = '' ) { - global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache; + global $wgOut, $wgRequest, $wgParser, $wgContLang; wfProfileIn( __METHOD__ ); # Get variables from query string :P $section = $wgRequest->getVal( 'section' ); - - $preload = $wgRequest->getVal( 'preload', + + $preload = $wgRequest->getVal( 'preload', // Custom preload text for new sections $section === 'new' ? 'MediaWiki:addsection-preload' : '' ); $undoafter = $wgRequest->getVal( 'undoafter' ); $undo = $wgRequest->getVal( 'undo' ); - $text = ''; // For message page not locally set, use the i18n message. // For other non-existent articles, use preload text if any. if ( !$this->mTitle->exists() ) { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { # If this is a system message, get the default text. - list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) ); - $wgMessageCache->loadAllMessages( $lang ); - $text = wfMsgGetKey( $message, false, $lang, false ); - if( wfEmptyMsg( $message, $text ) ) + $text = $this->mTitle->getDefaultMessageText(); + if( $text === false ) { $text = $this->getPreloadedText( $preload ); + } } else { # If requested, preload some text. $text = $this->getPreloadedText( $preload ); @@ -220,30 +218,39 @@ class EditPage { } /** - * Get the contents of a page from its title and remove includeonly tags + * Get the contents to be preloaded into the box, either set by + * an earlier setPreloadText() or by loading the given page. * - * @param $preload String: the title of the page. - * @return string The contents of the page. + * @param $preload String: representing the title to preload from. + * @return String */ protected function getPreloadedText( $preload ) { + global $wgUser, $wgParser; if ( !empty( $this->mPreloadText ) ) { return $this->mPreloadText; - } elseif ( $preload === '' ) { - return ''; - } else { - $preloadTitle = Title::newFromText( $preload ); - if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { - $rev = Revision::newFromTitle( $preloadTitle ); - if ( is_object( $rev ) ) { - $text = $rev->getText(); - // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing - // its own mini-parser! -ævar - $text = preg_replace( '~?includeonly>~', '', $text ); - return $text; - } else - return ''; + } elseif ( $preload !== '' ) { + $title = Title::newFromText( $preload ); + # Check for existence to avoid getting MediaWiki:Noarticletext + if ( isset( $title ) && $title->exists() && $title->userCanRead() ) { + $article = new Article( $title ); + + if ( $article->isRedirect() ) { + $title = Title::newFromRedirectRecurse( $article->getContent() ); + # Redirects to missing titles are displayed, to hidden pages are followed + # Copying observed behaviour from ?action=view + if ( $title->exists() ) { + if ($title->userCanRead() ) { + $article = new Article( $title ); + } else { + return ""; + } + } + } + $parserOptions = ParserOptions::newFromUser( $wgUser ); + return $wgParser->getPreloadText( $article->getContent(), $title, $parserOptions ); } } + return ''; } /* @@ -253,8 +260,12 @@ class EditPage { * deletes. */ protected function wasDeletedSinceLastEdit() { - if ( $this->deletedSinceEdit ) - return true; + if ( $this->deletedSinceEdit !== null ) { + return $this->deletedSinceEdit; + } + + $this->deletedSinceEdit = false; + if ( $this->mTitle->isDeletedQuick() ) { $this->lastDelete = $this->getLastDelete(); if ( $this->lastDelete ) { @@ -264,9 +275,28 @@ class EditPage { } } } + return $this->deletedSinceEdit; } + /** + * Checks whether the user entered a skin name in uppercase, + * e.g. "User:Example/Monobook.css" instead of "monobook.css" + */ + protected function isWrongCaseCssJsPage() { + if( $this->mTitle->isCssJsSubpage() ) { + $name = $this->mTitle->getSkinFromCssJsSubpage(); + $skins = array_merge( + array_keys( Skin::getSkinNames() ), + array( 'common' ) + ); + return !in_array( $name, $skins ) + && in_array( strtolower( $name ), $skins ); + } else { + return false; + } + } + function submit() { $this->edit(); } @@ -310,19 +340,18 @@ class EditPage { $this->preview = true; } - $wgOut->addScriptFile( 'edit.js' ); - + $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.action.edit' ) ); + if ( $wgUser->getOption( 'uselivepreview', false ) ) { - $wgOut->includeJQuery(); - $wgOut->addScriptFile( 'preview.js' ); + $wgOut->addModules( 'mediawiki.legacy.preview' ); } - // Bug #19334: textarea jumps when editing articles in IE8 - $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' ); $permErrors = $this->getEditPermissionErrors(); if ( $permErrors ) { wfDebug( __METHOD__ . ": User can't edit\n" ); - $this->readOnlyPage( $this->getContent( false ), true, $permErrors, 'edit' ); + $content = $this->getContent( null ); + $content = $content === '' ? null : $content; + $this->readOnlyPage( $content, true, $permErrors, 'edit' ); wfProfileOut( __METHOD__ ); return; } else { @@ -354,7 +383,7 @@ class EditPage { $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); $this->isCssSubpage = $this->mTitle->isCssSubpage(); $this->isJsSubpage = $this->mTitle->isJsSubpage(); - $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage(); + $this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage(); # Show applicable editing introductions if ( $this->formtype == 'initial' || $this->firsttime ) @@ -366,16 +395,18 @@ class EditPage { # Optional notices on a per-namespace and per-page basis $editnotice_ns = 'editnotice-'.$this->mTitle->getNamespace(); - if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) { - $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) ); + $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage(); + if ( $editnotice_ns_message->exists() ) { + $wgOut->addWikiText( $editnotice_ns_message->plain() ); } if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) { $parts = explode( '/', $this->mTitle->getDBkey() ); $editnotice_base = $editnotice_ns; while ( count( $parts ) > 0 ) { $editnotice_base .= '-'.array_shift( $parts ); - if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) { - $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) ); + $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage(); + if ( $editnotice_base_msg->exists() ) { + $wgOut->addWikiText( $editnotice_base_msg->plain() ); } } } @@ -484,7 +515,7 @@ class EditPage { /** * Does this EditPage class support section editing? * This is used by EditPage subclasses to indicate their ui cannot handle section edits - * + * * @return bool */ protected function isSectionEditSupported() { @@ -496,8 +527,8 @@ class EditPage { * This is used by EditPage subclasses when simply customizing the action * variable in the constructor is not enough. This can be used when the * EditPage lives inside of a Special page rather than a custom page action. - * - * @param Title $title The title for which is being edited (where we go to for &action= links) + * + * @param $title Title object for which is being edited (where we go to for &action= links) * @return string */ protected function getActionURL( Title $title ) { @@ -533,7 +564,7 @@ class EditPage { } # Truncate for whole multibyte characters. +5 bytes for ellipsis - $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' ); + $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 ); # Remove extra headings from summaries and new sections. $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary); @@ -646,8 +677,8 @@ class EditPage { * posted form to be placed in $this->textbox1, if using customized input * this method should be overrided and return the page text that will be used * for saving, preview parsing and so on... - * - * @praram WebRequest $request + * + * @param $request WebRequest */ protected function importContentFormData( &$request ) { return; // Don't do anything, EditPage already extracted wpTextbox1 @@ -681,7 +712,7 @@ class EditPage { if ( $namespace == NS_MEDIAWIKI ) { # Show a warning if editing an interface message - $wgOut->wrapWikiMsg( "
\n" . htmlspecialchars( $this->textbox1 ) . "\n\n"; } else { - $toparse = $this->textbox1; + $rt = Title::newFromRedirectArray( $this->textbox1 ); + if ( $rt ) { + $previewHTML = $this->mArticle->viewRedirect( $rt, false ); + } else { + $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 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; + } - wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); - - // Parse mediawiki messages with correct target language - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - list( /* $unused */, $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() ); - $obj = wfGetLangObj( $lang ); - $parserOptions->setTargetLanguage( $obj ); - } + wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); + // Parse mediawiki messages with correct target language + if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { + list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->mTitle->getText() ); + $obj = wfGetLangObj( $lang ); + $parserOptions->setTargetLanguage( $obj ); + } - $parserOptions->setTidy( true ); - $parserOptions->enableLimitReport(); - $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ), + $parserOptions->setTidy( true ); + $parserOptions->enableLimitReport(); + $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ), $this->mTitle, $parserOptions ); - $previewHTML = $parserOutput->getText(); - $this->mParserOutput = $parserOutput; - $wgOut->addParserOutputNoText( $parserOutput ); + $previewHTML = $parserOutput->getText(); + $this->mParserOutput = $parserOutput; + $wgOut->addParserOutputNoText( $parserOutput ); - if ( count( $parserOutput->getWarnings() ) ) { - $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); + if ( count( $parserOutput->getWarnings() ) ) { + $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() ); + } } } @@ -1987,8 +2075,9 @@ INPUTS * Produce the stock "your edit contains spam" page * * @param $match Text which triggered one or more filters + * @deprecated Use method spamPageWithContent() instead */ - function spamPage( $match = false ) { + static function spamPage( $match = false ) { global $wgOut, $wgTitle; $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) ); @@ -1997,13 +2086,46 @@ INPUTS $wgOut->addHTML( '