vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Bitfield confusion (https://vborg.vbsupport.ru/showthread.php?t=244060)

James Birkett 06-06-2010 12:00 PM

Bitfield confusion
 
Hi there,

I'm trying to understand vBulletin's use of bitfields and this has confused me. If anyone can clear it up, I'd appreciate it:

Code:

<group name="forumpermissions">
  <bitfield name="canview" group="forum_viewing_permissions" phrase="can_view_forum" install="1,2,3,4,5,6,7">1</bitfield>
  <bitfield name="canviewthreads" group="forum_viewing_permissions" phrase="can_view_threads" install="1,2,3,4,5,6,7">524288</bitfield>
  <bitfield name="canviewothers" group="forum_viewing_permissions" phrase="can_view_others_threads" install="1,2,3,4,5,6,7">2</bitfield>
  <bitfield name="cansearch" group="forum_searching_permissions" phrase="can_search_forums" install="1,2,3,4,5,6,7">4</bitfield>
  <bitfield name="canemail" group="forum_viewing_permissions" phrase="can_use_email_to_friend" install="1,2,3,4,5,6,7">8</bitfield>
  <bitfield name="canpostnew" group="post_thread_permissions" phrase="can_post_threads" install="2,5,6,7">16</bitfield>
  <bitfield name="canreplyown" group="post_thread_permissions" phrase="can_reply_to_own_threads" install="2,5,6,7">32</bitfield>
  <bitfield name="canreplyothers" group="post_thread_permissions" phrase="can_reply_to_others_threads" install="2,5,6,7">64</bitfield>
  <bitfield name="caneditpost" group="post_thread_permissions" phrase="can_edit_own_posts" install="2,5,6,7">128</bitfield>
  <bitfield name="candeletepost" group="post_thread_permissions" phrase="can_delete_own_posts" install="2,5,6,7">256</bitfield>
  <bitfield name="candeletethread" group="post_thread_permissions" phrase="can_delete_own_threads" install="5,6">512</bitfield>
  <bitfield name="canopenclose" group="post_thread_permissions" phrase="can_open_close_own_threads" install="5,6">1024</bitfield>
  <bitfield name="canmove" group="post_thread_permissions" phrase="can_move_own_threads" install="5,6">2048</bitfield>
  <bitfield name="cangetattachment" group="forum_viewing_permissions" phrase="can_download_attachments" install="2,5,6,7">4096</bitfield>
  <bitfield name="canpostattachment" group="attachment_permissions" phrase="can_upload_attachments" install="2,5,6,7">8192</bitfield>
  <bitfield name="attachlimit" intperm="true" group="attachment_permissions" phrase="space_in_bytes_attachlimit">1</bitfield>
  <bitfield name="canpostpoll" group="poll_permissions" phrase="can_post_polls" install="2,5,6,7">16384</bitfield>
  <bitfield name="canvote" group="poll_permissions" phrase="can_vote_on_polls" install="2,5,6,7">32768</bitfield>
  <bitfield name="canthreadrate" group="post_thread_permissions" phrase="can_rate_threads" install="2,5,6,7">65536</bitfield>
  <bitfield name="followforummoderation" group="post_thread_permissions" phrase="follow_forum_moderation_rules" install="1,2,3,4,5,6,7">131072</bitfield>
  <bitfield name="canseedelnotice" group="forum_viewing_permissions" phrase="can_see_deletion_notices" install="5,6">262144</bitfield>
  <bitfield name="cantagown" group="post_thread_permissions" phrase="can_tag_own_threads" install="2,5,6,7">1048576</bitfield>
  <bitfield name="cantagothers" group="post_thread_permissions" phrase="can_tag_others_threads" install="2,5,6,7">2097152</bitfield>
  <bitfield name="candeletetagown" group="post_thread_permissions" phrase="can_delete_tags_own_threads" install="5,6">4194304</bitfield>
  <bitfield name="canseethumbnails" group="forum_viewing_permissions" phrase="can_see_thumbnails" install="2,5,6,7">8388608</bitfield>
  </group>

Why does it go:
1, 524288, 2, 4, 8

I thought the generic method to go was: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc?

borbole 06-06-2010 12:03 PM

Have a look at this article:

https://vborg.vbsupport.ru/showthrea...ht=permissions

James Birkett 06-06-2010 12:05 PM

Hi borbole,

I've read that article, I just want to know why the format of the forumpermissions goes 1, 524288, 2, 4, 8 when the generic method is to go 1, 2, 4, 8, 16

Guest190829 06-06-2010 12:52 PM

You are correct, however, in terms of the XML file and the mechanics behind how vB parses the xml permissions data into a datastore array, the order doesn't matter. As long as the bitfield value is valid (and 524288 is), you won't run into problems.

From the looks of this, the reason that particular permission is placed out of order is for readability purposes; both 2 and 524288 deal with thread viewing permissions.

James Birkett 06-06-2010 01:21 PM

Ahh, thanks for that Danny!

I didn't even think of that... I knew it went off of the numbers rather than the actual order, but I didn't expect it to be for readability purposes.

Marco van Herwaarden 06-07-2010 08:27 AM

It was added at a later stage, when 524288 was the first available number. For readability it was placed at that location in the XML file.

Keep in mind that all these values are already stored/used in the database (in case of an upgrade) so you can not simply renumber the options without also performing an upgrade of the values already in the database when upgrading a vB version.

James Birkett 06-07-2010 02:31 PM

Thanks Marco,

I wasn't planning on changing anything anyway; I'm just trying to learn about bitfields!


All times are GMT. The time now is 05:01 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01060 seconds
  • Memory Usage 1,731KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete