- Description
- This form is a user's interface to the Manage your Favorites facility. A user may add a page to their list of favorites or remove a page from that list using this form.
- It must be used with the Semantic Forms extension. It has a companion template: Template:Favorites and relies on JavaScript (see below). The data being added to or removed from a subject page is the name of the current user. Therefore, this is actually managing a fanList (a.k.a. subscriber list) for the subject page however, the effect that each user sees at their user-page is the adding/removing of the subject page to/from a list of "Favorites".
- This is a partial form.
- The current user may only add or remove their own username. This is by design.
- Any user can easily view the usernames on the Favoredby list however to vandalize the list requires annotating the semantic property to a corrupt value. Recovering from such vandalism is as difficult as performing the vandalism. Note that the form field Favoredby is obfuscated/hidden from view and is tamper-proof thanks to the CSS properties that class="obfuscate" invokes. The template performs no action with that named parameter.
- Hiding the semantic FactBox is enforced by the companion Template:Favorites.
- Manage your Favorites relies on the JavaScript functions Favorites and synchronizeFavoredby being activated upon page load.
- It does not make use of Template:USERNAME. Indeed the display of a user's username can only be defeated by disabling JavaScript at this wiki - at which point the user cannot take advantage of the Manage your Favorites facility.
- A logged-off user will see no username displayed and will see Wikia's standard banner prompt inviting them to log in or create a username. If they proceed to click the Confirm button without first logging in then no change is effected.
- A user's user-page does not need to belong to Category:Members to be added to the fanList but this may be necessary for certain semantic queries.
- Initially the fanList contains data of Type:String. Whether it gets changed to Type:Page will depend on community feedback.
- Usage
- Add the link
[[Special:EditData/Favorites/{{PAGENAME}}|Manage your favorites]]
to a page requiring this feature.- Typically this is done via the template used by the default form for a page. Currently there is no other way for a user to know that this form is available for editing a page.
- Look into the Has alternate form feature to see if this can be changed. That might allow any page to make use of this handy facility.
- Code listing
- Copy to MediaWiki:Common.js
/**/*/ function synchronizeFavoredby() { /* For a description of when and why you might want to use a function like this read: http: //www.mediawiki.org/wiki/Extension_talk:Semantic_Forms#Possible_applications */ var str = $("#Favoredby").text(); /* accesses the contemporary semantic data */ $("#bodyContent form.createbox fieldset") .find("input.createboxInput[type='text'][name$='[Favoredby]']") .val(str.replace(/^\s+|\s+$/g, '')); /* populates the form's (input type = text) field - trimming whitespace */ } $( synchronizeFavoredby ); function Favorites() { /* Required for the "Manage your Favorites" feature. See also companions Template:Favorites and Form:Favorites */ $("#bodyContent form.createbox fieldset ") .find("input.createboxInput[type='text'][name$='[Thisuser]']") .val(wgUserName) /* Auto-populate the text input field with current user name */ .attr("readonly","readonly") /* Write-protect text input field */ .attr("size","0"); /* Shrink box to fit data */ /* Now set the Remove||Add radiobuttons based on the presence||absence of the wgUserName within the fanList */ var fans = $("#Favoredby").text(); /* Accesses the up-to-date semantic data */ var reg = new RegExp("[ ,]+", "g"); /* Both comma and space are delimiters */ var fanArr = fans.split(reg); if ( $.inArray(wgUserName,fanArr) < 0 ) { $("#bodyContent input:radio[checked][value!='Add'][name$='[Operation]']") .removeAttr("checked"); /* Uncheck any checked radio element that does not match the target value */ $("#bodyContent input:radio:not([checked])[value='Add'][name$='[Operation]']") .attr("checked","checked"); /* Check any unchecked radio element that does match the target value */ } else { $("#bodyContent input:radio[checked][value!='Remove'][name$='[Operation]']") .removeAttr("checked"); /* Uncheck any checked radio element that does not match the target value */ $("#bodyContent input:radio:not([checked])[value='Remove'][name$='[Operation]']") .attr("checked","checked"); /* Check any unchecked radio element that does match the target value */ } /* Finally check the Minor edit checkbox - we don't want [[Special:Recent changes]] to be cluttered with edits due to favorites. */ $("#wpMinoredit").attr("checked","checked"); } $( Favorites ); /*
- See also
- Template:Favorites
- Category:Members#Manage_your_Favorites
- MediaWiki:Common.css "Semantic forms extension related"
- Possible applications