Ajuda:Secció
La sintaxi de la capçalera de secció permet dividir una pàgina en seccions.
Creació de seccions i numeració
Per crear una secció, definiu-ne els encapçalaments de la manera següent:
==Secció== ===Subsecció=== ====Sub-subsecció====
Directrius per utilitzar encapçalaments de secció
- Els encapçalaments amb només un signe igual a cada costat (
=text aquí=) creen un títol de la mida del nom de la pàgina. - La capçalera de la secció no es pot combinar amb altres continguts a la mateixa línia. Per exemple,
==Section Header==<br>no es mostrarà com un encapçalament, sinó com un paràgraf. - Els noms de les seccions haurien de ser únics dins d'una pàgina, inclosos els noms de les subseccions. Els desavantatges dels noms de secció duplicats inclouen:
- Confusió d'edició - Diverses seccions amb el mateix títol poden causar confusió d'edició, cosa que pot provocar errors i dificultar que els col·laboradors editin el contingut amb precisió.
- Resums d'edició ambigus - MediaWiki genera resums d'edició per a les edicions de pàgines, però si diverses seccions tenen el mateix títol, poden esdevenir ambigus. Per exemple, el resum d'edició de dues seccions de "Dieta" podria ser "He editat la secció Dieta", cosa que confon els col·laboradors i dificulta la revisió dels canvis recents de manera efectiva.
- Podeu crear seccions separades en pàgines diferents amb els seus propis historials d'edició mitjançant una plantilla/pàgina. Cada plantilla/pàgina es pot inserir en una pàgina principal, afegint contingut sense canviar l'aspecte general. Aquesta configuració facilita el seguiment dels canvis i la gestió de parts específiques d'una pàgina. (Vegeu Ajuda:Plantilla#Possibles usos de les plantilles.)
- Una plantilla amb seccions en una pàgina nova manté el seu ordre original, unint el seu contingut a l'abans i el després de la plantilla que s'ha inserit. Això garanteix la numeració correcta de les seccions dins de la plantilla, sense afectar la numeració de les seccions a la pàgina principal. Aquesta funció no és compatible amb les aparences que mostren una taula de continguts fora del contingut de l'article, com ara l'aparença Vector 2022.
- Un encapçalament de secció a wikitext a MediaWiki s'especifica mitjançant l'expressió regular,
/(^={1,6}.*?={1,6}\s*?$)/m(mfa referència a un mode multilínia).
Índex (table of contents o TOC)
Es genera automàticament un índex (TOC) per a les pàgines que contenen més de tres encapçalaments de secció.
Tanmateix, els editors poden optar per excloure el TOC afegint la paraula màgica __NOTOC__ (entre dobles subratllats) al quadre d'edició de l'article.
Pautes per a l'ús de l'índex
- S'afegeix un TOC al wikitext, que substitueix __NOTOC__ quan s'afegeix __FORCETOC__ o __TOC__ (amb dos subratllats a cada costat del terme), fins i tot si la pàgina té menys de quatre encapçalaments.
- Si feu servir __FORCETOC__, l'índex (TOC) apareix abans del primer encapçalament de secció, mentre que __TOC__ la col·loca on voleu que comenci l'índex, cosa que permet un posicionament flexible, com ara a la dreta o dins d'una cel·la d'una taula.
- __TOC__ ajuda a controlar on apareix l'índex (TOC) en un article. Poseu __TOC__ on voleu que aparegui l'índex, com ara després d'una introducció o al final de la pàgina. Això garanteix que l'índex estigui al lloc correcte sense necessitat d'encapçalaments addicionals.
- Si feu servir __NOTOC__, s'evita que l'índex automàtic aparegui en una pàgina. Si voleu fer el vostre índex senzill, podeu crear manualment enllaços a diferents seccions de la pàgina utilitzant encapçalaments com ara == A == i després enllaçar-hi la secció mitjançant enllaços com aquest [[#A|A]]".
Resum:
| Paraula | Explicació |
|---|---|
| __NOTOC__ | L'índex (TOC) de la pàgina actual està ocult. |
| __FORCETOC__ | Fa que aparegui l'índex. |
| __TOC__ | Afegeix un índex en algun lloc de la pàgina, per tant, anul·lant qualsevol __NOTOC__. Si hi ha diverses paraules màgiques __TOC__, només la primera té efecte. |
Moure l'índex
El codi següent permet que l'índex es posicioni com una taula flotant a la part dreta de la pantalla.
{|align="right" | __TOC__ |}
Limitació de la profunditat de l'índex globalment
Podeu controlar la profunditat de l'índex (TOC) ajustant la configuració $wgMaxTocLevel al fitxer LocalSettings.php.
Per exemple, definir-la a 3 limita l'índex a mostrar només fins a tres nivells de profunditat.
Enllaç a una secció
Els encapçalaments de secció generaran automàticament HTML amb l'atribut id, al qual es pot enllaçar directament, sigui dins de la mateixa pàgina o des d'altres pàgines.
Per exemple, el codi HTML que es va crear al principi d'aquesta secció a la versió anglesa d'aquesta pàgina és:
<h2><span class="mw-headline" id="Linking_to_a_section">Linking to a section</span></h2>
Un enllaç a aquesta (secció) apareix com a:
[[Help:Section/ca#Linking to a section|Enllaç de secció]]
Podeu enllaçar a una secció dins d'una pàgina utilitzant [[#enllaç de secció|text mostrat]], i també enllaçar a una secció dins d'una pàgina diferent utilitzant [[nom de la pàgina#nom de la secció|text mostrat]].
Un enllaç a una subsecció, sub-subsecció, etc. serà [[#nom de la subsecció]] i [[#nom de la sub-subsecció]], etc., ja que les àncores no tenen en compte la profunditat de la secció.
Els noms de secció duplicats es diferencien afegint-hi un subratllat i un número. Per exemple, si hi ha tres seccions anomenades "Exemple", s'etiquetaran com a "Exemple", "Exemple_2" i "Exemple_3". Tanmateix, en editar les seccions "Exemple_2" o "Exemple_3", el resum de l'edició dirigeix confusament a "Exemple". Un encapçalament en blanc en una secció distorsiona l'índex (TOC).
Enllaçar seccions mitjançant un identificador arbitrari
Les àncores d'enllaç de secció poden canviar sense previ avís, especialment quan un article conté diverses seccions amb el mateix nom.
S'afegeixen identificadors addicionals com ara " 2", " 3", etc., per distingir aquestes seccions.
Si s'afegeix, s'elimina o es canvia de nom una secció, es pot alterar la destinació de l'enllaç, cosa que pot conduir a seccions incorrectes o inexistents.
Això es pot evitar mitjançant l'etiqueta HTML <span> i l'atribut id:
<spanid="nom_d'àncora"></span>
Assegureu-vos que el nom escollit sigui únic incorporant títols abreujats de seccions de nivell superior, com ara Ontario-Característiques_naturals per a la subsecció "Característiques naturals" dins de la secció "Ontario" d'un article de les províncies canadenques.
És possible que aquest mètode no funcioni en navegadors més antics, especialment els anteriors a MediaWiki 1.4.10, i és possible que no funcioni ni tan sols amb navegadors moderns si l'id conté espais.
Per exemple:
<span id="Ontario-Característiques naturals">(text opcional)</span> [no funcionarà] <span id="Terranova-Característiques_naturals">(text opcional)</span> [funcionarà] ... Vegeu [[#Ontario-Característiques naturals|característiques naturals d'Ontario]] i [[#Terranova-Característiques naturals|característiques naturals de Terranova]]
Substituïu els espais en l'id per subratllats per garantir que els enllaços funcionin perfectament tant amb subratllats com amb espais.
- Els enllaços interns als encapçalaments de secció no compliquen l'enllaç de seccions:
- Els enllaços de secció no són compatibles amb el truc de la barra vertical:
[[#section|]]-> [[#section|]][[page#section|]]-> [[page#section|]][[namespace:page#section|]]-> [[namespace:page#section|]]
Vegeu les àncores manuals per enllaçar a qualsevol secció d'una pàgina.
Enllaçar seccions i redireccions
Enllaçar a una secció específica d'una pàgina a través d'una redirecció normalment funciona de manera similar a enllaçar directament a aquesta secció.
Canviar el nom d'una pàgina genera una redirecció, però canviar el nom d'una secció no. A més, no hi ha cap funció d'enllaços entrants diferent per a les seccions; les pàgines que enllacen a una secció es mostren entre les pàgines que enllacen a tota la pàgina.
- En lloc d'enllaçar directament a una secció, utilitzeu una pàgina que redirigeixi a la secció. Aquest enfocament facilita el seguiment dels canvis als noms de les seccions i proporciona una funcionalitat de "què hi enllaça" per a les seccions. Per identificar enllaços a la secció, comproveu si hi ha redireccions que enllacen a la pàgina i seleccioneu la que correspongui.
- Inseriu una àncora dins de la secció i enllaceu-li en conseqüència.
- Afegiu un comentari al principi d'una secció al wikitext, enumerant les pàgines que enllacen a aquesta secció.
- Creeu una pàgina o plantilla separades per a la secció i transcloeu-la a la pàgina principal o enllaceu-hi. A continuació, en lloc d'enllaçar directament a la secció, enllaceu a la pàgina o plantilla separades.
Les pàgines de redirecció es poden classificar en categories afegint una etiqueta de categoria després de l'ordre de redirecció. Si la redirecció condueix a una secció, també categoritza d'alguna manera aquesta secció. Tanmateix, la secció no enllaçarà de tornada a la categoria tret que es faci específicament. A les pàgines de categories, les redireccions es mostren en cursiva. Per a més detalls, consulteu Categorització de redireccions.
Editing sections
To edit specific sections of a page, you can click on the [modifica] link next to the section heading.
Clicking on these links takes you to an edit page with a URL structured like this:
https://www.mediawiki.org/w/index.php?title=Help:Advanced_editing&action=edit§ion=9
Instead of using section titles, section editing uses section numbers.
Subsections are represented with a single number (e.g., In the link above, section 2 in the table of content is numbered as 9 in the link.
This allows for focused editing without the need to have the entire text of the page visible.
It is particularly useful for large pages, as it simplifies the editing process and reduces clutter.
Adding __NOEDITSECTION__ section editing via a URL you already have still works.
When inserting a section, edit the previous or following section, merge by deleting the heading if necessary, and adjust the edit summary accordingly.
Including a section at the end
To add a new section at the end of a page, you can use a URL like the following:
https://www.mediawiki.org/w/index.php?title=Project:Sandbox&action=edit§ion=new
On talk pages and pages with wikitext, you can use the code __NEWSECTIONLINK__ to generate a special link beside the edit tab titled ⧼skin-action-newsection⧽.
Clicking this link will open a text box where you can enter a headline for the new section.
The edit summary is automatically generated.
The edit summary produced will be /* Section Name */ /* Section Name */ secció nova, which is automatically rendered as a right arrow.
This leaves no option for providing a custom edit summary.
If the subject box is left blank, no empty == == delimiter is inserted, and the content is appended to the page's last section.
This approach does not support creating a new section without a title and does not allow for providing an edit summary.
The "Preloadtitle" parameter determines the first text displayed in the "Subject/headline" field:
https://www.mediawiki.org/w/index.php?title=Project:Sandbox&action=edit§ion=new&preloadtitle=pqr
The preload can be edited before it is saved.
Editing before a first section
Generally, there is no designated link for editing the introductory text before the first section heading (phab:T2156). However, you can apply the section editing feature to this part by using 0 as the section number in the link, like this:
https://www.mediawiki.org/w/index.php?title=Help:Advanced_editing&action=edit§ion=0
Alternatively, you can modify any section edit link on the page by changing the section number.
To generate the same URL using JavaScript, see w:Wikipedia:WikiProject User scripts/Scripts/Edit Top.
Preview
Section editing preview may differ from the full page if an image from a previous section overlaps with the current section.
The edit page displays all templates used on the entire page, including those from other sections.
Working with subsections
When editing a section, subsections are included and numbered relative to the edited part, starting at 1. Subsections are denoted with numbers like 1.1, 1.2, etc. The heading format follows the absolute level, with sub-subsections numbered accordingly. For example, a sub-subsection 3.2 would be numbered 3.2.1, 3.2.2
Editing a page with large sections
If a page has large sections or lacks division into sections, users can still modify the content by:
- Starting with a blank line before the new section heading, and adding a section with a specified large section number.
- Adding content to the last section without a heading, but unable to revert or edit the new text due to browser or connection limitations.
Editing sections of included templates
You can edit sections within included pages or templates. Clicking the edit link for a section takes you to the edit page of the separate page. This is also known as Transclusió .
The size of the section within the included page or template is determined by the headings in the main page where it is included. When a page is transcluded, all the text on the source page will be transcluded/included in the target page. This includes text placed before the first section heading on the source page. Consequently, if the edit link on the first section header of the transcluded text is clicked on the source page, section editing will open and the text before the first section header and the text of the next section will not be shown in the editor. In order to edit the entire source page's text, the editor must exit the editor when taken to the source page, and then click the edit link at the top of the source page. Similarly, if there are texts after the template tag without a heading, you need to click the headings before the template to edit it. This section shows how it works. To ensure clarity and consistency in rendered source pages that are transcluded to another page, follow these guidelines:
- Template structure – Avoid placing any text before the first section heading within a template.
- Handling sections – After using a template with sections, start a new section on the source page. This prevents conflicts between template sections and source page sections.
Additionally, consider the following practices for managing templates effectively:
- Template heading - Sometimes it's helpful to start a template with a heading, even if it's just one section. This makes editing easier.
- Parameter use - When editing templates, remember parameters, such as
{{{1}}}, are changed in the target page, not directly in the template. Although this may not be immediately apparent in the rendered page, providing explanatory text or an additional edit link can enhance user understanding. __NOEDITSECTION__behavior switch – The__NOEDITSECTION__behavior switch affects the template and any pages it's added to, along with other templates on the same page. Instead, consider replacing MediaWiki section header markup with HTML header markup within the template, causing the headers to remain visually consistent while avoiding recognition as editable sections. This approach eliminates the need for__NOEDITSECTION__within the template.
For example, think of a template structured as follows:
== Template heading 1 == Content === Template heading 2 === Content
To prevent "edit section" links from appearing when transcluding a template, add __NOEDITSECTION__ within the template's code. However, this suppresses all "edit section" links on pages where the template is used.
Alternatively, structuring the template with HTML heading tags (<h2>, <h3>, etc.) achieves the same visual effect without affecting other sections' edit links on transcluding pages.
<h2>Template heading 1</h2> Content <h3>Template heading 2</h3> Content
Sections within a parser function
When conditionally transcluding a template with sections using a parser function , the edit links for these sections may direct to the wrong section or show an error message claiming the section does not exist. This occurs because the content of conditionally included templates is considered part of the page itself, causing the sections to be counted after expansion.
As a result, the edit links for sections within the included template link to the page instead of the template, and the subsequent edit links refer to the correct page but with incorrect section numbers. This issue does not arise when transcluding a template with a conditional name, which offers additional advantages.
Editing footnotes
To edit a footnote in a section using <references />, find the section with the footnote mark and edit it.
Check Help:Footnotes for more help.
Viewing a section
You can use the section editing feature to view a specific section without loading the entire page.
Sections vs. separate pages vs. transclusion
Here are some advantages of each of them:
Advantages of one large page with sections:
- Faster access and simpler searching compared to accessing multiple smaller pages.
- Maintains conceptual cohesion for complex topics.
Advantages of separate pages:
- Easy navigation and editing with separate links and histories using the what links here feature.
- Faster loading times due to smaller page sizes.
- Automatic redirection upon renaming.
- Improved organization and data management through independent categorization and annotation.
- A few templates limit the apply per page.
Advantages of compound documents by Transclusió :
- Transclusió involves including the content of one page within another, often accomplished through templates.
- Users can navigate and search within the combined rendered page, which enhances usability.
Disadvantages:
- Users cannot search within the combined wikitext directly.
- Providing titles for each included page can be cumbersome.
- There is a limitation related to the size of post-expand includes, potentially causing technical issues, particularly with large or numerous included pages.
Sections and Table of Content (ToC)
Adding Non-Section Text to TOC
You can mark text as a TOC entry by using <h4>...</h4> header tags.
Customize formatting as usual inside these tags.
An Example usage (the second one is better formatted for clarity):
{| class="collapsible collapsed" style="text-align:left; border:0px; margin-top:0.2em"
|-
! style="background-color:#f2dfce" | <h4>Stuff</h4>
|-
| Contents about stuff here
|}
{| class="collapsible collapsed" style="text-align:left; border:0px; margin-top:0.2em"
|-
! style="background-color:#f2dfce; padding-top:0; padding-bottom:0" |
<h4 style="margin:0; padding:0;font-size:95%">More stuff</h4>
|-
| Contents about more stuff here
|}
To clarify, you want the collapse boxes headers treated as section titles, included in the table of contents (TOC), without necessitating formal "section titles" on the page itself.
Although not recommended, it is possible to create a TOC entry that is not in the text but acts as an anchor for linking to a section header with slightly different wording:
<h4 style="display:none">Your heading here</h4>
Sections for the above demo
Demo abc
This section is linked to from #Linking to a section.