Sleepinglion has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353019 )

Change subject:         수정함:        RelatedLinks.hooks.php      수정함:        
RelatedLinks.php    수정함:        SpecialRelatedLinks.php     수정함:        
i18n/en.json        수정함:        i18n/ko.json        수정함:        
modules/ext.related_links.js
......................................................................

수정함:        RelatedLinks.hooks.php
        수정함:        RelatedLinks.php
        수정함:        SpecialRelatedLinks.php
        수정함:        i18n/en.json
        수정함:        i18n/ko.json
        수정함:        modules/ext.related_links.js

Change-Id: Icbc3b89477983ca090680087b2b576ab4a2533d3
---
M RelatedLinks.hooks.php
M RelatedLinks.php
M SpecialRelatedLinks.php
M i18n/en.json
M i18n/ko.json
M modules/ext.related_links.js
6 files changed, 157 insertions(+), 84 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RelatedLinks 
refs/changes/19/353019/1

diff --git a/RelatedLinks.hooks.php b/RelatedLinks.hooks.php
index cf1a55f..c844712 100755
--- a/RelatedLinks.hooks.php
+++ b/RelatedLinks.hooks.php
@@ -11,18 +11,17 @@
     $dbw = wfGetDB(DB_MASTER);
     $query    = "CREATE TABLE " . $dbw->tableName('related_links') . " ( " .
         "      `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, " .
-        "      `user_id` INT(10) UNSIGNED NOT NULL DEFAULT 0, " .
-        "      `links_id` VARCHAR(50) NOT NULL DEFAULT '', " .
+        "      `user_id` INT(10) UNSIGNED NOT NULL, " .
+        "      `links_id` VARCHAR(60) 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_subject` VARCHAR(60) NOT NULL, " .
+        "      `links_url` VARCHAR(255) NOT NULL, " .
+        "      `links_enable` TINYINT(1) NOT NULL DEFAULT 0, " .
         "      `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);
 }
@@ -50,7 +49,7 @@
         $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);
+        $conds    = array('links_enable'    => 1,'links_id'=> $links_id);
         $opts    = array( 'ORDER BY'        => 'links_order' );
         $result    = $dbr->select($tbl_links, $fields, $conds, 
'Database::select', $opts);
         $rows    = $dbr->numRows($result); ?>
@@ -60,7 +59,7 @@
 <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>]
+[<a href="<?php echo(SkinTemplate::makeSpecialUrl('relatedlinks') . 
'&amp;link_id=' . $links_id)?>"><?php echo wfMessage('edit') ?></a>]
 </h3>
 <div class="pBody">
 <ul>
@@ -68,6 +67,7 @@
             ?>
 <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
diff --git a/RelatedLinks.php b/RelatedLinks.php
index d7fe21c..94147e4 100755
--- a/RelatedLinks.php
+++ b/RelatedLinks.php
@@ -33,8 +33,8 @@
         '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
+    $wgAutoloadClasses['SpecialRelatedLinks'] = __DIR__ . DIRECTORY_SEPARATOR 
. 'SpecialRelatedLinks.php';
+    $wgMessagesDirs['RelatedLinks'] = __DIR__ . DIRECTORY_SEPARATOR . 'i18n';
+    $wgExtensionMessagesFiles['RelatedLinksAlias'] = __DIR__ . 
DIRECTORY_SEPARATOR . 'RelatedLinks.alias.php';
+    $wgSpecialPages['RelatedLinks'] = 'SpecialRelatedLinks';
 }
diff --git a/SpecialRelatedLinks.php b/SpecialRelatedLinks.php
index cf5fc95..abe5be1 100755
--- a/SpecialRelatedLinks.php
+++ b/SpecialRelatedLinks.php
@@ -25,16 +25,27 @@
             return false;
         }
 
