2004-02-18 02:15:00 +00:00
< ? php
2004-09-02 23:28:24 +00:00
/**
2007-04-04 05:22:37 +00:00
* Contains the EditPage class
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
* @ file
2004-09-02 23:28:24 +00:00
*/
2003-08-02 20:43:11 +00:00
2004-09-02 23:28:24 +00:00
/**
2007-04-04 05:22:37 +00:00
* The edit page / HTML interface ( split from Article )
2004-09-02 23:28:24 +00:00
* The actual database and text munging is still in Article ,
* but it should get easier to call those from alternate
* interfaces .
2007-11-03 03:20:12 +00:00
*
* EditPage cares about two distinct titles :
2011-02-10 17:08:37 +00:00
* $this -> mContextTitle is the page that forms submit to , links point to ,
2007-11-03 03:20:12 +00:00
* redirects go to , etc . $this -> mTitle ( as well as $mArticle ) is the
* page in the database that is actually being edited . These are
* usually the same , but they are now allowed to be different .
2011-08-27 01:24:31 +00:00
*
2011-08-29 15:45:54 +00:00
* Surgeon General ' s Warning : prolonged exposure to this class is known to cause
2011-08-27 01:24:31 +00:00
* headaches , which may be fatal .
2004-09-02 23:28:24 +00:00
*/
2003-08-02 20:43:11 +00:00
class EditPage {
2010-07-20 15:12:29 +00:00
const AS_SUCCESS_UPDATE = 200 ;
const AS_SUCCESS_NEW_ARTICLE = 201 ;
const AS_HOOK_ERROR = 210 ;
const AS_FILTERING = 211 ;
const AS_HOOK_ERROR_EXPECTED = 212 ;
const AS_BLOCKED_PAGE_FOR_USER = 215 ;
const AS_CONTENT_TOO_BIG = 216 ;
const AS_USER_CANNOT_EDIT = 217 ;
const AS_READ_ONLY_PAGE_ANON = 218 ;
const AS_READ_ONLY_PAGE_LOGGED = 219 ;
const AS_READ_ONLY_PAGE = 220 ;
const AS_RATE_LIMITED = 221 ;
const AS_ARTICLE_WAS_DELETED = 222 ;
const AS_NO_CREATE_PERMISSION = 223 ;
const AS_BLANK_ARTICLE = 224 ;
const AS_CONFLICT_DETECTED = 225 ;
const AS_SUMMARY_NEEDED = 226 ;
const AS_TEXTBOX_EMPTY = 228 ;
2009-12-04 15:45:02 +00:00
const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229 ;
2010-07-20 15:12:29 +00:00
const AS_OK = 230 ;
const AS_END = 231 ;
const AS_SPAM_ERROR = 232 ;
const AS_IMAGE_REDIRECT_ANON = 233 ;
const AS_IMAGE_REDIRECT_LOGGED = 234 ;
2007-10-30 05:42:19 +00:00
2011-02-24 17:04:49 +00:00
/**
* @ var Article
*/
2006-05-11 22:40:38 +00:00
var $mArticle ;
2011-02-24 17:04:49 +00:00
/**
* @ var Title
*/
2007-11-01 17:56:19 +00:00
var $mTitle ;
2011-02-10 17:08:37 +00:00
private $mContextTitle = null ;
2008-08-27 05:56:34 +00:00
var $action ;
2006-05-11 22:40:38 +00:00
var $isConflict = false ;
var $isCssJsSubpage = false ;
2009-08-01 07:41:57 +00:00
var $isCssSubpage = false ;
var $isJsSubpage = false ;
2011-06-05 14:46:55 +00:00
var $isWrongCaseCssJsPage = false ;
2011-04-23 18:58:03 +00:00
var $isNew = false ; // new page or new section
2011-01-20 07:38:30 +00:00
var $deletedSinceEdit ;
2006-05-11 22:40:38 +00:00
var $formtype ;
var $firsttime ;
var $lastDelete ;
2006-06-06 06:21:50 +00:00
var $mTokenOk = false ;
2007-07-01 22:22:16 +00:00
var $mTokenOkExceptSuffix = false ;
2006-06-07 08:28:43 +00:00
var $mTriedSave = false ;
2011-02-14 03:10:08 +00:00
var $incompleteForm = false ;
2006-05-11 22:40:38 +00:00
var $tooBig = false ;
var $kblength = false ;
var $missingComment = false ;
var $missingSummary = false ;
var $allowBlankSummary = false ;
var $autoSumm = '' ;
var $hookError = '' ;
2008-08-27 05:56:34 +00:00
#var $mPreviewTemplates;
2011-05-26 19:52:56 +00:00
/**
* @ var ParserOutput
*/
2008-08-27 05:56:34 +00:00
var $mParserOutput ;
2011-05-26 19:52:56 +00:00
2008-07-15 08:43:40 +00:00
var $mBaseRevision = false ;
2009-11-23 13:27:34 +00:00
var $mShowSummaryField = true ;
2005-08-02 13:35:19 +00:00
2004-03-08 09:09:35 +00:00
# Form values
2006-05-11 22:40:38 +00:00
var $save = false , $preview = false , $diff = false ;
var $minoredit = false , $watchthis = false , $recreate = false ;
2009-12-08 17:17:24 +00:00
var $textbox1 = '' , $textbox2 = '' , $summary = '' , $nosummary = false ;
2006-05-11 22:40:38 +00:00
var $edittime = '' , $section = '' , $starttime = '' ;
2009-12-08 17:17:24 +00:00
var $oldid = 0 , $editintro = '' , $scrolltop = null , $bot = true ;
2005-08-02 13:35:19 +00:00
2006-11-22 20:53:11 +00:00
# Placeholders for text injection by hooks (must be HTML)
# extensions should take care to _append_ to the present value
2006-11-26 13:58:40 +00:00
public $editFormPageTop ; // Before even the preview
public $editFormTextTop ;
2007-11-03 03:20:12 +00:00
public $editFormTextBeforeContent ;
2006-11-26 13:58:40 +00:00
public $editFormTextAfterWarn ;
public $editFormTextAfterTools ;
public $editFormTextBottom ;
2009-10-22 13:54:36 +00:00
public $editFormTextAfterContent ;
public $previewTextAfterContent ;
2011-06-05 14:46:55 +00:00
public $mPreloadText ;
2008-04-14 07:45:50 +00:00
2007-11-03 03:20:12 +00:00
/* $didSave should be set to true whenever an article was succesfully altered. */
public $didSave = false ;
2009-01-17 00:53:23 +00:00
public $undidRev = 0 ;
2008-04-14 07:45:50 +00:00
2007-11-03 03:20:12 +00:00
public $suppressIntro = false ;
2006-11-22 20:53:11 +00:00
2004-09-03 16:51:45 +00:00
/**
* @ todo document
2011-05-26 20:26:51 +00:00
* @ param $article Article
2004-09-03 16:51:45 +00:00
*/
2010-08-30 16:52:51 +00:00
function __construct ( $article ) {
2007-11-03 03:20:12 +00:00
$this -> mArticle =& $article ;
$this -> mTitle = $article -> getTitle ();
2008-08-27 05:56:34 +00:00
$this -> action = 'submit' ;
2006-11-22 20:53:11 +00:00
# Placeholders for text injection by hooks (empty per default)
2006-11-26 13:58:40 +00:00
$this -> editFormPageTop =
$this -> editFormTextTop =
2007-11-03 03:20:12 +00:00
$this -> editFormTextBeforeContent =
2006-11-26 13:58:40 +00:00
$this -> editFormTextAfterWarn =
$this -> editFormTextAfterTools =
2009-06-18 17:41:33 +00:00
$this -> editFormTextBottom =
2009-10-22 13:54:36 +00:00
$this -> editFormTextAfterContent =
$this -> previewTextAfterContent =
2009-06-18 17:41:33 +00:00
$this -> mPreloadText = " " ;
2003-08-02 20:43:11 +00:00
}
2009-10-23 11:08:08 +00:00
2011-05-26 20:26:51 +00:00
/**
* @ return Article
*/
2008-12-20 01:15:40 +00:00
function getArticle () {
return $this -> mArticle ;
}
2008-04-14 07:45:50 +00:00
2011-02-10 17:08:37 +00:00
/**
* Set the context Title object
*
* @ param $title Title object or null
*/
public function setContextTitle ( $title ) {
$this -> mContextTitle = $title ;
}
/**
* Get the context title object .
* If not set , $wgTitle will be returned . This behavior might changed in
* the future to return $this -> mTitle instead .
*
* @ return Title object
*/
public function getContextTitle () {
if ( is_null ( $this -> mContextTitle ) ) {
global $wgTitle ;
return $wgTitle ;
} else {
return $this -> mContextTitle ;
}
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
2006-07-05 22:45:41 +00:00
/**
* Fetch initial editing page content .
2011-06-05 14:46:55 +00:00
*
* @ param $def_text string
2010-01-19 08:47:48 +00:00
* @ returns mixed string on success , $def_text for invalid sections
2008-01-24 04:33:21 +00:00
* @ private
2006-07-05 22:45:41 +00:00
*/
2008-01-24 04:33:21 +00:00
function getContent ( $def_text = '' ) {
2011-02-08 22:40:07 +00:00
global $wgOut , $wgRequest , $wgParser ;
2006-07-05 22:45:41 +00:00
2008-09-04 20:14:12 +00:00
wfProfileIn ( __METHOD__ );
2006-07-05 22:45:41 +00:00
# Get variables from query string :P
$section = $wgRequest -> getVal ( 'section' );
2010-07-20 15:50:25 +00:00
$preload = $wgRequest -> getVal ( 'preload' ,
2010-01-11 11:47:50 +00:00
// Custom preload text for new sections
2011-04-25 03:20:17 +00:00
$section === 'new' ? 'MediaWiki:addsection-preload' : '' );
2007-03-28 19:41:53 +00:00
$undoafter = $wgRequest -> getVal ( 'undoafter' );
2007-03-27 21:30:39 +00:00
$undo = $wgRequest -> getVal ( 'undo' );
2006-07-05 22:45:41 +00:00
2008-09-04 20:14:12 +00:00
// For message page not locally set, use the i18n message.
// For other non-existent articles, use preload text if any.
2008-09-16 04:59:49 +00:00
if ( ! $this -> mTitle -> exists () ) {
if ( $this -> mTitle -> getNamespace () == NS_MEDIAWIKI ) {
2008-04-14 07:45:50 +00:00
# If this is a system message, get the default text.
2011-02-05 15:11:52 +00:00
$text = $this -> mTitle -> getDefaultMessageText ();
2011-02-03 15:29:13 +00:00
if ( $text === false ) {
2009-09-29 13:34:59 +00:00
$text = $this -> getPreloadedText ( $preload );
2011-02-03 15:29:13 +00:00
}
2007-01-11 04:13:11 +00:00
} else {
# If requested, preload some text.
$text = $this -> getPreloadedText ( $preload );
}
2008-09-04 20:14:12 +00:00
// For existing pages, get text based on "undo" or section parameters.
2006-07-05 22:45:41 +00:00
} else {
$text = $this -> mArticle -> getContent ();
2008-09-16 04:59:49 +00:00
if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
2007-07-06 06:52:52 +00:00
# If they got undoafter and undo round the wrong way, switch them
2007-07-06 07:11:58 +00:00
list ( $undo , $undoafter ) = array ( $undoafter , $undo );
2007-07-06 06:52:52 +00:00
}
2008-09-16 04:59:49 +00:00
if ( $undo > 0 && $undo > $undoafter ) {
2007-03-28 19:41:53 +00:00
# Undoing a specific edit overrides section editing; section-editing
2006-11-26 10:54:01 +00:00
# doesn't work with undoing.
2008-09-16 04:59:49 +00:00
if ( $undoafter ) {
2009-10-25 15:02:33 +00:00
$undorev = Revision :: newFromId ( $undo );
$oldrev = Revision :: newFromId ( $undoafter );
2007-03-28 19:41:53 +00:00
} else {
2009-10-25 15:02:33 +00:00
$undorev = Revision :: newFromId ( $undo );
2007-03-28 19:41:53 +00:00
$oldrev = $undorev ? $undorev -> getPrevious () : null ;
}
2007-04-21 14:44:56 +00:00
2008-04-23 16:08:16 +00:00
# Sanity check, make sure it's the right page,
# the revisions exist and they were not deleted.
2006-11-26 10:54:01 +00:00
# Otherwise, $text will be left as-is.
2008-09-16 04:59:49 +00:00
if ( ! is_null ( $undorev ) && ! is_null ( $oldrev ) &&
2008-04-23 16:08:16 +00:00
$undorev -> getPage () == $oldrev -> getPage () &&
$undorev -> getPage () == $this -> mArticle -> getID () &&
! $undorev -> isDeleted ( Revision :: DELETED_TEXT ) &&
! $oldrev -> isDeleted ( Revision :: DELETED_TEXT ) ) {
2009-10-23 11:08:08 +00:00
2009-01-26 13:51:03 +00:00
$undotext = $this -> mArticle -> getUndoText ( $undorev , $oldrev );
if ( $undotext === false ) {
# Warn the user that something went wrong
2011-09-04 21:19:18 +00:00
$this -> editFormPageTop .= $wgOut -> parse ( '<div class="error mw-undo-failure">' .
wfMsgNoTrans ( 'undo-failure' ) . '</div>' , true , /* interface */ true );
2006-12-11 09:39:39 +00:00
} else {
2009-01-26 13:51:03 +00:00
$text = $undotext ;
2008-04-23 16:08:16 +00:00
# Inform the user of our success and set an automatic edit summary
2011-09-04 21:19:18 +00:00
$this -> editFormPageTop .= $wgOut -> parse ( '<div class="mw-undo-success">' .
wfMsgNoTrans ( 'undo-success' ) . '</div>' , true , /* interface */ true );
2008-04-23 16:08:16 +00:00
$firstrev = $oldrev -> getNext ();
# If we just undid one rev, use an autosummary
2008-09-16 04:59:49 +00:00
if ( $firstrev -> mId == $undo ) {
2009-01-14 19:01:56 +00:00
$this -> summary = wfMsgForContent ( 'undo-summary' , $undo , $undorev -> getUserText () );
2009-01-17 00:53:23 +00:00
$this -> undidRev = $undo ;
2008-04-23 16:08:16 +00:00
}
$this -> formtype = 'diff' ;
}
2007-03-05 20:58:17 +00:00
} else {
// Failed basic sanity checks.
// Older revisions may have been removed since the link
// was created, or we may simply have got bogus input.
2011-09-04 21:19:18 +00:00
$this -> editFormPageTop .= $wgOut -> parse ( '<div class="error mw-undo-norev">' .
2011-09-04 21:22:51 +00:00
wfMsgNoTrans ( 'undo-norev' ) . '</div>' , true , /* interface */ true );
2006-11-26 10:54:01 +00:00
}
2011-06-17 16:03:52 +00:00
} elseif ( $section != '' ) {
2011-04-25 03:20:17 +00:00
if ( $section == 'new' ) {
2007-03-10 23:14:55 +00:00
$text = $this -> getPreloadedText ( $preload );
} else {
2010-01-19 08:47:48 +00:00
// Get section edit text (returns $def_text for invalid sections)
2007-03-14 18:20:21 +00:00
$text = $wgParser -> getSection ( $text , $section , $def_text );
2007-03-10 23:14:55 +00:00
}
2006-07-05 22:45:41 +00:00
}
}
2007-01-13 19:58:40 +00:00
2006-07-05 22:45:41 +00:00
wfProfileOut ( __METHOD__ );
return $text ;
}
2009-10-23 11:08:08 +00:00
2011-06-05 14:46:55 +00:00
/**
* Use this method before edit () to preload some text into the edit box
*
* @ param $text string
*/
2009-06-18 17:41:33 +00:00
public function setPreloadedText ( $text ) {
$this -> mPreloadText = $text ;
}
2006-07-05 22:45:41 +00:00
/**
2010-03-03 02:41:14 +00:00
* Get the contents to be preloaded into the box , either set by
* an earlier setPreloadText () or by loading the given page .
2006-07-05 22:45:41 +00:00
*
2010-03-03 02:41:14 +00:00
* @ param $preload String : representing the title to preload from .
* @ return String
2006-07-05 22:45:41 +00:00
*/
2008-09-04 20:14:12 +00:00
protected function getPreloadedText ( $preload ) {
2010-03-03 02:41:14 +00:00
global $wgUser , $wgParser ;
2009-10-25 15:02:33 +00:00
if ( ! empty ( $this -> mPreloadText ) ) {
2009-06-18 17:41:33 +00:00
return $this -> mPreloadText ;
2010-03-03 02:41:14 +00:00
} 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 );
2006-07-05 22:45:41 +00:00
}
}
2010-03-03 02:41:14 +00:00
return '' ;
2006-07-05 22:45:41 +00:00
}
2003-08-02 20:43:11 +00:00
2011-05-21 19:35:16 +00:00
/**
2008-09-04 20:14:12 +00:00
* 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 .
*/
2008-03-03 16:40:42 +00:00
protected function wasDeletedSinceLastEdit () {
2011-01-20 07:38:30 +00:00
if ( $this -> deletedSinceEdit !== null ) {
return $this -> deletedSinceEdit ;
}
$this -> deletedSinceEdit = false ;
2009-02-24 16:17:23 +00:00
if ( $this -> mTitle -> isDeletedQuick () ) {
2008-03-03 16:40:42 +00:00
$this -> lastDelete = $this -> getLastDelete ();
2008-09-16 04:59:49 +00:00
if ( $this -> lastDelete ) {
2008-09-28 04:20:49 +00:00
$deleteTime = wfTimestamp ( TS_MW , $this -> lastDelete -> log_timestamp );
if ( $deleteTime > $this -> starttime ) {
2008-03-03 16:40:42 +00:00
$this -> deletedSinceEdit = true ;
}
}
}
2011-01-20 07:38:30 +00:00
2008-03-03 16:40:42 +00:00
return $this -> deletedSinceEdit ;
}
2004-12-29 13:46:10 +00:00
2010-11-25 23:12:05 +00:00
/**
* Checks whether the user entered a skin name in uppercase ,
* e . g . " User:Example/Monobook.css " instead of " monobook.css "
2011-06-05 14:46:55 +00:00
*
* @ return bool
2010-11-25 23:12:05 +00:00
*/
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 ;
}
}
2005-08-20 06:57:21 +00:00
function submit () {
$this -> edit ();
}
2004-09-03 16:51:45 +00:00
/**
2006-01-07 13:09:30 +00:00
* This is the function that gets called for " action=edit " . It
* sets up various member variables , then passes execution to
2005-08-20 06:57:21 +00:00
* another function , usually showEditForm ()
2006-01-07 13:09:30 +00:00
*
2005-08-20 06:57:21 +00:00
* The edit form is self - submitting , so that when things like
* preview and edit conflicts occur , we get the same form back
2010-07-20 15:12:29 +00:00
* with the extra stuff added . Only when the final submission
2005-08-20 06:57:21 +00:00
* is made and all is well do we actually save and redirect to
* the newly - edited page .
2004-09-03 16:51:45 +00:00
*/
function edit () {
2010-02-09 07:39:09 +00:00
global $wgOut , $wgRequest , $wgUser ;
2008-09-04 20:14:12 +00:00
// Allow extensions to modify/prevent this form or submission
2009-08-21 21:51:29 +00:00
if ( ! wfRunHooks ( 'AlternateEdit' , array ( $this ) ) ) {
2005-11-10 10:30:25 +00:00
return ;
2008-09-04 20:14:12 +00:00
}
2006-01-07 13:31:29 +00:00
2008-01-11 20:51:53 +00:00
wfProfileIn ( __METHOD__ );
wfDebug ( __METHOD__ . " : enter \n " );
2005-08-21 04:45:28 +00:00
2004-03-08 09:09:35 +00:00
$this -> importFormData ( $wgRequest );
2005-08-20 06:57:21 +00:00
$this -> firsttime = false ;
2005-08-02 13:35:19 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> live ) {
2004-12-19 02:36:04 +00:00
$this -> livePreview ();
2008-01-11 20:51:53 +00:00
wfProfileOut ( __METHOD__ );
2004-12-19 02:36:04 +00:00
return ;
}
2008-04-14 07:45:50 +00:00
2008-10-13 22:39:53 +00:00
if ( wfReadOnly () && $this -> save ) {
2009-09-10 06:43:01 +00:00
// Force preview
$this -> save = false ;
$this -> preview = true ;
2008-01-15 01:55:48 +00:00
}
2003-08-02 20:43:11 +00:00
2011-04-21 08:19:24 +00:00
$wgOut -> addModules ( array ( 'mediawiki.action.edit' ) );
2010-07-20 15:50:25 +00:00
2010-02-09 07:39:09 +00:00
if ( $wgUser -> getOption ( 'uselivepreview' , false ) ) {
2010-09-04 04:00:09 +00:00
$wgOut -> addModules ( 'mediawiki.legacy.preview' );
2010-02-09 07:39:09 +00:00
}
2011-02-19 19:21:52 +00:00
// Bug #19334: textarea jumps when editing articles in IE8
$wgOut -> addStyle ( 'common/IE80Fixes.css' , 'screen' , 'IE 8' );
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
2008-09-16 04:59:49 +00:00
$permErrors = $this -> getEditPermissionErrors ();
if ( $permErrors ) {
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : User can't edit \n " );
2010-09-28 08:16:42 +00:00
$content = $this -> getContent ( null );
$content = $content === '' ? null : $content ;
$this -> readOnlyPage ( $content , true , $permErrors , 'edit' );
2008-01-11 20:51:53 +00:00
wfProfileOut ( __METHOD__ );
2005-12-05 05:37:10 +00:00
return ;
2005-08-20 06:57:21 +00:00
} else {
2008-09-16 04:59:49 +00:00
if ( $this -> save ) {
2005-08-20 06:57:21 +00:00
$this -> formtype = 'save' ;
2011-06-17 16:03:52 +00:00
} elseif ( $this -> preview ) {
2005-08-20 06:57:21 +00:00
$this -> formtype = 'preview' ;
2011-06-17 16:03:52 +00:00
} elseif ( $this -> diff ) {
2005-08-20 06:57:21 +00:00
$this -> formtype = 'diff' ;
} else { # First time through
$this -> firsttime = true ;
2008-09-16 04:59:49 +00:00
if ( $this -> previewOnOpen () ) {
2005-08-20 06:57:21 +00:00
$this -> formtype = 'preview' ;
} else {
$this -> formtype = 'initial' ;
}
2003-08-02 20:43:11 +00:00
}
}
2009-10-23 11:08:08 +00:00
2009-09-30 19:12:41 +00:00
// 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 () );
}
2005-08-21 04:45:28 +00:00
2008-01-11 20:51:53 +00:00
wfProfileIn ( __METHOD__ . " -business-end " );
2006-01-07 13:31:29 +00:00
2005-08-20 06:57:21 +00:00
$this -> isConflict = false ;
// css / js subpages of user pages get a special treatment
2011-04-23 18:58:03 +00:00
$this -> isCssJsSubpage = $this -> mTitle -> isCssJsSubpage ();
$this -> isCssSubpage = $this -> mTitle -> isCssSubpage ();
$this -> isJsSubpage = $this -> mTitle -> isJsSubpage ();
2010-11-25 23:12:05 +00:00
$this -> isWrongCaseCssJsPage = $this -> isWrongCaseCssJsPage ();
2011-04-23 18:58:03 +00:00
$this -> isNew = ! $this -> mTitle -> exists () || $this -> section == 'new' ;
2006-01-07 13:31:29 +00:00
2007-06-11 11:57:20 +00:00
# Show applicable editing introductions
2008-09-16 04:59:49 +00:00
if ( $this -> formtype == 'initial' || $this -> firsttime )
2005-08-20 06:57:21 +00:00
$this -> showIntro ();
2008-04-14 07:45:50 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> mTitle -> isTalkPage () ) {
2008-02-18 07:25:35 +00:00
$wgOut -> addWikiMsg ( 'talkpagetext' );
2005-08-20 06:57:21 +00:00
}
2008-08-11 08:30:29 +00:00
# Optional notices on a per-namespace and per-page basis
2010-07-20 15:12:29 +00:00
$editnotice_ns = 'editnotice-' . $this -> mTitle -> getNamespace ();
2011-01-14 10:51:05 +00:00
$editnotice_ns_message = wfMessage ( $editnotice_ns ) -> inContentLanguage ();
2011-01-14 11:36:37 +00:00
if ( $editnotice_ns_message -> exists () ) {
2011-01-14 13:25:14 +00:00
$wgOut -> addWikiText ( $editnotice_ns_message -> plain () );
2008-08-11 08:30:29 +00:00
}
2008-09-16 04:59:49 +00:00
if ( MWNamespace :: hasSubpages ( $this -> mTitle -> getNamespace () ) ) {
2008-08-11 08:30:29 +00:00
$parts = explode ( '/' , $this -> mTitle -> getDBkey () );
$editnotice_base = $editnotice_ns ;
while ( count ( $parts ) > 0 ) {
$editnotice_base .= '-' . array_shift ( $parts );
2011-01-14 10:51:05 +00:00
$editnotice_base_msg = wfMessage ( $editnotice_base ) -> inContentLanguage ();
2011-01-14 22:46:08 +00:00
if ( $editnotice_base_msg -> exists () ) {
2011-01-14 10:51:05 +00:00
$wgOut -> addWikiText ( $editnotice_base_msg -> plain () );
2008-08-11 08:30:29 +00:00
}
}
}
2010-07-20 15:12:29 +00:00
# Attempt submission here. This will check for edit conflicts,
2005-08-20 06:57:21 +00:00
# and redundantly check for locked database, blocked IPs, etc.
# that edit() already checked just in case someone tries to sneak
# in the back door with a hand-edited submission URL.
2008-12-23 21:19:31 +00:00
2008-09-16 04:59:49 +00:00
if ( 'save' == $this -> formtype ) {
if ( ! $this -> attemptSave () ) {
2008-01-11 20:51:53 +00:00
wfProfileOut ( __METHOD__ . " -business-end " );
wfProfileOut ( __METHOD__ );
2005-08-20 06:57:21 +00:00
return ;
}
}
2006-01-07 13:31:29 +00:00
2005-08-20 06:57:21 +00:00
# First time through: get contents, set time for conflict
# checking, etc.
2008-09-16 04:59:49 +00:00
if ( 'initial' == $this -> formtype || $this -> firsttime ) {
2009-10-25 15:02:33 +00:00
if ( $this -> initialiseForm () === false ) {
2007-03-14 18:20:21 +00:00
$this -> noSuchSectionPage ();
2008-01-11 20:51:53 +00:00
wfProfileOut ( __METHOD__ . " -business-end " );
wfProfileOut ( __METHOD__ );
2007-03-14 18:20:21 +00:00
return ;
}
2008-09-16 04:59:49 +00:00
if ( ! $this -> mTitle -> getArticleId () )
2007-11-01 17:56:19 +00:00
wfRunHooks ( 'EditFormPreloadText' , array ( & $this -> textbox1 , & $this -> mTitle ) );
2010-02-20 17:05:56 +00:00
else
wfRunHooks ( 'EditFormInitialText' , array ( $this ) );
2005-08-20 06:57:21 +00:00
}
$this -> showEditForm ();
2008-01-11 20:51:53 +00:00
wfProfileOut ( __METHOD__ . " -business-end " );
wfProfileOut ( __METHOD__ );
2003-08-02 20:43:11 +00:00
}
2009-10-23 11:08:08 +00:00
2011-06-05 14:46:55 +00:00
/**
* @ return array
*/
2008-09-04 20:14:12 +00:00
protected function getEditPermissionErrors () {
global $wgUser ;
$permErrors = $this -> mTitle -> getUserPermissionsErrors ( 'edit' , $wgUser );
# Can this title be created?
2008-09-16 04:59:49 +00:00
if ( ! $this -> mTitle -> exists () ) {
2008-09-04 20:14:12 +00:00
$permErrors = array_merge ( $permErrors ,
wfArrayDiff2 ( $this -> mTitle -> getUserPermissionsErrors ( 'create' , $wgUser ), $permErrors ) );
}
# Ignore some permissions errors when a user is just previewing/viewing diffs
$remove = array ();
foreach ( $permErrors as $error ) {
2009-10-25 15:02:33 +00:00
if ( ( $this -> preview || $this -> diff ) &&
( $error [ 0 ] == 'blockedtext' || $error [ 0 ] == 'autoblockedtext' ) )
2008-09-04 20:14:12 +00:00
{
$remove [] = $error ;
}
}
$permErrors = wfArrayDiff2 ( $permErrors , $remove );
return $permErrors ;
}
2005-08-02 13:35:19 +00:00
2008-02-21 09:32:59 +00:00
/**
* Show a read - only error
* Parameters are the same as OutputPage : readOnlyPage ()
2008-02-26 06:10:24 +00:00
* Redirect to the article page if redlink = 1
2008-02-21 09:32:59 +00:00
*/
2008-05-23 10:34:11 +00:00
function readOnlyPage ( $source = null , $protected = false , $reasons = array (), $action = null ) {
2008-02-21 09:32:59 +00:00
global $wgRequest , $wgOut ;
2008-09-16 04:59:49 +00:00
if ( $wgRequest -> getBool ( 'redlink' ) ) {
2008-02-21 09:32:59 +00:00
// The edit page was reached via a red link.
2008-04-14 07:45:50 +00:00
// Redirect to the article page and let them click the edit tab if
2008-02-21 09:32:59 +00:00
// they really want a permission error.
$wgOut -> redirect ( $this -> mTitle -> getFullUrl () );
} else {
2008-05-23 10:34:11 +00:00
$wgOut -> readOnlyPage ( $source , $protected , $reasons , $action );
2008-02-21 09:32:59 +00:00
}
}
2005-06-30 06:51:43 +00:00
/**
2007-07-10 19:23:01 +00:00
* Should we show a preview when the edit form is first shown ?
*
2005-06-30 06:51:43 +00:00
* @ return bool
*/
2008-07-17 04:37:59 +00:00
protected function previewOnOpen () {
2009-12-08 17:17:24 +00:00
global $wgRequest , $wgUser , $wgPreviewOnOpenNamespaces ;
2008-09-16 04:59:49 +00:00
if ( $wgRequest -> getVal ( 'preview' ) == 'yes' ) {
2007-07-10 19:23:01 +00:00
// Explicit override from request
return true ;
2008-09-16 04:59:49 +00:00
} elseif ( $wgRequest -> getVal ( 'preview' ) == 'no' ) {
2007-07-10 19:23:01 +00:00
// Explicit override from request
return false ;
2011-06-17 16:03:52 +00:00
} elseif ( $this -> section == 'new' ) {
2007-07-10 19:23:01 +00:00
// Nothing *to* preview for new sections
return false ;
2009-02-22 13:58:42 +00:00
} elseif ( ( $wgRequest -> getVal ( 'preload' ) !== null || $this -> mTitle -> exists () ) && $wgUser -> getOption ( 'previewonfirst' ) ) {
2007-07-10 19:23:01 +00:00
// Standard preference behaviour
return true ;
2009-12-08 17:17:24 +00:00
} elseif ( ! $this -> mTitle -> exists () &&
isset ( $wgPreviewOnOpenNamespaces [ $this -> mTitle -> getNamespace ()]) &&
$wgPreviewOnOpenNamespaces [ $this -> mTitle -> getNamespace ()] )
{
2007-07-10 19:23:01 +00:00
// Categories are special
return true ;
} else {
return false ;
}
2005-06-30 06:51:43 +00:00
}
2003-08-02 20:43:11 +00:00
2009-12-02 07:22:29 +00:00
/**
* Does this EditPage class support section editing ?
* This is used by EditPage subclasses to indicate their ui cannot handle section edits
2010-07-20 15:50:25 +00:00
*
2009-12-02 07:22:29 +00:00
* @ return bool
*/
protected function isSectionEditSupported () {
return true ;
}
/**
* Returns the URL to use in the form ' s action attribute .
* 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 .
2010-07-20 15:50:25 +00:00
*
2010-03-17 22:02:43 +00:00
* @ param $title Title object for which is being edited ( where we go to for & action = links )
2009-12-02 07:22:29 +00:00
* @ return string
*/
protected function getActionURL ( Title $title ) {
return $title -> getLocalURL ( array ( 'action' => $this -> action ) );
}
2004-09-03 16:51:45 +00:00
/**
* @ todo document
2011-06-05 14:46:55 +00:00
* @ param $request WebRequest
2004-09-03 16:51:45 +00:00
*/
2004-03-08 09:09:35 +00:00
function importFormData ( & $request ) {
2006-04-12 02:49:14 +00:00
global $wgLang , $wgUser ;
2009-10-25 15:02:33 +00:00
wfProfileIn ( __METHOD__ );
2005-08-21 04:45:28 +00:00
2008-02-26 22:40:59 +00:00
# Section edit can come from either the form or a link
$this -> section = $request -> getVal ( 'wpSection' , $request -> getVal ( 'section' ) );
2008-09-16 04:59:49 +00:00
if ( $request -> wasPosted () ) {
2005-02-15 00:24:49 +00:00
# These fields need to be checked for encoding.
# Also remove trailing whitespace, but don't remove _initial_
# whitespace from the text boxes. This may be significant formatting.
2005-07-29 10:08:41 +00:00
$this -> textbox1 = $this -> safeUnicodeInput ( $request , 'wpTextbox1' );
2009-12-02 07:22:29 +00:00
if ( ! $request -> getCheck ( 'wpTextbox2' ) ) {
// Skip this if wpTextbox2 has input, it indicates that we came
// from a conflict page with raw page text, not a custom form
// modified by subclasses
wfProfileIn ( get_class ( $this ) . " ::importContentFormData " );
$textbox1 = $this -> importContentFormData ( $request );
if ( isset ( $textbox1 ) )
$this -> textbox1 = $textbox1 ;
wfProfileOut ( get_class ( $this ) . " ::importContentFormData " );
}
2010-02-20 17:05:56 +00:00
2005-10-08 22:33:46 +00:00
# Truncate for whole multibyte characters. +5 bytes for ellipsis
2011-01-07 00:17:52 +00:00
$this -> summary = $wgLang -> truncate ( $request -> getText ( 'wpSummary' ), 250 );
2008-04-14 07:45:50 +00:00
2008-04-06 17:58:21 +00:00
# Remove extra headings from summaries and new sections.
2008-04-08 18:04:55 +00:00
$this -> summary = preg_replace ( '/^\s*=+\s*(.*?)\s*=+\s*$/' , '$1' , $this -> summary );
2005-08-02 13:35:19 +00:00
2005-02-15 00:24:49 +00:00
$this -> edittime = $request -> getVal ( 'wpEdittime' );
2005-08-02 20:17:23 +00:00
$this -> starttime = $request -> getVal ( 'wpStarttime' );
2005-10-26 10:59:44 +00:00
2005-10-26 20:37:10 +00:00
$this -> scrolltop = $request -> getIntOrNull ( 'wpScrolltop' );
2005-10-26 10:59:44 +00:00
2011-02-14 03:10:08 +00:00
if ( $this -> textbox1 === '' && $request -> getVal ( 'wpTextbox1' ) === null ) {
// wpTextbox1 field is missing, possibly due to being "too big"
// according to some filter rules such as Suhosin's setting for
// suhosin.request.max_value_length (d'oh)
$this -> incompleteForm = true ;
} else {
// edittime should be one of our last fields; if it's missing,
// the submission probably broke somewhere in the middle.
$this -> incompleteForm = is_null ( $this -> edittime );
}
if ( $this -> incompleteForm ) {
2005-02-15 00:24:49 +00:00
# If the form is incomplete, force to preview.
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : Form data appears to be incomplete \n " );
2005-10-22 20:52:30 +00:00
wfDebug ( " POST DATA: " . var_export ( $_POST , true ) . " \n " );
2009-01-13 18:05:43 +00:00
$this -> preview = true ;
2005-02-15 00:24:49 +00:00
} else {
2006-02-20 21:18:11 +00:00
/* Fallback for live preview */
$this -> preview = $request -> getCheck ( 'wpPreview' ) || $request -> getCheck ( 'wpLivePreview' );
2005-10-31 22:36:35 +00:00
$this -> diff = $request -> getCheck ( 'wpDiff' );
2006-01-07 13:31:29 +00:00
2006-06-07 08:28:43 +00:00
// Remember whether a save was requested, so we can indicate
// if we forced preview due to session failure.
$this -> mTriedSave = ! $this -> preview ;
2007-01-13 19:58:40 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> tokenOk ( $request ) ) {
2006-06-06 06:21:50 +00:00
# Some browsers will not report any submit button
# if the user hits enter in the comment box.
# The unmarked state will be assumed to be a save,
# if the form seems otherwise complete.
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : Passed token check. \n " );
2011-06-17 16:03:52 +00:00
} elseif ( $this -> diff ) {
2006-10-25 08:31:44 +00:00
# Failed token check, but only requested "Show Changes".
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : Failed token check; Show Changes requested. \n " );
2006-06-06 06:21:50 +00:00
} else {
# Page might be a hack attempt posted from
# an external site. Preview instead of saving.
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : Failed token check; forcing preview \n " );
2006-06-06 06:21:50 +00:00
$this -> preview = true ;
2005-02-15 00:24:49 +00:00
}
}
2008-04-06 17:52:55 +00:00
$this -> save = ! $this -> preview && ! $this -> diff ;
2009-10-25 15:02:33 +00:00
if ( ! preg_match ( '/^\d{14}$/' , $this -> edittime ) ) {
2005-02-15 00:24:49 +00:00
$this -> edittime = null ;
}
2005-08-02 13:35:19 +00:00
2009-10-25 15:02:33 +00:00
if ( ! preg_match ( '/^\d{14}$/' , $this -> starttime ) ) {
2005-08-02 20:17:23 +00:00
$this -> starttime = null ;
}
2006-01-07 13:31:29 +00:00
2010-07-20 15:12:29 +00:00
$this -> recreate = $request -> getCheck ( 'wpRecreate' );
2005-08-02 20:17:23 +00:00
2005-02-15 00:24:49 +00:00
$this -> minoredit = $request -> getCheck ( 'wpMinoredit' );
$this -> watchthis = $request -> getCheck ( 'wpWatchthis' );
2006-04-12 02:49:14 +00:00
# Don't force edit summaries when a user is editing their own user or talk page
2009-10-23 11:08:08 +00:00
if ( ( $this -> mTitle -> mNamespace == NS_USER || $this -> mTitle -> mNamespace == NS_USER_TALK ) &&
$this -> mTitle -> getText () == $wgUser -> getName () )
2008-09-16 16:55:49 +00:00
{
2006-04-12 02:49:14 +00:00
$this -> allowBlankSummary = true ;
} else {
2008-09-16 16:55:49 +00:00
$this -> allowBlankSummary = $request -> getBool ( 'wpIgnoreBlankSummary' ) || ! $wgUser -> getOption ( 'forceeditsummary' );
2006-04-12 02:49:14 +00:00
}
2007-01-13 19:58:40 +00:00
2008-04-14 07:45:50 +00:00
$this -> autoSumm = $request -> getText ( 'wpAutoSummary' );
2005-02-15 00:24:49 +00:00
} else {
# Not a posted form? Start with nothing.
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : Not a posted form. \n " );
2010-07-20 15:12:29 +00:00
$this -> textbox1 = '' ;
$this -> summary = '' ;
$this -> edittime = '' ;
2005-08-02 20:17:23 +00:00
$this -> starttime = wfTimestampNow ();
2010-07-20 15:12:29 +00:00
$this -> edit = false ;
$this -> preview = false ;
$this -> save = false ;
$this -> diff = false ;
2005-02-15 00:24:49 +00:00
$this -> minoredit = false ;
2009-12-08 17:17:24 +00:00
$this -> watchthis = $request -> getBool ( 'watchthis' , false ); // Watch may be overriden by request parameters
2010-07-20 15:12:29 +00:00
$this -> recreate = false ;
2008-02-26 22:40:59 +00:00
2011-04-25 03:20:17 +00:00
if ( $this -> section == 'new' && $request -> getVal ( 'preloadtitle' ) ) {
2008-02-26 22:40:59 +00:00
$this -> summary = $request -> getVal ( 'preloadtitle' );
}
2011-04-25 03:20:17 +00:00
elseif ( $this -> section != 'new' && $request -> getVal ( 'summary' ) ) {
2009-01-13 02:10:17 +00:00
$this -> summary = $request -> getText ( 'summary' );
}
2009-10-23 11:08:08 +00:00
2009-01-13 02:10:17 +00:00
if ( $request -> getVal ( 'minor' ) ) {
$this -> minoredit = true ;
}
2005-02-15 00:24:49 +00:00
}
2004-03-18 06:56:14 +00:00
2009-12-08 17:17:24 +00:00
$this -> bot = $request -> getBool ( 'bot' , true );
$this -> nosummary = $request -> getBool ( 'nosummary' );
2011-05-17 22:03:20 +00:00
// @todo FIXME: Unused variable?
2004-03-08 09:09:35 +00:00
$this -> oldid = $request -> getInt ( 'oldid' );
2004-03-18 06:56:14 +00:00
2004-12-19 02:36:04 +00:00
$this -> live = $request -> getCheck ( 'live' );
2010-01-11 11:47:50 +00:00
$this -> editintro = $request -> getText ( 'editintro' ,
// Custom edit intro for new sections
2011-04-25 03:20:17 +00:00
$this -> section === 'new' ? 'MediaWiki:addsection-editintro' : '' );
2006-01-07 13:31:29 +00:00
2009-07-07 15:55:56 +00:00
// Allow extensions to modify form data
2009-08-21 21:51:29 +00:00
wfRunHooks ( 'EditPage::importFormData' , array ( $this , $request ) );
2011-02-10 16:04:19 +00:00
wfProfileOut ( __METHOD__ );
2004-03-08 09:09:35 +00:00
}
2004-03-18 06:56:14 +00:00
2009-12-02 07:22:29 +00:00
/**
* Subpage overridable method for extracting the page content data from the
* 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 ...
2010-07-20 15:50:25 +00:00
*
2010-03-17 22:02:43 +00:00
* @ param $request WebRequest
2009-12-02 07:22:29 +00:00
*/
protected function importContentFormData ( & $request ) {
return ; // Don't do anything, EditPage already extracted wpTextbox1
}
2005-02-04 06:19:37 +00:00
/**
2005-02-15 00:24:49 +00:00
* Make sure the form isn 't faking a user' s credentials .
*
2006-04-19 15:46:24 +00:00
* @ param $request WebRequest
2005-02-15 00:24:49 +00:00
* @ return bool
2006-04-19 15:46:24 +00:00
* @ private
2005-02-04 06:19:37 +00:00
*/
2005-02-15 00:24:49 +00:00
function tokenOk ( & $request ) {
global $wgUser ;
2007-07-01 22:22:16 +00:00
$token = $request -> getVal ( 'wpEditToken' );
$this -> mTokenOk = $wgUser -> matchEditToken ( $token );
$this -> mTokenOkExceptSuffix = $wgUser -> matchEditTokenNoSuffix ( $token );
2005-10-31 22:36:35 +00:00
return $this -> mTokenOk ;
2005-02-15 00:24:49 +00:00
}
2005-08-02 13:35:19 +00:00
2007-06-11 11:57:20 +00:00
/**
* Show all applicable editing introductions
*/
2008-07-17 04:37:59 +00:00
protected function showIntro () {
2005-10-06 01:07:25 +00:00
global $wgOut , $wgUser ;
2008-09-16 04:59:49 +00:00
if ( $this -> suppressIntro ) {
2007-11-27 18:04:24 +00:00
return ;
2008-09-04 19:32:58 +00:00
}
2009-02-22 13:58:42 +00:00
$namespace = $this -> mTitle -> getNamespace ();
if ( $namespace == NS_MEDIAWIKI ) {
# Show a warning if editing an interface message
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class='mw-editinginterface'> \n $ 1 \n </div> " , 'editinginterface' );
2009-02-22 13:58:42 +00:00
}
2010-02-10 13:08:24 +00:00
# Show a warning message when someone creates/edits a user (talk) page but the user does not exist
# Show log extract when the user is currently blocked
2009-02-22 13:58:42 +00:00
if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
2007-11-29 07:01:30 +00:00
$parts = explode ( '/' , $this -> mTitle -> getText (), 2 );
$username = $parts [ 0 ];
2010-02-19 10:37:20 +00:00
$user = User :: newFromName ( $username , false /* allow IP users*/ );
2007-11-29 07:01:30 +00:00
$ip = User :: isIP ( $username );
2010-02-19 10:37:20 +00:00
if ( ! $user -> isLoggedIn () && ! $ip ) { # User does not exist
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class= \" mw-userpage-userdoesnotexist error \" > \n $ 1 \n </div> " ,
2011-06-20 19:45:35 +00:00
array ( 'userpage-userdoesnotexist' , wfEscapeWikiText ( $username ) ) );
2011-06-17 16:03:52 +00:00
} elseif ( $user -> isBlocked () ) { # Show log extract if the user is currently blocked
2010-02-10 13:08:24 +00:00
LogEventsList :: showLogExtract (
$wgOut ,
'block' ,
2010-02-19 10:37:20 +00:00
$user -> getUserPage () -> getPrefixedText (),
2010-02-10 13:08:24 +00:00
'' ,
array (
'lim' => 1 ,
'showIfEmpty' => false ,
'msgKey' => array (
2010-02-19 10:37:20 +00:00
'blocked-notice-logextract' ,
$user -> getName () # Support GENDER in notice
2010-02-10 13:08:24 +00:00
)
)
);
2007-11-27 18:04:24 +00:00
}
}
2008-09-04 19:32:58 +00:00
# Try to add a custom edit intro, or use the standard one if this is not possible.
2008-09-16 04:59:49 +00:00
if ( ! $this -> showCustomIntro () && ! $this -> mTitle -> exists () ) {
if ( $wgUser -> isLoggedIn () ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class= \" mw-newarticletext \" > \n $ 1 \n </div> " , 'newarticletext' );
2007-06-11 11:57:20 +00:00
} else {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class= \" mw-newarticletextanon \" > \n $ 1 \n </div> " , 'newarticletextanon' );
2007-06-11 11:57:20 +00:00
}
}
2009-04-24 17:20:48 +00:00
# Give a notice if the user is editing a deleted/moved page...
2008-09-16 18:31:55 +00:00
if ( ! $this -> mTitle -> exists () ) {
2009-10-23 11:08:08 +00:00
LogEventsList :: showLogExtract ( $wgOut , array ( 'delete' , 'move' ), $this -> mTitle -> getPrefixedText (),
'' , array ( 'lim' => 10 ,
'conds' => array ( " log_action != 'revision' " ),
'showIfEmpty' => false ,
'msgKey' => array ( 'recreate-moveddeleted-warn' ) )
2009-09-16 17:17:16 +00:00
);
2008-09-16 04:59:49 +00:00
}
2007-06-11 11:57:20 +00:00
}
2007-11-27 18:04:24 +00:00
2007-06-11 11:57:20 +00:00
/**
* Attempt to show a custom editing introduction , if supplied
*
* @ return bool
*/
2008-07-17 04:37:59 +00:00
protected function showCustomIntro () {
2008-09-16 04:59:49 +00:00
if ( $this -> editintro ) {
2007-06-11 11:57:20 +00:00
$title = Title :: newFromText ( $this -> editintro );
2008-09-16 04:59:49 +00:00
if ( $title instanceof Title && $title -> exists () && $title -> userCanRead () ) {
2007-06-12 19:49:38 +00:00
global $wgOut ;
2011-01-17 03:34:08 +00:00
// Added using template syntax, to take <noinclude>'s into account.
$wgOut -> addWikiTextTitleTidy ( '{{:' . $title -> getFullText () . '}}' , $this -> mTitle );
2007-06-11 11:57:20 +00:00
return true ;
} else {
return false ;
}
} else {
return false ;
2005-08-20 06:57:21 +00:00
}
2003-08-02 20:43:11 +00:00
}
2004-09-03 16:51:45 +00:00
/**
2007-10-30 05:42:19 +00:00
* Attempt submission ( no UI )
2011-06-05 14:46:55 +00:00
*
* @ param $result
* @ param $bot bool
*
2011-08-26 16:26:17 +00:00
* @ return Status object , possibly with a message , but always with one of the AS_ * constants in $status -> value ,
*
* FIXME : This interface is TERRIBLE , but hard to get rid of due to various error display idiosyncrasies . There are
* also lots of cases where error metadata is set in the object and retrieved later instead of being returned , e . g .
* AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER . All that stuff needs to be cleaned up some time .
2004-09-03 16:51:45 +00:00
*/
2008-01-10 13:33:23 +00:00
function internalAttemptSave ( & $result , $bot = false ) {
2011-08-18 20:03:30 +00:00
global $wgFilterCallback , $wgUser , $wgRequest , $wgParser ;
2008-01-25 10:34:43 +00:00
global $wgMaxArticleSize ;
2011-09-04 21:40:17 +00:00
2011-08-26 16:26:17 +00:00
$status = Status :: newGood ();
2006-01-07 13:31:29 +00:00
2010-07-20 15:12:29 +00:00
wfProfileIn ( __METHOD__ );
2009-10-25 15:02:33 +00:00
wfProfileIn ( __METHOD__ . '-checks' );
2005-08-21 04:45:28 +00:00
2010-02-20 17:05:56 +00:00
if ( ! wfRunHooks ( 'EditPage::attemptSave' , array ( $this ) ) ) {
2009-01-13 20:28:54 +00:00
wfDebug ( " Hook 'EditPage::attemptSave' aborted article saving \n " );
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR ;
2011-02-10 15:53:54 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2006-12-01 21:18:40 +00:00
}
2008-01-20 07:05:59 +00:00
# Check image redirect
2008-12-01 17:14:30 +00:00
if ( $this -> mTitle -> getNamespace () == NS_FILE &&
2008-01-20 07:05:59 +00:00
Title :: newFromRedirect ( $this -> textbox1 ) instanceof Title &&
! $wgUser -> isAllowed ( 'upload' ) ) {
2011-08-26 16:26:17 +00:00
$code = $wgUser -> isAnon () ? self :: AS_IMAGE_REDIRECT_ANON : self :: AS_IMAGE_REDIRECT_LOGGED ;
$status -> setResult ( false , $code );
2011-02-10 15:53:54 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2008-01-20 07:05:59 +00:00
}
2005-08-20 06:57:21 +00:00
# Check for spam
2009-02-27 20:50:25 +00:00
$match = self :: matchSummarySpamRegex ( $this -> summary );
2008-09-16 04:59:49 +00:00
if ( $match === false ) {
2008-08-19 20:32:30 +00:00
$match = self :: matchSpamRegex ( $this -> textbox1 );
}
2008-09-16 04:59:49 +00:00
if ( $match !== false ) {
2008-08-19 20:32:30 +00:00
$result [ 'spam' ] = $match ;
2011-08-18 20:03:30 +00:00
$ip = $wgRequest -> getIP ();
2008-06-19 23:33:45 +00:00
$pdbk = $this -> mTitle -> getPrefixedDBkey ();
2008-08-19 20:32:30 +00:00
$match = str_replace ( " \n " , '' , $match );
2008-06-19 23:33:45 +00:00
wfDebugLog ( 'SpamRegex' , " $ip spam regex hit [[ $pdbk ]]: \" $match\ " " );
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'spamprotectionmatch' , $match );
$status -> value = self :: AS_SPAM_ERROR ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-08-02 20:17:23 +00:00
}
2008-09-16 04:59:49 +00:00
if ( $wgFilterCallback && $wgFilterCallback ( $this -> mTitle , $this -> textbox1 , $this -> section , $this -> hookError , $this -> summary ) ) {
2005-08-20 06:57:21 +00:00
# Error messages or other handling should be performed by the filter function
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_FILTERING );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2004-03-05 21:44:38 +00:00
}
2008-09-16 04:59:49 +00:00
if ( ! wfRunHooks ( 'EditFilter' , array ( $this , $this -> textbox1 , $this -> section , & $this -> hookError , $this -> summary ) ) ) {
2006-05-06 21:41:53 +00:00
# Error messages etc. could be handled within the hook...
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2008-09-16 04:59:49 +00:00
} elseif ( $this -> hookError != '' ) {
2006-05-06 21:41:53 +00:00
# ...or the hook could be expecting us to produce an error
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR_EXPECTED ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-09-29 23:35:31 +00:00
}
2011-09-04 21:40:17 +00:00
2008-09-16 04:59:49 +00:00
if ( $wgUser -> isBlockedFrom ( $this -> mTitle , false ) ) {
2005-08-20 06:57:21 +00:00
# Check block state against master, thus 'false'.
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_BLOCKED_PAGE_FOR_USER );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2003-08-02 20:43:11 +00:00
}
2011-09-04 21:40:17 +00:00
2009-10-25 15:02:33 +00:00
$this -> kblength = ( int )( strlen ( $this -> textbox1 ) / 1024 );
2008-09-16 04:59:49 +00:00
if ( $this -> kblength > $wgMaxArticleSize ) {
2006-02-22 00:55:25 +00:00
// Error will be displayed by showEditForm()
$this -> tooBig = true ;
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_CONTENT_TOO_BIG );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2006-02-22 00:55:25 +00:00
}
2007-01-13 19:58:40 +00:00
2009-10-25 15:02:33 +00:00
if ( ! $wgUser -> isAllowed ( 'edit' ) ) {
2008-09-16 04:59:49 +00:00
if ( $wgUser -> isAnon () ) {
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_READ_ONLY_PAGE_ANON );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2009-10-25 15:02:33 +00:00
} else {
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'readonlytext' );
$status -> value = self :: AS_READ_ONLY_PAGE_LOGGED ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-05-27 11:03:37 +00:00
}
2005-08-20 06:57:21 +00:00
}
New edit toolbar for bold, italic, links, headlines, math, images, media,
sigs, horizontal lines (more can be added easily). Select text and click
to apply, or just click to see an example. Mouseover should show speedtips.
Also, access keys for the edit window (ALT+P=Preview, ALT+S=Save) -> Moz+IE
2004-01-11 04:11:43 +00:00
2008-09-16 04:59:49 +00:00
if ( wfReadOnly () ) {
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'readonlytext' );
$status -> value = self :: AS_READ_ONLY_PAGE ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-08-20 06:57:21 +00:00
}
2008-09-16 04:59:49 +00:00
if ( $wgUser -> pingLimiter () ) {
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'actionthrottledtext' );
$status -> value = self :: AS_RATE_LIMITED ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-08-20 06:57:21 +00:00
}
# If the article has been deleted while editing, don't save it without
# confirmation
2008-09-16 04:59:49 +00:00
if ( $this -> wasDeletedSinceLastEdit () && ! $this -> recreate ) {
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_ARTICLE_WAS_DELETED );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-08-20 06:57:21 +00:00
}
2006-01-07 13:31:29 +00:00
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ . '-checks' );
2006-01-07 13:31:29 +00:00
2005-08-20 06:57:21 +00:00
# If article is new, insert it.
2010-09-30 19:13:25 +00:00
$aid = $this -> mTitle -> getArticleID ( Title :: GAID_FOR_UPDATE );
2011-01-15 15:21:36 +00:00
$new = ( $aid == 0 );
if ( $new ) {
2005-12-05 05:37:10 +00:00
// Late check for create permission, just in case *PARANOIA*
2008-09-16 04:59:49 +00:00
if ( ! $this -> mTitle -> userCan ( 'create' ) ) {
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'nocreatetext' );
$status -> value = self :: AS_NO_CREATE_PERMISSION ;
2009-10-25 15:02:33 +00:00
wfDebug ( __METHOD__ . " : no create permission \n " );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-12-05 05:37:10 +00:00
}
2006-01-07 13:31:29 +00:00
2005-08-20 06:57:21 +00:00
# Don't save a new article if it's blank.
2010-01-06 19:59:42 +00:00
if ( $this -> textbox1 == '' ) {
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_BLANK_ARTICLE );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-09-04 17:41:44 +00:00
}
2005-08-23 08:15:14 +00:00
2007-11-12 07:30:40 +00:00
// Run post-section-merge edit filter
2009-08-21 21:51:29 +00:00
if ( ! wfRunHooks ( 'EditFilterMerged' , array ( $this , $this -> textbox1 , & $this -> hookError , $this -> summary ) ) ) {
2007-11-12 07:30:40 +00:00
# Error messages etc. could be handled within the hook...
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2009-08-30 05:55:47 +00:00
} elseif ( $this -> hookError != '' ) {
# ...or the hook could be expecting us to produce an error
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR_EXPECTED ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2007-11-12 07:30:40 +00:00
}
2009-10-23 11:08:08 +00:00
2009-01-17 17:47:58 +00:00
# Handle the user preference to force summaries here. Check if it's not a redirect.
if ( ! $this -> allowBlankSummary && ! Title :: newFromRedirect ( $this -> textbox1 ) ) {
if ( md5 ( $this -> summary ) == $this -> autoSumm ) {
$this -> missingSummary = true ;
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
$status -> value = self :: AS_SUMMARY_NEEDED ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2009-01-17 17:47:58 +00:00
}
}
2007-11-12 07:30:40 +00:00
2011-01-15 15:21:36 +00:00
$text = $this -> textbox1 ;
2011-06-17 16:03:52 +00:00
if ( $this -> section == 'new' && $this -> summary != '' ) {
2011-01-15 15:21:36 +00:00
$text = wfMsgForContent ( 'newsectionheaderdefaultlevel' , $this -> summary ) . " \n \n " . $text ;
}
2008-04-14 07:45:50 +00:00
2011-08-26 16:26:17 +00:00
$status -> value = self :: AS_SUCCESS_NEW_ARTICLE ;
2006-01-07 13:31:29 +00:00
2011-01-15 15:21:36 +00:00
} else {
2004-03-18 15:02:56 +00:00
2011-01-15 15:21:36 +00:00
# Article exists. Check for edit conflict.
2003-08-02 20:43:11 +00:00
2011-01-15 15:21:36 +00:00
$this -> mArticle -> clear (); # Force reload of dates, etc.
2006-01-07 13:31:29 +00:00
2011-01-15 15:21:36 +00:00
wfDebug ( " timestamp: { $this -> mArticle -> getTimestamp () } , edittime: { $this -> edittime } \n " );
2007-03-11 03:59:37 +00:00
2011-01-15 15:21:36 +00:00
if ( $this -> mArticle -> getTimestamp () != $this -> edittime ) {
$this -> isConflict = true ;
2011-04-25 03:20:17 +00:00
if ( $this -> section == 'new' ) {
2011-01-15 15:21:36 +00:00
if ( $this -> mArticle -> getUserText () == $wgUser -> getName () &&
$this -> mArticle -> getComment () == $this -> summary ) {
// Probably a duplicate submission of a new comment.
// This can happen when squid resends a request after
// a timeout but the first one actually went through.
wfDebug ( __METHOD__ . " : duplicate new section submission; trigger edit conflict! \n " );
} else {
// New comment; suppress conflict.
$this -> isConflict = false ;
wfDebug ( __METHOD__ . " : conflict suppressed; new section \n " );
}
2011-08-06 20:39:15 +00:00
} elseif ( $this -> section == '' && $this -> userWasLastToEdit ( $wgUser -> getId (), $this -> edittime ) ) {
# Suppress edit conflict with self, except for section edits where merging is required.
wfDebug ( __METHOD__ . " : Suppressing edit conflict, same user. \n " );
$this -> isConflict = false ;
2005-12-11 12:07:18 +00:00
}
}
2006-01-07 13:31:29 +00:00
2011-01-15 15:21:36 +00:00
if ( $this -> isConflict ) {
wfDebug ( __METHOD__ . " : conflict! getting section ' $this->section ' for time ' $this->edittime ' (article time ' " .
$this -> mArticle -> getTimestamp () . " ') \n " );
$text = $this -> mArticle -> replaceSection ( $this -> section , $this -> textbox1 , $this -> summary , $this -> edittime );
} else {
wfDebug ( __METHOD__ . " : getting section ' $this->section ' \n " );
$text = $this -> mArticle -> replaceSection ( $this -> section , $this -> textbox1 , $this -> summary );
}
if ( is_null ( $text ) ) {
wfDebug ( __METHOD__ . " : activating conflict; section replace failed. \n " );
$this -> isConflict = true ;
$text = $this -> textbox1 ; // do not try to merge here!
2011-06-17 16:03:52 +00:00
} elseif ( $this -> isConflict ) {
2011-01-15 15:21:36 +00:00
# Attempt merge
if ( $this -> mergeChangesInto ( $text ) ) {
// Successful merge! Maybe we should tell the user the good news?
$this -> isConflict = false ;
wfDebug ( __METHOD__ . " : Suppressing edit conflict, successful merge. \n " );
} else {
$this -> section = '' ;
$this -> textbox1 = $text ;
wfDebug ( __METHOD__ . " : Keeping edit conflict, failed merge. \n " );
}
}
2007-11-12 07:30:40 +00:00
2011-01-15 15:21:36 +00:00
if ( $this -> isConflict ) {
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_CONFLICT_DETECTED );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2006-11-02 13:33:38 +00:00
}
2011-01-15 15:21:36 +00:00
// Run post-section-merge edit filter
if ( ! wfRunHooks ( 'EditFilterMerged' , array ( $this , $text , & $this -> hookError , $this -> summary ) ) ) {
# Error messages etc. could be handled within the hook...
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR ;
2011-01-15 15:21:36 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2011-01-15 15:21:36 +00:00
} elseif ( $this -> hookError != '' ) {
# ...or the hook could be expecting us to produce an error
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'hookaborted' );
$status -> value = self :: AS_HOOK_ERROR_EXPECTED ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2006-03-25 02:48:31 +00:00
}
2006-03-25 00:57:14 +00:00
2011-01-15 15:21:36 +00:00
# Handle the user preference to force summaries here, but not for null edits
2011-08-06 20:39:15 +00:00
if ( $this -> section != 'new' && ! $this -> allowBlankSummary
&& 0 != strcmp ( $this -> mArticle -> getContent (), $text )
2011-01-15 15:21:36 +00:00
&& ! Title :: newFromRedirect ( $text ) ) # check if it's not a redirect
{
if ( md5 ( $this -> summary ) == $this -> autoSumm ) {
$this -> missingSummary = true ;
wfProfileOut ( __METHOD__ );
return self :: AS_SUMMARY_NEEDED ;
}
2006-03-01 23:00:07 +00:00
}
2011-01-15 15:21:36 +00:00
# And a similar thing for new sections
2011-06-17 16:03:52 +00:00
if ( $this -> section == 'new' && ! $this -> allowBlankSummary ) {
2011-01-15 15:21:36 +00:00
if ( trim ( $this -> summary ) == '' ) {
$this -> missingSummary = true ;
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'missingsummary' ); // or 'missingcommentheader' if $section == 'new'. Blegh
$status -> value = self :: AS_SUMMARY_NEEDED ;
2011-01-15 15:21:36 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2011-01-15 15:21:36 +00:00
}
2005-08-20 06:57:21 +00:00
}
2011-01-15 15:21:36 +00:00
# All's well
wfProfileIn ( __METHOD__ . '-sectionanchor' );
$sectionanchor = '' ;
2011-06-17 16:03:52 +00:00
if ( $this -> section == 'new' ) {
2011-01-15 15:21:36 +00:00
if ( $this -> textbox1 == '' ) {
$this -> missingComment = true ;
2011-08-26 16:26:17 +00:00
$status -> fatal ( 'missingcommenttext' );
$status -> value = self :: AS_TEXTBOX_EMPTY ;
2011-01-15 15:21:36 +00:00
wfProfileOut ( __METHOD__ . '-sectionanchor' );
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2011-01-15 15:21:36 +00:00
}
if ( $this -> summary != '' ) {
$sectionanchor = $wgParser -> guessLegacySectionNameFromWikiText ( $this -> summary );
# This is a new section, so create a link to the new section
# in the revision summary.
$cleanSummary = $wgParser -> stripSectionName ( $this -> summary );
$this -> summary = wfMsgForContent ( 'newsectionsummary' , $cleanSummary );
}
} elseif ( $this -> section != '' ) {
# Try to get a section anchor from the section source, redirect to edited section if header found
# XXX: might be better to integrate this into Article::replaceSection
# for duplicate heading checking and maybe parsing
$hasmatch = preg_match ( " /^ *([=] { 1,6})(.*?)( \\ 1) * \\ n/i " , $this -> textbox1 , $matches );
# we can't deal with anchors, includes, html etc in the header for now,
# headline would need to be parsed to improve this
2011-05-28 14:52:55 +00:00
if ( $hasmatch && strlen ( $matches [ 2 ] ) > 0 ) {
2011-01-15 15:21:36 +00:00
$sectionanchor = $wgParser -> guessLegacySectionNameFromWikiText ( $matches [ 2 ] );
}
2005-08-20 06:57:21 +00:00
}
2011-01-15 15:21:36 +00:00
$result [ 'sectionanchor' ] = $sectionanchor ;
wfProfileOut ( __METHOD__ . '-sectionanchor' );
2005-08-20 06:57:21 +00:00
2011-01-15 15:21:36 +00:00
// Save errors may fall down to the edit form, but we've now
// merged the section into full text. Clear the section field
// so that later submission of conflict forms won't try to
// replace that into a duplicated mess.
$this -> textbox1 = $text ;
$this -> section = '' ;
2011-08-26 16:26:17 +00:00
$status -> value = self :: AS_SUCCESS_UPDATE ;
2011-01-15 15:21:36 +00:00
}
2005-08-20 06:57:21 +00:00
2006-02-22 00:55:25 +00:00
// Check for length errors again now that the section is merged in
2009-10-25 15:02:33 +00:00
$this -> kblength = ( int )( strlen ( $text ) / 1024 );
2008-09-16 04:59:49 +00:00
if ( $this -> kblength > $wgMaxArticleSize ) {
2006-02-22 00:55:25 +00:00
$this -> tooBig = true ;
2011-08-26 16:26:17 +00:00
$status -> setResult ( false , self :: AS_MAX_ARTICLE_SIZE_EXCEEDED );
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2006-02-22 00:55:25 +00:00
}
2011-01-15 15:21:36 +00:00
$flags = EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
( $new ? EDIT_NEW : EDIT_UPDATE ) |
2011-04-23 18:58:03 +00:00
( ( $this -> minoredit && ! $this -> isNew ) ? EDIT_MINOR : 0 ) |
2011-01-15 15:21:36 +00:00
( $bot ? EDIT_FORCE_BOT : 0 );
2011-08-26 16:26:17 +00:00
$doEditStatus = $this -> mArticle -> doEdit ( $text , $this -> summary , $flags );
2011-01-15 15:21:36 +00:00
2011-08-26 16:26:17 +00:00
if ( $doEditStatus -> isOK () ) {
2011-01-15 15:21:36 +00:00
$result [ 'redirect' ] = Title :: newFromRedirect ( $text ) !== null ;
$this -> commitWatch ();
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $status ;
2005-08-23 08:15:14 +00:00
} else {
$this -> isConflict = true ;
2011-08-26 16:26:17 +00:00
$doEditStatus -> value = self :: AS_END ; // Destroys data doEdit() put in $status->value but who cares
2011-01-15 15:21:36 +00:00
wfProfileOut ( __METHOD__ );
2011-08-26 16:26:17 +00:00
return $doEditStatus ;
2011-01-15 15:21:36 +00:00
}
}
/**
* Commit the change of watch status
*/
protected function commitWatch () {
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
global $wgUser ;
2011-01-15 15:21:36 +00:00
if ( $this -> watchthis xor $this -> mTitle -> userIsWatching () ) {
$dbw = wfGetDB ( DB_MASTER );
$dbw -> begin ();
if ( $this -> watchthis ) {
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
WatchAction :: doWatch ( $this -> mTitle , $wgUser );
2011-01-15 15:21:36 +00:00
} else {
WatchAction requires token (BREAKING CHANGE)
* (bug 27655) Require token for watching/unwatching pages
* Previously done for API (bug 29070) in r88522
* As with markpatrolled, the tokens are not compatible and made that way on purpose. The API requires the POST method and uses a universal token per-session. Since the front-end is all GET based (also per convention like in markpatrolled and rollback) they are stronger salted (title / action specific)
* ajax.watch used the API already and was switched in r88554.
* The actual watching/unwatching code was moved from WatchAction->onView to WatchAction::doWatch. This was done to allow the API to do the action without needing to generate a token like the front-end needs (or having to duplicate code). It is now similar to RecentChange::markPatrolled (in that it also a "central" function that does not care about tokens, it's called after the token-handling)
* JavaScript / Gadgets that utilize action=watch in their scripts:
** Effects should be minimal as they should be using the API (see r88522 and wikitech-l)
** If they use index.php and scrap the link from the page, they can continue to do so.
* There are links to the watch action all over the place. I've tried to catch most of them, but there may be some I miss. Migration in most cases is just a matter of adding an array item to the $query for:
'token' => WatchAction::getWatchToken( $title, $user [, $action] )
or changing:
Action::factory( 'watch', $article )->execute();
to:
WatchAction::doWatch( $title, $user );
While replacing the usages in some cases an instance of Article() no longer had to be created, in others $wgUser had to be retrieved from global (which was implied before but needs to be given directly now)
Other notes:
* Article->unwatch() and Article->watch(), which were deprecated as of 1.18 and are no longer used in core, may be broken in scenarios where the Request does not have a 'token' but is making a call to $article->watch()
* Some extensions need to be fixed, I'm currently running a grep search and will fix them a.s.a.p
[1] http://www.mediawiki.org/wiki/ResourceLoader/Default_modules?mw.user#tokens
2011-06-06 00:09:03 +00:00
WatchAction :: doUnwatch ( $this -> mTitle , $wgUser );
2011-01-15 15:21:36 +00:00
}
$dbw -> commit ();
2003-08-02 20:43:11 +00:00
}
2005-08-20 06:57:21 +00:00
}
2009-10-23 11:08:08 +00:00
2008-10-13 14:48:17 +00:00
/**
* Check if no edits were made by other users since
* the time a user started editing the page . Limit to
2008-10-15 14:23:23 +00:00
* 50 revisions for the sake of performance .
2011-06-05 14:46:55 +00:00
*
* @ param $id int
* @ param $edittime string
*
* @ return bool
2008-10-13 14:48:17 +00:00
*/
protected function userWasLastToEdit ( $id , $edittime ) {
2009-01-13 18:05:43 +00:00
if ( ! $id ) return false ;
2008-10-13 14:48:17 +00:00
$dbw = wfGetDB ( DB_MASTER );
$res = $dbw -> select ( 'revision' ,
'rev_user' ,
2009-10-23 11:08:08 +00:00
array (
2008-10-13 19:08:27 +00:00
'rev_page' => $this -> mArticle -> getId (),
'rev_timestamp > ' . $dbw -> addQuotes ( $dbw -> timestamp ( $edittime ) )
),
2008-10-13 14:48:17 +00:00
__METHOD__ ,
2008-10-15 14:23:23 +00:00
array ( 'ORDER BY' => 'rev_timestamp ASC' , 'LIMIT' => 50 ) );
2010-10-13 23:11:40 +00:00
foreach ( $res as $row ) {
2008-10-13 14:48:17 +00:00
if ( $row -> rev_user != $id ) {
return false ;
}
}
return true ;
}
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
2008-08-19 20:32:30 +00:00
/**
* Check given input text against $wgSpamRegex , and return the text of the first match .
2011-06-05 14:46:55 +00:00
*
* @ param $text string
*
* @ return string | false matching string or false
2008-08-19 20:32:30 +00:00
*/
public static function matchSpamRegex ( $text ) {
global $wgSpamRegex ;
2009-02-27 20:50:25 +00:00
// For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
$regexes = ( array ) $wgSpamRegex ;
return self :: matchSpamRegexInternal ( $text , $regexes );
}
2009-10-23 11:08:08 +00:00
2009-02-27 20:50:25 +00:00
/**
* Check given input text against $wgSpamRegex , and return the text of the first match .
2011-06-05 14:46:55 +00:00
*
* @ parma $text string
*
* @ return string | false matching string or false
2009-02-27 20:50:25 +00:00
*/
public static function matchSummarySpamRegex ( $text ) {
global $wgSummarySpamRegex ;
$regexes = ( array ) $wgSummarySpamRegex ;
return self :: matchSpamRegexInternal ( $text , $regexes );
}
2009-10-23 11:08:08 +00:00
2011-06-05 14:46:55 +00:00
/**
* @ param $text string
* @ param $regexes array
* @ return bool | string
*/
2009-02-27 20:50:25 +00:00
protected static function matchSpamRegexInternal ( $text , $regexes ) {
foreach ( $regexes as $regex ) {
$matches = array ();
if ( preg_match ( $regex , $text , $matches ) ) {
return $matches [ 0 ];
2008-08-19 20:32:30 +00:00
}
}
return false ;
}
2005-08-20 06:57:21 +00:00
/**
* Initialise form fields in the object
* Called on the first invocation , e . g . when a user clicks an edit link
2011-06-05 14:46:55 +00:00
* @ return bool -- if the requested section is valid
2005-08-20 06:57:21 +00:00
*/
function initialiseForm () {
2009-12-08 17:17:24 +00:00
global $wgUser ;
2005-08-20 06:57:21 +00:00
$this -> edittime = $this -> mArticle -> getTimestamp ();
2008-10-07 18:10:08 +00:00
$this -> textbox1 = $this -> getContent ( false );
2009-12-08 17:17:24 +00:00
// activate checkboxes if user wants them to be always active
# 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 ;
}
2011-06-05 14:46:55 +00:00
if ( $wgUser -> getOption ( 'minordefault' ) && ! $this -> isNew ) {
$this -> minoredit = true ;
}
if ( $this -> textbox1 === false ) {
return false ;
}
2006-06-01 08:19:02 +00:00
wfProxyCheck ();
2007-03-14 18:20:21 +00:00
return true ;
2005-08-20 06:57:21 +00:00
}
2008-08-27 05:56:34 +00:00
function setHeaders () {
2011-02-10 17:08:37 +00:00
global $wgOut ;
2008-08-27 05:56:34 +00:00
$wgOut -> setRobotPolicy ( 'noindex,nofollow' );
2008-09-16 04:59:49 +00:00
if ( $this -> formtype == 'preview' ) {
2008-08-27 05:56:34 +00:00
$wgOut -> setPageTitleActionText ( wfMsg ( 'preview' ) );
}
2008-09-16 04:59:49 +00:00
if ( $this -> isConflict ) {
2011-02-10 17:08:37 +00:00
$wgOut -> setPageTitle ( wfMsg ( 'editconflict' , $this -> getContextTitle () -> getPrefixedText () ) );
2008-09-16 04:59:49 +00:00
} elseif ( $this -> section != '' ) {
2011-04-25 03:20:17 +00:00
$msg = $this -> section == 'new' ? 'editingcomment' : 'editingsection' ;
2011-02-10 17:08:37 +00:00
$wgOut -> setPageTitle ( wfMsg ( $msg , $this -> getContextTitle () -> getPrefixedText () ) );
2008-08-27 05:56:34 +00:00
} else {
# Use the title defined by DISPLAYTITLE magic word when present
2009-10-25 15:02:33 +00:00
if ( isset ( $this -> mParserOutput )
2008-12-31 16:49:38 +00:00
&& ( $dt = $this -> mParserOutput -> getDisplayTitle () ) !== false ) {
$title = $dt ;
2008-08-27 05:56:34 +00:00
} else {
2011-02-10 17:08:37 +00:00
$title = $this -> getContextTitle () -> getPrefixedText ();
2008-08-27 05:56:34 +00:00
}
2008-12-31 16:49:38 +00:00
$wgOut -> setPageTitle ( wfMsg ( 'editing' , $title ) );
2008-08-27 05:56:34 +00:00
}
}
2005-08-20 06:57:21 +00:00
/**
* Send the edit form and related headers to $wgOut
2011-04-23 13:55:27 +00:00
* @ param $formCallback Callback that takes an OutputPage parameter ; will be called
* during form output near the top , for captchas and the like .
2005-08-20 06:57:21 +00:00
*/
2011-07-30 15:56:54 +00:00
function showEditForm ( $formCallback = null ) {
2011-08-24 13:03:03 +00:00
global $wgOut , $wgUser , $wgEnableInterwikiTranscluding , $wgEnableInterwikiTemplatesTracking ;
2005-08-20 06:57:21 +00:00
2009-10-25 15:02:33 +00:00
wfProfileIn ( __METHOD__ );
2005-08-21 04:45:28 +00:00
2008-08-27 05:56:34 +00:00
#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
#setting work instead of leaving it in getPreviewText
$previewOutput = '' ;
2008-09-16 04:59:49 +00:00
if ( $this -> formtype == 'preview' ) {
2008-08-27 05:56:34 +00:00
$previewOutput = $this -> getPreviewText ();
}
2009-10-23 11:08:08 +00:00
2011-08-04 21:04:59 +00:00
wfRunHooks ( 'EditPage::showEditForm:initial' , array ( & $this ) );
2008-08-27 05:56:34 +00:00
$this -> setHeaders ();
2004-03-18 06:56:14 +00:00
2004-01-17 09:49:43 +00:00
# Enabled article-related sidebar, toplinks, etc.
$wgOut -> setArticleRelated ( true );
2003-08-02 20:43:11 +00:00
2011-02-10 15:53:54 +00:00
if ( $this -> showHeader () === false ) {
wfProfileOut ( __METHOD__ );
2009-12-02 07:22:29 +00:00
return ;
2011-02-10 15:53:54 +00:00
}
2009-12-02 07:22:29 +00:00
2011-02-10 17:08:37 +00:00
$action = htmlspecialchars ( $this -> getActionURL ( $this -> getContextTitle () ) );
2009-12-02 07:22:29 +00:00
if ( $wgUser -> getOption ( 'showtoolbar' ) and ! $this -> isCssJsSubpage ) {
# prepare toolbar for edit buttons
$toolbar = EditPage :: getEditToolbar ();
} else {
$toolbar = '' ;
}
$wgOut -> addHTML ( $this -> editFormPageTop );
if ( $wgUser -> getOption ( 'previewontop' ) ) {
$this -> displayPreviewArea ( $previewOutput , true );
}
$wgOut -> addHTML ( $this -> editFormTextTop );
$templates = $this -> getTemplates ();
2011-07-16 19:19:01 +00:00
$formattedtemplates = Linker :: formatTemplates ( $templates , $this -> preview , $this -> section != '' );
2009-12-02 07:22:29 +00:00
2011-08-24 13:03:03 +00:00
$distantTemplates = $this -> getDistantTemplates ();
$formattedDistantTemplates = Linker :: formatDistantTemplates ( $distantTemplates , $this -> preview , $this -> section != '' );
2009-12-02 07:22:29 +00:00
$hiddencats = $this -> mArticle -> getHiddenCategories ();
2011-07-16 19:19:01 +00:00
$formattedhiddencats = Linker :: formatHiddenCategories ( $hiddencats );
2009-12-02 07:22:29 +00:00
if ( $this -> wasDeletedSinceLastEdit () && 'save' != $this -> formtype ) {
$wgOut -> wrapWikiMsg (
2010-05-28 21:22:45 +00:00
" <div class='error mw-deleted-while-editing'> \n $ 1 \n </div> " ,
2009-12-02 07:22:29 +00:00
'deletedwhileediting' );
} elseif ( $this -> wasDeletedSinceLastEdit () ) {
// Hide the toolbar and edit area, user can click preview to get it back
// Add an confirmation checkbox and explanation.
$toolbar = '' ;
// @todo move this to a cleaner conditional instead of blanking a variable
}
2009-12-07 08:51:52 +00:00
$wgOut -> addHTML ( <<< HTML
2009-12-02 07:22:29 +00:00
< form id = " editform " name = " editform " method = " post " action = " $action " enctype = " multipart/form-data " >
2009-12-07 08:51:52 +00:00
HTML
2009-12-02 07:22:29 +00:00
);
if ( is_callable ( $formCallback ) ) {
call_user_func_array ( $formCallback , array ( & $wgOut ) );
}
wfRunHooks ( 'EditPage::showEditForm:fields' , array ( & $this , & $wgOut ) );
// Put these up at the top to ensure they aren't lost on early form submission
$this -> showFormBeforeText ();
if ( $this -> wasDeletedSinceLastEdit () && 'save' == $this -> formtype ) {
2011-01-09 11:30:36 +00:00
$username = $this -> lastDelete -> user_name ;
$comment = $this -> lastDelete -> log_comment ;
2011-02-12 04:06:22 +00:00
2011-01-09 11:30:36 +00:00
// It is better to not parse the comment at all than to have templates expanded in the middle
// TODO: can the checkLabel be moved outside of the div so that wrapWikiMsg could be used?
2011-03-30 18:06:05 +00:00
$key = $comment === ''
? 'confirmrecreate-noreason'
: 'confirmrecreate' ;
2009-12-02 07:22:29 +00:00
$wgOut -> addHTML (
'<div class="mw-confirm-recreate">' .
2011-03-30 17:04:03 +00:00
wfMsgExt ( $key , 'parseinline' , $username , " <nowiki> $comment </nowiki> " ) .
2009-12-02 07:22:29 +00:00
Xml :: checkLabel ( wfMsg ( 'recreate' ), 'wpRecreate' , 'wpRecreate' , false ,
2011-07-16 19:19:01 +00:00
array ( 'title' => Linker :: titleAttrib ( 'recreate' ), 'tabindex' => 1 , 'id' => 'wpRecreate' )
2009-12-02 07:22:29 +00:00
) .
'</div>'
);
}
# If a blank edit summary was previously provided, and the appropriate
# user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
# user being bounced back more than once in the event that a summary
# is not required.
#####
# For a bit more sophisticated detection of blank summaries, hash the
# automatic one and pass that in the hidden field wpAutoSummary.
if ( $this -> missingSummary ||
2011-04-25 03:20:17 +00:00
( $this -> section == 'new' && $this -> nosummary ) )
2010-10-31 16:33:48 +00:00
$wgOut -> addHTML ( Html :: hidden ( 'wpIgnoreBlankSummary' , true ) );
2009-12-02 07:22:29 +00:00
$autosumm = $this -> autoSumm ? $this -> autoSumm : md5 ( $this -> summary );
2010-10-31 16:33:48 +00:00
$wgOut -> addHTML ( Html :: hidden ( 'wpAutoSummary' , $autosumm ) );
2009-12-02 07:22:29 +00:00
2010-10-31 16:33:48 +00:00
$wgOut -> addHTML ( Html :: hidden ( 'oldid' , $this -> mArticle -> getOldID () ) );
2010-02-05 15:01:07 +00:00
2011-04-25 03:20:17 +00:00
if ( $this -> section == 'new' ) {
2009-12-02 07:22:29 +00:00
$this -> showSummaryInput ( true , $this -> summary );
$wgOut -> addHTML ( $this -> getSummaryPreview ( true , $this -> summary ) );
}
2009-09-16 20:43:14 +00:00
2009-12-02 07:22:29 +00:00
$wgOut -> addHTML ( $this -> editFormTextBeforeContent );
2011-06-17 16:03:52 +00:00
2011-04-25 11:35:40 +00:00
$wgOut -> addHTML ( $toolbar );
2010-07-20 15:50:25 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> isConflict ) {
2009-12-02 07:22:29 +00:00
// In an edit conflict bypass the overrideable content form method
// and fallback to the raw wpTextbox1 since editconflicts can't be
// resolved between page source edits and custom ui edits using the
// custom edit ui.
2010-04-10 14:11:40 +00:00
$this -> showTextbox1 ( null , $this -> getContent () );
2009-12-02 07:22:29 +00:00
} else {
$this -> showContentForm ();
}
$wgOut -> addHTML ( $this -> editFormTextAfterContent );
$wgOut -> addWikiText ( $this -> getCopywarn () );
if ( isset ( $this -> editFormTextAfterWarn ) && $this -> editFormTextAfterWarn !== '' )
$wgOut -> addHTML ( $this -> editFormTextAfterWarn );
$this -> showStandardInputs ();
$this -> showFormAfterText ();
$this -> showTosSummary ();
$this -> showEditTools ();
2009-12-07 08:51:52 +00:00
$wgOut -> addHTML ( <<< HTML
2009-12-02 07:22:29 +00:00
{ $this -> editFormTextAfterTools }
< div class = 'templatesUsed' >
{ $formattedtemplates }
</ div >
2011-08-24 13:03:03 +00:00
HTML
);
if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
$wgOut -> addHTML ( <<< HTML
{ $this -> editFormTextAfterTools }
< div class = 'distantTemplatesUsed' >
{ $formattedDistantTemplates }
</ div >
HTML
);
}
$wgOut -> addHTML ( <<< HTML
{ $this -> editFormTextAfterTools }
2009-12-02 07:22:29 +00:00
< div class = 'hiddencats' >
{ $formattedhiddencats }
</ div >
2009-12-07 08:51:52 +00:00
HTML
2009-12-02 07:22:29 +00:00
);
if ( $this -> isConflict )
$this -> showConflict ();
2010-07-20 15:50:25 +00:00
2009-12-02 07:22:29 +00:00
$wgOut -> addHTML ( $this -> editFormTextBottom );
$wgOut -> addHTML ( " </form> \n " );
if ( ! $wgUser -> getOption ( 'previewontop' ) ) {
$this -> displayPreviewArea ( $previewOutput , false );
}
2003-08-02 20:43:11 +00:00
2009-12-02 07:22:29 +00:00
wfProfileOut ( __METHOD__ );
}
2010-07-20 15:50:25 +00:00
2009-12-08 17:17:24 +00:00
protected function showHeader () {
2011-02-10 17:08:37 +00:00
global $wgOut , $wgUser , $wgMaxArticleSize , $wgLang ;
2009-12-02 07:22:29 +00:00
if ( $this -> isConflict ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class='mw-explainconflict'> \n $ 1 \n </div> " , 'explainconflict' );
2004-03-08 09:09:35 +00:00
$this -> edittime = $this -> mArticle -> getTimestamp ();
2003-08-02 20:43:11 +00:00
} else {
2009-12-02 07:22:29 +00:00
if ( $this -> section != '' && ! $this -> isSectionEditSupported () ) {
// We use $this->section to much before this and getVal('wgSection') directly in other places
// at this point we can't reset $this->section to '' to fallback to non-section editing.
// Someone is welcome to try refactoring though
$wgOut -> showErrorPage ( 'sectioneditnotsupported-title' , 'sectioneditnotsupported-text' );
return false ;
}
2011-04-25 03:20:17 +00:00
if ( $this -> section != '' && $this -> section != 'new' ) {
2008-08-27 05:56:34 +00:00
$matches = array ();
2008-09-16 04:59:49 +00:00
if ( ! $this -> summary && ! $this -> preview && ! $this -> diff ) {
2009-01-16 19:56:57 +00:00
preg_match ( " /^(=+)(.+) \\ 1/mi " , $this -> textbox1 , $matches );
2008-09-16 04:59:49 +00:00
if ( ! empty ( $matches [ 2 ] ) ) {
2008-08-27 05:56:34 +00:00
global $wgParser ;
$this -> summary = " /* " .
$wgParser -> stripSectionName ( trim ( $matches [ 2 ])) .
" */ " ;
2006-01-07 13:31:29 +00:00
}
2004-03-20 01:18:19 +00:00
}
2003-08-02 20:43:11 +00:00
}
2006-03-01 23:00:07 +00:00
2009-12-08 17:17:24 +00:00
if ( $this -> missingComment ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div id='mw-missingcommenttext'> \n $ 1 \n </div> " , 'missingcommenttext' );
2009-12-08 17:17:24 +00:00
}
2007-01-13 19:58:40 +00:00
2011-04-25 03:20:17 +00:00
if ( $this -> missingSummary && $this -> section != 'new' ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div id='mw-missingsummary'> \n $ 1 \n </div> " , 'missingsummary' );
2009-12-08 17:17:24 +00:00
}
2006-11-03 01:37:06 +00:00
2011-04-25 03:20:17 +00:00
if ( $this -> missingSummary && $this -> section == 'new' ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div id='mw-missingcommentheader'> \n $ 1 \n </div> " , 'missingcommentheader' );
2009-12-08 17:17:24 +00:00
}
2007-01-13 19:58:40 +00:00
2009-12-08 17:17:24 +00:00
if ( $this -> hookError !== '' ) {
2006-05-06 21:41:53 +00:00
$wgOut -> addWikiText ( $this -> hookError );
2009-12-08 17:17:24 +00:00
}
2006-03-01 23:00:07 +00:00
2009-12-08 17:17:24 +00:00
if ( ! $this -> checkUnicodeCompliantBrowser () ) {
2008-02-18 07:25:35 +00:00
$wgOut -> addWikiMsg ( 'nonunicodebrowser' );
2009-12-08 17:17:24 +00:00
}
2009-12-02 07:22:29 +00:00
2008-12-23 21:19:31 +00:00
if ( isset ( $this -> mArticle ) && isset ( $this -> mArticle -> mRevision ) ) {
// Let sysop know that this will make private content public if saved
2008-09-04 13:57:52 +00:00
2008-09-16 04:59:49 +00:00
if ( ! $this -> mArticle -> mRevision -> userCan ( Revision :: DELETED_TEXT ) ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class='mw-warning plainlinks'> \n $ 1 \n </div> \n " , 'rev-deleted-text-permission' );
2011-06-17 16:03:52 +00:00
} elseif ( $this -> mArticle -> mRevision -> isDeleted ( Revision :: DELETED_TEXT ) ) {
2010-05-28 21:22:45 +00:00
$wgOut -> wrapWikiMsg ( " <div class='mw-warning plainlinks'> \n $ 1 \n </div> \n " , 'rev-deleted-text-view' );
2007-02-17 04:17:53 +00:00
}
2008-12-23 21:19:31 +00:00
2008-09-16 04:59:49 +00:00
if ( ! $this -> mArticle -> mRevision -> isCurrent () ) {
2007-02-17 04:17:53 +00:00
$this -> mArticle -> setOldSubtitle ( $this -> mArticle -> mRevision -> getId () );
2008-02-18 07:25:35 +00:00
$wgOut -> addWikiMsg ( 'editingold' );
2007-02-17 04:17:53 +00:00
}
2003-08-02 20:43:11 +00:00
}
}
2008-09-16 04:59:49 +00:00
if ( wfReadOnly () ) {
2008-08-20 21:27:12 +00:00
$wgOut -> wrapWikiMsg ( " <div id= \" mw-read-only-warning \" > \n $ 1 \n </div> " , array ( 'readonlywarning' , wfReadOnlyReason () ) );
2010-03-29 22:44:59 +00:00
} elseif ( $wgUser -> isAnon () ) {
if ( $this -> formtype != 'preview' ) {
$wgOut -> wrapWikiMsg ( " <div id= \" mw-anon-edit-warning \" > \n $ 1</div> " , 'anoneditwarning' );
} else {
$wgOut -> wrapWikiMsg ( " <div id= \" mw-anon-preview-warning \" > \n $ 1</div> " , 'anonpreviewwarning' );
}
2008-12-23 21:19:31 +00:00
} else {
if ( $this -> isCssJsSubpage ) {
# Check the skin exists
2010-11-25 23:12:05 +00:00
if ( $this -> isWrongCaseCssJsPage ) {
2011-02-10 17:08:37 +00:00
$wgOut -> wrapWikiMsg ( " <div class='error' id='mw-userinvalidcssjstitle'> \n $ 1 \n </div> " , array ( 'userinvalidcssjstitle' , $this -> getContextTitle () -> getSkinFromCssJsSubpage () ) );
2006-02-23 14:37:51 +00:00
}
2009-08-01 08:19:53 +00:00
if ( $this -> formtype !== 'preview' ) {
if ( $this -> isCssSubpage )
2010-06-02 19:30:55 +00:00
$wgOut -> wrapWikiMsg ( " <div id='mw-usercssyoucanpreview'> \n $ 1 \n </div> " , array ( 'usercssyoucanpreview' ) );
2009-08-01 08:19:53 +00:00
if ( $this -> isJsSubpage )
2010-06-02 19:30:55 +00:00
$wgOut -> wrapWikiMsg ( " <div id='mw-userjsyoucanpreview'> \n $ 1 \n </div> " , array ( 'userjsyoucanpreview' ) );
2009-08-01 08:19:53 +00:00
}
2006-02-23 14:37:51 +00:00
}
2003-08-02 20:43:11 +00:00
}
2007-01-12 04:43:33 +00:00
2009-12-02 07:22:29 +00:00
if ( $this -> mTitle -> getNamespace () != NS_MEDIAWIKI && $this -> mTitle -> isProtected ( 'edit' ) ) {
2007-01-20 19:17:45 +00:00
# Is the title semi-protected?
2008-09-16 04:59:49 +00:00
if ( $this -> mTitle -> isSemiProtected () ) {
2008-02-18 07:25:35 +00:00
$noticeMsg = 'semiprotectedpagewarning' ;
2006-02-06 09:49:28 +00:00
} else {
2008-01-09 21:40:40 +00:00
# Then it must be protected based on static groups (regular)
2008-02-18 07:25:35 +00:00
$noticeMsg = 'protectedpagewarning' ;
2006-02-06 09:49:28 +00:00
}
2009-10-23 11:08:08 +00:00
LogEventsList :: showLogExtract ( $wgOut , 'protect' , $this -> mTitle -> getPrefixedText (), '' ,
2009-09-16 17:17:16 +00:00
array ( 'lim' => 1 , 'msgKey' => array ( $noticeMsg ) ) );
2003-08-02 20:43:11 +00:00
}
2008-09-16 04:59:49 +00:00
if ( $this -> mTitle -> isCascadeProtected () ) {
2007-04-21 19:02:02 +00:00
# Is this page under cascading protection from some source pages?
2007-11-01 17:56:19 +00:00
list ( $cascadeSources , /* $restrictions */ ) = $this -> mTitle -> getCascadeProtectionSources ();
2010-01-14 17:14:49 +00:00
$notice = " <div class='mw-cascadeprotectedwarning'> \n $ 1 \n " ;
2009-01-22 12:57:09 +00:00
$cascadeSourcesCount = count ( $cascadeSources );
if ( $cascadeSourcesCount > 0 ) {
2008-12-23 21:19:31 +00:00
# Explain, and list the titles responsible
foreach ( $cascadeSources as $page ) {
$notice .= '* [[:' . $page -> getPrefixedText () . " ]] \n " ;
}
2007-08-21 03:57:54 +00:00
}
2009-01-22 12:57:09 +00:00
$notice .= '</div>' ;
$wgOut -> wrapWikiMsg ( $notice , array ( 'cascadeprotectedwarning' , $cascadeSourcesCount ) );
2007-04-21 19:02:02 +00:00
}
2008-09-16 04:59:49 +00:00
if ( ! $this -> mTitle -> exists () && $this -> mTitle -> getRestrictions ( 'create' ) ) {
2010-01-16 11:24:23 +00:00
LogEventsList :: showLogExtract ( $wgOut , 'protect' , $this -> mTitle -> getPrefixedText (), '' ,
2010-07-20 15:12:29 +00:00
array ( 'lim' => 1 ,
2010-01-16 11:24:23 +00:00
'showIfEmpty' => false ,
'msgKey' => array ( 'titleprotectedwarning' ),
'wrap' => " <div class= \" mw-titleprotectedwarning \" > \n $ 1</div> " ) );
2008-01-02 19:51:34 +00:00
}
2006-02-22 00:55:25 +00:00
2009-12-08 17:17:24 +00:00
if ( $this -> kblength === false ) {
2009-10-25 15:02:33 +00:00
$this -> kblength = ( int )( strlen ( $this -> textbox1 ) / 1024 );
2009-12-08 17:17:24 +00:00
}
2009-12-02 07:22:29 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> tooBig || $this -> kblength > $wgMaxArticleSize ) {
2010-11-23 12:57:27 +00:00
$wgOut -> wrapWikiMsg ( " <div class='error' id='mw-edit-longpageerror'> \n $ 1 \n </div> " ,
array ( 'longpageerror' , $wgLang -> formatNum ( $this -> kblength ), $wgLang -> formatNum ( $wgMaxArticleSize ) ) );
} else {
2011-01-14 10:51:05 +00:00
if ( ! wfMessage ( 'longpage-hint' ) -> isDisabled () ) {
2010-11-23 12:57:27 +00:00
$wgOut -> wrapWikiMsg ( " <div id='mw-edit-longpage-hint'> \n $ 1 \n </div> " ,
array ( 'longpage-hint' , $wgLang -> formatSize ( strlen ( $this -> textbox1 ) ), strlen ( $this -> textbox1 ) )
);
}
2003-08-02 20:43:11 +00:00
}
2009-12-02 07:22:29 +00:00
}
New edit toolbar for bold, italic, links, headlines, math, images, media,
sigs, horizontal lines (more can be added easily). Select text and click
to apply, or just click to see an example. Mouseover should show speedtips.
Also, access keys for the edit window (ALT+P=Preview, ALT+S=Save) -> Moz+IE
2004-01-11 04:11:43 +00:00
2009-12-02 07:22:29 +00:00
/**
* Standard summary input and label ( wgSummary ), abstracted so EditPage
* subclasses may reorganize the form .
* Note that you do not need to worry about the label ' s for = , it will be
* inferred by the id given to the input . You can remove them both by
* passing array ( 'id' => false ) to $userInputAttrs .
2010-07-20 15:50:25 +00:00
*
2011-06-05 14:46:55 +00:00
* @ param $summary string The value of the summary input
* @ param $labelText string The html to place inside the label
* @ param $inputAttrs array of attrs to use on the input
* @ param $spanLabelAttrs array of attrs to use on the span inside the label
2010-07-20 15:50:25 +00:00
*
2009-12-02 07:22:29 +00:00
* @ return array An array in the format array ( $label , $input )
*/
2009-12-08 17:17:24 +00:00
function getSummaryInput ( $summary = " " , $labelText = null , $inputAttrs = null , $spanLabelAttrs = null ) {
2010-05-26 09:10:56 +00:00
//Note: the maxlength is overriden in JS to 250 and to make it use UTF-8 bytes, not characters.
2009-12-08 17:17:24 +00:00
$inputAttrs = ( is_array ( $inputAttrs ) ? $inputAttrs : array () ) + array (
2009-12-02 07:22:29 +00:00
'id' => 'wpSummary' ,
'maxlength' => '200' ,
2010-02-10 15:15:36 +00:00
'tabindex' => '1' ,
2009-12-02 07:22:29 +00:00
'size' => 60 ,
'spellcheck' => 'true' ,
2011-07-04 08:28:27 +00:00
) + Linker :: tooltipAndAccesskeyAttribs ( 'summary' );
2010-04-28 18:40:51 +00:00
2009-12-08 17:17:24 +00:00
$spanLabelAttrs = ( is_array ( $spanLabelAttrs ) ? $spanLabelAttrs : array () ) + array (
2009-12-02 18:51:19 +00:00
'class' => $this -> missingSummary ? 'mw-summarymissed' : 'mw-summary' ,
2009-12-02 07:22:29 +00:00
'id' => " wpSummaryLabel "
);
2006-11-26 13:58:40 +00:00
2009-12-02 07:22:29 +00:00
$label = null ;
if ( $labelText ) {
$label = Xml :: tags ( 'label' , $inputAttrs [ 'id' ] ? array ( 'for' => $inputAttrs [ 'id' ] ) : null , $labelText );
$label = Xml :: tags ( 'span' , $spanLabelAttrs , $label );
2005-03-19 12:01:57 +00:00
}
2009-12-02 07:22:29 +00:00
$input = Html :: input ( 'wpSummary' , $summary , 'text' , $inputAttrs );
2008-12-23 21:19:31 +00:00
2009-12-02 07:22:29 +00:00
return array ( $label , $input );
}
2008-04-14 07:45:50 +00:00
2009-12-02 07:22:29 +00:00
/**
2010-03-17 22:02:43 +00:00
* @ param $isSubjectPreview Boolean : true if this is the section subject / title
2010-07-20 15:12:29 +00:00
* up top , or false if this is the comment summary
* down below the textarea
2010-03-17 22:02:43 +00:00
* @ param $summary String : The text of the summary to display
* @ return String
2009-12-02 07:22:29 +00:00
*/
protected function showSummaryInput ( $isSubjectPreview , $summary = " " ) {
2009-12-08 17:17:24 +00:00
global $wgOut , $wgContLang ;
2009-12-02 07:22:29 +00:00
# Add a class if 'missingsummary' is triggered to allow styling of the summary line
$summaryClass = $this -> missingSummary ? 'mw-summarymissed' : 'mw-summary' ;
if ( $isSubjectPreview ) {
2011-06-05 14:46:55 +00:00
if ( $this -> nosummary ) {
2009-12-02 07:22:29 +00:00
return ;
2011-06-05 14:46:55 +00:00
}
2005-08-20 06:57:21 +00:00
} else {
2011-06-05 14:46:55 +00:00
if ( ! $this -> mShowSummaryField ) {
2009-12-02 07:22:29 +00:00
return ;
2011-06-05 14:46:55 +00:00
}
2005-09-29 23:35:31 +00:00
}
2009-12-02 07:22:29 +00:00
$summary = $wgContLang -> recodeForEdit ( $summary );
$labelText = wfMsgExt ( $isSubjectPreview ? 'subject' : 'summary' , 'parseinline' );
list ( $label , $input ) = $this -> getSummaryInput ( $summary , $labelText , array ( 'class' => $summaryClass ), array ());
$wgOut -> addHTML ( " { $label } { $input } " );
}
2005-12-02 03:29:37 +00:00
2009-12-02 07:22:29 +00:00
/**
2010-03-17 22:02:43 +00:00
* @ param $isSubjectPreview Boolean : true if this is the section subject / title
2010-07-20 15:12:29 +00:00
* up top , or false if this is the comment summary
* down below the textarea
2010-03-17 22:02:43 +00:00
* @ param $summary String : the text of the summary to display
* @ return String
2009-12-02 07:22:29 +00:00
*/
protected function getSummaryPreview ( $isSubjectPreview , $summary = " " ) {
if ( ! $summary || ( ! $this -> preview && ! $this -> diff ) )
return " " ;
2010-07-20 15:50:25 +00:00
2011-07-16 19:19:01 +00:00
global $wgParser ;
2010-07-20 15:50:25 +00:00
2009-12-02 07:22:29 +00:00
if ( $isSubjectPreview )
$summary = wfMsgForContent ( 'newsectionsummary' , $wgParser -> stripSectionName ( $summary ) );
2005-12-02 03:29:37 +00:00
2010-05-09 12:41:57 +00:00
$message = $isSubjectPreview ? 'subject-preview' : 'summary-preview' ;
2011-07-16 19:19:01 +00:00
$summary = wfMsgExt ( $message , 'parseinline' ) . Linker :: commentBlock ( $summary , $this -> mTitle , $isSubjectPreview );
2009-12-02 07:22:29 +00:00
return Xml :: tags ( 'div' , array ( 'class' => 'mw-summary-preview' ), $summary );
}
2005-12-04 00:35:14 +00:00
2009-12-02 07:22:29 +00:00
protected function showFormBeforeText () {
global $wgOut ;
$section = htmlspecialchars ( $this -> section );
2010-08-29 19:07:06 +00:00
$wgOut -> addHTML ( <<< HTML
2009-12-02 07:22:29 +00:00
< input type = 'hidden' value = " { $section } " name = " wpSection " />
< input type = 'hidden' value = " { $this -> starttime } " name = " wpStarttime " />
< input type = 'hidden' value = " { $this -> edittime } " name = " wpEdittime " />
< input type = 'hidden' value = " { $this -> scrolltop } " name = " wpScrolltop " id = " wpScrolltop " />
2010-08-29 19:07:06 +00:00
HTML
2009-12-02 07:22:29 +00:00
);
if ( ! $this -> checkUnicodeCompliantBrowser () )
2010-10-31 16:33:48 +00:00
$wgOut -> addHTML ( Html :: hidden ( 'safemode' , '1' ));
2009-12-02 07:22:29 +00:00
}
2010-07-20 15:50:25 +00:00
2009-12-02 07:22:29 +00:00
protected function showFormAfterText () {
global $wgOut , $wgUser ;
2008-02-24 02:02:19 +00:00
/**
* 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 .
*
* For anon editors , who may not have a session , we just
* include the constant suffix to prevent editing from
* broken text - mangling proxies .
*/
2010-10-31 16:33:48 +00:00
$wgOut -> addHTML ( " \n " . Html :: hidden ( " wpEditToken " , $wgUser -> editToken () ) . " \n " );
2008-08-27 05:56:34 +00:00
}
2007-01-13 19:58:40 +00:00
2009-12-02 07:22:29 +00:00
/**
* Subpage overridable method for printing the form for page content editing
* By default this simply outputs wpTextbox1
* Subclasses can override this to provide a custom UI for editing ;
* be it a form , or simply wpTextbox1 with a modified content that will be
* reverse modified when extracted from the post data .
* Note that this is basically the inverse for importContentFormData
*/
protected function showContentForm () {
$this -> showTextbox1 ();
2008-08-27 05:56:34 +00:00
}
2009-10-23 11:08:08 +00:00
2009-12-02 07:22:29 +00:00
/**
* Method to output wpTextbox1
* The $textoverride method can be used by subclasses overriding showContentForm
* to pass back to this method .
2010-07-20 15:50:25 +00:00
*
2010-03-17 22:02:43 +00:00
* @ param $customAttribs An array of html attributes to use in the textarea
* @ param $textoverride String : optional text to override $this -> textarea1 with
2009-12-02 07:22:29 +00:00
*/
protected function showTextbox1 ( $customAttribs = null , $textoverride = null ) {
$classes = array (); // Textarea CSS
if ( $this -> mTitle -> getNamespace () != NS_MEDIAWIKI && $this -> mTitle -> isProtected ( 'edit' ) ) {
# Is the title semi-protected?
if ( $this -> mTitle -> isSemiProtected () ) {
$classes [] = 'mw-textarea-sprotected' ;
} else {
# Then it must be protected based on static groups (regular)
$classes [] = 'mw-textarea-protected' ;
}
2011-05-19 19:48:50 +00:00
# Is the title cascade-protected?
if ( $this -> mTitle -> isCascadeProtected () ) {
$classes [] = 'mw-textarea-cprotected' ;
}
2009-12-02 07:22:29 +00:00
}
2008-08-27 05:56:34 +00:00
$attribs = array ( 'tabindex' => 1 );
2009-12-02 07:22:29 +00:00
if ( is_array ( $customAttribs ) )
$attribs += $customAttribs ;
2009-10-23 11:08:08 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> wasDeletedSinceLastEdit () )
2008-08-27 05:56:34 +00:00
$attribs [ 'type' ] = 'hidden' ;
2009-12-02 07:22:29 +00:00
if ( ! empty ( $classes ) ) {
if ( isset ( $attribs [ 'class' ]) )
$classes [] = $attribs [ 'class' ];
2009-10-25 15:02:33 +00:00
$attribs [ 'class' ] = implode ( ' ' , $classes );
2009-12-02 07:22:29 +00:00
}
2010-07-20 15:50:25 +00:00
2009-12-02 07:22:29 +00:00
$this -> showTextbox ( isset ( $textoverride ) ? $textoverride : $this -> textbox1 , 'wpTextbox1' , $attribs );
2008-08-27 05:56:34 +00:00
}
2009-10-23 11:08:08 +00:00
2008-08-27 05:56:34 +00:00
protected function showTextbox2 () {
2011-05-14 22:57:55 +00:00
$this -> showTextbox ( $this -> textbox2 , 'wpTextbox2' , array ( 'tabindex' => 6 , 'readonly' ) );
2008-08-27 05:56:34 +00:00
}
2009-10-23 11:08:08 +00:00
2009-12-02 07:22:29 +00:00
protected function showTextbox ( $content , $name , $customAttribs = array () ) {
2008-08-27 05:56:34 +00:00
global $wgOut , $wgUser ;
2009-10-23 11:08:08 +00:00
2008-08-27 05:56:34 +00:00
$wikitext = $this -> safeUnicodeOutput ( $content );
2008-09-16 04:59:49 +00:00
if ( $wikitext !== '' ) {
2008-08-27 05:56:34 +00:00
// Ensure there's a newline at the end, otherwise adding lines
// is awkward.
// But don't add a newline if the ext is empty, or Firefox in XHTML
// mode will show an extra newline. A bit annoying.
$wikitext .= " \n " ;
}
2009-10-23 11:08:08 +00:00
2009-12-02 07:22:29 +00:00
$attribs = $customAttribs + array (
'accesskey' => ',' ,
'id' => $name ,
2010-07-20 15:50:25 +00:00
'cols' => $wgUser -> getIntOption ( 'cols' ),
2009-12-02 07:22:29 +00:00
'rows' => $wgUser -> getIntOption ( 'rows' ),
2010-04-15 18:11:24 +00:00
'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
2009-12-02 07:22:29 +00:00
);
2009-10-23 11:08:08 +00:00
2011-07-06 02:26:06 +00:00
$pageLang = $this -> mTitle -> getPageLanguage ();
$attribs [ 'lang' ] = $pageLang -> getCode ();
$attribs [ 'dir' ] = $pageLang -> getDir ();
2011-06-17 21:48:43 +00:00
2009-12-02 07:22:29 +00:00
$wgOut -> addHTML ( Html :: textarea ( $name , $wikitext , $attribs ) );
}
2006-02-20 21:18:11 +00:00
2008-08-27 14:47:41 +00:00
protected function displayPreviewArea ( $previewOutput , $isOnTop = false ) {
2008-08-27 05:56:34 +00:00
global $wgOut ;
2008-08-29 13:46:06 +00:00
$classes = array ();
2008-09-16 04:59:49 +00:00
if ( $isOnTop )
2008-08-29 13:46:06 +00:00
$classes [] = 'ontop' ;
$attribs = array ( 'id' => 'wikiPreview' , 'class' => implode ( ' ' , $classes ) );
2008-09-16 04:59:49 +00:00
if ( $this -> formtype != 'preview' )
2008-08-29 13:46:06 +00:00
$attribs [ 'style' ] = 'display: none;' ;
2008-08-28 21:16:46 +00:00
$wgOut -> addHTML ( Xml :: openElement ( 'div' , $attribs ) );
2008-08-29 13:46:06 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> formtype == 'preview' ) {
2008-08-27 05:56:34 +00:00
$this -> showPreview ( $previewOutput );
2008-08-26 14:07:31 +00:00
}
2008-08-29 13:46:06 +00:00
2008-08-28 21:16:46 +00:00
$wgOut -> addHTML ( '</div>' );
2008-08-26 14:07:31 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> formtype == 'diff' ) {
2008-08-27 05:56:34 +00:00
$this -> showDiff ();
}
2003-08-02 20:43:11 +00:00
}
2006-01-07 13:31:29 +00:00
2008-08-28 21:16:46 +00:00
/**
* Append preview output to $wgOut .
* Includes category rendering if this is a category page .
*
2010-03-17 22:02:43 +00:00
* @ param $text String : the HTML to be output for the preview .
2008-08-28 21:16:46 +00:00
*/
protected function showPreview ( $text ) {
global $wgOut ;
2008-09-16 04:59:49 +00:00
if ( $this -> mTitle -> getNamespace () == NS_CATEGORY ) {
2008-08-28 21:16:46 +00:00
$this -> mArticle -> openShowCategory ();
}
2008-09-04 20:14:12 +00:00
# This hook seems slightly odd here, but makes things more
# consistent for extensions.
2008-08-28 21:16:46 +00:00
wfRunHooks ( 'OutputPageBeforeHTML' , array ( & $wgOut , & $text ) );
$wgOut -> addHTML ( $text );
2008-09-16 04:59:49 +00:00
if ( $this -> mTitle -> getNamespace () == NS_CATEGORY ) {
2008-08-28 21:16:46 +00:00
$this -> mArticle -> closeShowCategory ();
}
}
2010-03-26 11:21:14 +00:00
/**
* Give a chance for site and per - namespace customizations of
* terms of service summary link that might exist separately
* from the copyright notice .
2010-07-20 15:50:25 +00:00
*
2010-03-26 11:21:14 +00:00
* This will display between the save button and the edit tools ,
* so should remain short !
*/
2009-06-24 16:49:28 +00:00
protected function showTosSummary () {
$msg = 'editpage-tos-summary' ;
wfRunHooks ( 'EditPageTosSummary' , array ( $this -> mTitle , & $msg ) );
2011-01-14 10:51:05 +00:00
if ( ! wfMessage ( $msg ) -> isDisabled () ) {
2009-06-24 16:49:28 +00:00
global $wgOut ;
$wgOut -> addHTML ( '<div class="mw-tos-summary">' );
2011-07-16 19:19:01 +00:00
$wgOut -> addWikiMsg ( $msg );
2009-06-24 16:49:28 +00:00
$wgOut -> addHTML ( '</div>' );
}
}
2009-06-30 11:42:51 +00:00
2008-08-27 05:56:34 +00:00
protected function showEditTools () {
global $wgOut ;
2011-07-16 19:19:01 +00:00
$wgOut -> addHTML ( '<div class="mw-editTools">' .
wfMessage ( 'edittools' ) -> inContentLanguage () -> parse () .
'</div>' );
2008-08-27 05:56:34 +00:00
}
2010-07-20 15:50:25 +00:00
2009-12-02 07:22:29 +00:00
protected function getCopywarn () {
global $wgRightsText ;
if ( $wgRightsText ) {
$copywarnMsg = array ( 'copyrightwarning' ,
'[[' . wfMsgForContent ( 'copyrightpage' ) . ']]' ,
$wgRightsText );
} else {
$copywarnMsg = array ( 'copyrightwarning2' ,
'[[' . wfMsgForContent ( 'copyrightpage' ) . ']]' );
}
// Allow for site and per-namespace customization of contribution/copyright notice.
wfRunHooks ( 'EditPageCopyrightWarning' , array ( $this -> mTitle , & $copywarnMsg ) );
2010-07-20 15:50:25 +00:00
2011-02-13 23:20:53 +00:00
return " <div id= \" editpage-copywarn \" > \n " .
call_user_func_array ( " wfMsgNoTrans " , $copywarnMsg ) . " \n </div> " ;
2009-12-02 07:22:29 +00:00
}
2010-07-20 15:50:25 +00:00
2009-12-02 07:22:29 +00:00
protected function showStandardInputs ( & $tabindex = 2 ) {
2011-07-16 19:19:01 +00:00
global $wgOut ;
2009-12-02 07:22:29 +00:00
$wgOut -> addHTML ( " <div class='editOptions'> \n " );
2011-04-25 03:20:17 +00:00
if ( $this -> section != 'new' ) {
2009-12-02 07:22:29 +00:00
$this -> showSummaryInput ( false , $this -> summary );
$wgOut -> addHTML ( $this -> getSummaryPreview ( false , $this -> summary ) );
}
2011-07-16 19:19:01 +00:00
$checkboxes = $this -> getCheckboxes ( $tabindex ,
2009-12-02 07:22:29 +00:00
array ( 'minor' => $this -> minoredit , 'watch' => $this -> watchthis ) );
$wgOut -> addHTML ( " <div class='editCheckboxes'> " . implode ( $checkboxes , " \n " ) . " </div> \n " );
$wgOut -> addHTML ( " <div class='editButtons'> \n " );
$wgOut -> addHTML ( implode ( $this -> getEditButtons ( $tabindex ), " \n " ) . " \n " );
$cancel = $this -> getCancelLink ();
2011-07-12 15:38:07 +00:00
if ( $cancel !== '' ) {
$cancel .= wfMsgExt ( 'pipe-separator' , 'escapenoentities' );
}
2009-12-02 07:22:29 +00:00
$edithelpurl = Skin :: makeInternalOrExternalUrl ( wfMsgForContent ( 'edithelppage' ) );
$edithelp = '<a target="helpwindow" href="' . $edithelpurl . '">' .
htmlspecialchars ( wfMsg ( 'edithelp' ) ) . '</a> ' .
htmlspecialchars ( wfMsg ( 'newwindow' ) );
2011-07-12 15:38:07 +00:00
$wgOut -> addHTML ( " <span class='editHelp'> { $cancel } { $edithelp } </span> \n " );
2009-12-02 07:22:29 +00:00
$wgOut -> addHTML ( " </div><!-- editButtons --> \n </div><!-- editOptions --> \n " );
}
2010-04-10 14:11:40 +00:00
2011-05-21 19:35:16 +00:00
/**
2010-04-10 14:11:40 +00:00
* Show an edit conflict . textbox1 is already shown in showEditForm () .
* If you want to use another entry point to this function , be careful .
*/
2009-12-02 07:22:29 +00:00
protected function showConflict () {
global $wgOut ;
$this -> textbox2 = $this -> textbox1 ;
$this -> textbox1 = $this -> getContent ();
if ( wfRunHooks ( 'EditPageBeforeConflictDiff' , array ( & $this , & $wgOut ) ) ) {
$wgOut -> wrapWikiMsg ( '<h2>$1</h2>' , " yourdiff " );
$de = new DifferenceEngine ( $this -> mTitle );
$de -> setText ( $this -> textbox2 , $this -> textbox1 );
$de -> showDiff ( wfMsg ( " yourtext " ), wfMsg ( " storedversion " ) );
$wgOut -> wrapWikiMsg ( '<h2>$1</h2>' , " yourtext " );
$this -> showTextbox2 ();
}
}
2008-08-27 05:56:34 +00:00
2009-03-09 09:21:48 +00:00
protected function getLastDelete () {
2007-01-22 23:50:42 +00:00
$dbr = wfGetDB ( DB_SLAVE );
2008-09-16 04:59:49 +00:00
$data = $dbr -> selectRow (
2005-08-02 20:17:23 +00:00
array ( 'logging' , 'user' ),
array ( 'log_type' ,
2011-02-12 04:06:22 +00:00
'log_action' ,
'log_timestamp' ,
'log_user' ,
'log_namespace' ,
'log_title' ,
'log_comment' ,
'log_params' ,
'log_deleted' ,
'user_name' ),
2007-11-01 17:56:19 +00:00
array ( 'log_namespace' => $this -> mTitle -> getNamespace (),
2011-02-12 04:06:22 +00:00
'log_title' => $this -> mTitle -> getDBkey (),
'log_type' => 'delete' ,
'log_action' => 'delete' ,
'user_id=log_user' ),
2008-09-16 04:59:49 +00:00
__METHOD__ ,
2009-03-09 09:21:48 +00:00
array ( 'LIMIT' => 1 , 'ORDER BY' => 'log_timestamp DESC' )
);
// Quick paranoid permission checks...
2009-10-25 15:02:33 +00:00
if ( is_object ( $data ) ) {
2009-03-09 09:21:48 +00:00
if ( $data -> log_deleted & LogPage :: DELETED_USER )
2009-10-25 15:02:33 +00:00
$data -> user_name = wfMsgHtml ( 'rev-deleted-user' );
2009-03-09 09:21:48 +00:00
if ( $data -> log_deleted & LogPage :: DELETED_COMMENT )
2009-10-25 15:02:33 +00:00
$data -> log_comment = wfMsgHtml ( 'rev-deleted-comment' );
2009-03-09 09:21:48 +00:00
}
2005-08-02 20:17:23 +00:00
return $data ;
}
2005-03-19 12:01:57 +00:00
/**
2008-08-02 02:39:09 +00:00
* Get the rendered text for previewing .
* @ return string
2005-03-19 12:01:57 +00:00
*/
2005-08-20 06:57:21 +00:00
function getPreviewText () {
2011-01-26 15:42:04 +00:00
global $wgOut , $wgUser , $wgParser ;
2005-08-21 04:45:28 +00:00
2008-08-27 05:56:34 +00:00
wfProfileIn ( __METHOD__ );
2005-08-21 04:45:28 +00:00
2008-09-16 04:59:49 +00:00
if ( $this -> mTriedSave && ! $this -> mTokenOk ) {
if ( $this -> mTokenOkExceptSuffix ) {
2007-12-10 06:02:29 +00:00
$note = wfMsg ( 'token_suffix_mismatch' );
2007-07-01 22:22:16 +00:00
} else {
2007-12-10 06:02:29 +00:00
$note = wfMsg ( 'session_fail_preview' );
2007-07-01 22:22:16 +00:00
}
2011-06-17 16:03:52 +00:00
} elseif ( $this -> incompleteForm ) {
2011-02-14 03:10:08 +00:00
$note = wfMsg ( 'edit_form_incomplete' );
2006-06-07 08:28:43 +00:00
} else {
2007-12-10 06:02:29 +00:00
$note = wfMsg ( 'previewnote' );
2004-12-19 02:36:04 +00:00
}
$parserOptions = ParserOptions :: newFromUser ( $wgUser );
$parserOptions -> setEditSection ( false );
2009-01-26 18:02:13 +00:00
$parserOptions -> setIsPreview ( true );
$parserOptions -> setIsSectionPreview ( ! is_null ( $this -> section ) && $this -> section !== '' );
2004-12-19 02:36:04 +00:00
2006-06-06 06:21:50 +00:00
global $wgRawHtml ;
2008-09-16 04:59:49 +00:00
if ( $wgRawHtml && ! $this -> mTokenOk ) {
2006-06-06 06:21:50 +00:00
// Could be an offsite preview attempt. This is very unsafe if
// HTML is enabled, as it could be an attack.
2011-06-26 02:40:00 +00:00
$parsedNote = '' ;
if ( $this -> textbox1 !== '' ) {
// Do not put big scary notice, if previewing the empty
// string, which happens when you initially edit
// a category page, due to automatic preview-on-open.
$parsedNote = $wgOut -> parse ( " <div class='previewnote'> " .
2011-09-04 21:19:18 +00:00
wfMsg ( 'session_fail_preview_html' ) . " </div> " , true , /* interface */ true );
2011-06-26 02:40:00 +00:00
}
2011-02-10 15:53:54 +00:00
wfProfileOut ( __METHOD__ );
return $parsedNote ;
2006-06-06 06:21:50 +00:00
}
2011-08-11 17:21:31 +00:00
# don't parse non-wikitext pages, show message about preview
2011-02-10 17:08:37 +00:00
# XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
2010-12-07 14:53:36 +00:00
2011-08-11 17:21:31 +00:00
if ( $this -> isCssJsSubpage || ! $this -> mTitle -> isWikitextPage () ) {
if ( $this -> mTitle -> isCssJsSubpage () ) {
$level = 'user' ;
} elseif ( $this -> mTitle -> isCssOrJsPage () ) {
2010-12-11 22:44:42 +00:00
$level = 'site' ;
2011-08-11 17:21:31 +00:00
} else {
$level = false ;
2010-12-07 14:53:36 +00:00
}
2007-01-13 19:58:40 +00:00
2010-12-07 17:25:49 +00:00
# Used messages to make sure grep find them:
2010-12-11 22:44:42 +00:00
# Messages: usercsspreview, userjspreview, sitecsspreview, sitejspreview
2011-08-11 17:21:31 +00:00
if ( $level ) {
if ( preg_match ( " / \\ .css $ / " , $this -> mTitle -> getText () ) ) {
$previewtext = " <div id='mw- { $level } csspreview'> \n " . wfMsg ( " { $level } csspreview " ) . " \n </div> " ;
$class = " mw-code mw-css " ;
} elseif ( preg_match ( " / \\ .js $ / " , $this -> mTitle -> getText () ) ) {
$previewtext = " <div id='mw- { $level } jspreview'> \n " . wfMsg ( " { $level } jspreview " ) . " \n </div> " ;
$class = " mw-code mw-js " ;
} else {
throw new MWException ( 'A CSS/JS (sub)page but which is not css nor js!' );
}
2004-12-19 02:36:04 +00:00
}
2010-12-07 14:53:36 +00:00
2009-10-25 15:02:33 +00:00
$parserOptions -> setTidy ( true );
2008-09-28 14:56:07 +00:00
$parserOutput = $wgParser -> parse ( $previewtext , $this -> mTitle , $parserOptions );
$previewHTML = $parserOutput -> mText ;
2010-12-07 14:53:36 +00:00
$previewHTML .= " <pre class= \" $class\ " dir = \ " ltr \" > \n " . htmlspecialchars ( $this -> textbox1 ) . " \n </pre> \n " ;
2004-12-19 02:36:04 +00:00
} else {
2010-11-01 00:07:17 +00:00
$rt = Title :: newFromRedirectArray ( $this -> textbox1 );
if ( $rt ) {
$previewHTML = $this -> mArticle -> viewRedirect ( $rt , false );
} else {
$toparse = $this -> textbox1 ;
2006-01-07 13:31:29 +00:00
2010-11-01 00:07:17 +00:00
# If we're adding a comment, we need to show the
# summary as the headline
2011-04-25 03:20:17 +00:00
if ( $this -> section == " new " && $this -> summary != " " ) {
2010-11-01 00:07:17 +00:00
$toparse = " == { $this -> summary } == \n \n " . $toparse ;
}
2006-01-07 13:31:29 +00:00
2010-11-01 00:07:17 +00:00
wfRunHooks ( 'EditPageGetPreviewText' , array ( $this , & $toparse ) );
2008-03-07 14:02:12 +00:00
2010-11-01 00:07:17 +00:00
$parserOptions -> setTidy ( true );
$parserOptions -> enableLimitReport ();
$parserOutput = $wgParser -> parse ( $this -> mArticle -> preSaveTransform ( $toparse ),
2007-11-03 03:20:12 +00:00
$this -> mTitle , $parserOptions );
2005-08-02 13:35:19 +00:00
2010-11-01 00:07:17 +00:00
$previewHTML = $parserOutput -> getText ();
$this -> mParserOutput = $parserOutput ;
$wgOut -> addParserOutputNoText ( $parserOutput );
2008-04-14 07:45:50 +00:00
2010-11-01 00:07:17 +00:00
if ( count ( $parserOutput -> getWarnings () ) ) {
$note .= " \n \n " . implode ( " \n \n " , $parserOutput -> getWarnings () );
}
2007-12-10 06:02:29 +00:00
}
2004-12-19 02:36:04 +00:00
}
2007-12-10 06:02:29 +00:00
2009-05-17 17:55:15 +00:00
if ( $this -> isConflict ) {
$conflict = '<h2 id="mw-previewconflict">' . htmlspecialchars ( wfMsg ( 'previewconflict' ) ) . " </h2> \n " ;
} else {
$conflict = '<hr />' ;
2007-12-10 06:02:29 +00:00
}
2008-04-14 07:45:50 +00:00
2009-05-17 17:55:15 +00:00
$previewhead = " <div class='previewnote'> \n " .
'<h2 id="mw-previewheader">' . htmlspecialchars ( wfMsg ( 'preview' ) ) . " </h2> " .
2011-09-04 21:19:18 +00:00
$wgOut -> parse ( $note , true , /* interface */ true ) . $conflict . " </div> \n " ;
2009-05-17 17:55:15 +00:00
2011-07-06 02:26:06 +00:00
$pageLang = $this -> mTitle -> getPageLanguage ();
$attribs = array ( 'lang' => $pageLang -> getCode (), 'dir' => $pageLang -> getDir (),
'class' => 'mw-content-' . $pageLang -> getDir () );
$previewHTML = Html :: rawElement ( 'div' , $attribs , $previewHTML );
2011-06-18 14:01:12 +00:00
wfProfileOut ( __METHOD__ );
2009-10-22 13:54:36 +00:00
return $previewhead . $previewHTML . $this -> previewTextAfterContent ;
2008-08-27 05:56:34 +00:00
}
2009-10-23 11:08:08 +00:00
2011-05-26 19:52:56 +00:00
/**
* @ return Array
*/
2008-08-27 05:56:34 +00:00
function getTemplates () {
2008-09-16 04:59:49 +00:00
if ( $this -> preview || $this -> section != '' ) {
2008-08-27 05:56:34 +00:00
$templates = array ();
2011-05-26 19:52:56 +00:00
if ( ! isset ( $this -> mParserOutput ) ) {
return $templates ;
}
2008-08-27 05:56:34 +00:00
foreach ( $this -> mParserOutput -> getTemplates () as $ns => $template ) {
foreach ( array_keys ( $template ) as $dbk ) {
$templates [] = Title :: makeTitle ( $ns , $dbk );
}
}
return $templates ;
2008-04-09 22:20:01 +00:00
} else {
2008-08-27 05:56:34 +00:00
return $this -> mArticle -> getUsedTemplates ();
2008-04-09 22:20:01 +00:00
}
2004-12-19 02:36:04 +00:00
}
2005-08-02 13:35:19 +00:00
2011-08-24 13:03:03 +00:00
function getDistantTemplates () {
global $wgEnableInterwikiTemplatesTracking ;
if ( ! $wgEnableInterwikiTemplatesTracking ) {
return array ( );
}
if ( $this -> preview || $this -> section != '' ) {
$templates = array ();
if ( ! isset ( $this -> mParserOutput ) ) return $templates ;
$templatesList = $this -> mParserOutput -> getDistantTemplates ();
foreach ( $templatesList as $prefix => $templatesbyns ) {
foreach ( $templatesbyns as $ns => $template ) {
foreach ( array_keys ( $template ) as $dbk ) {
$templates [] = Title :: makeTitle ( $ns , $dbk , null , $prefix );
}
}
}
return $templates ;
} else {
return $this -> mArticle -> getUsedDistantTemplates ();
}
}
2004-09-03 16:51:45 +00:00
/**
2006-05-02 17:06:24 +00:00
* Call the stock " user is blocked " page
2004-09-03 16:51:45 +00:00
*/
2006-06-24 20:58:10 +00:00
function blockedPage () {
2009-12-08 17:17:24 +00:00
global $wgOut ;
2006-06-24 20:58:10 +00:00
$wgOut -> blockedPage ( false ); # Standard block notice on the top, don't 'return'
2007-01-13 19:58:40 +00:00
2006-06-24 20:58:10 +00:00
# If the user made changes, preserve them when showing the markup
2007-01-13 19:58:40 +00:00
# (This happens when a user is blocked during edit, for instance)
2006-06-24 20:58:10 +00:00
$first = $this -> firsttime || ( ! $this -> save && $this -> textbox1 == '' );
2008-09-16 04:59:49 +00:00
if ( $first ) {
2007-11-01 17:56:19 +00:00
$source = $this -> mTitle -> exists () ? $this -> getContent () : false ;
2006-07-13 10:03:45 +00:00
} else {
$source = $this -> textbox1 ;
}
2007-01-13 19:58:40 +00:00
2006-06-24 20:58:10 +00:00
# Spit out the source or the user's modified version
2008-09-16 04:59:49 +00:00
if ( $source !== false ) {
2008-11-06 22:20:29 +00:00
$wgOut -> addHTML ( '<hr />' );
2008-02-18 07:25:35 +00:00
$wgOut -> addWikiMsg ( $first ? 'blockedoriginalsource' : 'blockededitsource' , $this -> mTitle -> getPrefixedText () );
2009-12-08 17:17:24 +00:00
$this -> showTextbox1 ( array ( 'readonly' ), $source );
2006-07-13 10:03:45 +00:00
}
2003-08-02 20:43:11 +00:00
}
2004-09-03 16:51:45 +00:00
/**
2006-05-02 16:53:32 +00:00
* Produce the stock " please login to edit pages " page
2004-09-03 16:51:45 +00:00
*/
function userNotLoggedInPage () {
2011-07-16 19:19:01 +00:00
global $wgOut ;
2007-01-13 19:58:40 +00:00
2006-10-30 06:25:31 +00:00
$loginTitle = SpecialPage :: getTitleFor ( 'Userlogin' );
2011-07-16 19:19:01 +00:00
$loginLink = Linker :: linkKnown (
2009-06-06 22:42:48 +00:00
$loginTitle ,
wfMsgHtml ( 'loginreqlink' ),
array (),
2011-07-16 19:19:01 +00:00
array ( 'returnto' => $this -> getContextTitle () -> getPrefixedText () )
2009-06-06 22:42:48 +00:00
);
2007-01-13 19:58:40 +00:00
2004-08-22 17:24:50 +00:00
$wgOut -> setPageTitle ( wfMsg ( 'whitelistedittitle' ) );
2006-05-02 17:06:24 +00:00
$wgOut -> setRobotPolicy ( 'noindex,nofollow' );
2004-01-17 09:49:43 +00:00
$wgOut -> setArticleRelated ( false );
2007-01-13 19:58:40 +00:00
2011-07-16 19:19:01 +00:00
$wgOut -> addHTML ( wfMessage ( 'whitelistedittext' ) -> rawParams ( $loginLink ) -> parse () );
2011-02-10 17:08:37 +00:00
$wgOut -> returnToMain ( false , $this -> getContextTitle () );
2003-08-05 11:04:02 +00:00
}
2007-03-14 18:20:21 +00:00
/**
* Creates a basic error page which informs the user that
2009-01-01 02:02:03 +00:00
* they have attempted to edit a nonexistent section .
2007-03-14 18:20:21 +00:00
*/
function noSuchSectionPage () {
2010-01-16 07:18:16 +00:00
global $wgOut ;
2007-03-14 18:20:21 +00:00
$wgOut -> setPageTitle ( wfMsg ( 'nosuchsectiontitle' ) );
$wgOut -> setRobotPolicy ( 'noindex,nofollow' );
$wgOut -> setArticleRelated ( false );
2010-01-18 00:58:22 +00:00
$res = wfMsgExt ( 'nosuchsectiontext' , 'parse' , $this -> section );
wfRunHooks ( 'EditPageNoSuchSection' , array ( & $this , & $res ) );
$wgOut -> addHTML ( $res );
2010-01-16 07:18:16 +00:00
$wgOut -> returnToMain ( false , $this -> mTitle );
2007-03-14 18:20:21 +00:00
}
2004-09-03 16:51:45 +00:00
/**
2006-05-02 17:06:24 +00:00
* Produce the stock " your edit contains spam " page
*
* @ param $match Text which triggered one or more filters
2011-05-06 21:50:18 +00:00
* @ deprecated since 1.17 Use method spamPageWithContent () instead
2004-09-03 16:51:45 +00:00
*/
2010-07-27 10:30:07 +00:00
static function spamPage ( $match = false ) {
2007-11-03 03:20:12 +00:00
global $wgOut , $wgTitle ;
2006-05-02 17:06:24 +00:00
2004-08-22 17:24:50 +00:00
$wgOut -> setPageTitle ( wfMsg ( 'spamprotectiontitle' ) );
2006-05-02 17:06:24 +00:00
$wgOut -> setRobotPolicy ( 'noindex,nofollow' );
2004-05-29 07:41:16 +00:00
$wgOut -> setArticleRelated ( false );
2008-11-06 22:20:29 +00:00
$wgOut -> addHTML ( '<div id="spamprotected">' );
2008-02-18 07:25:35 +00:00
$wgOut -> addWikiMsg ( 'spamprotectiontext' );
2010-07-27 10:30:07 +00:00
if ( $match ) {
2008-05-03 12:27:53 +00:00
$wgOut -> addWikiMsg ( 'spamprotectionmatch' , wfEscapeWikiText ( $match ) );
2010-07-27 10:30:07 +00:00
}
2008-11-06 22:20:29 +00:00
$wgOut -> addHTML ( '</div>' );
2007-01-13 19:58:40 +00:00
2007-11-03 03:20:12 +00:00
$wgOut -> returnToMain ( false , $wgTitle );
2004-05-29 07:41:16 +00:00
}
2010-11-26 07:48:41 +00:00
/**
* Show " your edit contains spam " page with your diff and text
*
* @ param $match Text which triggered one or more filters
*/
public function spamPageWithContent ( $match = false ) {
2011-02-10 17:08:37 +00:00
global $wgOut ;
2010-11-26 07:48:41 +00:00
$this -> textbox2 = $this -> textbox1 ;
$wgOut -> setPageTitle ( wfMsg ( 'spamprotectiontitle' ) );
$wgOut -> setRobotPolicy ( 'noindex,nofollow' );
$wgOut -> setArticleRelated ( false );
$wgOut -> addHTML ( '<div id="spamprotected">' );
$wgOut -> addWikiMsg ( 'spamprotectiontext' );
if ( $match ) {
$wgOut -> addWikiMsg ( 'spamprotectionmatch' , wfEscapeWikiText ( $match ) );
}
$wgOut -> addHTML ( '</div>' );
$wgOut -> wrapWikiMsg ( '<h2>$1</h2>' , " yourdiff " );
$de = new DifferenceEngine ( $this -> mTitle );
$de -> setText ( $this -> getContent (), $this -> textbox2 );
$de -> showDiff ( wfMsg ( " storedversion " ), wfMsg ( " yourtext " ) );
$wgOut -> wrapWikiMsg ( '<h2>$1</h2>' , " yourtext " );
$this -> showTextbox2 ();
2011-02-10 17:08:37 +00:00
$wgOut -> addReturnTo ( $this -> getContextTitle (), array ( 'action' => 'edit' ) );
2010-11-26 07:48:41 +00:00
}
2004-09-03 16:51:45 +00:00
/**
2006-04-19 15:46:24 +00:00
* @ private
2004-09-03 16:51:45 +00:00
* @ todo document
2011-06-05 14:46:55 +00:00
*
* @ parma $editText string
*
* @ return bool
2004-09-03 16:51:45 +00:00
*/
2005-06-28 23:19:56 +00:00
function mergeChangesInto ( & $editText ){
2009-10-25 15:02:33 +00:00
wfProfileIn ( __METHOD__ );
2005-07-25 07:00:20 +00:00
2007-01-22 23:50:42 +00:00
$db = wfGetDB ( DB_MASTER );
2005-08-02 13:35:19 +00:00
2005-06-28 23:19:56 +00:00
// This is the revision the editor started from
2008-07-15 08:43:40 +00:00
$baseRevision = $this -> getBaseRevision ();
2008-09-16 04:59:49 +00:00
if ( is_null ( $baseRevision ) ) {
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2005-06-28 23:19:56 +00:00
return false ;
}
$baseText = $baseRevision -> getText ();
// The current state, we want to merge updates into it
2009-01-16 19:56:57 +00:00
$currentRevision = Revision :: loadFromTitle ( $db , $this -> mTitle );
2008-09-16 04:59:49 +00:00
if ( is_null ( $currentRevision ) ) {
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2005-06-28 23:19:56 +00:00
return false ;
}
$currentText = $currentRevision -> getText ();
2005-08-02 13:35:19 +00:00
2006-11-23 08:25:56 +00:00
$result = '' ;
2008-09-16 04:59:49 +00:00
if ( wfMerge ( $baseText , $editText , $currentText , $result ) ) {
2005-06-28 23:19:56 +00:00
$editText = $result ;
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2004-03-14 15:05:52 +00:00
return true ;
} else {
2009-10-25 15:02:33 +00:00
wfProfileOut ( __METHOD__ );
2004-03-14 15:05:52 +00:00
return false ;
}
}
2004-10-10 21:30:17 +00:00
2005-10-22 20:27:26 +00:00
/**
* Check if the browser is on a blacklist of user - agents known to
* mangle UTF - 8 data on form submission . Returns true if Unicode
* should make it through , false if it ' s known to be a problem .
* @ return bool
2006-04-19 15:46:24 +00:00
* @ private
2005-10-22 20:27:26 +00:00
*/
2004-10-10 21:30:17 +00:00
function checkUnicodeCompliantBrowser () {
global $wgBrowserBlackList ;
2008-09-16 04:59:49 +00:00
if ( empty ( $_SERVER [ " HTTP_USER_AGENT " ] ) ) {
2005-10-22 20:27:26 +00:00
// No User-Agent header sent? Trust it by default...
return true ;
}
2004-10-10 21:30:17 +00:00
$currentbrowser = $_SERVER [ " HTTP_USER_AGENT " ];
foreach ( $wgBrowserBlackList as $browser ) {
2008-09-16 04:59:49 +00:00
if ( preg_match ( $browser , $currentbrowser ) ) {
2004-10-10 21:30:17 +00:00
return false ;
}
}
return true ;
}
2004-10-26 05:44:54 +00:00
/**
* Format an anchor fragment as it would appear for a given section name
2010-03-17 22:02:43 +00:00
* @ param $text String
* @ return String
2006-04-19 15:46:24 +00:00
* @ private
2004-10-26 05:44:54 +00:00
*/
function sectionAnchor ( $text ) {
2007-09-08 02:08:08 +00:00
global $wgParser ;
return $wgParser -> guessSectionNameFromWikiText ( $text );
2004-10-26 05:44:54 +00:00
}
2004-11-25 13:52:56 +00:00
/**
* Shows a bulletin board style toolbar for common editing functions .
* It can be disabled in the user preferences .
2008-06-09 17:53:04 +00:00
* The necessary JavaScript code can be found in skins / common / edit . js .
2009-10-23 11:08:08 +00:00
*
2008-06-09 14:17:16 +00:00
* @ return string
2004-11-25 13:52:56 +00:00
*/
2008-06-09 14:17:16 +00:00
static function getEditToolbar () {
2010-09-04 04:00:09 +00:00
global $wgStylePath , $wgContLang , $wgLang , $wgOut ;
2010-09-29 23:27:26 +00:00
global $wgUseTeX , $wgEnableUploads , $wgForeignFileRepos ;
$imagesAvailable = $wgEnableUploads || count ( $wgForeignFileRepos );
2004-11-25 13:52:56 +00:00
/**
2011-02-17 18:41:44 +00:00
* $toolarray is an array of arrays each of which includes the
* filename of the button image ( without path ), the opening
* tag , the closing tag , optionally a sample text that is
* inserted between the two when no selection is highlighted
2011-07-20 23:51:52 +00:00
* and . The tip text is shown when the user moves the mouse
* over the button .
2004-11-25 13:52:56 +00:00
*
2011-02-17 18:41:44 +00:00
* Also here : accesskeys ( key ), which are not used yet until
* someone can figure out a way to make them work in
* IE . However , we should make sure these keys are not defined
* on the edit page .
2004-11-25 13:52:56 +00:00
*/
2007-02-19 11:46:52 +00:00
$toolarray = array (
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-bold' ),
'id' => 'mw-editbutton-bold' ,
'open' => '\'\'\'' ,
'close' => '\'\'\'' ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'bold_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'bold_tip' ),
'key' => 'B'
2007-02-19 11:46:52 +00:00
),
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-italic' ),
'id' => 'mw-editbutton-italic' ,
'open' => '\'\'' ,
'close' => '\'\'' ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'italic_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'italic_tip' ),
'key' => 'I'
2007-02-19 11:46:52 +00:00
),
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-link' ),
'id' => 'mw-editbutton-link' ,
'open' => '[[' ,
'close' => ']]' ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'link_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'link_tip' ),
'key' => 'L'
2007-02-19 11:46:52 +00:00
),
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-extlink' ),
'id' => 'mw-editbutton-extlink' ,
'open' => '[' ,
'close' => ']' ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'extlink_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'extlink_tip' ),
'key' => 'X'
2007-02-19 11:46:52 +00:00
),
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-headline' ),
'id' => 'mw-editbutton-headline' ,
'open' => " \n == " ,
'close' => " == \n " ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'headline_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'headline_tip' ),
'key' => 'H'
2007-02-19 11:46:52 +00:00
),
2010-09-29 23:27:26 +00:00
$imagesAvailable ? array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-image' ),
'id' => 'mw-editbutton-image' ,
'open' => '[[' . $wgContLang -> getNsText ( NS_FILE ) . ':' ,
'close' => ']]' ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'image_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'image_tip' ),
2011-02-17 18:41:44 +00:00
'key' => 'D' ,
2010-09-29 23:27:26 +00:00
) : false ,
$imagesAvailable ? array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-media' ),
'id' => 'mw-editbutton-media' ,
'open' => '[[' . $wgContLang -> getNsText ( NS_MEDIA ) . ':' ,
'close' => ']]' ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'media_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'media_tip' ),
'key' => 'M'
2010-09-29 23:27:26 +00:00
) : false ,
$wgUseTeX ? array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-math' ),
'id' => 'mw-editbutton-math' ,
'open' => " <math> " ,
'close' => " </math> " ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'math_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'math_tip' ),
'key' => 'C'
2010-09-29 23:27:26 +00:00
) : false ,
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-nowiki' ),
'id' => 'mw-editbutton-nowiki' ,
'open' => " <nowiki> " ,
'close' => " </nowiki> " ,
2009-10-25 15:02:33 +00:00
'sample' => wfMsg ( 'nowiki_sample' ),
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'nowiki_tip' ),
'key' => 'N'
2007-02-19 11:46:52 +00:00
),
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-sig' ),
'id' => 'mw-editbutton-signature' ,
'open' => '--~~~~' ,
'close' => '' ,
2008-07-04 10:34:41 +00:00
'sample' => '' ,
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'sig_tip' ),
'key' => 'Y'
2007-02-19 11:46:52 +00:00
),
2008-07-04 10:34:41 +00:00
array (
2010-07-20 15:12:29 +00:00
'image' => $wgLang -> getImageFile ( 'button-hr' ),
'id' => 'mw-editbutton-hr' ,
'open' => " \n ---- \n " ,
'close' => '' ,
2008-07-04 10:34:41 +00:00
'sample' => '' ,
2010-07-20 15:12:29 +00:00
'tip' => wfMsg ( 'hr_tip' ),
'key' => 'R'
2007-02-19 11:46:52 +00:00
)
2004-11-25 13:52:56 +00:00
);
2006-04-17 10:36:21 +00:00
$toolbar = " <div id='toolbar'> \n " ;
2004-11-25 13:52:56 +00:00
2009-08-11 00:09:24 +00:00
$script = '' ;
foreach ( $toolarray as $tool ) {
2010-11-25 22:22:53 +00:00
if ( ! $tool ) {
continue ;
}
2010-09-29 23:27:26 +00:00
2008-03-03 01:53:45 +00:00
$params = array (
2009-10-25 15:02:33 +00:00
$image = $wgStylePath . '/common/images/' . $tool [ 'image' ],
2008-03-03 01:53:45 +00:00
// Note that we use the tip both for the ALT tag and the TITLE tag of the image.
// Older browsers show a "speedtip" type message only for ALT.
// Ideally these should be different, realistically they
// probably don't need to be.
$tip = $tool [ 'tip' ],
$open = $tool [ 'open' ],
$close = $tool [ 'close' ],
$sample = $tool [ 'sample' ],
$cssId = $tool [ 'id' ],
);
2008-04-14 07:45:50 +00:00
2008-03-03 02:48:38 +00:00
$paramList = implode ( ',' ,
array_map ( array ( 'Xml' , 'encodeJsVar' ), $params ) );
2011-04-21 08:19:24 +00:00
$script .= " mw.toolbar.addButton( $paramList ); \n " ;
2004-11-25 13:52:56 +00:00
}
2010-09-04 04:00:09 +00:00
$wgOut -> addScript ( Html :: inlineScript (
2011-04-26 10:08:46 +00:00
" if ( window.mediaWiki ) { { $script } } "
2010-09-04 04:00:09 +00:00
) );
2011-02-12 04:06:22 +00:00
2009-08-11 00:09:24 +00:00
$toolbar .= " \n </div> " ;
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
2009-05-29 21:40:19 +00:00
wfRunHooks ( 'EditPageBeforeEditToolbar' , array ( & $toolbar ) );
here it is ... the upload-api, script-server, js2 (javascript phase2) branch merge 1st attempt.
Here is a short overview of changes and associated default configuration variables (most everything is off by default) also see ~soon to be updated~: http://www.mediawiki.org/wiki/Media_Projects_Overview
= Upload Improvements =
==Upload API ==
* Based on the early work of Bryan Tong and others it adds the upload option to the api.
* We rewrite Special:Upload page to include use the new refactoring
* Added in token checks in both the SpecialUpload.php page so avoids DOS / xss copy-by-url JavaScript based cross site POST file submissions
== Copy by URL==
$wgAllowCopyUploads = false;
* http class rewrite includes a new http background download see: includes/HttpFunctions.php
* spins off a php process that calls: maintenance/http_session_download.php
* pushes updates to the session and gives the user a progress bar on http copy uploads from other server progress (using js2 upload interface) (if not using the js2 upload interface it does the request in-place but the download is limited to the php ini timeout time)
== Firefogg ==
* Firefogg enables resumable upload by chunks
* progress indicators and conditional invokation (js2 system)
* and of-course client side transcoding.
= Script Server =
$wgEnableScriptLoader = false;
* off by default if $wgEnableScriptLoader is turned on script files are grouped, gziped, cached etc.
for more info see: http://www.mediawiki.org/wiki/Extension:ScriptLoader
* Includes some early skin js include fixes (skin/script system still lots of love)
* Includes a "javascript class autoloader" this is packaged into mwEmbed so that the mwEmbed library can work in stand alone mode (while retaining localization and script serving) (one such application is the make page for firefogg.org : http://www.firefogg.org/make/index.html )
* The file that contains the autojavascript loading classes is: js2/php/jsAutoloadLocalClasses.php
* One can use this auto class loading dependency system with extensions and add-ons but I need to better document that.
= js2 system / mwEmbed=
$wgEnableJS2system = false
* includes initial rewrite towards more jquery based javascript code
* especially for the Special:Upload page.
* Also the edit page include support for the "add-media-wizard"
* includes dependency loader for javascript that optionally takes advantage of the script-loader
* remote embedding of javascript interfaces (like embedding video, or commons media searching)
* $wgDebugJavaScript = false; .. .this variable lets you always get "always fresh javascript". When used with the script-loader it does not minify the script-loader output.
= mwEmbed =
* Will commit a separate patch to oggHandler that conditionally outputs <video tag> to use the new javascript video player.
** mv_embed player includes: play-head, volume control, remote embedding, oggz-chop support across plugins.
* add-media-wizard adds easy inserts of media to pages (with import)
== jQuery==
* we include a base install of jQuery, jQuery ui and some plugins.
* all the javascript classes are in the scriptloader so its easy to load any set of jquery ui components that you may need using the script-server. You get a callback so you can then execute js with dependencies loaded.
== other stuff ==
there is a bit more code in js2 that pertains to sequence editing, timed text display and basic image editing. We include a base import of pixastic-lib & pixastic-editor... will work with the pixastic developer to try and ensure upstream compatibility on our usage of the library for in-browser photo and sequence manipulation.
2009-07-14 23:52:14 +00:00
2004-11-25 13:52:56 +00:00
return $toolbar ;
}
2005-08-02 13:35:19 +00:00
2007-02-10 15:30:31 +00:00
/**
* Returns an array of html code of the following checkboxes :
* minor and watch
*
* @ param $tabindex Current tabindex
* @ param $checked Array of checkbox => bool , where bool indicates the checked
2010-07-20 15:12:29 +00:00
* status of the checkbox
2007-02-10 15:30:31 +00:00
*
* @ return array
*/
2011-07-16 19:19:01 +00:00
public function getCheckboxes ( & $tabindex , $checked ) {
2007-02-10 15:30:31 +00:00
global $wgUser ;
$checkboxes = array ();
2011-04-23 18:58:03 +00:00
// don't show the minor edit checkbox if it's a new page or section
if ( ! $this -> isNew ) {
$checkboxes [ 'minor' ] = '' ;
$minorLabel = wfMsgExt ( 'minoredit' , array ( 'parseinline' ) );
if ( $wgUser -> isAllowed ( 'minoredit' ) ) {
$attribs = array (
'tabindex' => ++ $tabindex ,
'accesskey' => wfMsg ( 'accesskey-minoredit' ),
'id' => 'wpMinoredit' ,
);
$checkboxes [ 'minor' ] =
Xml :: check ( 'wpMinoredit' , $checked [ 'minor' ], $attribs ) .
"  <label for='wpMinoredit' id='mw-editpage-minoredit' " .
2011-07-16 19:19:01 +00:00
Xml :: expandAttributes ( array ( 'title' => Linker :: titleAttrib ( 'minoredit' , 'withaccess' ) ) ) .
2011-04-23 18:58:03 +00:00
" > { $minorLabel } </label> " ;
}
2007-02-10 15:30:31 +00:00
}
2009-10-25 15:02:33 +00:00
$watchLabel = wfMsgExt ( 'watchthis' , array ( 'parseinline' ) );
2007-02-10 15:30:31 +00:00
$checkboxes [ 'watch' ] = '' ;
2008-09-16 04:59:49 +00:00
if ( $wgUser -> isLoggedIn () ) {
2007-02-10 15:30:31 +00:00
$attribs = array (
2010-07-20 15:12:29 +00:00
'tabindex' => ++ $tabindex ,
2007-02-10 15:30:31 +00:00
'accesskey' => wfMsg ( 'accesskey-watch' ),
2010-07-20 15:12:29 +00:00
'id' => 'wpWatchthis' ,
2007-02-10 15:30:31 +00:00
);
$checkboxes [ 'watch' ] =
Xml :: check ( 'wpWatchthis' , $checked [ 'watch' ], $attribs ) .
2010-12-12 18:35:19 +00:00
"  <label for='wpWatchthis' id='mw-editpage-watch' " .
2011-07-16 19:19:01 +00:00
Xml :: expandAttributes ( array ( 'title' => Linker :: titleAttrib ( 'watch' , 'withaccess' ) ) ) .
2010-12-12 18:35:19 +00:00
" > { $watchLabel } </label> " ;
2007-02-10 15:30:31 +00:00
}
2008-12-20 01:15:40 +00:00
wfRunHooks ( 'EditPageBeforeEditChecks' , array ( & $this , & $checkboxes , & $tabindex ) );
2007-02-10 15:30:31 +00:00
return $checkboxes ;
}
/**
* Returns an array of html code of the following buttons :
* save , diff , preview and live
*
* @ param $tabindex Current tabindex
*
* @ return array
*/
2010-11-07 23:17:04 +00:00
public function getEditButtons ( & $tabindex ) {
2007-02-10 15:30:31 +00:00
$buttons = array ();
$temp = array (
2010-07-20 15:12:29 +00:00
'id' => 'wpSave' ,
'name' => 'wpSave' ,
'type' => 'submit' ,
'tabindex' => ++ $tabindex ,
'value' => wfMsg ( 'savearticle' ),
2009-10-25 15:02:33 +00:00
'accesskey' => wfMsg ( 'accesskey-save' ),
2010-07-20 15:12:29 +00:00
'title' => wfMsg ( 'tooltip-save' ) . ' [' . wfMsg ( 'accesskey-save' ) . ']' ,
2007-02-10 15:30:31 +00:00
);
2008-12-31 17:10:02 +00:00
$buttons [ 'save' ] = Xml :: element ( 'input' , $temp , '' );
2007-02-10 15:30:31 +00:00
++ $tabindex ; // use the same for preview and live preview
2009-11-26 12:00:36 +00:00
$temp = array (
2010-07-20 15:12:29 +00:00
'id' => 'wpPreview' ,
'name' => 'wpPreview' ,
'type' => 'submit' ,
'tabindex' => $tabindex ,
'value' => wfMsg ( 'showpreview' ),
2009-11-26 12:00:36 +00:00
'accesskey' => wfMsg ( 'accesskey-preview' ),
2010-07-20 15:12:29 +00:00
'title' => wfMsg ( 'tooltip-preview' ) . ' [' . wfMsg ( 'accesskey-preview' ) . ']' ,
2009-11-26 12:00:36 +00:00
);
$buttons [ 'preview' ] = Xml :: element ( 'input' , $temp , '' );
$buttons [ 'live' ] = '' ;
2007-02-10 15:30:31 +00:00
$temp = array (
2010-07-20 15:12:29 +00:00
'id' => 'wpDiff' ,
'name' => 'wpDiff' ,
'type' => 'submit' ,
'tabindex' => ++ $tabindex ,
'value' => wfMsg ( 'showdiff' ),
2009-10-25 15:02:33 +00:00
'accesskey' => wfMsg ( 'accesskey-diff' ),
2010-07-20 15:12:29 +00:00
'title' => wfMsg ( 'tooltip-diff' ) . ' [' . wfMsg ( 'accesskey-diff' ) . ']' ,
2007-02-10 15:30:31 +00:00
);
2009-10-25 15:02:33 +00:00
$buttons [ 'diff' ] = Xml :: element ( 'input' , $temp , '' );
2008-04-14 07:45:50 +00:00
2008-12-20 01:15:40 +00:00
wfRunHooks ( 'EditPageBeforeEditButtons' , array ( & $this , & $buttons , & $tabindex ) );
2007-02-10 15:30:31 +00:00
return $buttons ;
}
2009-09-17 01:14:00 +00:00
/**
* Output preview text only . This can be sucked into the edit page
* via JavaScript , and saves the server time rendering the skin as
* well as theoretically being more robust on the client ( doesn ' t
* disturb the edit box 's undo history, won' t eat your text on
* failure , etc ) .
*
* @ todo This doesn ' t include category or interlanguage links .
2010-07-20 15:12:29 +00:00
* Would need to enhance it a bit , < s > maybe wrap them in XML
* or something ...</ s > that might also require more skin
* initialization , so check whether that ' s a problem .
2009-09-17 01:14:00 +00:00
*/
function livePreview () {
global $wgOut ;
$wgOut -> disable ();
header ( 'Content-type: text/xml; charset=utf-8' );
header ( 'Cache-control: no-cache' );
$previewText = $this -> getPreviewText ();
#$categories = $skin->getCategoryLinks();
$s =
'<?xml version="1.0" encoding="UTF-8" ?>' . " \n " .
Xml :: tags ( 'livepreview' , null ,
Xml :: element ( 'preview' , null , $previewText )
#. Xml::element( 'category', null, $categories )
);
echo $s ;
}
2011-06-05 14:46:55 +00:00
/**
* @ return string
*/
2009-12-02 07:22:29 +00:00
public function getCancelLink () {
$cancelParams = array ();
2010-02-05 15:01:07 +00:00
if ( ! $this -> isConflict && $this -> mArticle -> getOldID () > 0 ) {
$cancelParams [ 'oldid' ] = $this -> mArticle -> getOldID ();
}
2011-07-16 19:19:01 +00:00
return Linker :: linkKnown (
2011-02-10 17:08:37 +00:00
$this -> getContextTitle (),
2009-12-02 07:22:29 +00:00
wfMsgExt ( 'cancel' , array ( 'parseinline' ) ),
array ( 'id' => 'mw-editform-cancel' ),
2011-07-16 19:19:01 +00:00
$cancelParams
2009-12-02 07:22:29 +00:00
);
}
2005-05-15 11:11:23 +00:00
/**
* Get a diff between the current contents of the edit box and the
* version of the page we ' re editing from .
*
* If this is a section edit , we ' ll replace the section as for final
* save and then make a comparison .
*/
2007-06-13 20:08:19 +00:00
function showDiff () {
2005-06-29 00:31:07 +00:00
$oldtext = $this -> mArticle -> fetchContent ();
2005-08-21 07:28:11 +00:00
$newtext = $this -> mArticle -> replaceSection (
2005-05-15 11:11:23 +00:00
$this -> section , $this -> textbox1 , $this -> summary , $this -> edittime );
2010-02-20 17:05:56 +00:00
wfRunHooks ( 'EditPageGetDiffText' , array ( $this , & $newtext ) );
2006-05-28 21:59:03 +00:00
$newtext = $this -> mArticle -> preSaveTransform ( $newtext );
2009-10-25 15:02:33 +00:00
$oldtitle = wfMsgExt ( 'currentrev' , array ( 'parseinline' ) );
$newtitle = wfMsgExt ( 'yourtext' , array ( 'parseinline' ) );
2010-07-20 15:12:29 +00:00
if ( $oldtext !== false || $newtext != '' ) {
2007-11-01 17:56:19 +00:00
$de = new DifferenceEngine ( $this -> mTitle );
2005-11-15 11:12:21 +00:00
$de -> setText ( $oldtext , $newtext );
$difftext = $de -> getDiff ( $oldtitle , $newtitle );
2007-06-13 20:08:19 +00:00
$de -> showDiffStyle ();
2005-11-15 11:12:21 +00:00
} else {
$difftext = '' ;
2005-05-15 11:11:23 +00:00
}
2005-08-02 13:35:19 +00:00
2007-06-13 20:08:19 +00:00
global $wgOut ;
2008-11-06 22:20:29 +00:00
$wgOut -> addHTML ( '<div id="wikiDiff">' . $difftext . '</div>' );
2005-05-15 11:11:23 +00:00
}
2005-07-29 10:08:41 +00:00
/**
* Filter an input field through a Unicode de - armoring process if it
* came from an old browser with known broken Unicode editing issues .
*
2010-03-17 22:02:43 +00:00
* @ param $request WebRequest
* @ param $field String
* @ return String
2006-04-19 15:46:24 +00:00
* @ private
2005-07-29 10:08:41 +00:00
*/
function safeUnicodeInput ( $request , $field ) {
$text = rtrim ( $request -> getText ( $field ) );
return $request -> getBool ( 'safemode' )
? $this -> unmakesafe ( $text )
: $text ;
}
2006-01-07 13:31:29 +00:00
2011-05-26 19:52:56 +00:00
/**
* @ param $request WebRequest
* @ param $text string
* @ return string
*/
2009-12-02 07:22:29 +00:00
function safeUnicodeText ( $request , $text ) {
$text = rtrim ( $text );
return $request -> getBool ( 'safemode' )
? $this -> unmakesafe ( $text )
: $text ;
}
2005-07-29 10:08:41 +00:00
/**
2005-07-30 08:03:04 +00:00
* Filter an output field through a Unicode armoring process if it is
* going to an old browser with known broken Unicode editing issues .
2005-07-29 10:08:41 +00:00
*
2010-03-17 22:02:43 +00:00
* @ param $text String
* @ return String
2006-04-19 15:46:24 +00:00
* @ private
2005-07-29 10:08:41 +00:00
*/
function safeUnicodeOutput ( $text ) {
global $wgContLang ;
$codedText = $wgContLang -> recodeForEdit ( $text );
return $this -> checkUnicodeCompliantBrowser ()
? $codedText
: $this -> makesafe ( $codedText );
}
2006-01-07 13:31:29 +00:00
2005-07-29 10:08:41 +00:00
/**
* A number of web browsers are known to corrupt non - ASCII characters
* in a UTF - 8 text editing environment . To protect against this ,
* detected browsers will be served an armored version of the text ,
* with non - ASCII chars converted to numeric HTML character references .
*
* Preexisting such character references will have a 0 added to them
* to ensure that round - trips do not alter the original data .
*
2010-03-17 22:02:43 +00:00
* @ param $invalue String
* @ return String
2006-04-19 15:46:24 +00:00
* @ private
2005-07-29 10:08:41 +00:00
*/
function makesafe ( $invalue ) {
// Armor existing references for reversability.
$invalue = strtr ( $invalue , array ( " &#x " => " � " ) );
2006-01-07 13:31:29 +00:00
2005-07-29 10:08:41 +00:00
$bytesleft = 0 ;
$result = " " ;
$working = 0 ;
for ( $i = 0 ; $i < strlen ( $invalue ); $i ++ ) {
2011-04-17 07:59:58 +00:00
$bytevalue = ord ( $invalue [ $i ] );
2008-09-16 04:59:49 +00:00
if ( $bytevalue <= 0x7F ) { //0xxx xxxx
2005-07-29 10:08:41 +00:00
$result .= chr ( $bytevalue );
$bytesleft = 0 ;
2008-09-16 04:59:49 +00:00
} elseif ( $bytevalue <= 0xBF ) { //10xx xxxx
2005-07-29 10:08:41 +00:00
$working = $working << 6 ;
$working += ( $bytevalue & 0x3F );
$bytesleft -- ;
2008-09-16 04:59:49 +00:00
if ( $bytesleft <= 0 ) {
2005-07-29 10:08:41 +00:00
$result .= " &#x " . strtoupper ( dechex ( $working ) ) . " ; " ;
}
2008-09-16 04:59:49 +00:00
} elseif ( $bytevalue <= 0xDF ) { //110x xxxx
2005-07-29 10:08:41 +00:00
$working = $bytevalue & 0x1F ;
$bytesleft = 1 ;
2008-09-16 04:59:49 +00:00
} elseif ( $bytevalue <= 0xEF ) { //1110 xxxx
2005-07-29 10:08:41 +00:00
$working = $bytevalue & 0x0F ;
$bytesleft = 2 ;
} else { //1111 0xxx
$working = $bytevalue & 0x07 ;
$bytesleft = 3 ;
}
}
return $result ;
}
2006-01-07 13:31:29 +00:00
2005-07-29 10:08:41 +00:00
/**
* Reverse the previously applied transliteration of non - ASCII characters
* back to UTF - 8. Used to protect data from corruption by broken web browsers
* as listed in $wgBrowserBlackList .
*
2010-03-17 22:02:43 +00:00
* @ param $invalue String
* @ return String
2006-04-19 15:46:24 +00:00
* @ private
2005-07-29 10:08:41 +00:00
*/
function unmakesafe ( $invalue ) {
$result = " " ;
for ( $i = 0 ; $i < strlen ( $invalue ); $i ++ ) {
2011-04-17 07:59:58 +00:00
if ( ( substr ( $invalue , $i , 3 ) == " &#x " ) && ( $invalue [ $i + 3 ] != '0' ) ) {
2005-07-29 10:08:41 +00:00
$i += 3 ;
$hexstring = " " ;
do {
2011-04-17 07:59:58 +00:00
$hexstring .= $invalue [ $i ];
2005-07-29 10:08:41 +00:00
$i ++ ;
2011-04-17 07:59:58 +00:00
} while ( ctype_xdigit ( $invalue [ $i ] ) && ( $i < strlen ( $invalue ) ) );
2006-01-07 13:31:29 +00:00
2005-07-29 10:08:41 +00:00
// Do some sanity checks. These aren't needed for reversability,
2006-01-07 13:09:30 +00:00
// but should help keep the breakage down if the editor
2005-07-29 10:08:41 +00:00
// breaks one of the entities whilst editing.
2008-09-16 04:59:49 +00:00
if ( ( substr ( $invalue , $i , 1 ) == " ; " ) and ( strlen ( $hexstring ) <= 6 ) ) {
2005-07-29 10:08:41 +00:00
$codepoint = hexdec ( $hexstring );
$result .= codepointToUtf8 ( $codepoint );
} else {
$result .= " &#x " . $hexstring . substr ( $invalue , $i , 1 );
}
} else {
$result .= substr ( $invalue , $i , 1 );
}
}
// reverse the transform that we made for reversability reasons.
return strtr ( $result , array ( " � " => " &#x " ) );
}
2006-01-07 13:31:29 +00:00
2005-12-05 05:37:10 +00:00
function noCreatePermission () {
2006-06-20 18:20:58 +00:00
global $wgOut ;
2005-12-05 05:37:10 +00:00
$wgOut -> setPageTitle ( wfMsg ( 'nocreatetitle' ) );
2008-02-18 07:25:35 +00:00
$wgOut -> addWikiMsg ( 'nocreatetext' );
2005-12-05 05:37:10 +00:00
}
2008-04-14 07:45:50 +00:00
2007-10-30 05:42:19 +00:00
/**
* Attempt submission
* @ return bool false if output is done , true if the rest of the form should be displayed
*/
function attemptSave () {
2011-02-10 17:08:37 +00:00
global $wgUser , $wgOut ;
2007-10-30 05:42:19 +00:00
$resultDetails = false ;
2009-01-24 05:37:43 +00:00
# Allow bots to exempt some edits from bot flagging
2009-12-08 17:17:24 +00:00
$bot = $wgUser -> isAllowed ( 'bot' ) && $this -> bot ;
2011-08-26 16:26:17 +00:00
$status = $this -> internalAttemptSave ( $resultDetails , $bot );
// FIXME: once the interface for internalAttemptSave() is made nicer, this should use the message in $status
2008-04-14 07:45:50 +00:00
2011-08-26 16:26:17 +00:00
if ( $status -> value == self :: AS_SUCCESS_UPDATE || $status -> value == self :: AS_SUCCESS_NEW_ARTICLE ) {
2007-11-03 03:20:12 +00:00
$this -> didSave = true ;
}
2007-11-20 08:34:59 +00:00
2011-08-26 16:26:17 +00:00
switch ( $status -> value ) {
2007-10-30 05:42:19 +00:00
case self :: AS_HOOK_ERROR_EXPECTED :
case self :: AS_CONTENT_TOO_BIG :
2011-02-12 04:06:22 +00:00
case self :: AS_ARTICLE_WAS_DELETED :
2007-10-30 05:42:19 +00:00
case self :: AS_CONFLICT_DETECTED :
case self :: AS_SUMMARY_NEEDED :
case self :: AS_TEXTBOX_EMPTY :
2008-01-25 10:34:43 +00:00
case self :: AS_MAX_ARTICLE_SIZE_EXCEEDED :
2007-10-30 05:42:19 +00:00
case self :: AS_END :
return true ;
2008-01-24 01:59:35 +00:00
2007-10-30 05:42:19 +00:00
case self :: AS_HOOK_ERROR :
case self :: AS_FILTERING :
2011-01-15 15:21:36 +00:00
return false ;
2007-10-30 05:42:19 +00:00
case self :: AS_SUCCESS_NEW_ARTICLE :
2011-01-15 15:21:36 +00:00
$query = $resultDetails [ 'redirect' ] ? 'redirect=no' : '' ;
$wgOut -> redirect ( $this -> mTitle -> getFullURL ( $query ) );
return false ;
2007-10-30 05:42:19 +00:00
case self :: AS_SUCCESS_UPDATE :
2011-01-15 15:21:36 +00:00
$extraQuery = '' ;
$sectionanchor = $resultDetails [ 'sectionanchor' ];
// Give extensions a chance to modify URL query on update
wfRunHooks ( 'ArticleUpdateBeforeRedirect' , array ( $this -> mArticle , & $sectionanchor , & $extraQuery ) );
if ( $resultDetails [ 'redirect' ] ) {
if ( $extraQuery == '' ) {
$extraQuery = 'redirect=no' ;
} else {
$extraQuery = 'redirect=no&' . $extraQuery ;
}
}
$wgOut -> redirect ( $this -> mTitle -> getFullURL ( $extraQuery ) . $sectionanchor );
2007-10-30 05:42:19 +00:00
return false ;
case self :: AS_SPAM_ERROR :
2010-11-26 07:48:41 +00:00
$this -> spamPageWithContent ( $resultDetails [ 'spam' ] );
2007-10-30 05:42:19 +00:00
return false ;
case self :: AS_BLOCKED_PAGE_FOR_USER :
$this -> blockedPage ();
return false ;
2008-01-20 07:05:59 +00:00
case self :: AS_IMAGE_REDIRECT_ANON :
$wgOut -> showErrorPage ( 'uploadnologin' , 'uploadnologintext' );
return false ;
2007-10-30 05:42:19 +00:00
case self :: AS_READ_ONLY_PAGE_ANON :
$this -> userNotLoggedInPage ();
return false ;
2011-02-12 04:06:22 +00:00
case self :: AS_READ_ONLY_PAGE_LOGGED :
case self :: AS_READ_ONLY_PAGE :
$wgOut -> readOnlyPage ();
return false ;
2007-10-30 05:42:19 +00:00
2011-02-12 04:06:22 +00:00
case self :: AS_RATE_LIMITED :
$wgOut -> rateLimited ();
return false ;
2007-10-30 05:42:19 +00:00
2011-02-12 04:06:22 +00:00
case self :: AS_NO_CREATE_PERMISSION :
$this -> noCreatePermission ();
2011-06-05 14:46:55 +00:00
return false ;
2008-04-14 07:45:50 +00:00
2007-10-30 05:42:19 +00:00
case self :: AS_BLANK_ARTICLE :
2011-02-12 04:06:22 +00:00
$wgOut -> redirect ( $this -> getContextTitle () -> getFullURL () );
return false ;
2008-01-20 07:05:59 +00:00
case self :: AS_IMAGE_REDIRECT_LOGGED :
$wgOut -> permissionRequired ( 'upload' );
return false ;
2007-10-30 05:42:19 +00:00
}
}
2009-10-23 11:08:08 +00:00
2011-06-05 14:46:55 +00:00
/**
* @ return Revision
*/
2008-07-15 08:43:40 +00:00
function getBaseRevision () {
2010-06-09 11:44:05 +00:00
if ( ! $this -> mBaseRevision ) {
2008-07-15 08:43:40 +00:00
$db = wfGetDB ( DB_MASTER );
$baseRevision = Revision :: loadFromTimestamp (
$db , $this -> mTitle , $this -> edittime );
return $this -> mBaseRevision = $baseRevision ;
} else {
return $this -> mBaseRevision ;
}
2010-07-20 15:50:25 +00:00
}
2003-08-02 20:43:11 +00:00
}