Jason.ji has uploaded a new change for review.
https://gerrit.wikimedia.org/r/185984
Change subject: Initial commit of VikiTitleIcon.
......................................................................
Initial commit of VikiTitleIcon.
Change-Id: I8f00b063dc7695871b68f343de35bf19af43de47
---
A ApiGetTitleIcons.php
A VikiTitleIcon.i18n.php
A VikiTitleIcon.js
A VikiTitleIcon.php
A docs/config.json
A i18n/en.json
A i18n/qqq.json
7 files changed, 395 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VikiTitleIcon
refs/changes/84/185984/1
diff --git a/ApiGetTitleIcons.php b/ApiGetTitleIcons.php
new file mode 100644
index 0000000..93df067
--- /dev/null
+++ b/ApiGetTitleIcons.php
@@ -0,0 +1,126 @@
+<?php
+/*
+ * Copyright (c) 2014 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+class ApiGetTitleIcons extends ApiBase {
+ public function __construct( $main, $action ) {
+ parent::__construct( $main, $action );
+ }
+
+ public function execute() {
+ $pageTitle = $this->getMain()->getVal( 'pageTitle' );
+
+ global $TitleIcon_TitleIconPropertyName;
+ $myTitleIconName = $TitleIcon_TitleIconPropertyName;
+
+ $pageNameWithSpaces = str_replace( '_', ' ', $pageTitle );
+ $titleIconWithSpaces = str_replace( '+', ' ', $myTitleIconName
);
+
+ $api = new ApiMain(
+ new DerivativeRequest(
+ $this->getRequest(),
+ array(
+ 'action' => 'askargs',
+ 'conditions' => $pageTitle,
+ 'printouts' => $titleIconWithSpaces
+ )
+ ),
+ false
+ );
+
+ $api->execute();
+ $data = $api->getResultData();
+
+ if ( is_array( $data["query"]["results"] ) && count(
$data["query"]["results"] ) == 0 ) {
+ $this->getResult()->addValue( null,
$this->getModuleName(),
+ array( 'pageTitle' => $pageTitle,
+ 'titleIcons' => array()
+ ) );
+
+ return true;
+ }
+
+ if ( array_key_exists( $pageNameWithSpaces,
$data["query"]["results"] ) )
+ $titleIconNames =
$data["query"]["results"]["$pageNameWithSpaces"]["printouts"]["$titleIconWithSpaces"];
+ else {
+ $key = array_shift( array_keys(
$data["query"]["results"] ) );
+ $titleIconNames =
$data["query"]["results"][$key]["printouts"]["$titleIconWithSpaces"];
+ }
+ $titleIconURLs = array();
+
+ foreach ( $titleIconNames as $name ) {
+
+ $api = new ApiMain(
+ new DerivativeRequest(
+ $this->getRequest(),
+ array(
+ 'action' => 'query',
+ 'titles' => 'File:' . $name,
+ 'prop' => 'imageinfo',
+ 'iiprop' => 'url'
+ )
+ ),
+ false
+ );
+
+ $api->execute();
+ $data = $api->getResultData();
+ $key = array_shift( array_keys( $data["query"]["pages"]
) );
+ $url =
$data["query"]["pages"][$key]["imageinfo"][0]["url"];
+ $titleIconURLs[] = $url;
+ }
+
+ $this->getResult()->addValue( null, $this->getModuleName(),
+ array( 'pageTitle' => $pageTitle,
+ 'titleIcons' => $titleIconURLs
+ ) );
+
+ return true;
+
+ }
+ public function getDescription() {
+ return "Get the URLs of all Title Icons for the page, if any
exist.
+
+Note that because the returned value is a JSON object, you must specify ".
+"format=json in this query; the default xml format will return only an error.";
+ }
+ public function getAllowedParams() {
+ return array(
+ 'pageTitle' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true
+ )
+ );
+ }
+ public function getParamDescription() {
+ return array(
+ 'pageTitle' => 'title of the page whose title icons you
wish to retrieve'
+ );
+ }
+ public function getExamples() {
+ return array(
+
'api.php?action=getTitleIcons&pageTitle=Test_Page_C&format=jsonfm' );
+ }
+ public function getHelpUrls() {
+ return '';
+ }
+}
diff --git a/VikiTitleIcon.i18n.php b/VikiTitleIcon.i18n.php
new file mode 100644
index 0000000..ee6b710
--- /dev/null
+++ b/VikiTitleIcon.i18n.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * This is a backwards-compatibility shim, generated by:
+ *
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
+ *
+ * Beginning with MediaWiki 1.23, translation strings are stored in json files,
+ * and the EXTENSION.i18n.php file only exists to provide compatibility with
+ * older releases of MediaWiki. For more information about this migration, see:
+ * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
+ *
+ * This shim maintains compatibility back to MediaWiki 1.17.
+ */
+$messages = array();
+if ( !function_exists( 'wfJsonI18nShimac18849c6fde4c68' ) ) {
+ function wfJsonI18nShimac18849c6fde4c68( $cache, $code, &$cachedData ) {
+ $codeSequence = array_merge( array( $code ),
$cachedData['fallbackSequence'] );
+ foreach ( $codeSequence as $csCode ) {
+ $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
+ if ( is_readable( $fileName ) ) {
+ $data = FormatJson::decode( file_get_contents(
$fileName ), true );
+ foreach ( array_keys( $data ) as $key ) {
+ if ( $key === '' || $key[0] === '@' ) {
+ unset( $data[$key] );
+ }
+ }
+ $cachedData['messages'] = array_merge( $data,
$cachedData['messages'] );
+ }
+
+ $cachedData['deps'][] = new FileDependency( $fileName );
+ }
+ return true;
+ }
+
+ $GLOBALS['wgHooks']['LocalisationCacheRecache'][] =
'wfJsonI18nShimac18849c6fde4c68';
+}
diff --git a/VikiTitleIcon.js b/VikiTitleIcon.js
new file mode 100644
index 0000000..9abd489
--- /dev/null
+++ b/VikiTitleIcon.js
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2014 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+window.VIKI = ( function( mw, my ) {
+ /**
+ * @class VikiTitleIcon
+ *
+ * Create VikiTitleIcon, a plugin to VIKI to handle pages using the
Title Icon extension.
+ * These pages will show up with their title icons rather than wiki
logos in VIKI.
+ *
+ */
+ my.VikiTitleIcon = {
+ hookName: "",
+
+ /**
+ * Hook function to check this page for the existence of a
title icon.
+ *
+ * This is the hook function registered with VIKI to check for
title icon usage.
+ * It calls queryForTitleIcon to execute the actual query.
+ *
+ * @param {Object} vikiObject reference to the VIKI object that
this is a plugin to
+ * @param {Array} parameters all VIKI hook calls come with
parameters
+ * @param {string} hookName name of the hook this function was
registered with
+ */
+ checkForTitleIcon: function( vikiObject, parameters, hookName )
{
+ this.hookName = hookName;
+ var node = parameters[ 0 ];
+
+ this.queryForTitleIcon( vikiObject, node );
+ },
+
+ /**
+ * Query this page for usage of a title icon.
+ *
+ * @param {Object} vikiObject reference to the VIKI object that
this is a plugin to
+ * @param {Object} node node to check for title icon
+ */
+ queryForTitleIcon: function( vikiObject, node ) {
+ var self = this;
+ jQuery.ajax( {
+ url: node.apiURL,
+ dataType: node.sameServer ? 'json' : 'jsonp',
+ data: {
+ action: 'getTitleIcons',
+ format: 'json',
+ pageTitle: node.pageTitle
+ },
+ beforeSend: function( ) {},
+ success: function( data ) {
+ self.titleIconSuccessHandler(
vikiObject, data, node );
+ },
+ error: function( ) {
+ vikiObject.showError( mw.message(
'vikititleicon-error-fetch', node.pageTitle )
+ .text() );
+ vikiObject.hookCompletion(
self.hookName );
+ }
+ } );
+ },
+
+ /**
+ * Process query result from queryForTitleIcon.
+ *
+ * This method is called from queryForTitleIcon to process the
data returned from the query.
+ * The node's hook icon URL is set to the URL of the title icon
so it will render with
+ * the title icon, rather than the wiki logo.
+ *
+ * @param {Object} vikiObject reference to the VIKI object that
this is a plugin to
+ * @param {Object} data data returned from the query
+ * @param {Object} node node to check for title icon
+ */
+ titleIconSuccessHandler: function( vikiObject, data, node ) {
+ if ( data.error && data.error.code && data.error.code
=== "unknown_action" ) {
+ vikiObject.hookCompletion( my.hookName );
+ return;
+ }
+
+ var titleIconURLs = data.getTitleIcons.titleIcons;
+ if ( titleIconURLs.length === 0 || titleIconURLs[ 0 ]
=== null ) {
+ vikiObject.hookCompletion( my.hookName );
+ return;
+ }
+
+ node.hookIconURL = titleIconURLs[ 0 ];
+ vikiObject.hookCompletion( my.hookName, {
+ "redrawNode": true,
+ "node": node
+ } );
+
+ }
+
+ };
+
+ return my;
+}( mediaWiki, window.VIKI || {} ) );
diff --git a/VikiTitleIcon.php b/VikiTitleIcon.php
new file mode 100644
index 0000000..87f0aa3
--- /dev/null
+++ b/VikiTitleIcon.php
@@ -0,0 +1,94 @@
+<?php
+/*
+ * Copyright (c) 2014 The MITRE Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+* To activate the functionality of this extension include the following
+* in your LocalSettings.php file:
+* include_once("$IP/extensions/VikiTitleIcon/VikiTitleIcon.php");
+*/
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+ die( '<b>Error:</b> This file is part of a MediaWiki extension and
cannot be run standalone.' );
+}
+
+if ( !defined( 'VIKIJS_VERSION' ) ) {
+ die( '<b>Error:</b> The extension VikiTitleIcon requires ' .
+ 'VIKI to be installed first. Be sure that VIKI is included '
+ . 'on a line ABOVE the line where you\'ve included
VikiTitleIcon.' );
+}
+
+if ( version_compare( $wgVersion, '1.22', 'lt' ) ) {
+ die( '<b>Error:</b> This version of VikiTitleIcon '
+ . 'is only compatible with MediaWiki 1.22 or above.' );
+}
+
+if ( !defined( 'SMW_VERSION' ) ) {
+ die( '<b>Error:</b> You need to have ' .
+ '<a
href="https://semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic
MediaWiki</a>' .
+ ' installed in order to use VikiTitleIcon.' );
+}
+
+if ( version_compare( SMW_VERSION, '1.9', '<' ) ) {
+ die( '<b>Error:</b> VikiTitleIcon is only compatible with Semantic
MediaWiki 1.9 or above.' );
+}
+
+$wgExtensionCredits['parserhook'][] = array (
+ 'path' => __FILE__,
+ 'name' => 'VikiTitleIcon',
+ 'version' => '1.0',
+ 'author' => '[http://www.mediawiki.org/wiki/User:Jji Jason Ji]',
+ 'descriptionmsg' => 'vikititleicon-desc',
+ 'url' => 'http://www.mediawiki.org/wiki/Extension:VikiTitleIcon'
+);
+
+$wgMessagesDirs['VikiTitleIcon'] = __DIR__ . '/i18n';
+
+$wgResourceModules['ext.VikiTitleIcon'] = array(
+ 'localBasePath' => dirname( __FILE__ ),
+ 'remoteExtPath' => 'VikiTitleIcon',
+ 'scripts' => array(
+ 'VikiTitleIcon.js'
+ ),
+ 'messages' => array(
+ 'vikititleicon-error-fetch'
+ )
+);
+
+global $wgVIKI_Function_Hooks;
+
+if ( !isset( $wgVIKI_Function_Hooks ) )
+ $wgVIKI_Function_Hooks = array();
+
+if ( array_key_exists( 'AfterVisitNodeHook', $wgVIKI_Function_Hooks ) )
+ $wgVIKI_Function_Hooks['AfterVisitNodeHook'][] =
'VIKI.VikiTitleIcon.checkForTitleIcon';
+else
+ $wgVIKI_Function_Hooks['AfterVisitNodeHook'] = array(
'VIKI.VikiTitleIcon.checkForTitleIcon' );
+
+$wgHooks['ParserFirstCallInit'][] = 'efVikiTitleIcon_AddResource';
+$wgAPIModules['getTitleIcons'] = 'ApiGetTitleIcons';
+$wgAutoloadClasses['ApiGetTitleIcons'] = __DIR__ . '/ApiGetTitleIcons.php';
+
+function efVikiTitleIcon_AddResource ( & $parser ) {
+ VikiJS::addResourceModule( "ext.VikiTitleIcon" );
+ return true;
+}
diff --git a/docs/config.json b/docs/config.json
new file mode 100644
index 0000000..56e6c28
--- /dev/null
+++ b/docs/config.json
@@ -0,0 +1,10 @@
+{
+ "--title": "VikiTitleIcon - Documentation",
+ "--warnings": ["-nodoc(class,public)"],
+ "--warnings-exit-nonzero": true,
+ "--footer": "Documentation for VikiTitleIcon. Generated on {DATE} by
{JSDUCK} {VERSION}.",
+ "--output": "../docs/js",
+ "--": [
+ "../VikiTitleIcon.js"
+ ]
+}
\ No newline at end of file
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..0a4a958
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,7 @@
+{
+ "@metadata": {
+ "authors": []
+ },
+ "vikititleicon-desc": "VIKI plugin to show logo from pages using Title
Icon extension",
+ "vikititleicon-error-fetch" : "Error fetching title icon data for node:
$1."
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..ec78be9
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,10 @@
+{
+ "@metadata": {
+ "authors": [
+ "Cindy Cicalese",
+ "Jason Ji"
+ ]
+ },
+ "vikititleicon-desc":
"{{desc|name=VikiTitleIcon|url=http://www.mediawiki.org/wiki/Extension/VikiTitleIcon}}",
+ "vikititleicon-error-fetch": "Error message to be displayed when a
title icon data fetch has failed. $1 = pageTitle of node for which title icon
data fetch has failed"
+}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/185984
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f00b063dc7695871b68f343de35bf19af43de47
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VikiTitleIcon
Gerrit-Branch: master
Gerrit-Owner: Jason.ji <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits