Please wait, Page is Loading...
 

Summary: How could I check / validate my page
Version:0.1b
Status: Devel
Maintainer: Dfolio
License: LGPL
Download: CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php  (md5sum: 9c128e0fcdf632b64b3cc15529e6b51e)
Categories: PmWiki | PHP | Validation | LGPL

Description

How could I check / validate my page.

The XhtmlValidator can be used to validate XHTML documents. It uses XML Parser Functions available in PHP, that is the expat extension functions, which is always available since PHP3 and it does not need other external XML processing extensions. That’s why only XHTML documents could be validate:

XHTML= XML+HTML
The Extensible Hyper-Text Markup Language, or XHTML, is a markup language that has the same depth of expression as HTML, but also conforms to XML syntax.
(further details on wikipedia)

This recipe is based on the XhtmlValidator class provide by Bermi Ferrer, which is licensed under LGPL. The class parses the documents and check whether the tags and attributes used by the documents are allowed within the XHTML standard. I have extented the the class to reconnize (a little bit) more tags/attributes, and to be PmWiki friendly. Then, I provide an interface to PmWiki to validate your pages, and a way to request some validation status.

Lets notice that the validation results is not guaranteed to be fully valid. In doubt I strongly recommanded to referrer to the W3C recommendation


Install

First, download: CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php. Then put CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php in the PmWiki {$FarmD}/cookbook/ directory, and add the the following line to your {$FarmD}/local/config.php:

include_once("$FarmD/cookbook/xhtmlValidator.php");

Configuration:

CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php provide the following customizable variable

  • SDV($ValidXhtmlBeforePost,true);: if enabled perform validation before posting a page
  • SDV($ValidXhtmlAllowExternal,true);: if enabled external link could be valided…
  • SDV($ValidXhtmlExpiresTime,2592000);: allow to setup the validation expiration time.

Let’s notice that not all customizable variable are presented (mainly ‘Fmt’ variables). See CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php for some others variables you may want to customize to be more suitable on your web site.

To setup the variables above, simply set your own values in your {$FarmD}/local/config.php.


Howto use xhtmlValidator:

CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php provide different way to check or validate your XHTML pages.

The validation action (action=ValidXhtml)

CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php provide a new action allowing you to check/validate a page: ?action=ValidXhtml.

You can customize the validation action name by modifying the value of $ValidXhtmlName in your {$FarmD}/local/config.php (by default: SDV($ValidXhtmlName,’ValidXhtml’);)

The validation forms markup: (:xhtmlValidator:)

CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php provide a forms allowing you to submit the page to check:

(:xhtmlValidator:)
Validate a document online

At this time the markup take no arguments…

To use the forms, simple fill a page target, usually in the following syntax ‘${Group}/${Page}’, and just hit check… A special keywords self simply address the current page.
External URI document (http://www.others.host.org/...) could be checked. But this could be disabled by setting $ValidXhtmlAllowExternal=0; in your config (see note on the customizable variable $ValidXhtmlAllowExternal).

Validation condition: isXhtmlValidate FullName, isXhtmlValid FullName, isXhtmlValidNoWarnings FullName

CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php provide some test to check the validation status of your pages.

  • (:if isXhtmlValidate ApageName :) ... (:if:) : true, if page is validate
  • (:if isXhtmlValid ApageName:) ... (:if:): true if page is validate, and does not have errors and was not expired
  • (:if isXhtmlExpired ApageName:) ... (:if:): true, if page was expired

Some validation condition examples:

(:if isXhtmlValidate self:)Current page
has been validate
(:else:)Current page has NOT been
validate (:if:)
----
(:if isXhtmlValid self:)Current page is
 XHML valid 
(:else:) Current page is not XHML
valid(:if:)
----
(:if isXhtmlValid Main/HomePage
:)Main/HomePage is  XHML valid 
(:else:)Main/HomePage  is not  XHML
valid(:if:) 
----
(:if isXhtmlExpired Main/HomePage :)The
validation result of Main/HomePage was
expired
(:else:)The validation result of
Main/HomePage  is not  expired (:if:) 

Current page has been validate


Current page is not XHML valid


HomePage is not XHML valid


The validation result of HomePage is not expired

The pagelists validation markup: (:pagelist ...:) or (:validpages ...:)

Cool I have checked/validated some pages, but How could I check some part or all pages of my web site?

CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php provide a page list template for the (:pagelist ... fmt=template :) directives allowing to look for your pages status.

You may also use the validation conditions in a (:pagelist fmt=ValidXhtml ... if=“condition” :) directives. For example the following markup allow you lists pages which are not valid:

 (:pagelist fmt=ValidXhtml  if="! isXhtmlValid {=$FullName}" :)

I strongly recommanded to use validation conditions only with ValidXhtml template.

If it is the first time you use CookBook/xhtmlValidator.php[CookBook/xhtmlValidator.php] Type: application/x-php Taille:76,92 Ko Dernière modification:30/11/2007 15:09Mime:php, and you have many pages (I think about >100) the pagelists could take very long time to check all pages. That why, I provide a hack using javascript XMLHttpRequest to load the page and wait data to be displayed (see WaitPage)


In particular in the case of using the isXhtmlValid conditions where a

See Also

Contributors

« Google Ad Sense | CookBook | Wait Page »



Commentaire

Remark, suggestion post a comment:

Signer en tant qu'auteur 
Website 

Veuillez indiquer un nom d'auteur, et entrer la valeur du code (limite le spam...). Merci.


  • Add This
  • Add
  • Get
  • Google

default