-        $param = $wgRequest -> getText('title');
-        $links_id = str_replace('Special:RelatedLinks/', '', $param);
+      //  $param = $wgRequest -> getText('title');
+        $link_id = filter_var($_GET['link_id'], FILTER_SANITIZE_STRING);
 
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-            $id = filter_var($_POST['id'], FILTER_SANITIZE_STRING);
+            $link_id = filter_var($_POST['link_id'], FILTER_SANITIZE_STRING);
+            $return_url = SkinTemplate::makeSpecialUrl('RelatedLinks') . 
'&amp;link_id=' . $link_id;
 
             switch ($_POST['submit_type']) {
-                case 'INSERT':
-                    $new_url = filter_var($_POST['new_url'], 
FILTER_VALIDATE_URL);
-                    $return_url = SkinTemplate::makeSpecialUrl('RelatedLinks') 
. '/' . $id;
+                case 'insert':
+                    $new_subject = filter_var($_POST['subject'], 
FILTER_SANITIZE_STRING);
+                    $new_url = filter_var($_POST['url'], FILTER_VALIDATE_URL);
+
+                    if (empty($new_url)) {
+                        throw new Exception("url not validate", 1);
+                    }
+
+                    if (empty($_POST['enable'])) {
+                        $new_enable=0;
+                    } else {
+                        $new_enable=1;
+                    }
 
                     $dbw = wfGetDB(DB_MASTER);
 
@@ -49,30 +60,27 @@
                     }
 
                     ob_start();
-                    echo '<strong>' . $id . '</strong>';
+                    echo '<strong>' . $link_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 = $dbw -> selectField($tbl_links, 'MAX( links_order 
)', array('links_id' => $link_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);
+                    $data = array('user_id' => $wgUser->getId(),'links_order' 
=> $order, 'links_subject' => $new_subject, 'links_url' => $new_url, 
'links_enable' => $new_enable, 'links_datetime' => date("Y-m-d H:i:s"), 
'links_id' => $link_id);
                     $result = $dbw -> insert($tbl_links, $data);
-
-                    $output .= '<h4>Inserted into sidebar</h4>' . '<ul><li>' . 
$_POST['new_subject'] . ' (' . $new_url . ')</li></ul>';
+                    $output .= 
'<h4>'.wfMessage('insert_related_links').'</h4>' . '<ul><li>' . 
$_POST['subject'] . ' (' . $new_url . ')</li></ul>';
 
                     // return link
-                    $output .= '<br /><a href="' . $return_url . '">Return 
Page</a>';
+                    $output .= '<br /><a href="' . $return_url . 
'">'.wfMessage('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>';
+                    echo '<strong>' . $link_id . '</strong>';
 
                     $output = ob_get_contents();
                     ob_clean();
@@ -80,36 +88,40 @@
                     // delete sidebar
                     if ($_POST['check']) {
                         $result = $dbw -> delete($tbl_links, array('id' => 
$_POST['check']));
-
-                        $output .= '<h4>Deleted sidebar</h4>';
+                        $output .= 
'<h4>'.wfMessage('delete_related_links').'</h4>';
                     }
 
                     // return link
-                    $output .= '<br /><a href="' . $return_url . '">Return  
Page</a>';
+                    $output .= '<br /><a href="' . $return_url . 
'">'.wfMessage('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>';
+                    echo '<strong>' . $link_id . '</strong>';
                     $output = ob_get_contents();
                     ob_clean();
 
                     // update sidebars
-                    $output .= '<h4>Updated Sidebar</h4>' . '<ul>';
+                    $output .= 
'<h4>'.wfMessage('update_related_links').'</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>';
+                    foreach ($_POST['order'] as $index => $order) {
+                        $links_enable=0;
+
+                        if (isset($_POST['enable'][$index])) {
+                            $links_enable=1;
+                        }
+
+                        $data = array('links_order' => $order, 'links_subject' 
=> $_POST['subject'][$index], 'links_url' => $_POST['url'][$index], 
'links_enable' => $links_enable);
+                        $dbw -> update($tbl_links, $data, array('id' => 
$index));
+                        $output .= '<li>' . $_POST['subject'][$index] . ' (' . 
$_POST['url'][$index] . ')' . ($links_enable ? ' : '.wfMessage('enable') : ' : 
'.wfMessage('disable')) . '</li>';
                     }
+
                     $output .= '</ul>';
 
                     // return link
-                    $output .= '<br /><a href="' . $return_url . '">Return 
relatedlinks Page</a>';
+                    $output .= '<br /><a href="' . $return_url . 
'">'.wfMessage('return_page').'</a>';
             }
         } else {
             $dbr = wfGetDB(DB_SLAVE);
@@ -125,7 +137,7 @@
             }
 
             $fields = array('id', 'links_order', 'links_subject', 'links_url', 
'links_enable');
-            $conds = array('user_id' => '', 'links_id' => $links_id);
+            $conds = array('links_id' => $link_id);
             $opts = array('ORDER BY' => 'links_order');
             $result = $dbr -> select($tbl_links, $fields, $conds, 
'Database::select', $opts);
             $rows = $dbr -> numRows($result);
@@ -133,54 +145,94 @@
             ob_start(); ?>
                                        <form id="related_links_form" 
method="post" action="">
                                                <fieldset>
-                                                       <legend><a 
href="/index.php/<?=$links_id ?>"><?=$links_id ?></a></legend>
+                                                       <legend><?php echo 
wfMessage('edit') ?>,<?php echo wfMessage('delete') ?></legend>
                                                        <?php if (!$rows): ?>
                                                        <h4><?php echo 
wfMessage('no_data') ?></h4>
-                                                       <?php endif ?>
+              <?php else: ?>
                                                        <input type="hidden" 
id="submit_type" name="submit_type" value="">
-                                                       <input type="hidden" 
id="submit_id" name="id" value="<?=$links_id ?>">
+                                                       <input type="hidden" 
id="submit_id" name="link_id" value="<?=$link_id ?>">
                                                        <table class="lieTable" 
style="width: 100%;">
-                                                       <colgroup 
style="width:10%;">
-                                                       <colgroup 
style="width:10%">
-                                                       <colgroup 
style="width:15%">
-                                                       <colgroup>
-                                                       <colgroup 
style="width:10%">
+                <colgroup>
+                  <col style="width:10%" />
+                  <col style="width:15%" />
+                  <col />
+                  <col style="width:10%" />
+                  <col style="width:10%" />
+                </colgroup>
                                                        <thead>
                                                        <tr>
-                                                               <th><input 
type="checkbox" id="checkall" /></th>
-                                                               <th><?php echo 
wfMessage('no') ?></th>
+                                                               <th><?php echo 
wfMessage('order_no') ?></th>
                                                                <th><?php echo 
wfMessage('subject') ?></th>
                                                                <th><?php echo 
wfMessage('rel_url') ?></th>
                                                                <th><?php echo 
wfMessage('enable') ?></th>
+                                                               
<th><label><?php echo wfMessage('delete_select') ?><input id="checkall" 
type="checkbox" /></label></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>
+                                                               <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="1"<?=($row -> 
links_enable == '1' ? ' checked' : '') ?> /></td>
+                                                               <td><input 
type="checkbox" class="checkitem" name="check[<?=$row -> id ?>]" value="<?=$row 
-> id ?>" /></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>
+              <tfoot>
+                <tr>
+                  <td><input type="submit" value="<?php echo 
wfMessage('modify_all') ?>" /></td>
+                  <td colspan="3">&nbsp;</td>
+                  <td><input type="button" id="btn_delete-sidebar" 
value="<?php echo wfMessage('delete') ?>" /></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') ?>">
+                                           <?php endif ?>
                                                </fieldset>
                                        </form>
+                                       <form id="related_links_insert_form" 
method="post" action="">
+            <fieldset>
+                                                       <legend><?php echo 
wfMessage('insert') ?></legend>
+                                               <input type="hidden" 
name="link_id" value="<?=$_GET['link_id'] ?>" />
+                                               <input type="hidden" 
name="submit_type" value="insert" />
+                                               <table class="lieTable" 
style="width: 100%;">
+              <colgroup>
+                <col style="width:10%" />
+                <col style="width:15%" />
+                <col />
+                <col style="width:10%" />
+                <col style="width:10%" />
+              </colgroup>
+              <thead>
+                                                       <tr>
+                                                               <th><?php echo 
wfMessage('order_no') ?></th>
+                                                               <th><?php echo 
wfMessage('subject') ?></th>
+                                                               <th><?php echo 
wfMessage('rel_url') ?></th>
+                                                               <th><?php echo 
wfMessage('enable') ?></th>
+                                                               <th>&nbsp;</th>
+                                                       <tr>
+                                                       </thead>
+              <tbody>
+            <tr>
+                                                       <td><input 
type="number" name="order" value="1" min="1" class="s_order" /></td>
+              <td><input type="text" name="subject" style="width: 92%" 
required="required" /></td>
+              <td><input type="url" name="url" style="width: 92%" 
required="required" /></td>
+                                                       <td><input 
type="checkbox" name="enable" value="1" checked="checked" /></td>
+              <td>&nbsp;</td>
+            </tr>
+          </tbody>
+          <tfoot>
+            <td><input type="submit" value="<?php echo wfMessage('insert') ?>" 
/></td>
+            <td colspan="5">&nbsp;</td>
+          </tfoot>
+          </table>
+                                               </fieldset>
+          </form>
+
                                <?php
                 $output = ob_get_contents();
             ob_clean();
diff --git a/i18n/en.json b/i18n/en.json
index 9ec334d..6890a81 100755
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -2,8 +2,9 @@
        "@metadata": {
                "authors": "Sleeping-Lion"
        },
-       "relatedlinks": "Related Links",        
+       "relatedlinks": "Related Links",
        "no": "No",
+       "order_no" : "Order",
        "subject": "Subject",
        "rel_url": "URL",
        "enable": "Enable",
@@ -14,5 +15,12 @@
        "no_link" : "No Link...",
        "insert" : "Insert",
        "delete" : "Delete",
-       "modify_all" : "Modify All"     
-}
\ No newline at end of file
+       "delete_select" : "Delete Select",
+       "modify_all" : "Modify",
+       "return_page" : "Return  Page",
+       "enable" : "enable",
+       "disable" : "disable",
+       "update_related_links" : "Updated Related Links",
+       "delete_related_links" : "Deleted Related Links",
+       "insert_related_links" : "Inserted Related Links"
+}
diff --git a/i18n/ko.json b/i18n/ko.json
index 183753f..ac2f781 100755
--- a/i18n/ko.json
+++ b/i18n/ko.json
@@ -1,18 +1,26 @@
 {
        "@metadata": {
-               "authors": "Sleeping-Lion"
+               "authors": "잠자는-사자"
        },
-       "relatedlinks": "연관사이트",        
+       "relatedlinks": "연관사이트",
        "no": "번호",
+       "order_no" : "우선순위값",
        "subject": "제목",
        "rel_url": "연관 URL",
        "enable": "사용여부",
        "edit" : "수정",
-       "please_login" : "먼저 로그인 해주세요", 
+       "please_login" : "먼저 로그인 해주세요",
        "add_site" : "Add new site..",
        "no_data" : "데이터 없음..!!",
        "no_link" : "No Link...",
        "insert" : "입력",
        "delete" : "삭제",
-       "modify_all" : "수정 적용"  
-}
\ No newline at end of file
+       "delete_select" : "삭제선택",
+       "modify_all" : "수정",
+       "return_page" : "돌아가기",
+       "enable" : "사용",
+       "disable" : "사용 안함",
+       "update_related_links" : "연관사이트 수정됨",
+       "delete_related_links" : "연관사이트 삭제됨",
+       "insert_related_links" : "연관사이트 입력됨"
+}
diff --git a/modules/ext.related_links.js b/modules/ext.related_links.js
index e7158a8..de8a9da 100755
--- a/modules/ext.related_links.js
+++ b/modules/ext.related_links.js
@@ -1,12 +1,12 @@
 $(document).ready(function(){
-       $('#checkall').click(function () {
+       $('#checkall').change(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');
@@ -15,20 +15,25 @@
                        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..' );
+
+       $("#related_links_insert_form").submit(function(){
+               if($.trim($('#related_links_insert_form 
input[type="text"]').val())=='') {
+                       alert('insert subject');
+                       $('#related_links_insert_form 
input[type="text"]').focus();
+                       return false;
+               }
+
+               if($.trim($('#related_links_insert_form 
input[type="url"]').val())=='') {
+                       alert('insert url');
+                       $('#related_links_insert_form 
input[type="url"]').focus();
+                       return false;
                }
        });
 });
-       
+
 function isSelected () {
        var is_checked = false;
-       
+
        $('input.checkitem').each(function() {
                if($(this).is(':checked'))
                        is_checked=true;

-- 
To view, visit https://gerrit.wikimedia.org/r/353019
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icbc3b89477983ca090680087b2b576ab4a2533d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RelatedLinks
Gerrit-Branch: master
Gerrit-Owner: Sleepinglion <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to