-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
927c19a
commit 9f7662b
Showing
21 changed files
with
5 additions
and
2,526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,8 @@ | |
* | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < [email protected] > | ||
* @author Daniel Werner | ||
*/ | ||
final class MapsHooks { | ||
/** | ||
* Helper flag indicating whether the page has been purged. | ||
* @var bool | ||
* | ||
* TODO: Figure out a better way to do this, not requiring this flag and make sure it works with | ||
* later MW versions (purging mechanism got changed somewhat around 1.18). | ||
*/ | ||
static $purgedBeforeStore = false; | ||
|
||
/** | ||
* Adds a link to Admin Links page. | ||
|
@@ -44,30 +35,14 @@ public static function addToAdminLinks( ALTree &$admin_links_tree ) { | |
return true; | ||
} | ||
|
||
/** | ||
* Intercept pages in the Layer namespace to handle them correctly. | ||
* | ||
* @param $title: Title | ||
* @param $article: Article or null | ||
* | ||
* @return boolean | ||
*/ | ||
public static function onArticleFromTitle( Title &$title, /* Article */ &$article ) { | ||
if ( $title->getNamespace() == Maps_NS_LAYER ) { | ||
$article = new MapsLayerPage( $title ); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Adds global JavaScript variables. | ||
* | ||
* @since 1.0 | ||
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript | ||
* @param array &$vars Variables to be added into the output | ||
* @param OutputPage $outputPage OutputPage instance calling the hook | ||
* @return boolean true in all cases | ||
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript | ||
* @param array &$vars Variables to be added into the output | ||
* @param OutputPage $outputPage OutputPage instance calling the hook | ||
* @return boolean true in all cases | ||
*/ | ||
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $outputPage ) { | ||
global $egMapsGlobalJSVars; | ||
|
@@ -80,140 +55,5 @@ public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $ou | |
return true; | ||
} | ||
|
||
/** | ||
* @since 0.7 | ||
* | ||
* @param array $list | ||
* | ||
* @return boolean | ||
*/ | ||
public static function onCanonicalNamespaces( array &$list ) { | ||
$list[Maps_NS_LAYER] = 'Layer'; | ||
$list[Maps_NS_LAYER_TALK] = 'Layer_talk'; | ||
return true; | ||
} | ||
|
||
/** | ||
* This will setup database tables for layer functionality. | ||
* | ||
* @since 3.0 | ||
* | ||
* @param DatabaseUpdater $updater | ||
* | ||
* @return true | ||
*/ | ||
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { | ||
switch( $GLOBALS['wgDBtype'] ) { | ||
case 'mysql': | ||
case 'sqlite': | ||
$updater->addExtensionTable( 'maps_layers', __DIR__ . '/schema/MapsLayers.sql' ); | ||
break; | ||
case 'postgres': | ||
$updater->addExtensionTable( 'maps_layers', __DIR__ . '/schema/MapsLayers-postgres.sql' ); | ||
break; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Make sure layer data will be stored into database when purging the page | ||
* | ||
* @since 3.0 | ||
* | ||
* @param $article WikiPage|Article (depending on MW version, WikiPage in 1.18+) | ||
* @return type | ||
*/ | ||
public static function onArticlePurge( &$article ) { | ||
self::$purgedBeforeStore = true; | ||
return true; | ||
} | ||
|
||
/** | ||
* At the end of article parsing, in case of layer page, save layers to database | ||
* | ||
* @since 3.0 | ||
* | ||
* @param Parser &$parser | ||
* @param string &$text | ||
* | ||
* @return true | ||
*/ | ||
public static function onParserAfterTidy( Parser &$parser, &$text ) { | ||
|
||
$title = $parser->getTitle(); | ||
|
||
if( $title === null | ||
|| self::$purgedBeforeStore !== true | ||
) { | ||
// just preprocessing some stuff or no purge | ||
return true; | ||
} | ||
|
||
self::processLayersStoreCandidate( $parser->getOutput(), $title ); | ||
|
||
// Set helper to false immediately so we won't run into job-processing weirdness: | ||
self::$purgedBeforeStore = false; | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* After article was edited and parsed, in case of layer page, save layers to database | ||
* | ||
* @since 3.0 | ||
* | ||
* @param LinksUpdate &$linksUpdate | ||
* | ||
* @return true | ||
*/ | ||
public static function onLinksUpdateConstructed( LinksUpdate &$linksUpdate ) { | ||
$title = $linksUpdate->getTitle(); | ||
|
||
self::processLayersStoreCandidate( $linksUpdate->mParserOutput, $title ); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Checks whether the parser output has some layer data which should be stored of the | ||
* given title and performs the task. | ||
* | ||
* @since 3.0 | ||
* | ||
* @param ParserOutput $parserOutput | ||
* @param Title $title | ||
*/ | ||
protected static function processLayersStoreCandidate( ParserOutput $parserOutput, Title $title ) { | ||
|
||
// if site which is being parsed is in maps namespace: | ||
if( $title->getNamespace() === Maps_NS_LAYER ) { | ||
|
||
if( ! isset( $parserOutput->mExtMapsLayers ) ) { | ||
$parserOutput->mExtMapsLayers = new MapsLayerGroup(); | ||
} | ||
|
||
// get MapsLayerGroup object with layers to be stored: | ||
$mapsForStore = $parserOutput->mExtMapsLayers; | ||
|
||
// store layers in database (also deletes previous definitions still in db): | ||
MapsLayers::storeLayers( $mapsForStore, $title ); | ||
} | ||
} | ||
|
||
/** | ||
* If a new parser process is getting started, clear collected layer data of the | ||
* previous one. | ||
* | ||
* @since 3.0 | ||
* | ||
* @param Parser $parser | ||
* | ||
* @return true | ||
*/ | ||
public static function onParserClearState( Parser &$parser ) { | ||
$parser->getOutput()->mExtMapsLayers = null; | ||
return true; | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.