Sleepinglion has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/335599 )
Change subject: 새 파일: RelatedLinks.alias.php 새 파일: RelatedLinks.hooks.php 새 파일: RelatedLinks.php 새 파일: SpecialRelatedLinks.php 새 파일: extension.json 새 파일: i18n/en.json 새 파일: i18n/ko.json 새 파일: modules/ext.related_lin ...................................................................... 새 파일: RelatedLinks.alias.php 새 파일: RelatedLinks.hooks.php 새 파일: RelatedLinks.php 새 파일: SpecialRelatedLinks.php 새 파일: extension.json 새 파일: i18n/en.json 새 파일: i18n/ko.json 새 파일: modules/ext.related_links.css 새 파일: modules/ext.related_links.js Change-Id: Ibacc4de8cf446a5f274871ce98c39e8b8b1a1ed2 --- A RelatedLinks.alias.php A RelatedLinks.hooks.php A RelatedLinks.php A SpecialRelatedLinks.php A extension.json A i18n/en.json A i18n/ko.json A modules/ext.related_links.css A modules/ext.related_links.js 9 files changed, 470 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RelatedLinks refs/changes/99/335599/1 diff --git a/RelatedLinks.alias.php b/RelatedLinks.alias.php new file mode 100755 index 0000000..c6d0d29 --- /dev/null +++ b/RelatedLinks.alias.php @@ -0,0 +1,19 @@ +<?php +/** + * Aliases for myextension + * + * @file + * @ingroup Extensions + */ + +$specialPageAliases = array(); + +/** English + * @author SleepingLion + */ +$specialPageAliases['en'] = array('RelatedLinks' => array('RelatedLinks', 'Related Links')); + +/** korean + * @author SleepingLion + */ +$specialPageAliases['ko'] = array('RelatedLinks' => array('연관사이트', '연관 사이트')); diff --git a/RelatedLinks.hooks.php b/RelatedLinks.hooks.php new file mode 100755 index 0000000..f587211 --- /dev/null +++ b/RelatedLinks.hooks.php @@ -0,0 +1,83 @@ +<?php +/** + * Hooks for RelatedLinks extension + * + * @file + * @ingroup Extensions + */ + +function initiateSettingsForRelatedLinks() { + $dbw = wfGetDB( DB_MASTER ); + $query = "CREATE TABLE " . $dbw->tableName( 'related_links' ) . " ( " . + " `id` INT(11) NOT NULL AUTO_INCREMENT, " . + " `user_id` INT(11) NOT NULL DEFAULT 0, " . + " `links_id` VARCHAR(50) NOT NULL DEFAULT '', " . + " `links_order` TINYINT(3) NOT NULL DEFAULT 0, " . + " `links_subject` VARCHAR(60) NOT NULL DEFAULT '', " . + " `links_url` VARCHAR(255) NOT NULL DEFAULT '', " . + " `links_enable` ENUM( 'true', 'false' ) NOT NULL DEFAULT 'true', " . + " `links_datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " . + " `links_import_domain` VARCHAR(50) NOT NULL DEFAULT '', " . + " PRIMARY KEY (`id`), " . + " UNIQUE KEY (`user_id`, `links_id`, `links_url`), " . + " KEY index_sort (`links_id`, `links_order`), " . + " KEY index_enable (`user_id`, `links_enable`) " . + ")"; + return $dbw->query( $query ); +} + +class RelatedLinksHooks +{ + /* + * Draw Related Links Management + */ + public static function SkinTemplateToolboxEnd($this) { + $dbr = wfGetDB( DB_SLAVE ); + + if ($dbr->tableExists( 'related_links' )) { + $tbl_links = $dbr->tableName( 'related_links' ); + } else { + $result = initiateSettingsForRelatedLinks(); + + if (!$result ) { + die( 'Failed to create table Related Links' ); + } + $tbl_links = $dbr->tableName( 'related_links' ); + } + + $links_id = filter_var($_GET['title'],FILTER_SANITIZE_STRING); + + $fields = array( 'links_subject', 'links_url' ); + $conds = array('user_id'=> '','links_enable' => 'true','links_id'=> $links_id); + $opts = array( 'ORDER BY' => 'links_order' ); + $result = $dbr->select( $tbl_links, $fields, $conds, 'Database::select', $opts ); + $rows = $dbr->numRows( $result ); +?> +</ul> +</div> +</div> +<div class="portlet" id="p-relatedlinks"> +<h3> +<?php echo wfMessage( 'relatedlinks' ) ?> +[<a href="<?php echo ( SkinTemplate::makeSpecialUrl( 'relatedlinks' ) . '/' . $links_id )?>"><?php echo wfMessage( 'edit' ) ?></a>] +</h3> +<div class="pBody"> +<ul> +<?php while ( $row = $dbr->fetchObject( $result ) ) { ?> +<li id="related-<?php echo $links_id?>"><a href="<?php echo htmlspecialchars( $row->links_url )?>" target="_blank"><?php echo $row->links_subject?></a></li> +<?php } ?> + +<?php +if ( !$rows ) +{ +?> +<li id="related-<?php echo $links_id?>"><?php echo wfMessage( 'no_link' ) ?></li> +<?php +} + + return true; + } +} + + + diff --git a/RelatedLinks.php b/RelatedLinks.php new file mode 100755 index 0000000..2d8d415 --- /dev/null +++ b/RelatedLinks.php @@ -0,0 +1,47 @@ +<?php + +/*********************************************************** + * Name: RelatedLinks + * Desc: Custom Related Link SideBar + * + * Version: 1.0.0 + * + * Author: sleepinglion + * Homepage: https://www.mediawiki.org/wiki/Extension:RelatedLinks + * https://github.com/sleepinglion + * http://www.sleepinglion.pe.kr + * + * + * License: MIT + * + *********************************************************** + */ + +if ( function_exists( 'wfLoadExtension' ) ) { + wfLoadExtension( 'RelatedLinks' ); + + /* + # Tell MediaWiki about the new special page and its class name + /* wfWarn( + 'Deprecated PHP entry point used for WikiEditor extension. Please use wfLoadExtension instead, ' . + 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' + );*/ + + return true; +} else { + //die( 'This version of the Nuke extension requires MediaWiki 1.25+' ); + + $wgExtensionCredits['specialpage'][] = array( + 'path' => __FILE__, + 'name' => 'RelatedLinks', + 'author' => 'sleepinglion', + 'url' => 'https://www.mediawiki.org/wiki/Extension:RelatedLinks', + 'descriptionmsg' => 'Custom Related Link SideBar', + 'version' => '1.0' + ); + + $wgAutoloadClasses['SpecialRelatedLinks'] = __DIR__ . '/SpecialRelatedLinks.php'; # Location of the SpecialMyExtension class (Tell MediaWiki to load this file) + $wgMessagesDirs['RelatedLinks'] = __DIR__ . "/i18n"; # Location of localisation files (Tell MediaWiki to load them) + $wgExtensionMessagesFiles['RelatedLinksAlias'] = __DIR__ . '/RelatedLinks.alias.php'; # Location of an aliases file (Tell MediaWiki to load it) + $wgSpecialPages['RelatedLinks'] = 'SpecialRelatedLinks'; # Tell MediaWiki about the new special page and its class name +} diff --git a/SpecialRelatedLinks.php b/SpecialRelatedLinks.php new file mode 100755 index 0000000..9ba4276 --- /dev/null +++ b/SpecialRelatedLinks.php @@ -0,0 +1,187 @@ +<?php + +if( !defined( 'MEDIAWIKI' ) ) + die( 'Not an entry point.' ); + +class SpecialRelatedLinks extends SpecialPage { + public function __construct() { + parent::__construct( 'RelatedLinks','editinterface'); + } + + public function execute($par) { + $wgRequest = $this -> getRequest(); + $wgOutput = $this -> getOutput(); + $wgUser = $this -> getUser(); + + $wgOutput->addModules('ext.relatedLinks'); + $this -> setHeaders(); + + if (in_array("sysop", $wgUser -> mGroups) == false) { + $wgOutput -> addHTML(wfMessage('please_login')); + return false; + } + + $param = $wgRequest -> getText('title'); + $links_id = str_replace('Special:RelatedLinks/', '', $param); + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $id = filter_var($_POST['id'], FILTER_SANITIZE_STRING); + + switch($_POST['submit_type']) { + case 'INSERT' : + $new_url = filter_var($_POST['new_url'], FILTER_VALIDATE_URL); + $return_url = SkinTemplate::makeSpecialUrl('RelatedLinks') . '/' . $id; + + $dbw = wfGetDB(DB_MASTER); + + if ($dbw -> tableExists('related_links')) { + $tbl_links = $dbw -> tableName('related_links'); + } else { + $result = initiateSettingsForRelatedLinks();http://localhost:20010/index.php?title=%ED%8A%B9%EC%88%98%3A%EC%97%B0%EA%B4%80%EC%82%AC%EC%9D%B4%ED%8A%B8/Main_Page + if (!$result) { + die('Failed to create table Related Links'); + } + $tbl_links = $dbw -> tableName('related_links'); + } + + ob_start(); + echo '<strong>' . $id . '</strong>'; + $output = ob_get_contents(); + ob_clean(); + + // insert new related site + $order = $dbw -> selectField($tbl_links, 'MAX( links_order )', array('user_id' => '', 'links_id' => $id)); + $order = ($order) ? $order + 1 : 1; + $data = array('links_order' => $order, 'links_subject' => $_POST['new_subject'], 'links_url' => $new_url, 'links_enable' => 'true', 'links_datetime' => date("Y-m-d H:i:s"), 'links_id' => $id); + $result = $dbw -> insert($tbl_links, $data); + + $output .= '<h4>Inserted into sidebar</h4>' . '<ul><li>' . $_POST['new_subject'] . ' (' . $new_url . ')</li></ul>'; + + // return link + $output .= '<br /><a href="' . $return_url . '">Return Page</a>'; + + break; + case 'DELETE' : + $return_url = SkinTemplate::makeSpecialUrl('RelatedLinks') . ($id != 'Related Links' ? '/' . $id : ''); + + $dbw = wfGetDB(DB_MASTER); + $tbl_links = $dbw -> tableName('related_links'); + + ob_start(); + echo '<strong>' . $id . '</strong>'; + + $output = ob_get_contents(); + ob_clean(); + + // delete sidebar + if ($_POST['check']) { + $result = $dbw -> delete($tbl_links, array('id' => $_POST['check'])); + + $output .= '<h4>Deleted sidebar</h4>'; + } + + // return link + $output .= '<br /><a href="' . $return_url . '">Return Page</a>'; + break; + default : + $return_url = SkinTemplate::makeSpecialUrl('RelatedLinks') . '/' . $id; + + $dbw = wfGetDB(DB_MASTER); + $tbl_links = $dbw -> tableName('related_links'); + + ob_start(); + echo '<strong>' . $id . '</strong>'; + $output = ob_get_contents(); + ob_clean(); + + // update sidebars + $output .= '<h4>Updated Sidebar</h4>' . '<ul>'; + + foreach ($_POST['order'] as $endex => $order) { + $data = array('links_order' => $order, 'links_subject' => $_POST['subject'][$endex], 'links_url' => $_POST['url'][$endex], 'links_enable' => ($_POST['enable'][$endex] == 'true' ? 'true' : 'false')); + $dbw -> update($tbl_links, $data, array('id' => $endex)); + $output .= '<li>' . $_POST['subject'][$endex] . ' (' . $_POST['url'][$endex] . ')' . ($_POST['enable'][$endex] == 'true' ? ' : enabled' : ' : disabled') . '</li>'; + } + $output .= '</ul>'; + + // return link + $output .= '<br /><a href="' . $return_url . '">Return relatedlinks Page</a>'; + } + + } else { + $dbr = wfGetDB(DB_SLAVE); + + if ($dbr -> tableExists('related_links')) { + $tbl_links = $dbr -> tableName('related_links'); + } else { + $result = initiateSettingsForRelatedLinks(); + if (!$result) { + die('Failed to create table Related Links'); + } + $tbl_links = $dbr -> tableName('related_links'); + } + + $fields = array('id', 'links_order', 'links_subject', 'links_url', 'links_enable'); + $conds = array('user_id' => '', 'links_id' => $links_id); + $opts = array('ORDER BY' => 'links_order'); + $result = $dbr -> select($tbl_links, $fields, $conds, 'Database::select', $opts); + $rows = $dbr -> numRows($result); + + ob_start(); + ?> + <form id="related_links_form" method="post" action=""> + <fieldset> + <legend><a href="/index.php/<?=$links_id ?>"><?=$links_id ?></a></legend> + <?php if ( !$rows ): ?> + <h4><?php echo wfMessage( 'no_data' ) ?></h4> + <?php endif ?> + <input type="hidden" id="submit_type" name="submit_type" value=""> + <input type="hidden" id="submit_id" name="id" value="<?=$links_id ?>"> + <table class="lieTable" style="width: 100%;"> + <colgroup style="width:10%;"> + <colgroup style="width:10%"> + <colgroup style="width:15%"> + <colgroup> + <colgroup style="width:10%"> + <thead> + <tr> + <th><input type="checkbox" id="checkall" /></th> + <th><?php echo wfMessage('no') ?></th> + <th><?php echo wfMessage('subject') ?></th> + <th><?php echo wfMessage('rel_url') ?></th> + <th><?php echo wfMessage('enable') ?></th> + <tr> + </thead> + <tbody id="links_list"> + <?php while ( $row = $dbr->fetchObject( $result ) ) { ?> + <tr> + <td><input type="checkbox" class="checkitem" name="check[<?=$row -> id ?>]" value="<?=$row -> id ?>"></td> + <td><input type="number" name="order[<?=$row -> id ?>]" value="<?=$row -> links_order ?>" min="1" class="s_order"></td> + <td><input type="text" name="subject[<?=$row -> id ?>]" value="<?=$row -> links_subject ?>" style="width: 92%;"></td> + <td><input type="url" name="url[<?=$row -> id ?>]" value="<?=$row -> links_url ?>" style="width: 92%;"></td> + <td><input type="checkbox" name="enable[<?=$row -> id ?>]" value="true"<?=($row -> links_enable == 'true' ? ' checked' : '') ?>></td> + </tr> + <?php } $dbr->freeResult( $result ); ?> + </tbody> + <tfoot> + <tr> + <th colspan="2"><?php echo wfMessage( 'add_site' ) ?></th> + <td><input type="text" id="new_subject" name="new_subject" value="" style="width: 92%;"></td> + <td><input type="text" id="new_url" name="new_url" value="" style="width: 92%;"></td> + <td><input type="button" id="btn_insert-sidebar" value="<?php echo wfMessage( 'insert' ) ?>"></td> + </tr> + </tfoot> + </table> + <input type="submit" value="<?php echo wfMessage('modify_all') ?>"> + <input type="button" id="btn_delete-sidebar" value="<?php echo wfMessage('delete') ?>"> + </fieldset> + </form> + <?php + $output = ob_get_contents(); + ob_clean(); + } + $wgOutput -> addHTML($output); + } + + } + \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100755 index 0000000..9ee3bed --- /dev/null +++ b/extension.json @@ -0,0 +1,39 @@ +{ + "name": "RelatedLinks", + "author": "Sleeping-Lion", + "version": "1.0.0", + "url": "https://www.mediawiki.org/wiki/Extension:RelatedLinks", + "descriptionmsg": "Special Page Related Links", + "type": "specialpage", + "license-name": "MIT", + "requires": { + "MediaWiki": ">= 1.25.0" + }, + "ResourceModules": { + "ext.relatedLinks": { + "scripts": "ext.related_links.js", + "styles": "ext.related_links.css" + } + }, + "ResourceFileModulePaths": { + "localBasePath": "modules", + "remoteExtPath": "RelatedLinks/modules" + }, + "Hooks": { + "MonoBookTemplateToolboxEnd": ["RelatedLinksHooks::SkinTemplateToolboxEnd"] + }, + "ExtensionMessagesFiles": { + "RelatedLinksAlias": "RelatedLinks.alias.php" + }, + "MessagesDirs": { + "RelatedLinks": ["i18n"] + }, + "SpecialPages": { + "RelatedLinks": "SpecialRelatedLinks" + }, + "AutoloadClasses": { + "RelatedLinksHooks": "RelatedLinks.hooks.php", + "SpecialRelatedLinks": "SpecialRelatedLinks.php" + }, + "manifest_version": 1 +} diff --git a/i18n/en.json b/i18n/en.json new file mode 100755 index 0000000..9ec334d --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,18 @@ +{ + "@metadata": { + "authors": "Sleeping-Lion" + }, + "relatedlinks": "Related Links", + "no": "No", + "subject": "Subject", + "rel_url": "URL", + "enable": "Enable", + "edit" : "Edit", + "please_login" : "Please Login", + "add_site" : "Add new site..", + "no_data" : "no data..!!", + "no_link" : "No Link...", + "insert" : "Insert", + "delete" : "Delete", + "modify_all" : "Modify All" +} \ No newline at end of file diff --git a/i18n/ko.json b/i18n/ko.json new file mode 100755 index 0000000..183753f --- /dev/null +++ b/i18n/ko.json @@ -0,0 +1,18 @@ +{ + "@metadata": { + "authors": "Sleeping-Lion" + }, + "relatedlinks": "연관사이트", + "no": "번호", + "subject": "제목", + "rel_url": "연관 URL", + "enable": "사용여부", + "edit" : "수정", + "please_login" : "먼저 로그인 해주세요", + "add_site" : "Add new site..", + "no_data" : "데이터 없음..!!", + "no_link" : "No Link...", + "insert" : "입력", + "delete" : "삭제", + "modify_all" : "수정 적용" +} \ No newline at end of file diff --git a/modules/ext.related_links.css b/modules/ext.related_links.css new file mode 100755 index 0000000..7611b6f --- /dev/null +++ b/modules/ext.related_links.css @@ -0,0 +1,22 @@ +table.lieTable { + border-top: 2px solid #79d; + border-bottom: 2px solid #79d; + border-collapse: collapse; +} + +table.lieTable th { + padding: 3px; + border-bottom: 1px solid #8ae; + background: #dfefff; +} + +table.lieTable td { + padding: 3px; + border-bottom: 1px solid #8ae; + text-align: center; +} + +.s_order { + width: 30px; + text-align: right; +} \ No newline at end of file diff --git a/modules/ext.related_links.js b/modules/ext.related_links.js new file mode 100755 index 0000000..e7158a8 --- /dev/null +++ b/modules/ext.related_links.js @@ -0,0 +1,37 @@ +$(document).ready(function(){ + $('#checkall').click(function () { + if($(this).is(':checked')) { + $('input.checkitem').prop('checked',true); + } else { + $('input.checkitem').prop('checked',false); + } + }); + + $('#btn_delete-sidebar').click(function () { + if(isSelected() == true ) { + $('#submit_type').val('DELETE'); + $('#related_links_form' ).submit(); + } else { + alert( 'Select items..' ); + } + }); + + $('#btn_insert-sidebar').click(function () { + if($('#new_subject' ).val() && $('#new_url').val()) { + $('#submit_type' ).val('INSERT'); + $('#related_links_form').submit(); + } else { + alert( 'Input data..' ); + } + }); +}); + +function isSelected () { + var is_checked = false; + + $('input.checkitem').each(function() { + if($(this).is(':checked')) + is_checked=true; + }); + return is_checked; +} -- To view, visit https://gerrit.wikimedia.org/r/335599 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibacc4de8cf446a5f274871ce98c39e8b8b1a1ed2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/RelatedLinks Gerrit-Branch: master Gerrit-Owner: Sleepinglion <ad...@sleepinglion.pe.kr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits