- /**
- * Fetch initial editing page content.
- *
- * @param $def_text string
- * @returns mixed string on success, $def_text for invalid sections
- * @private
- */
- function getContent( $def_text = '' ) {
- global $wgOut, $wgRequest, $wgParser;
-
- wfProfileIn( __METHOD__ );
- # Get variables from query string :P
- $section = $wgRequest->getVal( 'section' );
-
- $preload = $wgRequest->getVal( 'preload',
- // Custom preload text for new sections
- $section === 'new' ? 'MediaWiki:addsection-preload' : '' );
- $undoafter = $wgRequest->getVal( 'undoafter' );
- $undo = $wgRequest->getVal( 'undo' );
-
- // 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.
- $text = $this->mTitle->getDefaultMessageText();
- if( $text === false ) {
- $text = $this->getPreloadedText( $preload );
- }
- } else {
- # If requested, preload some text.
- $text = $this->getPreloadedText( $preload );
- }
- // For existing pages, get text based on "undo" or section parameters.
- } else {
- $text = $this->mArticle->getContent();
- if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
- # If they got undoafter and undo round the wrong way, switch them
- list( $undo, $undoafter ) = array( $undoafter, $undo );
- }
- if ( $undo > 0 && $undo > $undoafter ) {
- # Undoing a specific edit overrides section editing; section-editing
- # doesn't work with undoing.
- if ( $undoafter ) {
- $undorev = Revision::newFromId( $undo );
- $oldrev = Revision::newFromId( $undoafter );
- } else {
- $undorev = Revision::newFromId( $undo );
- $oldrev = $undorev ? $undorev->getPrevious() : null;
- }
-
- # Sanity check, make sure it's the right page,
- # the revisions exist and they were not deleted.
- # Otherwise, $text will be left as-is.
- if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
- $undorev->getPage() == $oldrev->getPage() &&
- $undorev->getPage() == $this->mArticle->getID() &&
- !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
- !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
-
- $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
- if ( $undotext === false ) {
- # Warn the user that something went wrong
- $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
- } else {
- $text = $undotext;
- # Inform the user of our success and set an automatic edit summary
- $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
- $firstrev = $oldrev->getNext();
- # If we just undid one rev, use an autosummary
- if ( $firstrev->mId == $undo ) {
- $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
- $this->undidRev = $undo;
- }
- $this->formtype = 'diff';
- }
- } else {
- // Failed basic sanity checks.
- // Older revisions may have been removed since the link
- // was created, or we may simply have got bogus input.
- $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
- }
- } elseif ( $section != '' ) {
- if ( $section == 'new' ) {
- $text = $this->getPreloadedText( $preload );
- } else {
- // Get section edit text (returns $def_text for invalid sections)
- $text = $wgParser->getSection( $text, $section, $def_text );
- }
- }
- }
-
- wfProfileOut( __METHOD__ );
- return $text;
- }
-
- /**
- * Use this method before edit() to preload some text into the edit box
- *
- * @param $text string
- */
- public function setPreloadedText( $text ) {
- $this->mPreloadText = $text;
- }
-
- /**
- * Get the contents to be preloaded into the box, either set by
- * an earlier setPreloadText() or by loading the given 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 !== '' ) {
- $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 '';
- }
-
- /**
- * Check if a page was deleted while the user was editing it, before submit.
- * Note that we rely on the logging table, which hasn't been always there,
- * but that doesn't matter, because this only applies to brand new
- * deletes.
- */
- protected function wasDeletedSinceLastEdit() {
- if ( $this->deletedSinceEdit !== null ) {
- return $this->deletedSinceEdit;
- }
-
- $this->deletedSinceEdit = false;
-
- if ( $this->mTitle->isDeletedQuick() ) {
- $this->lastDelete = $this->getLastDelete();
- if ( $this->lastDelete ) {
- $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
- if ( $deleteTime > $this->starttime ) {
- $this->deletedSinceEdit = true;
- }
- }
- }
-
- return $this->deletedSinceEdit;
- }
-
- /**
- * Checks whether the user entered a skin name in uppercase,
- * e.g. "User:Example/Monobook.css" instead of "monobook.css"
- *
- * @return bool
- */
- 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;
- }
- }
-