2010-09-15 03:02:35 +00:00
|
|
|
<?php
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
2010-10-01 18:15:10 +00:00
|
|
|
* Hooks for WikiEditor extension
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-09-15 22:40:50 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WikiEditorHooks {
|
2015-02-05 16:47:49 +00:00
|
|
|
// ID used for grouping entries all of a session's entries together in
|
|
|
|
// EventLogging.
|
|
|
|
private static $statsId = false;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 23:41:08 +00:00
|
|
|
/* Protected Static Members */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 23:41:08 +00:00
|
|
|
protected static $features = array(
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2013-05-25 15:07:46 +00:00
|
|
|
/* Toolbar Features */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
'toolbar' => array(
|
2012-04-11 13:40:13 +00:00
|
|
|
'preferences' => array(
|
|
|
|
// Ideally this key would be 'wikieditor-toolbar'
|
|
|
|
'usebetatoolbar' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-preference',
|
2013-05-25 15:07:46 +00:00
|
|
|
'section' => 'editing/editor',
|
2012-04-11 13:40:13 +00:00
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'usebetatoolbar' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.toolbar',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2014-04-08 20:36:38 +00:00
|
|
|
'stylemodules' => array(
|
|
|
|
'ext.wikiEditor.toolbar.styles',
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
'dialogs' => array(
|
2012-04-16 22:17:41 +00:00
|
|
|
'preferences' => array(
|
|
|
|
// Ideally this key would be 'wikieditor-toolbar-dialogs'
|
|
|
|
'usebetatoolbar-cgd' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-dialogs-preference',
|
2013-05-25 15:07:46 +00:00
|
|
|
'section' => 'editing/editor',
|
2012-04-16 22:17:41 +00:00
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'usebetatoolbar-cgd' => true,
|
2011-02-17 22:44:29 +00:00
|
|
|
'usebetatoolbar' => true,
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.dialogs',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
|
|
|
),
|
2011-04-22 12:10:18 +00:00
|
|
|
'hidesig' => array(
|
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-toolbar-hidesig' => array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-toolbar-hidesig',
|
2013-05-25 15:07:46 +00:00
|
|
|
'section' => 'editing/editor',
|
2011-04-22 12:10:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-toolbar-hidesig' => true,
|
|
|
|
'usebetatoolbar' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
|
|
|
'ext.wikiEditor.toolbar.hideSig',
|
|
|
|
),
|
|
|
|
),
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
/* Labs Features */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
'preview' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-preview' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-preview-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-preview' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.preview',
|
2010-09-15 22:40:50 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'publish' => array(
|
2010-09-16 21:11:46 +00:00
|
|
|
'preferences' => array(
|
|
|
|
'wikieditor-publish' => array(
|
2010-09-15 22:40:50 +00:00
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'wikieditor-publish-preference',
|
|
|
|
'section' => 'editing/labs',
|
|
|
|
),
|
|
|
|
),
|
2010-09-16 21:11:46 +00:00
|
|
|
'requirements' => array(
|
|
|
|
'wikieditor-publish' => true,
|
|
|
|
),
|
|
|
|
'modules' => array(
|
2010-09-20 20:06:18 +00:00
|
|
|
'ext.wikiEditor.publish',
|
2010-09-16 21:11:46 +00:00
|
|
|
),
|
2014-04-03 14:25:10 +00:00
|
|
|
)
|
2010-09-15 22:40:50 +00:00
|
|
|
);
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2011-02-25 00:01:57 +00:00
|
|
|
/* Static Methods */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2011-02-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Checks if a certain option is enabled
|
|
|
|
*
|
|
|
|
* This method is public to allow other extensions that use WikiEditor to use the
|
|
|
|
* same configuration as WikiEditor itself
|
|
|
|
*
|
2012-01-31 20:19:22 +00:00
|
|
|
* @param $name string Name of the feature, should be a key of $features
|
|
|
|
* @return bool
|
2011-02-25 00:01:57 +00:00
|
|
|
*/
|
|
|
|
public static function isEnabled( $name ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures, $wgUser;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 22:40:24 +00:00
|
|
|
// Features with global set to true are always enabled
|
2010-09-16 21:11:46 +00:00
|
|
|
if ( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['global'] ) {
|
|
|
|
return true;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
2010-09-16 21:11:46 +00:00
|
|
|
// Features with user preference control can have any number of preferences to be specific values to be enabled
|
|
|
|
if ( $wgWikiEditorFeatures[$name]['user'] ) {
|
|
|
|
if ( isset( self::$features[$name]['requirements'] ) ) {
|
|
|
|
foreach ( self::$features[$name]['requirements'] as $requirement => $value ) {
|
|
|
|
// Important! We really do want fuzzy evaluation here
|
|
|
|
if ( $wgUser->getOption( $requirement ) != $value ) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-16 21:11:46 +00:00
|
|
|
return true;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
// Features controlled by $wgWikiEditorFeatures with both global and user set to false are awlways disabled
|
2010-09-16 21:11:46 +00:00
|
|
|
return false;
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2015-02-05 16:47:49 +00:00
|
|
|
/**
|
|
|
|
* Log stuff to EventLogging's Schema:Edit - see https://meta.wikimedia.org/wiki/Schema:Edit
|
|
|
|
* If you don't have EventLogging installed, does nothing.
|
|
|
|
*
|
|
|
|
* @param string $action
|
|
|
|
* @param Article $article Which article (with full context, page, title, etc.)
|
|
|
|
* @param array $data Data to log for this action
|
|
|
|
* @return bool Whether the event was logged or not.
|
|
|
|
*/
|
|
|
|
public static function doEventLogging( $action, $article, $data = array() ) {
|
|
|
|
global $wgVersion;
|
|
|
|
if ( !class_exists( 'EventLogging' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $article->getContext()->getUser();
|
|
|
|
$page = $article->getPage();
|
|
|
|
$title = $article->getTitle();
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'action' => $action,
|
|
|
|
'version' => 1,
|
|
|
|
'editor' => 'wikitext',
|
|
|
|
'platform' => 'desktop', // FIXME
|
|
|
|
'integration' => 'page',
|
|
|
|
'page.length' => -1, // FIXME
|
|
|
|
'page.id' => $page->getId(),
|
|
|
|
'page.title' => $title->getPrefixedText(),
|
|
|
|
'page.ns' => $title->getNamespace(),
|
|
|
|
'page.revid' => $page->getRevision() && $page->getRevision()->getId(),
|
|
|
|
'user.id' => $user->getId(),
|
|
|
|
'user.editCount' => $user->getEditCount(),
|
|
|
|
'mediawiki.version' => $wgVersion
|
|
|
|
) + $data;
|
|
|
|
|
|
|
|
if ( $user->isAnon() ) {
|
|
|
|
$data['user.class'] = 'IP';
|
|
|
|
}
|
|
|
|
|
|
|
|
return EventLogging::logEvent( 'Edit', 11448630, $data );
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
2010-09-16 21:11:46 +00:00
|
|
|
* EditPage::showEditForm:initial hook
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2010-09-15 22:40:50 +00:00
|
|
|
* Adds the modules to the edit form
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2014-09-22 02:50:01 +00:00
|
|
|
* @param EditPage $editPage the current EditPage object.
|
|
|
|
* @param OutputPage $outputPage object.
|
2012-01-31 20:19:22 +00:00
|
|
|
* @return bool
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
2014-06-22 14:30:30 +00:00
|
|
|
public static function editPageShowEditFormInitial( $editPage, $outputPage ) {
|
|
|
|
if ( $editPage->contentModel !== CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
// Add modules for enabled features
|
|
|
|
foreach ( self::$features as $name => $feature ) {
|
2014-04-08 20:36:38 +00:00
|
|
|
if ( !self::isEnabled( $name ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( isset( $feature['stylemodules'] ) ) {
|
2014-06-22 14:30:30 +00:00
|
|
|
$outputPage->addModuleStyles( $feature['stylemodules'] );
|
2014-04-08 20:36:38 +00:00
|
|
|
}
|
|
|
|
if ( isset( $feature['modules'] ) ) {
|
2014-06-22 14:30:30 +00:00
|
|
|
$outputPage->addModules( $feature['modules'] );
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-05 16:47:49 +00:00
|
|
|
|
|
|
|
$article = $editPage->getArticle();
|
|
|
|
$request = $article->getContext()->getRequest();
|
|
|
|
// Don't run this if the request was posted - we don't want to log 'init' when the
|
|
|
|
// user just pressed 'Show preview' or 'Show changes', or switched from VE keeping
|
|
|
|
// changes.
|
|
|
|
if ( class_exists( 'EventLogging' ) && !$request->wasPosted() ) {
|
|
|
|
$data = array();
|
|
|
|
$data['editingSessionId'] = self::getEditingStatsId();
|
|
|
|
if ( $request->getVal( 'section', false ) ) {
|
|
|
|
$data['action.init.type'] = 'section';
|
|
|
|
} else {
|
|
|
|
$data['action.init.type'] = 'page';
|
|
|
|
}
|
|
|
|
if ( $request->getHeader( 'Referer' ) ) {
|
|
|
|
if ( $request->getVal( 'section' ) === 'new' || !$article->exists() ) {
|
|
|
|
$data['action.init.mechanism'] = 'new';
|
|
|
|
} else {
|
|
|
|
$data['action.init.mechanism'] = 'click';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$data['action.init.mechanism'] = 'url';
|
|
|
|
}
|
|
|
|
|
|
|
|
self::doEventLogging( 'init', $article, $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EditPage::showEditForm:fields hook
|
|
|
|
*
|
|
|
|
* Adds the event fields to the edit form
|
|
|
|
*
|
|
|
|
* @param EditPage $editPage the current EditPage object.
|
|
|
|
* @param OutputPage $outputPage object.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function editPageShowEditFormFields( $editPage, $outputPage ) {
|
|
|
|
if ( $editPage->contentModel !== CONTENT_MODEL_WIKITEXT ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$req = $outputPage->getContext()->getRequest();
|
|
|
|
$editingStatsId = $req->getVal( 'editingStatsId' );
|
|
|
|
if ( !$editingStatsId ) {
|
|
|
|
$editingStatsId = self::getEditingStatsId();
|
|
|
|
}
|
|
|
|
$outputPage->addHTML(
|
|
|
|
Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'editingStatsId',
|
|
|
|
'id' => 'editingStatsId',
|
|
|
|
'value' => $editingStatsId
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2010-09-15 22:40:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2012-02-17 22:13:11 +00:00
|
|
|
/**
|
|
|
|
* EditPageBeforeEditToolbar hook
|
|
|
|
*
|
|
|
|
* Disable the old toolbar if the new one is enabled
|
|
|
|
*
|
|
|
|
* @param $toolbar html
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function EditPageBeforeEditToolbar( &$toolbar ) {
|
|
|
|
if ( self::isEnabled( 'toolbar' ) ) {
|
2012-04-17 22:19:03 +00:00
|
|
|
$toolbar = Html::rawElement(
|
|
|
|
'div', array(
|
2014-04-08 20:36:38 +00:00
|
|
|
'class' => 'wikiEditor-oldToolbar'
|
2012-04-17 22:19:03 +00:00
|
|
|
),
|
|
|
|
$toolbar
|
|
|
|
);
|
2012-02-17 22:13:11 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
|
|
|
* GetPreferences hook
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2014-09-22 02:50:01 +00:00
|
|
|
* Adds WikiEditor-related items to the preferences
|
2011-09-13 08:56:32 +00:00
|
|
|
*
|
2014-09-22 02:50:01 +00:00
|
|
|
* @param User $user current user
|
|
|
|
* @param array $defaultPreferences list of default user preference controls
|
2012-01-31 20:19:22 +00:00
|
|
|
* @return bool
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
|
|
|
public static function getPreferences( $user, &$defaultPreferences ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-16 21:11:46 +00:00
|
|
|
foreach ( self::$features as $name => $feature ) {
|
|
|
|
if (
|
|
|
|
isset( $feature['preferences'] ) &&
|
|
|
|
( !isset( $wgWikiEditorFeatures[$name] ) || $wgWikiEditorFeatures[$name]['user'] )
|
|
|
|
) {
|
2010-10-01 19:14:33 +00:00
|
|
|
foreach ( $feature['preferences'] as $key => $options ) {
|
|
|
|
$defaultPreferences[$key] = $options;
|
|
|
|
}
|
2010-09-15 22:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
/**
|
2012-01-31 20:19:22 +00:00
|
|
|
* @param $vars array
|
|
|
|
* @return bool
|
2010-09-15 22:40:50 +00:00
|
|
|
*/
|
2011-03-13 10:51:45 +00:00
|
|
|
public static function resourceLoaderGetConfigVars( &$vars ) {
|
2010-09-16 21:11:46 +00:00
|
|
|
global $wgWikiEditorFeatures;
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 22:40:50 +00:00
|
|
|
$configurations = array();
|
2010-09-16 21:11:46 +00:00
|
|
|
foreach ( self::$features as $name => $feature ) {
|
2010-09-15 22:40:50 +00:00
|
|
|
if (
|
2010-09-16 21:11:46 +00:00
|
|
|
isset( $feature['configurations'] ) &&
|
|
|
|
( !isset( $wgWikiEditorFeatures[$name] ) || self::isEnabled( $name ) )
|
2010-09-15 22:40:50 +00:00
|
|
|
) {
|
2010-09-16 21:11:46 +00:00
|
|
|
foreach ( $feature['configurations'] as $configuration ) {
|
2010-09-15 22:40:50 +00:00
|
|
|
global $$configuration;
|
|
|
|
$configurations[$configuration] = $$configuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( count( $configurations ) ) {
|
|
|
|
$vars = array_merge( $vars, $configurations );
|
|
|
|
}
|
2012-05-27 19:14:34 +00:00
|
|
|
//expose magic words for use by the wikieditor toolbar
|
|
|
|
WikiEditorHooks::getMagicWords( $vars );
|
2010-09-15 22:40:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2012-01-31 20:19:22 +00:00
|
|
|
/**
|
2014-09-01 14:07:28 +00:00
|
|
|
* ResourceLoaderTestModules hook
|
|
|
|
*
|
|
|
|
* Registers JavaScript test modules
|
|
|
|
*
|
|
|
|
* @param $testModules array of javascript testing modules. 'qunit' is fed using tests/qunit/QUnitTestResources.php.
|
|
|
|
* @param $resourceLoader object
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function resourceLoaderTestModules( &$testModules, &$resourceLoader ) {
|
|
|
|
$testModules['qunit']['ext.wikiEditor.toolbar.test'] = array(
|
|
|
|
'scripts' => array( 'tests/qunit/ext.wikiEditor.toolbar.test.js' ),
|
|
|
|
'dependencies' => array( 'ext.wikiEditor.toolbar' ),
|
|
|
|
'localBasePath' => dirname( __FILE__ ),
|
|
|
|
'remoteExtPath' => 'WikiEditor',
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MakeGlobalVariablesScript hook
|
|
|
|
*
|
|
|
|
* Adds enabled/disabled switches for WikiEditor modules
|
2012-01-31 20:19:22 +00:00
|
|
|
* @param $vars array
|
|
|
|
* @return bool
|
|
|
|
*/
|
2011-03-13 10:55:33 +00:00
|
|
|
public static function makeGlobalVariablesScript( &$vars ) {
|
|
|
|
// Build and export old-style wgWikiEditorEnabledModules object for back compat
|
|
|
|
$enabledModules = array();
|
|
|
|
foreach ( self::$features as $name => $feature ) {
|
|
|
|
$enabledModules[$name] = self::isEnabled( $name );
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2011-03-13 10:55:33 +00:00
|
|
|
$vars['wgWikiEditorEnabledModules'] = $enabledModules;
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-27 19:14:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose useful magic words which are used by the wikieditor toolbar
|
|
|
|
* @param $vars array
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private static function getMagicWords( &$vars ){
|
|
|
|
$requiredMagicWords = array(
|
|
|
|
'redirect',
|
|
|
|
'img_right',
|
|
|
|
'img_left',
|
|
|
|
'img_none',
|
|
|
|
'img_center',
|
|
|
|
'img_thumbnail',
|
|
|
|
'img_framed',
|
|
|
|
'img_frameless',
|
|
|
|
);
|
2014-09-22 02:50:01 +00:00
|
|
|
$magicWords = array();
|
2012-05-27 19:14:34 +00:00
|
|
|
foreach ( $requiredMagicWords as $name ) {
|
2014-09-22 02:50:01 +00:00
|
|
|
$magicWords[$name] = MagicWord::get( $name )->getSynonym( 0 );
|
|
|
|
}
|
2012-05-27 19:14:34 +00:00
|
|
|
$vars['wgWikiEditorMagicWords'] = $magicWords;
|
|
|
|
}
|
|
|
|
|
2015-02-05 16:47:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds WikiEditor JS to the output.
|
|
|
|
*
|
|
|
|
* This is attached to the MediaWiki 'BeforePageDisplay' hook.
|
|
|
|
*
|
|
|
|
* @param OutputPage $output
|
|
|
|
* @param Skin $skin
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function onBeforePageDisplay( OutputPage &$output, Skin &$skin ) {
|
|
|
|
$output->addModules( array( 'ext.wikiEditor.init' ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a 32 character alphanumeric random string to be used for stats.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private static function getEditingStatsId() {
|
|
|
|
if ( self::$statsId ) {
|
|
|
|
return self::$statsId;
|
|
|
|
}
|
|
|
|
return self::$statsId = MWCryptRand::generateHex( 32 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is attached to the MediaWiki 'EditPage::attemptSave' hook.
|
|
|
|
*
|
|
|
|
* @param EditPage $editPage
|
|
|
|
* @param Status $status
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function editPageAttemptSave( EditPage $editPage ) {
|
|
|
|
$article = $editPage->getArticle();
|
|
|
|
$request = $article->getContext()->getRequest();
|
|
|
|
if ( $request->getVal( 'editingStatsId', false ) !== false ) {
|
|
|
|
self::doEventLogging(
|
|
|
|
'saveAttempt',
|
|
|
|
$article,
|
|
|
|
array( 'editingSessionId' => $request->getVal( 'editingStatsId' ) )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is attached to the MediaWiki 'EditPage::attemptSave:after' hook.
|
|
|
|
*
|
|
|
|
* @param EditPage $editPage
|
|
|
|
* @param Status $status
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function editPageAttemptSaveAfter( EditPage $editPage, Status $status ) {
|
|
|
|
$article = $editPage->getArticle();
|
|
|
|
$request = $article->getContext()->getRequest();
|
|
|
|
if ( $request->getVal( 'editingStatsId', false ) !== false ) {
|
|
|
|
$data = array();
|
|
|
|
$data['editingStatsId'] = $request->getVal( 'editingStatsId' );
|
|
|
|
|
|
|
|
if ( $status->isOK() ) {
|
|
|
|
$action = 'saveSuccess';
|
|
|
|
} else {
|
|
|
|
$action = 'saveFailure';
|
|
|
|
$errors = $status->getErrorsArray();
|
|
|
|
|
|
|
|
if ( isset( $errors[0][0] ) ) {
|
|
|
|
$data['action.saveFailure.message'] = $errors[0][0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $status->value === EditPage::AS_CONFLICT_DETECTED ) {
|
|
|
|
$data['action.saveFailure.type'] = 'editConflict';
|
|
|
|
} else if ( $status->value === EditPage::AS_ARTICLE_WAS_DELETED ) {
|
|
|
|
$data['action.saveFailure.type'] = 'editPageDeleted';
|
|
|
|
} else if ( isset( $errors[0][0] ) && $errors[0][0] === 'abusefilter-disallowed' ) {
|
|
|
|
$data['action.saveFailure.type'] = 'extensionAbuseFilter';
|
|
|
|
} else if ( isset( $editPage->getArticle()->getPage()->ConfirmEdit_ActivateCaptcha ) ) {
|
|
|
|
// TODO: :(
|
|
|
|
$data['action.saveFailure.type'] = 'extensionCaptcha';
|
|
|
|
} else if ( isset( $errors[0][0] ) && $errors[0][0] === 'spamprotectiontext' ) {
|
|
|
|
$data['action.saveFailure.type'] = 'extensionSpamBlacklist';
|
|
|
|
} else {
|
|
|
|
// Catch everything else... We don't seem to get userBadToken or
|
|
|
|
// userNewUser through this hook.
|
|
|
|
$data['action.saveFailure.type'] = 'responseUnknown';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self::doEventLogging( $action, $article, $data );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-19 13:59:34 +00:00
|
|
|
}
|